2022 Developer Survey is open! Take survey.

Questions tagged [counting]

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

Filter by
Sorted by
Tagged with
8 votes
0 answers
248 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 ...
user avatar
15 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, ...
user avatar
  • 9,426
20 votes
34 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. ...
user avatar
19 votes
2 answers
536 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 ...
user avatar
  • 1,367
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 ...
user avatar
24 votes
37 answers
1k 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, <...
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 <...
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 ...
user avatar
19 votes
13 answers
933 views

Count strictly overlapping substrings

Given two strings a and b, count how many times b occurs as a substring in ...
user avatar
  • 18.6k
22 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 ...
user avatar
  • 1,973
3 votes
2 answers
415 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? ...
user avatar
13 votes
6 answers
466 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. ...
user avatar
  • 166k
25 votes
7 answers
928 views

Analyze the flow

On a toroidal square grid (you can wrap around) where each cell indicates one direction (^ > ...
user avatar
  • 1,973
19 votes
1 answer
640 views

Acyclic orientations of an n-dimensional cube

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 ...
user avatar
  • 199
32 votes
6 answers
2k views

Slash the matrix

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 ...
user avatar
  • 14.5k
5 votes
19 answers
324 views

How many spaces are there? [duplicate]

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. ...
user avatar
  • 3,704
34 votes
28 answers
3k views

Count rook moves 1D

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 ...
user avatar
  • 137k
3 votes
1 answer
218 views

Black and white shirt 2

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 ...
user avatar
  • 289
24 votes
43 answers
4k views

Character Frequency in a String [duplicate]

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 ...
user avatar
  • 2,823
29 votes
23 answers
6k views

A scene of Jimmy diversity

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 ...
user avatar
  • 2,464
50 votes
27 answers
8k views

Covering a Skyline with brush strokes

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]...
user avatar
  • 27.1k
19 votes
32 answers
3k views

How fast am I vrooooming?

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, ...
user avatar
  • 897
21 votes
5 answers
428 views

Count cyclically self-describing lists

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 ...
user avatar
  • 42k
7 votes
14 answers
4k views

Recursively count lines of code, excluding empty lines and comments

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 ...
user avatar
17 votes
18 answers
4k views

Longest Repeating Subsequence of a Single Digit

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: <...
user avatar
10 votes
5 answers
684 views

Saddle points in a matrix

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 ...
user avatar
  • 14.5k
-13 votes
20 answers
477 views

How long is this string?

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 ...
user avatar
  • 1,593
16 votes
10 answers
3k views

Assign Airliner Seats

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 ...
user avatar
  • 27.1k
34 votes
22 answers
3k views

Alphabet Histogram

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

Count the Matchsticks

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

Count stacking sequences [duplicate]

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: ...
user avatar
  • 2,997
23 votes
25 answers
1k views

Count edits accounting for grace period

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 <...
user avatar
  • 137k
35 votes
24 answers
3k views

Plus Primes vs Minus Primes

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

Sequence Without Sevens [duplicate]

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 ...
user avatar
  • 1,241
23 votes
28 answers
2k views

Count forth and back then double up

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

Number Lockers!

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

How much reputation does a steam user have? [closed]

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 ...
user avatar
12 votes
11 answers
2k views

Count how many months are having a full 31 days by counting knuckles

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 ...
user avatar
7 votes
1 answer
323 views

Count # of Cookie Chocolate Chips

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 ...
user avatar
  • 81
33 votes
60 answers
4k views

GET your dubs together

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 ...
user avatar
  • 1,355
19 votes
8 answers
3k views

How Many Holes?

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 ...
user avatar
  • 40.2k
24 votes
5 answers
661 views

How great is your land?

In this challenge, you'll calculate how great your land is. Write a program or function that calculates the size of your land, given a wall you have built. You're given a non-empty input string ...
user avatar
11 votes
18 answers
1k views

Round the string

Some decimal numbers cannot be precisely represented as binary floats due to the internal representation of the binary floats. For example: rounding 14.225 to two decimal digits does not result in 14....
user avatar
  • 217
36 votes
53 answers
5k views

How much do I have to write?

Writing out numbers is among the Hello worlds of programming, often the numbers 1-10. I want to write out many numbers! Many, Many numbers. But how many numbers do I have to write? Task Given an ...
user avatar
  • 3,583
6 votes
14 answers
807 views

Find the frequency of triplets in a phrase

For context, this problem is based on a old chat-bot project I did. Problem: Given a string of words containing any of the characters: ...
user avatar
61 votes
26 answers
5k views

Cantor's unspeakable numbers

An unspeakable number is a number which is divisible by seven or has seven as one of its digits. A children game is to count skipping unspeakable numbers ...
user avatar
  • 1,717
22 votes
20 answers
2k views

Find the "Recursive Size" of a List

Inspired by Find the “unwrapped size” of a list. Define the Recursive Size, RS, of a list containing no lists as its length (number of items contained) and the ...
user avatar
12 votes
33 answers
2k views

Find the "unwrapped size" of a list

Let's define the "unwrapped size" function u of a nested list l (containing only lists) by the following rules: If ...
user avatar
59 votes
56 answers
4k views

Count trailing truths

Inspired by, and in memory of, my dear friend and colleague, Dan Baronet, 1956 – 2016. R.I.P. He found the shortest possible APL solution to this task: Task Given a Boolean list, count the number of ...
user avatar
  • 27.1k
46 votes
23 answers
9k views

Count down from "Infinity"

Seems like an impossible task right? Well, it's actually not that hard. If we write the word Infinity as 8-bit binary ASCII code, we'll get: ...
user avatar