Questions tagged [counting]

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

Filter by
Sorted by
Tagged with
33
votes
43answers
6k views

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: ...
7
votes
4answers
510 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 ...
74
votes
193answers
13k views

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 ...
1
vote
12answers
751 views

Count the unique fractions with only integers

Count the number of unique fractions with numerators and denominators from 1 to 100, and print the counted number. Example: 2/3 = 4/6 = ... Rules: You must actually count in some way. Only integers ...
24
votes
6answers
862 views

Analyze the flow

On a toroidal square grid (you can wrap around) where each cell indicates one direction (^ > ...
12
votes
6answers
420 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. ...
31
votes
26answers
2k views

Say What You See

The "Look and say" or "Say what you see" sequence is a series of numbers where each describes the last. ...
33
votes
22answers
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 ...
2
votes
1answer
259 views

count number of valid, unique sequences for moving on a 1xn board [closed]

There's a board with n squares in a horizontal row. You start in the leftmost square, and roll a 3-faced dice. 3 possible outcomes for a single roll of the die: Left: you move 1 step to the left, ...
7
votes
13answers
2k 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 ...
24
votes
45answers
3k views

Non Unique Elements

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 ...
25
votes
51answers
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 ...
18
votes
54answers
3k views

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 ...
39
votes
36answers
4k views

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,...
-2
votes
7answers
336 views

Remove Duplicates From One List

Task: Remove all duplicates from one list of integers. A list is simply a sequence of connected values that allows the same values to be stored at different positions in this sequence. If an item ...
-13
votes
20answers
389 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 ...
26
votes
21answers
5k 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 ...
38
votes
18answers
6k views

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 ...
32
votes
6answers
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 ...
5
votes
19answers
309 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. ...
46
votes
18answers
6k views

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 ...
33
votes
28answers
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 ...
22
votes
54answers
6k views

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 ...
3
votes
1answer
170 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 ...
24
votes
43answers
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 ...
39
votes
24answers
4k views

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 ...
35
votes
24answers
7k views

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 ...
8
votes
18answers
1k views

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-...
46
votes
23answers
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: ...
24
votes
63answers
9k views

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 ...
37
votes
15answers
5k views

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, ...
42
votes
27answers
8k views

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 ...
11
votes
2answers
1k views

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 ...
43
votes
23answers
6k 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]...
17
votes
18answers
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: <...
20
votes
20answers
1k 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 ...
0
votes
0answers
115 views

Count the score of a Code Golf code [duplicate]

My challenge is to make a Java method(s) that is given a String (another code in Java), removes any unnecessary characters, counts and returns the score, and displays the cleaned-up code in a way that ...
19
votes
32answers
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, ...
19
votes
3answers
385 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 ...
59
votes
54answers
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 ...
16
votes
13answers
2k views

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 ...
50
votes
38answers
4k views

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 ...
58
votes
25answers
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 ...
16
votes
10answers
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 ...
11
votes
7answers
382 views

Create an unlimited counterstring

A counterstring is some sort of self-describing test data that is used in software testing. Not sure it was actually invented by James Bach, but I know it from there. The idea is as follows: the test ...
20
votes
21answers
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 ...
3
votes
2answers
76 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: ...
26
votes
9answers
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: ...
35
votes
53answers
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 ...
23
votes
25answers
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 <...