Questions tagged [number]
A competition to solve a particular problem through the usage and manipulation of numbers.
1,300
questions
234
votes
366
answers
65k
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 ...
192
votes
175
answers
20k
views
What is the smallest positive base 10 integer that can be printed by a program shorter (in characters) than itself?
I think the question as above is clear, but just in case:
Write a full program (not just a function) which prints a positive base 10 integer, optionally followed by a single newline.
Qualifying ...
168
votes
6
answers
18k
views
Hyperprogramming: N+N, N×N, N^N all in one
Write a program that takes in a number N from 1 to 9 inclusive. In its native form your program should output N+N. E.g. output 2 if N is ...
167
votes
70
answers
24k
views
How high can you count?
Challenge:
Your task is to write as many programs / functions / snippets as you can, where each one outputs / prints / returns an integer. The first program must output the integer ...
149
votes
330
answers
42k
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 ...
144
votes
93
answers
31k
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 ...
116
votes
27
answers
9k
views
Sort a list and write some English!
Your boss managed to read the secret hidden message. He didn't end up firing you, though, he just made you a secretary and forbade you from writing code.
But you're a programmer. You need to write ...
109
votes
36
answers
12k
views
What are the five most powerful characters in your language?
Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 permutations.
Choose your ...
103
votes
41
answers
13k
views
The Versatile Integer Printer
Write a piece of code that is executable in at least three different languages. The code must output the integer 1 in language number one, ...
100
votes
90
answers
17k
views
It was just a bug
Inspired by the bugged output in @Carcigenicate's Clojure answer for the Print this diamond challenge.
Print this exact text:
...
91
votes
109
answers
27k
views
4, 8, 15, 16, 23, 42 [closed]
4, 8, 15, 16, 23, 42
Write a program that outputs this sequence of numbers infinitely. However, The Numbers must not appear in your source code anywhere.
The following is not a valid Java program to ...
87
votes
75
answers
17k
views
Largest number in ten bytes of code [closed]
Your goal is to print (to the standard output) the largest number possible, using just ten characters of code.
You may use any features of your language, except built-in exponentiation functions.
...
86
votes
221
answers
16k
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 ...
85
votes
222
answers
17k
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 ...
84
votes
28
answers
6k
views
You're on a 8 day streak!
Duolingo, the language learning app, has a lot of things going for it, but there is one major issue that drives me crazy. It tells me how many days in a row I've used the app with a message like You'...
83
votes
192
answers
10k
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 ...
83
votes
55
answers
12k
views
Can you outgolf me? (Cops section)
Cops section
The robbers section can be found here.
Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.
Challenge
Your task is to write 2 ...
82
votes
73
answers
14k
views
Is this relationship creepy?
According to this XKCD comic, there is a formula to determine whether or not the age gap in a relationship is "creepy". This formula is defined as:
(Age/2) + 7
...
81
votes
43
answers
12k
views
Am I a Rude Number?
For a while now, I've been running into a problem when counting on my fingers, specifically, that I can only count to ten. My solution to that problem has been to count in binary on my fingers, ...
77
votes
62
answers
8k
views
Is it a Cyclops number? "Nobody" knows!
Task:
Given an integer input, figure out whether or not it is a Cyclops Number.
What is a Cyclops number, you may ask? Well, it's a number whose binary representation only has one ...
74
votes
97
answers
7k
views
Is the number binary-heavy?
An integer is binary-heavy if its binary representation contains more 1s than 0s while ignoring leading zeroes. For example 1 is ...
74
votes
16
answers
15k
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 ...
74
votes
13
answers
4k
views
Generate Dennis Numbers
This challenge is a tribute to PPCG user Dennis for winning the robbers' part of The Programming Language Quiz.
Looking at Dennis' PPCG profile page we can see some pretty impressive stuff:
He ...
73
votes
84
answers
6k
views
No strings (or numbers) attached
If you like this, consider participating in:
The Official Dyalog APL 2016 Year Game
The monthly Dyalog APL 2017 Code Golf Challenge
Make 12 snippets/expressions, in the same language, that result in ...
73
votes
29
answers
6k
views
2016 Time Capsule String: How Versatile Is Your Language?
About a year ago on Dec 31, 2015, I had the idea that:
We should make a time capsule string. Everybody gets to add one character and next new years we'll see who can make the best program out of all ...
68
votes
47
answers
9k
views
Compute the Kolakoski sequence
This is a repost of an old challenge, in order to adjust the I/O requirements to our recent standards. This is done in an effort to allow more languages to participate in a challenge about this ...
68
votes
27
answers
15k
views
xkcd-Style Page Numbering
Randall Munroe's book "xkcd, volume 0" uses a rather odd number system for the page numbers. The first few page numbers are
...
67
votes
161
answers
10k
views
Print all integers
Write a program or function which will provably print all integers exactly once given infinite time and memory.
Possible outputs could be:
...
67
votes
62
answers
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 ...
66
votes
170
answers
16k
views
Print 0 to 100 without 1-9 characters
Print integers 0 to 100 (inclusive) without using characters 123456789 in your code.
Separator of numbers can be comma or white space (by default <blank>, <...
66
votes
50
answers
8k
views
Increment The Time
Every digital clock contains a small creature that has to advance the time every minute [citation needed]. Due to the popularty of digital clocks and the popularity of catching them in the wild, they ...
66
votes
13
answers
4k
views
Operator precedence: How wrong can I be?
Say I have an expression:
9 * 8 + 1 - 4
This expression can be interpreted in six different ways, depending on operator precedence:
...
61
votes
90
answers
11k
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 ...
61
votes
26
answers
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
...
59
votes
57
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:
...
59
votes
18
answers
7k
views
Count like Chuck Norris
As is well known,
Chuck Norris counted to infinity. Twice
Besides,
Chuck Norris can count to infinity backwards.
Also, although perhaps less known, Chuck Norris can speak a little Spanish in ...
59
votes
13
answers
4k
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.
...
58
votes
258
answers
17k
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 ...
58
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.
...
58
votes
27
answers
4k
views
Expand the number
You may remember in first or second grade using expanded form to learn about place value of numbers. It's easier to explain with an example, so consider the number ...
57
votes
35
answers
7k
views
Superstitious hotel elevator
Description
Here's a very superstitious hotel elevator in Shanghai:
It avoids the number 13, because ...
55
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 ...
55
votes
9
answers
11k
views
Golf a number bigger than TREE(3)
The function TREE(k) gives the length of the longest sequence of trees T1, T2, ... where each vertex is labelled with one of k colours, the tree Ti has at most i vertices, and no tree is a minor of ...
54
votes
128
answers
18k
views
Is this number evil?
Introduction
In number theory, a number is considered evil if there are an even number of 1's in its binary representation. In today's challenge, you will be identifying whether or not a given number ...
54
votes
49
answers
26k
views
Outputting ordinal numbers (1st, 2nd, 3rd)
I would like to generate (as a return result of a function, or simply as the output of a program) the ordinal suffix of a positive integer concatenated to the number.
Samples:
...
53
votes
155
answers
10k
views
Stay away from zero
Task
Given a non-negative integer n, output 1 if n is 0,...
53
votes
34
answers
7k
views
Golf a transcendental number
Definitions
An algebraic number is a number that is a zero of a non-zero polynomial with integer coefficients. For example, the square root of 2 is algebraic, ...
53
votes
43
answers
3k
views
Illustrate the Least Common Multiple
Given two positive integers, \$A\$ and \$B\$, illustrate their least common multiple by outputting two lines of dashes (-) with length \$\text{lcm}\$\$(A, B)\$ ...
53
votes
11
answers
3k
views
Surrounded Countries
Countries own a series of territories on a 1D world. Each country is uniquely identified by a number. Ownership of the territories can be represented by a list as follows:
...
52
votes
81
answers
7k
views
It's Hip to be Square
Challenge
So, um, it seems that, while we have plenty of challenges that work with square numbers or numbers of other shapes, we don't have one that simply asks:
Given an integer ...