Questions tagged [counting]
For challenges regarding counting the number of occurrences of some characteristic.
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 ...
Counting Grains of Rice
Consider these 10 images of various amounts of uncooked grains of white rice. THESE ARE ONLY THUMBNAILS. Click an image to view it at full size. A: B: C: D: E: F: G: H: I: J: Grain Counts: <...
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 ...
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 ...
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 ...
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 ...
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]...
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 ...
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: ...
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 ...
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 ...
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 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 ...
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: ...
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, ...
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 ...
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 ...
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 ...
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 ...
Say What You See
The "Look and say" or "Say what you see" sequence is a series of numbers where each describes the last. ...
How many IP addresses are in a given range?
Inspired by... Networking - How can I work out how many IP addresses there are in a given range? Write a program or function that takes two strings as input, each being an IPv4 address ...
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 ...
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 ...
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 ...
Robot on a ladder
Background I have a ladder leaning on a wall, and a remote-controlled robot that can climb it. I can send three different commands to the robot: UP: the robot ...
"You must construct additional pylons!"
Introduction In the strategy game Starcraft 2, there are three "races" to choose from: Terran, Zerg, and Protoss. In this challenge we will be focusing on the Protoss and the iconic phrase "You must ...
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, <...
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 ...
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 ...
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: ...
Given a positive integer < 100 (from 1 to 99, including 1 and 99), output that many lockers. A locker is defined as the following: ...
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 ...
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 ...
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 ...
Prime Wednesdays Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime ...
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 <...
Analyze the flow
On a toroidal square grid (you can wrap around) where each cell indicates one direction (^ > ...
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 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 ...
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 ...
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 ...
Write a Chat Ping Counter
Your task is to write a program, that given a list of chat messages, count how many times each person gets pinged, so I can know how popular everyone is. But, since I have to do it surreptitiously, I ...
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 ...
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 ...
How varied is my obstacle course?
Background I have constructed a simple obstacle course by placing boxes in a rectangular room. Now I want to count the number of essentially different ways in which it can be solved. I need you to ...
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 ...