Skip to main content

Questions tagged [counting]

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

16 votes
17 answers
1k views

Count N-Rich Permutations of an Integer Sequence

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 ...
EphraimRuttenberg's user avatar
29 votes
48 answers
2k views

Replace 0s In a String With Their Consecutive Counts

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

Count /[^a-z]/ig with /[a-z]/ig

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
341 views

Counting overlapping objects

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

Count count count

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
  • 10.8k
21 votes
35 answers
2k views

Return all letter counts as an integer

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
  • 347
19 votes
2 answers
594 views

Counting and so on

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
14 votes
12 answers
2k views

How many Sets are there?

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 ...
EphraimRuttenberg's user avatar
33 votes
55 answers
2k views

Replace all items with their counts

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 Programs's user avatar
26 votes
19 answers
1k views

Possible periods of input

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 Programs's user avatar
13 votes
10 answers
1k views

Autogrammatic pairs

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

Count strictly overlapping substrings

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

Eye test - How many squares are in this picture?

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 ...
Domenico's user avatar
  • 2,333
3 votes
2 answers
559 views

Remove duplicates from list and order it by count? (python 3)

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

Number of solutions to a binary weight equation

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
  • 194k

15 30 50 per page
1
2 3 4 5
9