Skip to main content

Questions tagged [counting]

For challenges regarding counting the number of occurrences of some characteristic.

Filter by
Sorted by
Tagged with
3 votes
1 answer
304 views

CHALLENGE This problem has a math background. For n=1,2,3,4 we want to count the number of families of sets with maximum n elements that satisfy many criteria of the form: $$\bigoplus_{k\in A,A\in \...
Fabius Wiesner's user avatar
17 votes
20 answers
2k views

A 1D go position on a board of size n is a sequence of length n consisting of the numbers0, <...
Lucenaposition's user avatar
33 votes
21 answers
3k views

Go Fish! Given a school of fish, for example: ...
Klumpy7's user avatar
  • 453
7 votes
12 answers
821 views

Challenge: Write a program or function that, given positive integers n, t, b, c, counts permutations of 1..n where: Exactly t numbers are in their original position Exactly b numbers are higher than ...
Peter Thomas's user avatar
-1 votes
1 answer
192 views

Inspired by this problem. Golomb's self-describing sequence g(n) is a sequence where any natural number n is repeated within the sequence g(n) times. Given an input of \$ n \$, output: $$ \left( \sum_{...
shlby696's user avatar
16 votes
17 answers
1k views

Given a sequence of integers with length \$L\$ and an integer \$1 \le N \le L\$, an "\$N\$-rich" permutation is one whose the longest strictly increasing contiguous subsequence has length ...
EmilyR's user avatar
  • 1,533
31 votes
50 answers
3k views

Challenge Given a string of any length which contains only digits from 0 to 9, replace each consecutive run of the digit ...
user avatar
28 votes
49 answers
3k views

Write a program or function which takes a string of text as input and outputs the number of non-alphabetical characters in it (standard I/O rules apply). A non-alphabetical character is any character ...
thejonymyster's user avatar
10 votes
1 answer
419 views

Consider a NxN pixel grid with up to M objects drawn on it, either squares or diamonds: square    diamond The objects may overlap, so recognition is hard. The task is to give the minimal possible ...
Hans-Peter Stricker's user avatar
16 votes
14 answers
1k views

Description You have a list of integers and start counting from the first term to the next and continue from that to the next and so on.. How many times have you counted? For example given [ 2, 5, 3, ...
AZTECCO's user avatar
  • 11k
34 votes
30 answers
2k views

Your challenge is to, given a positive integer n, count up to each digit of it, giving the effect of converging on it. Basically, count up to the first digit of n by its place value (\$⌊\log_{10}\left(...
emanresu A's user avatar
  • 46.2k
22 votes
36 answers
2k views

Definition Given some string return an integer whose digits are the number ocurrences of a-z (case insensitive, in alphabetical order) in that string. Any character with 0 instances is skipped. ...
Nigel's user avatar
  • 357
19 votes
2 answers
650 views

Content You count numbers every day (I think), and most of you know how to count properly, the one next to 1 is 2, and the next ...
okie's user avatar
  • 1,807
15 votes
12 answers
2k views

This is similar in concept to this challenge, but that is pretty restrictive on input and output and I think opening up these restrictions would lead to a completely different set of solutions that ...
EmilyR's user avatar
  • 1,533
33 votes
55 answers
2k views

Task: Given an array of numbers as input (you can choose what subset, such as integers or natural numbers), replace all items with the number of times they appear within the array. As an example, <...
rydwolf's user avatar
  • 19.3k
27 votes
19 answers
2k views

Background: Take this input as an example: 1 1 2 1 1 2 1 3 1 3 If you look only at the first few digits, between 1 1 2 and <...
rydwolf's user avatar
  • 19.3k
13 votes
10 answers
1k views

For today's task, we have two programs, P and Q, both in the same language. Each of them receives a single-character input. If P receives character K, P says how many times K appeared in Q. (You can ...
AndrewTheCodegolfer's user avatar
19 votes
13 answers
1k views

Given two strings a and b, count how many times b occurs as a substring in ...
pxeger's user avatar
  • 25.3k
23 votes
2 answers
2k views

The picture: Sick of the same old grid where the answer is simply a square pyramidal number? Accept the challenge and write a program that given a positive integer \$n\$ counts how many squares are in ...
Domenico's user avatar
  • 2,463
3 votes
2 answers
667 views

How do I remove all duplicates from list and order it based on count? ...
12944qwerty's user avatar
13 votes
6 answers
512 views

We define \$a(n)\$ as the 1-indexed position of \$n\$ in the sequence of positive integers with the same binary weight, i.e. the same number of 1's in their binary representation. This is A263017. ...
Arnauld's user avatar
  • 206k
28 votes
9 answers
1k views

On a toroidal square grid (you can wrap around) where each cell indicates one direction (^ > ...
Domenico's user avatar
  • 2,463
20 votes
1 answer
819 views

The goal of this challenge is to check and extend the OEIS sequence A334248: Number of distinct acyclic orientations of the edges of an n-dimensional cube. Take an n-dimensional cube (if n=1, this is ...
mscroggs's user avatar
  • 309
32 votes
6 answers
2k views

You are given a matrix of forward and back slashes, for instance: //\\ \//\ //\/ A slash cuts along the diagonal of its cell corner-to-corner, splitting it in ...
ngn's user avatar
  • 15.6k
5 votes
19 answers
475 views

Your task is to input a string, and output the number of spaces in the string. This is code-golf, so least number of bytes win. Your Test Cases Double quotes are not part of the test cases. ...
TwilightSparkle's user avatar
34 votes
28 answers
3k views

Given a position with a row of rooks and/or empty spaces, output how many different rook moves are possible. A rook can move left or right to an empty space, but not to one that requires passing over ...
xnor's user avatar
  • 150k
3 votes
1 answer
257 views

This is a more complicated version of this puzzle. The premise is the same but a few rules differ in a few key places, making for a more complex problem. Assume I have some number of black shirts and ...
Ed Marty's user avatar
  • 299
25 votes
43 answers
5k views

Given a string of printable ASCII, output the frequency of each character in that string. The Challenge Input is given as a string of printable ASCII characters (decimal ...
bigyihsuan's user avatar
  • 11.5k
29 votes
23 answers
6k views

As you probably know, there have been multiple lovely Jimmy challenges recently popping up. In these challenges, you were challenged with our beloved friend's acrobatics skills. Now we've got a ...
moltarze's user avatar
  • 2,578
51 votes
34 answers
10k views

Given a non-negative integer skyline height list, answer how many uninterrupted 1-unit-high horizontal brush strokes are needed to cover it. [1,3,2,1,2,1,5,3,3,4,2]...
Adám's user avatar
  • 31.8k
20 votes
32 answers
3k views

Introduction My car speedometer was hacked! Instead of showing me how fast i'm driving, it just shows: "Vroooom!" Please help me know how fast i'm going. Challenge Take a string as input, ...
kepe's user avatar
  • 941
21 votes
5 answers
507 views

Cyclically self-describing lists A list \$L\$ of positive integers is cyclically self-describing, if the following conditions hold. \$L\$ is nonempty. The first and last elements of \$L\$ are ...
Zgarb's user avatar
  • 43.2k
8 votes
14 answers
7k views

Requirement: Write a program (in any language) that counts the number of lines of code in files matching *.sh in the directory tree starting from the directory that ...
Aaron Esau's user avatar
19 votes
20 answers
4k views

Challenge: Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer). An example: Input: <...
Kevin Cruijssen's user avatar
11 votes
5 answers
828 views

A matrix can be thought of as the altitudes of a surface in 3D space. Consider the 8 neighbours (orthogonal and diagonal) of a cell as a cyclic sequence in clockwise (or anticlockwise) order. Some ...
ngn's user avatar
  • 15.6k
-11 votes
20 answers
725 views

It's strange this question hasn't been asked yet, so here it is: Calculate the length of a string given through STDIN Rules As said, your string will be given through STDIN, not via command line ...
univalence's user avatar
  • 1,669
16 votes
10 answers
3k views

Inspired by last week's APL lesson. Given an uppercase 2D seat map and a 1D list of customers, return the seat map and the customer list but modified as follows (to indicate occupied seats and seated ...
Adám's user avatar
  • 31.8k
34 votes
22 answers
4k views

Given an input sentence consisting of one or more words [a-z]+ and zero or more spaces , output an ASCII-art histogram (bar ...
AdmBorkBork's user avatar
  • 43.7k
22 votes
21 answers
2k views

Most people here are familiar with seven segment displays, which are also used in matchstick puzzles. Below are the digits 0 through ...
AdmBorkBork's user avatar
  • 43.7k
3 votes
2 answers
116 views

Given a list of stack heights, calculate the number of ways those heights could have been arrived at by stacking blocks one at a time. Shortest code wins. Test cases: ...
user1502040's user avatar
  • 4,210
27 votes
29 answers
2k views

When you edit a post on SE, any further edits within a 5-minute grace period are merged into it. Given a list of times you edit a post, count the edits not in a grace period. Say you edit at minutes <...
xnor's user avatar
  • 150k
37 votes
24 answers
4k views

Most of us know... that all primes p>3 are of the form But, how many are the Plus Primes (6n+1) and how many are the ...
user avatar
16 votes
11 answers
936 views

This challenge is based on a drinking game. I advise against alcohol consumption while programming. In this game, the players count up in turns: the first player says ...
Arfie's user avatar
  • 1,241
24 votes
28 answers
2k views

Let's count... Count up to 2 and back to 1 Count up to 4 and back to 1 Count up to 6 and back to 1 ... ok you got it... put all these together and you'll get the following sequence ...
user avatar
26 votes
10 answers
1k views

Given a positive integer < 100 (from 1 to 99, including 1 and 99), output that many lockers. A locker is defined as the following: ...
sporkl's user avatar
  • 6,954
20 votes
19 answers
3k views

Introduction For those not familiar with steam - or at least this particular aspect: Often on peoples' profiles, people leave comments saying either "+rep _____" or "-rep _____". These are an ...
Jacob Garby's user avatar
12 votes
11 answers
2k views

How many of you that still use your own knuckle to determine whether a month is having a full 31 days or less? You job is to write a program to count how many months, in a month range, are having a ...
Rizki Pratama's user avatar
7 votes
1 answer
395 views

Note: this is my first post here. The Challenge The challenge is to count the number of chocolate chips in a cookie. A cookie in this case is a circle with dots (the chips) in it. Given any square ...
Nobody's user avatar
  • 81
36 votes
68 answers
5k views

On 4chan, a popular game is get. Every post on the site gets a sequential post ID. Since you can't influence or determine them, people try to guess (at least a part of) their own post number, usually ...
sagiksp's user avatar
  • 1,405
19 votes
8 answers
4k views

Challenge Given a graphical input of a shape, determine how many holes there are in it. Not Duplicate This question was marked as a possible duplicate of Count Islands. I believe this challenge is ...
hyperneutrino's user avatar
  • 42.8k