Questions tagged [number]

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

Filter by
Sorted by
Tagged with
29
votes
23answers
4k views

Binary Numbers Magic Trick

The challenge is simply; output the following six 2D integer arrays: ...
29
votes
23answers
3k views

Print rotation-safe numbers

Background You are working for some board-game manufacturer and need to produce wooden tiles with the numbers from 0 to n engraved on them for some game. However, without further ado, some tiles ...
29
votes
17answers
1k 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 ...
29
votes
12answers
20k views

Four is the magic number

I didn't check the sandbox before posting this challenge - it looks like this challenge was proposed by Cᴏɴᴏʀ O'Bʀɪᴇɴ. Given an integer input, write a program that prints the "four is a magic number" ...
29
votes
12answers
3k 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, ...
29
votes
13answers
2k views

Generate Keyboard Friendly Numbers

Most common computer keyboard layouts have the decimal digit keys 1234567890 running along at their top, above the keys for letters. Let a decimal digit's neighborhood be the set of digits from ...
29
votes
4answers
721 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 ... ...
28
votes
60answers
3k views

Triangle a number!

We are used to the term "squaring" n to mean calculating n2. We are also used to the term "cubing" n to mean n3. That being said, why couldn't we also triangle a number? How to triangle a number? ...
28
votes
40answers
4k views

Simple integer operation calculator

Implement a simple integer operation scriptable calculator. Concept The accumulator starts at 0 and has operations performed on it. At the end of the program output the value of the accumulator. ...
28
votes
54answers
6k views

Integer Lists of Noah

Introduction: I think we've all heard of it, but here a very brief summary: Noah gathered two of every species of animal on the planet, male and female, to save in his Ark during a great flood. The ...
28
votes
16answers
2k views

Output the Euler Numbers

Given a non-negative integer \$n ,\$ output the \$n^{\text{th}}\$ Euler number (OEIS A122045). All odd-indexed Euler numbers are \$0 .\$ The even-indexed Euler numbers can be computed with the ...
28
votes
25answers
3k views

Calculate A190810

Your task is pretty simple, calculate the n-th element of A190810. Elements of A190810 are calculated according to these rules: The first element is 1 The sequence is increasing If ...
28
votes
36answers
3k views

Rotate a number

Given a positive number n, rotate its base-10 digits m positions rightward. That is, output the result of ...
28
votes
32answers
5k views

Round away from zero

Round away from zero Inspired by Round towards zero. Given a number input via any reasonable method, round the number "away from zero" - positive numbers round up, and negative numbers round down. ...
28
votes
36answers
3k views

Print an arch of ascending / descending numbers

I figured an "arch" was the best way to describe this pattern of numbers: ...
28
votes
11answers
6k views

Negative Fibonacci Numbers

You probably all know the fibonacci sequence: fibonacci(n)=fibonacci(n-1)+fibonacci(n-2) fibonacci(0)=0 fibonacci(1)=1 Your task is as simple as it could be: ...
28
votes
25answers
4k views

Smallest Zeroless Base

Given a positive integer n, output the smallest base b >= 2 where the representation of n ...
28
votes
36answers
3k views

Find the unique twins

You will be given two Arrays / Lists / Vectors of non-negative integers A and B. Your task is to output the highest integer N that appears in both A and B, and is also unique in both A and B. You ...
28
votes
20answers
2k views

A sequence of sums of integers that aren't in the sequence

Background Consider a sequence defined as follows: The first element is 0; The second element is 4; From the third element onwards, its value can be calculated by: Taking the set of integers from 0 ...
28
votes
23answers
2k views

String Distance

Challenge Given an input of an all-lowercase string [a-z], output the total distance between the letters. Example ...
28
votes
19answers
3k views

Monday Mini-Golf #1: Reverse Fibonacci Solver

Monday Mini-Golf: A series of short code-golf challenges, posted (hopefully!) every Monday. A Fibonacci-like sequence is obtained using the same method as the famous Fibonacci sequence; that is, each ...
28
votes
21answers
3k views

Is it a Chen prime?

A number is a Chen prime if it satisfies two conditions: It is prime itself Itself plus two is either a prime or a semi-prime. A prime is a number where it has exactly two divisors and those ...
28
votes
23answers
2k views

Find the largest number n positions away from n

A sequel to this question. Task Given an array of positive integers, find the largest element k for which: There exists some positive integer distance n, so that the element in the array located ...
28
votes
11answers
2k views

Cardinals and ordinals, 1 to 100

Here's a simple one to stretch your compression muscles. Your code (a complete program) must output the spelled-out English representation of all the cardinal numbers from 1 to 100, and then all the ...
28
votes
24answers
2k views

Operator that combines sum, product and difference between two numbers

Challenge: There's a silly puzzle circulating on social networks that reads: 8 + 2 = 16106 5 + 4 = 2091 9 + 6 = ? Implement a function or operator that, when ...
28
votes
20answers
2k views

Convert to Suzhou numerals

Suzhou numerals (蘇州碼子; also 花碼) are Chinese decimal numerals: 0 〇 1 〡 一 2 〢 二 3 〣 三 4 〤 5 〥 6 〦 7 〧 8 〨 9 〩 They pretty much work like Arabic numerals, except ...
28
votes
19answers
2k views

Find the sortable years

The year 2013 had an interesting property: the digits are consecutive when sorted (0123). Let's call this type of number a sortable number: a non-negative integer whose base-10 digits are consecutive ...
28
votes
6answers
3k views

Help! My calculator malfunctions!

Introduction My calculator is behaving weird. Sometimes when I type in an 8 it displays a 2. And sometimes when I type in a <...
28
votes
2answers
2k views

Zero an arbitrarily large cell in Brainf***

Your task is to write a piece of code that zeros the current cell in the Brainfuck variant that, each cell can contain a signed integer of arbitrarily large magnitude, instead of the normal 0 to 255. ...
27
votes
90answers
13k views

Reciprocal of a number (1/x)

Challenge Given a (floating-point/decimal) number, return its reciprocal, i.e. 1 divided by the number. The output must be a floating-point/decimal number, not just an integer. Detailed ...
27
votes
56answers
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 ...
27
votes
48answers
4k views

Golf a Custom Fibonacci Sequence

The Fibonacci sequence is a fairly well known thing around here. Heck, it even has its own tag. However, for all that, we sure like to stick to our roots of ...
27
votes
43answers
3k views

Up go the bits!

Given an integer N perform the following steps: (using 9 as an example). Receive input N. (9) Convert N from base10 to base2. (...
27
votes
48answers
2k views

Create a checkerboard matrix

Take a positive integer n as input, and output a n-by-n checkerboard matrix consisting of 1 and 0. The top left digit should always be 1. Test cases: ...
27
votes
29answers
2k views

Parenthifiable Binary Numbers

If you express some positive integer in binary with no leading zeros and replace every 1 with a ( and every ...
27
votes
22answers
1k views

Natural construction

The natural numbers including 0 are formally defined as sets, in the following way: Number 0 is defined as the empty set, {} For n ≥ 0, number n+1 is defined as n ∪ {n}. As a consequence, n = {0, 1, ...
27
votes
41answers
2k views

Enumerate each series of identical numbers in-place

Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series. Examples ...
27
votes
33answers
2k views

Rotation summation

Take a square matrix containing positive integers as input, and calculate the "rotated sum" of the matrix. Rotated sum: Take the sum of the original matrix and the same matrix rotated 90, 180 and ...
27
votes
22answers
2k views

No one, please!

I absolutely hate the digit 1. So, I need your help to convert numbers to their "proper forms". Numbers in proper form never have two ...
27
votes
25answers
3k views

Find the next 1-sparse binary number

A positive integer N is K-sparse if there are at least K 0s between any two consecutive 1s in its binary representation. So, the number 1010101 is 1-sparse whereas 101101 is not. Your task is to ...
27
votes
24answers
1k views

When integers join the queue

Introduction A queue is an abstract data type where elements are added to the front (enqueue) and removed from the back (dequeue). This is also known as the FIFO (First In First Out) principle. It is ...
27
votes
16answers
2k views

Output an upside-down tent

Given an integer, output an upside-down tent. The input determines both the size of the tent (absolute value) and whether the entrance is on the left side (negative numbers) or the right side (...
27
votes
23answers
2k views

Sum It Up with a Digital Triangle

Well, sum it down really. Write a program or function that takes in a nonempty list of decimal integers (0-9) and outputs a downward pointing "triangle" of digits with the input list at the top where ...
27
votes
22answers
4k views

Can the number reach 1 by repeatedly subtracting the largest prime less than it?

Challenge: Given a number, take the largest prime strictly less than it, subtract it from this number, do this again to this new number with the biggest prime less than it, and continue doing this ...
27
votes
21answers
2k views

Find prime gaps

A prime gap is the difference between two consecutive primes. More specifically, if p and q are primes with p <q and p+1, p+2, ..., q−1 are not primes, the primes p and q define a gap of n = q−p. ...
27
votes
23answers
2k views

How many peaks in my mountain range?

A list of positive integers can be visualized as a quantized mountain range where each list entry represents the height of one vertical section of the mountains. For example, the list ...
27
votes
18answers
1k views

Sums of prime factors

2013 has the prime factorization 3*11*61. 2014 has the prime factorization 2*19*53. An interesting property regarding these ...
27
votes
19answers
9k views

Convert to and from the factorial number system

The Factorial Number System, also called factoradic, is a mixed radix numeral system. The factorials determine the place value of a number. In this system, the right most digit can be either 0 or 1, ...
27
votes
15answers
2k views

Evaluate Conway chained arrow notation

Background Conway chained arrow notation is a notation to express very large numbers. It consists of zero or more positive integers separated by right arrows, e.g. \$2 \to 3 \to 4 \to 5 \to 6 \$. ...
27
votes
13answers
3k views

Valid Badminton Score?

Introduction: I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here ...

1
3 4
5
6 7
23