This challenge is intended to be solved by using, manipulating, accepting as input, or outputting numeric values.

learn more… | top users | synonyms

21
votes
24answers
2k views

The plus-minus sequence

The plus-minus sequence The plus-minus sequence is one that starts with two seeds, a(0) and b(0). Each iteration of this sequence is the addition and subtraction of the previous two members of the ...
18
votes
3answers
163 views

Highest score on the field

Introduction Let a field be a rectangle filled with only the characters - and [0-9]. An example of a field is: 11-011123 111-010-- 0010---01 111-01234 You see that this field has been separated ...
21
votes
5answers
595 views

Commutation of 27 functions

Introduction Let's define a ternary function as a function from the three-element set S = {0,1,2} to itself: it associates to each element of S another element of S. One example of a ternary function ...
17
votes
12answers
616 views

Equality in the sum of digits

Introduction Let's take the number 180. This is an interesting number because the sum of digits of this number is equal to: 1 + 8 + 0 = 9 And the squared version of this number, or: 180² = 32400 ...
12
votes
3answers
403 views

How many sides does this polygon have?

So in 1st grade math, you learn the names of polygons. Three sides is a triangle, 4 is a square, and 5 is a pentagon. However, in 1st grade honors, you go a bit further. Your challenge There is a ...
-2
votes
16answers
340 views

Print all the numbers! (At least, as many as possible.) [closed]

Your task is to print a number. Simple, right? It is simple, but not as simple as this. The first answer is to print the number 1, the second answer is to print the number 2, etc. Rules The first ...
29
votes
34answers
3k views

Yahtzee Small Straight Detection

In the game Yahtzee, players roll five six-sided dice, and attempt to create certain hands to score points. One such hand is a small straight: four consecutive numbers, not necessarily in order. The ...
36
votes
35answers
4k views

Making a coin fair

You have a coin that produces 0 or 1. But you suspect the coin may be biased, meaning that the probability of 0 (or 1) is not necessarily 1/2. A well known procedure to "transform" a biased coin into ...
19
votes
0answers
197 views

Cycles in run-length encoding

Consider some binary sequence, using 1 and 2, e.g.: 1, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 1 ... Let's write down the run lengths of that: 1, 2, 1, 1, 2, 2, 1, 2, 1, 2, 2, 1 ... _ _ ____ ____ _ _ ...
10
votes
4answers
952 views

The Unholy numbers

This challenged is highly inspired by what @Mego created with his Holy and Holier numbers, lots of thanks to him and his puns. Holy numbers are numbers composed of only the digits with holes, which ...
7
votes
1answer
170 views

Leaping Lizards!

Suppose we define a simple program that takes an array L of natural numbers with some length N and does the following: i=0 #start at the first element in the source array P=[] ...
5
votes
2answers
219 views

Chaotic Number Shuffling

You have a deck of cards, consisting of cards with non-negative numbers on them, and you haven't shuffled it yet, and no player trusts the other players to be fair at shuffling. You devise a way to ...
20
votes
9answers
820 views

Highly composite numbers

A highly composite number is a positive integer that has more divisors than any smaller positive integer has. This is OEIS sequence A002182. Its first 20 terms are 1, 2, 4, 6, 12, 24, 36, 48, 60, ...
16
votes
20answers
600 views

Descending digit sequences

Introduction As an example, let's take the number 7. We then duplicate this and place 7 spaces in between. We get this: 7_______7 After that, we are going to decrease the number, until there are ...
42
votes
12answers
2k views

Calculate the number of primes up to n

π(n) is the number of primes less than or equal to n. Input: a natural number, n. Output: π(n). Scoring: This is a fastest-code challenge. Score will be the sum of times for the score cases. I ...
-5
votes
7answers
130 views

Find if a number contains a digit without ever using using its string representation

The Challenge: Find if a number contains a digit. The number and the digit are to be taken as input. Output must be a boolean value. But you are not allowed to use the string representation of the ...
50
votes
10answers
3k views

Quack the Angry Duck

No one is quite certain what the emoticon >:U is intended to represent, but many scholars believe it looks like an angry duck. Let's assume that's the case. Task Given an integer n between 0 and ...
2
votes
1answer
204 views

Implement my method of adding numbers mentally

Note: This challenge has been changed to eliminate the strict whitespace manipulation requirements that made this challenge low-quality. Some rules regarding whitespace have been changed. I'm ...
21
votes
3answers
310 views

The Holier Numbers

As we learned from The Holy Numbers, there are 5 holy digits (0, 4, 6, 8, 9), and positive integers consisting solely of those digits are holy. Additionally, the holiness of a number is the sum of the ...
15
votes
9answers
420 views

Block-diagonal matrix from columns

Inspired by Copied from this question at Stack Overflow. Given a matrix A, create a matrix B such that the columns of A are arranged in a block-diagonal fashion. For example, given 1 2 3 4 5 6 the ...
21
votes
9answers
1k views

Generate lazy values

Related: Program my microwave oven. Inspired by Generate lazy microwave input. The lazy value of the non-negative integer N is the smallest of the integers that are closest to N while all their ...
17
votes
3answers
274 views

Generate lazy microwave input

Related: Program my microwave oven and Generate lazy values. My colleague is so lazy that he doesn't even bother to move his finger when programming the microwave oven. (This is actually true!) Help ...
18
votes
1answer
145 views

Sandpile integers

Challenge You will be given a positive integer n as input. Output should be a pyramid-like sandpile built on the rules specified below: Each integer "falls" downward from the same initial starting ...
23
votes
31answers
1k views

Adding up the digits and the digits reversed

Given a number > 0, output the sum with all digits (1 .. n) concatenated and reversed and add them up. For example, with n = 6: The numbers 1 to 6 concatenated: 123456 Reversed: 654321 Adding ...
9
votes
1answer
135 views

Taxi me some numbers

Taxicab Numbers or OEIS A011541 are the least numbers that are able to be represented as n different sums of two positive cubed integers, for successive n. You'll need to print out the nth taxicab ...
24
votes
8answers
2k views

That's a prime… almost

If you've ever learned about primes in math class, you've probably have had to, at one point, determine if a number is prime. You've probably messed up while you were still learning them, for example, ...
17
votes
13answers
1k views

The middle-square method

Introduction The middle-square method is used for the generation of pseudorandom numbers. However, this is not a good method in practice, since its period is usually very short and has some severe ...
27
votes
15answers
887 views

Repair the ranges

Given an input of a list of positive integers with some replaced with 0, output the list with the missing numbers that were changed to 0 replaced. Characteristics of the input list: The list will ...
10
votes
1answer
252 views

How many letters in this word?

Inspired by Project Euler #17, this is your challenge. Write a full program or function that takes a number as input, then print or return how many letters it would take to count up to and including ...
45
votes
19answers
5k views

The Holy Numbers

In many fonts (specifically in the Consolas font), 5 out of the 10 decimal digits have "holes" in them. We will call these holy digits: 46890 The 5 unholy digits are thus: 12357 An integer may ...
15
votes
4answers
329 views

Find the missing number in an undelimited string

The challenge is to identify the missing number in a string of undelimited integers. You are given a string of digits (valid input will match the regular expression ^[1-9][0-9]+$). The string ...
5
votes
3answers
254 views

Output the smallest powers of 2 with two identical sub-strings of digits n long

For each integer n, 0 or higher, output the lowest power of 2 that has two identical sub-strings of n digits in decimal, and the two indices where the digit sub-strings start (0-based). n      ...
18
votes
15answers
1k views

Compute minimax of an array

Inspired by this question Consider an array x such as [1 5 3 4] and a number n, for example 2. Write all length-n sliding subarrays: [1 5], [5 3], [3 4]. Let the minimax of the array be defined as ...
-3
votes
1answer
93 views

Implement decimal-multiplication modulo

Most people can't easily do modulus (or work out if a number is divisible by another number) in their heads because long division is harder than addition, subtraction and multiplication. The following ...
13
votes
20answers
1k views

Output the juggler sequence

The juggler sequence is described as follows. Beginning with an input a1, the next term is defined by the recurrence relation The sequence terminates when it reaches 1, as all subsequent terms ...
7
votes
4answers
149 views

Compute overall ranking

You are given a table that represents the rankings of S subjects according to a number C of different criteria. The purpose is to compute an overall ranking according to a weighted sum of the C ...
15
votes
13answers
867 views

Get the closest value to number

In this code golf, you need to get the closest number from another one in a list. The output may be the closest number to the input. Example: value: (Input) 5 --- [1,2,3] --- 3 And, the program ...
36
votes
56answers
9k views

How even is a number?

The ancient Greeks had these things called singly and doubly even numbers. An example of a singly even number is 14. It can be divided by 2 once, and has at that point become an odd number (7), after ...
16
votes
31answers
802 views

Filter out and add up

Task The task is very simple. Given a non-empty string containing numbers, uppercase and lowercase letters, output the sum of the remaining numbers. For example: a1wAD5qw45REs5Fw4eRQR33wqe4WE ...
4
votes
1answer
81 views

Convert to and from the backwards-factorial number base

I wanted to ask this question: Convert to and from the factorial number system but I'm a couple of years too late! So, instead you must convert to and from the lairotcaf backwards-factorial number ...
12
votes
11answers
2k views

Convert English to a number without built-ins or libraries

This challenge is similar to this other, however I made a restriction (see bold text below) that I think would made it much diffent and (I hope) fun either. The Challenge Write a program or a ...
12
votes
6answers
813 views

Number of steps for a binary search

Given an input of a positive integer, output the number of steps it takes to find the input via a binary search starting at 1. We are simulating a binary search for the integer that was given as ...
6
votes
3answers
144 views

Inverse Champernowne Substrings

The Champernowne Constant is the irrational number 0.1234567891011... extending ad infinum. We've done a question about it before. But this question is about its reciprocal, known as the Inverse ...
28
votes
18answers
3k views

Sort by Multiplying

You should write a program or function that given a list of positive integers multiplies each element with the smallest positive integer possible to create a strictly increasing list. For example if ...
6
votes
1answer
118 views

Implement almost-equals for IEEE numbers

Isn't it annoying when you're working with floating point numbers and your code doesn't work because two numbers are not equal by the least significant bit? Now you can fix that! Write some code that ...
12
votes
4answers
311 views

All the numbers that fit in a string

Write a program or function that takes in a positive integer N. Output a list of all the distinct decimal numbers that can be written in exactly N characters using digits (0123456789), decimal points ...
20
votes
33answers
3k views

Electrical outlet

This is a problem from NCPC 2005. Roy has an apartment with only one single electrical outlet, but he has a bunch of power strips. Compute the maximum number of outlets he can have using the power ...
17
votes
8answers
343 views

Print the Super Collatz numbers

The Collatz Sequence (also called the 3x + 1 problem) is where you start with any positive integer, for this example we will use 10, and apply this set of steps to it: if n is even: Divide it by ...
20
votes
17answers
997 views

Rearranging the sequence

Introduction Let's observe the following sequence (non-negative integers): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... For example, let's take the first three numbers. These are 0, 1, 2. ...
16
votes
13answers
463 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 ...