2022 Developer Survey is open! Take survey.

Questions tagged [number]

A competition to solve a particular problem through the usage and manipulation of numbers.

Filter by
Sorted by
Tagged with
9 votes
19 answers
96 views

Previous Fibonacci number

The sequence of Fibonacci numbers is defined as follows: \$ F_0 = 0 \\ F_1 = 1 \\ F_n = F_{n-1} + F_{n-2} \$ Given a Fibonacci number, return the previous Fibonacci number in the sequence. You do not ...
14 votes
23 answers
2k views

There's more than one way to skin a set

Given a set of positive integers \$ S \$, output the set of all positive integers \$ n \$ such that \$ n \$ can be made by summing a subset of \$ S \$ in more than one different way, i.e., that are ...
144 votes
297 answers
37k views

Fibonacci function or sequence

The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it. The first two numbers in the sequence are both 1. Here are the first ...
138 votes
91 answers
28k views

Largest Number Printable

Your goal is to write a program that prints a number. The bigger the number, the more points you'll get. But be careful! Code length is both limited and heavily weighted in the scoring function. Your ...
35 votes
64 answers
5k views

Find the highest unique digit

Surprisingly we haven't had a simple "find the highest digit" challenge yet, but I think that's a little too trivial. Given input of a non-negative integer, return the highest unique (ie not ...
82 votes
183 answers
9k views

Output the sign

Given a number N, output the sign of N: If N is positive, output 1 If N is negative, output -1 If N is 0, output 0 N will be an integer within the representable range of integers in your chosen ...
57 votes
137 answers
14k views

Print 0 to 100 without 1-9 characters

Print 0 to 100 without using characters 1,2,3,4,5,6,7,8,9 in your code. Seperator of numbers can be comma, whitespace or newline. Shortest code wins.
30 votes
72 answers
6k views

How long is my number?

Challenge Given an integer \$Q\$ in the range \$-2^{100} ≤ Q ≤ 2^{100}\$, output the number of digits in that number (in base 10). Rules Yes, you may take the number as a string and find its length. ...
12 votes
11 answers
2k views

Output two numbers (Robbers' thread)

This is the robbers' thread to a cops-and-robbers challenge. Click the link to find the cops' thread. In the cops' thread of this challenge, answerers will be writing programs which output two ...
8 votes
35 answers
3k views

Find the weight of five apples

Problem John bought 5 apples. You are given the weights of every group of four apples, and must then find the weights of the apples themselves. For example, if all apples without the first one weigh ...
22 votes
29 answers
2k views

Calculate the area of a regular polygon

Task Given an integer, n, where 3 <= n < 2^32, calculate the area of a regular n-gon, ...
86 votes
203 answers
15k 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 ...
45 votes
34 answers
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 ...
28 votes
26 answers
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 ...
10 votes
8 answers
2k views

How many times do I break my own rule?

Introduction: In my recent Strikethrough the Word Search List challenge I mentioned the following: When I do the word-search puzzles, I (almost) always go over the words in order, and strike them ...
4 votes
18 answers
2k views

Palindromic Powers

Powers We define an important power as a number that can be represented as \$ x^y \$ where \$ x ≥ 2 \$ and \$ y ≥ 2 \$. Palindrome We define an ...
17 votes
19 answers
1k views

Bounce-modulo two numbers

The graph of the modulo operation (\$y = x \mod k\$) looks like this: This is a very useful function, as it allows us to create "wrapping" behavior. However, it is very cumbersome when I want to use ...
5 votes
6 answers
534 views

Batt to the Basics

One of your acquaintances has a hobby of making make-shift electrical gadgets using various types of batteries. However, since they're thrifty, they want to use as few batteries as possible for their ...
9 votes
8 answers
2k views

Music with pi and e

Because I forgot to celebrate Pi Day (14.3), let's celebrate with \$\pi\$, \$e\$ (Euler's number) and music! Challenge No, we don't have time to eat a pi-pizza, let's make a program. What you need is ...
228 votes
335 answers
58k views

Is this number a prime?

Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in ...
20 votes
8 answers
2k views

ASCII-Art n'th Root

Challenge: Given two integers \$a\$ and \$b\$, with lengths \$A=length(a), B=length(b)\$, output an ASCII-art of the \$a^{th}\$ root of \$b\$, including the answer rounded to \$A\$ amount of decimal ...
29 votes
25 answers
6k views

Numbers with Rotational Symmetry

Given an integer, output a truthy value if it is the same upside-down (rotated 180°) or a falsy value otherwise. 0, 1, and <...
28 votes
79 answers
3k views

Range, Reverse, Sum!

Given a positive integer n as input, output the reversed range sum of n. A reversed range sum is created by making an inclusive range up to n, starting with 1 and including n, reversing each of the ...
19 votes
20 answers
2k views

Reverse Maths Cycles

Inspired by this In the linked challenge, we are asked to apply addition to the elements of the original and the reverse of the input array. In this challenge, we are going to make it slightly more ...
14 votes
6 answers
658 views

Rounding a range

You have a line with two endpoints a and b (0 ≤ a < b) on a 1D space. When ...
50 votes
27 answers
8k 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]...
33 votes
43 answers
3k views

Rotate a number

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

Can you Golf Golf?

You are required to generate a random 18-hole golf course. Example output: [3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4] Rules: Your program must output a list of hole ...
44 votes
46 answers
8k views

Shift right by half a bit

The challenge is to implement a program or function (subsequently referred to as "program") that takes a nonnegative integer \$n\$ as input and returns \$n\over\sqrt{2}\$ (the input divided by the ...
55 votes
50 answers
6k views

Increment an Array

Given a nonempty array of positive integers, "increment" it once as follows: If all the array elements are equal, append a 1 to the end of the array. For example: ...
22 votes
9 answers
950 views

Sequence of integers not the sum of powers of earlier terms

Starting with 1, output the sequence of integers which cannot be represented as the sum of powers of earlier terms. Each previous term can be used at most once, and the exponents must be non-negative ...
26 votes
6 answers
4k views

Golf a number bigger than Loader's number

As a follow up to Shortest terminating program whose output size exceeds Graham's number and Golf a number bigger than TREE(3), I present a new challenge. Loader's number is a very large number, ...
23 votes
35 answers
4k views

Am I a golfy array?

Definition and Rules A golfy array is an array of integers, where each element is higher than or equal to the arithmetic mean of all the previous elements. Your task is to determine whether an array ...
44 votes
46 answers
5k views

The Rien Number

The Champernowne constant is a number that is constructed by concatenating the first n numbers, with n tending to infinity. It ...
56 votes
251 answers
16k views

Print numbers from 1 to 10

This might be a very simple challenge, but I am surprised it hasn't been done on code-golf yet: Print all Integers from 1 to 10 inclusive in ascending order to standard output. Your output format ...
78 votes
182 answers
15k views

Sum of all integers from 1 to n

I'm honestly surprised that this hasn't been done already. If you can find an existing thread, by all means mark this as a duplicate or let me know. Input Your input is in the form of any positive ...
34 votes
52 answers
5k views

The first n numbers without consecutive equal binary digits

The sequence contains the decimal representation of the binary numbers of the form: 10101..., where the n-th term has n bits. The sequence is probably easiest to ...
17 votes
17 answers
3k views

Numbers in 2050

It's 2050, and people have decided to write numbers in a new way. They want less to memorize, and number to be able to be written quicker. For every place value(ones, tens, hundreds, etc.) the number ...
12 votes
18 answers
1k views

Words with Easy Letters in a Word Search

Introduction: Apparently I keep coming up with word search related challenges lately. :) When I do the word search in the Dutch news paper, some words are very easy to find because they contain ...
10 votes
26 answers
2k views

Machine Epsilon

Machine epsilon is an important floating point number to know when doing numerical calculations. One way to understand it is when this relation ...
39 votes
78 answers
10k views

Determine if all decimal digits are unique

Deleted questions on Stack Overflow sometimes make for great golf material. Write a function that takes a nonnegative integer as input, and returns true if all the digits in the base 10 ...
21 votes
21 answers
5k views

Find the Missing Numbers in the Fibonacci Sequence Mod K

Inspired by this Math.SE question. Background The Fibonacci Sequence (called F) is the sequence, starting 0, 1 such that each ...
14 votes
13 answers
1k views

Average-ignorant sets of integers

Recently a friend of mine posed the following: What subset of the integers satisfies the condition if distinct a and b are in the subset, their average is not in the subset? I know the set of non-0 ...
34 votes
18 answers
8k views

Balanced Ternary Converter

Credits for the challenge idea go to @AndrewPiliser. His original proposal in the sandbox was abandoned and since he has not been active here for several months, I have taken over the challenge. ...
16 votes
13 answers
997 views

Number of complete rhyme schemes

A rhyme scheme is the pattern of rhymes at the end of the lines in a poem. They are typically represented using letters, like ABAB. We consider two rhyme schemes ...
44 votes
77 answers
8k views

Print a bunch of uninteresting numbers!

An uninteresting number (which I totally didn't make up only for this challenge) is created like this: Take a positive integer N Create a new number O by adding the digits of N at the end of N ...
57 votes
150 answers
6k views

Evolution of OEIS

In this challenge, the goal is to recreate the On-Line Encyclopedia of Integer Sequences one sequence at a time. Similar to the Evolution of Hello World, each answer depends on a previous answer. ...
30 votes
133 answers
9k views

Multiply two numbers

Input: Two decimal integers. These can be given to the code in standard input, as arguments to the program or function, or as a list. Output: Their product, as a decimal integer. For example, the ...
3 votes
9 answers
1k views

int, float or neither?

Given a string, determine if it is an int, a float or neither. Examples 123 - int 62727.0033 - float 644c.33 - neither Your code should output a different value depending on which it is. For example ...
11 votes
18 answers
2k views

Prime numbers in large number

Given a large number (in base 10), such as 1234567891011121314151617, find prime "subnumbers" in it. A prime "subnumber" is a consecutive sequence of digits (taken from the input), which represents a ...

1
2 3 4 5
25