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

learn more… | top users | synonyms

-2
votes
2answers
149 views

Restricted average (arithmetic mean) – i.e. without obvious built-ins [closed]

Introduction The arithmetic mean is defined as being equal to the sum of the numerical values of each and every observation divided by the total number of observations. Symbolically, if we have a ...
7
votes
1answer
200 views

How many shapes are in this picture?

Children are very good at classifying objects and counting them. Computers seem to have more trouble. This is a simplified version of this problem. Can you write a small program that can classify and ...
18
votes
9answers
775 views

The Back-and-Forth Sequence

Imagine a path made up of < and > and ending in a @, e.g. ><>@ A walker starts on the left-most cell. He will traverse the path as follows: If the walker is on a @ cell, he's ...
11
votes
10answers
585 views

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 group of indistinguishable numbers has ...
19
votes
5answers
1k views

Are there More Hard Objects or Soft Objects

Tangentially inspired by the opening to the What-If book. The input is a rectangle of spaces as a string, list of string, etc., with objects made of #'s inside: ######## # # ...
41
votes
33answers
3k 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 ...
15
votes
3answers
295 views

Go to opposite corner of rectangle in all directions - Harder

This is essentially the same thing as this question, except harder. You are again to write a program that gets from the lower-left corner of a rectangle to the upper-right corner. However, this time ...
13
votes
13answers
643 views

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 ...
29
votes
23answers
3k views

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 takes one step upwards. If it was on ...
17
votes
1answer
227 views

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 ...
24
votes
29answers
2k 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: [1, [[2, 3, ...
14
votes
5answers
420 views

Find the coastline

Your task is to find the length of the coastline of a map of islands provided in an ASCII map. The input map will consist of 1 or more # characters that indicate land, and spaces which indicate water. ...
16
votes
13answers
476 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. 1 11 (one one) 21 (two ones) 1211 (one two one one) 111221 (one one one two two ones) 312211 ...
19
votes
15answers
2k views

Hypercube elements

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 ...
10
votes
23answers
711 views

Zeroes in interval

Your task is to write a function or program that takes two non-negative integers i and k (i ≤ k), and figure out how many zeroes you'd write if you wrote all whole numbers from i to k (inclusive) in ...
11
votes
6answers
298 views

Trim and Count the Decimals

In this challenge, you will write a program to output how many decimal places are in the input string and trim the input if needed. Examples -12.32 2 32 0 3231.432 3 -34.0 0 -34 023 0 23 ...
23
votes
9answers
949 views

“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 ...
7
votes
1answer
234 views

I spy with my little eye a number beginning with n++

If you have ever travelled with kids more than about 20 minutes, you will have no doubt heard cries of "Are we there yet?" and "How much further?" So we play games like "I Spy" to help pass the time ...
11
votes
2answers
158 views

Counting icons for Innovation splays

Innovation is a card game where players battle through the ages, from prehistory to modern times, in an attempt to earn achievements faster than their opponents. Each card in Innovation is unique, ...
14
votes
10answers
763 views

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 A to player B). When a number p that has a 7 in it OR is ...
21
votes
3answers
532 views

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 ...
40
votes
108answers
8k 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 STDOUT is not available. Your program must be a full, runnable ...
12
votes
8answers
477 views

Typesetting multidimensional labels

In a steam-punk multidimensional world, our boss wants to affix printed index labels to each drawer in our conglomerate's multidimensional file cabinet. The boss wants to typeset the entire label ...
17
votes
35answers
2k 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 ...
44
votes
12answers
2k views

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 Sample input: H2O Your input ...
14
votes
4answers
385 views

Counting the Endpoints of an ASCII Art

You should write a program or function which receives a string representing an ASCII art as input and outputs or returns the number of endpoints in the input. The input will consist of the characters ...
12
votes
38answers
2k 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 character y occurs in string x. The shortest program in bytes to do so ...
5
votes
5answers
484 views

Count from 1 to n in Negabinary and Negaquaternary

Instead of normal binary, you must count from 1 to an input in negabinary concatenated to negaquaternary. Here's an example, put in the form of an array: [11, 1102, 1113, 100130, 101131, 11010132, ...
20
votes
16answers
2k views

Write a program that finds the most occurring paired letter in a string

The program must output the letter that is paired the most. For example, if your program was given the following string: "Sally's friend Bobby searched for seashells." it must output L because "ll" ...
10
votes
5answers
650 views

Count the crossing words

Consider the following standard 15×15 crossword puzzle grid. We can represent this in ASCII art by using # for blocks and (space) for white squares. # # # # ...
12
votes
1answer
202 views

Find the Fenceposts

Background An atomic bomb has exploded near the fencepost factory! Since fenceposts are essential for the survival of our civilization, we must rescue as many as possible. We are sending ...
7
votes
2answers
200 views

Non-crossing X's and crossing non-X's

You should write a program or function which given a text as input outputs or returns the sum of the following three integers: Number of lowercase x's which are not part of a cross-formation. Number ...
15
votes
6answers
752 views

Overlapping circle

You should write a program or function that given an N by N equally spaced square grid and a solid inscribed circle outputs or returns the number of grid squares which are overlapped partially or ...
4
votes
7answers
541 views

N-gram histogram

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 be read from a file, stdin, passed ...
14
votes
45answers
4k views

Count the number of ones in unsigned 16 bit integer

Write some statement(s) which will count the number of ones in an unsigned sixteen bit integer. For example, if a variable s = 1337, then set ones to 6 because 1337 as a sixteen bit binary number is ...
2
votes
1answer
213 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, ...
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 rotate its body by 90 degree. If we ...
4
votes
0answers
81 views

Resistent counter [duplicate]

You just have to ouput exactly all the numbers from 1 to 10 separated by spaces. Your programme should work all the times even if a random character is deleted before compiling/interpreting. This is ...
39
votes
14answers
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 ...
13
votes
3answers
2k views

Computer: you do the math

This challenge is partly an algorithms challenge, involves some math and is partly simply a fastest code challenge. For some positive integer n, consider a uniformly random string of 1s and 0s of ...
67
votes
9answers
8k views

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 ...
12
votes
7answers
651 views

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 or external function, program or ...
15
votes
13answers
1k 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 ...
15
votes
3answers
735 views

How many characters per character?

At http://shakespeare.mit.edu/ you can find the full text of each of Shakespeare's plays on one page (e.g. Hamlet). Write a script that takes in the url of a play from stdin, such as ...
25
votes
22answers
3k views

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 ...
41
votes
28answers
7k 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 ...
52
votes
34answers
11k views

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 ...
0
votes
11answers
648 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 ...
13
votes
38answers
2k views

Count occurrences of an integer

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 Y containing the Integer Z. Z can ...
10
votes
35answers
4k 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 should be like this(not sorted in any ...