Questions tagged [counting]
For challenges regarding counting the number of occurrences of some characteristic.
Say What You See
The "Look and say" or "Say what you see" sequence is a series of numbers where each describes the last. ...
Count up forever
Write a program that counts up forever, starting from one. Rules: Your program must log to STDOUT or an acceptable alternative, if ...
Determine the depth of an array
A simple challenge for your Monday evening (well, or Tuesday morning in the other half of the world...) You're given as input a nested, potentially ragged array of positive integers: ...
Display number of occurrences for every character in an input string
The code should take a string as input from keyboard: The definition of insanity is quoting the same phrase again and again and not expect despair. The output ...
Find the occurrences of a character in an input string
Challenge Write a program that, given a string x which is 10 characters long and a character y, outputs the number of times ...
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 ...
Count the number of ones in an unsigned 16-bit integer
Write some statement(s) which will count the number of ones in an unsigned sixteen-bit integer. For example, if the input is 1337, then the result is ...
Write a program which finds the non-unique elements of an array of signed integers. The resulting array can be in any order. Your answer may be a snippet which assumes the input to be stored in a ...
A penny saved is a penny
...counted! You will pass your program a variable which represents a quantity of money in dollars and/or cents and an array of coin values. Your challenge is to output the number of possible ...
Calculate the nth term of Golomb's self-describing sequence
Inspired by the previous question. Golomb's self-describing sequence g(n) is a sequence where any natural number n is repeated within the sequence g(n) times. The ...
Square-free semiprime counting
Definition A square-free semiprime is a natural number that is the product of two distinct prime numbers. The task Given a natural number n, count all square-free ...
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 ...
Molecules to Atoms
The Challenge Write a program that can break down an input chemical formula (see below), and output its respective atoms in the form element: atom-count. Input ...
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 ...
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. ...
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 ...
Write a function or program that outputs the number of each type of element (vertex, edge, face, etc.) of an N-dimensional hypercube. As an example, the 3 dimensional cube has 1 cell (i.e. 1 3-...
The game of Sevens! Who said what?
The game of Sevens is played as follows: n players sit in a circle, and start counting up from 1, passing to the left (or from player ...
Line numbering - implement nl
Your task is to implement a program similar to the nl command-line tool from the GNU core utilities. Standard loopholes are banned. You may not use any built-in ...
Avoid the evil integers! [closed]
You are developing some code to generate ID numbers. Policy requires that no ID numbers include the digit sequence 666. Create a function (or your language's equivalent) which takes a positive ...
Stretch the word
The input is a word of lowercase letters not separated by whitespace. A newline at the end is optional. The same word must be output in a modified version: For each character, double it the second ...
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]...
Into how many pieces can you cut this string?
Consider a piece of string (as in "rope", not as in "a bunch of characters"), which is folded back and forth on the real line. We can describe the shape of the string with a list of points it passes ...
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: ...
Count to 100 in Danish
Print all the numbers from 0-100 in the right order using the Danish way of counting How they count Like English, they have dedicated words for 0-20, 30, 40 and 100 Instead of saying ...
Fast, Cheap, and Good - Choose any Two
As programmers, we all know the saying: "You can have it fast and good, but it won't be cheap, you can have it cheap and good, but it won't be fast, or you can have it fast and cheap, but it won't be ...
Detriplicate a string
A lot of languages have built-in ways to get rid of duplicates, or "deduplicate" or "uniquify" a list or string. A less common task is to "detriplicate" a string. That is,...
How many lights are on?
You are little speck on a Cartesian plane. Pondering your existence, you decide to roam around your plane and touch things. You notice that every coordinate pair you visit has a light switch. To ...
How long is a Welsh word?
Write a program or function which receives as input a string representing a Welsh word (UTF-8 unless otherwise specified by you). The following are all single letters in Welsh: a, b, c, ch, d, dd, ...
Checkmate (aka the urinal problem)
My Precalc teacher has one of his favorite problems that he made up (or more likely stole inspired by xkcd) that involves a row of n urinals. "Checkmate" is a ...
Given an input sentence consisting of one or more words [a-z]+ and zero or more spaces , output an ASCII-art histogram (bar ...
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 ...
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 ...
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 <...
I think most people around here know what a 7-segment display for digits is: ...
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 ...
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 ...
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 ...
You should write a program or function that given an N by N equally spaced square grid and a solid inscribed circle outputs or ...
Display a tally (in varying bases)
Tallying is a simple counting system that works in base 5. There are various different tallying systems used around the world, but the one that is used in most English-speaking countries is perhaps ...
Count occurrences of an integer [closed]
Based on the question How many positive integers < 1,000,000 contain the digit 2?. I'm looking for the most creative solution to count all the Integers from X to ...
Permutations with Indistinguishable Items
Given a list of integers, output the number of permutations of the integers, with indistinguishable permutations counted once. If there are n integers, and each ...
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 ...
Optimal solution to go to opposite corner of a rectangle
Your job is to write a program that finds the optimal number of moves it takes to get from the lower-left corner of a rectangle to the upper-right corner directly opposite. Your program will accept ...
The number of reachable snake orientations
This challenge is not about the game Snake. Imagine a 2d snake formed by drawing a horizontal line of length n. At integer points along its body, this snake can ...
Convert from binary to unary in 7x7 Manufactoria
In the game manufactoria, take in a binary number and output that number of red pieces. The catch? The board-size is only 7x7: Here's the manufactoria code for the problem: http://pleasingfungus.com/...
Given a text and a number N, output, in a human readable format, the set of the character N-grams with their respective percentages. The smallprint The text can ...
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 ...