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
211
votes
309answers
51k 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 ...
186
votes
156answers
18k 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 ...
162
votes
66answers
23k 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 ...
160
votes
5answers
14k 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 ...
122
votes
257answers
30k 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 ...
118
votes
74answers
25k 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 ...
105
votes
35answers
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 ...
102
votes
22answers
8k 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 ...
97
votes
39answers
12k 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, ...
91
votes
109answers
24k 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 ...
85
votes
28answers
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
54answers
11k 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 ...
80
votes
68answers
15k views

Largest number in ten bytes of code

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. ...
80
votes
76answers
15k 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: ...
76
votes
39answers
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, ...
75
votes
183answers
13k 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 ...
74
votes
158answers
8k 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 ...
73
votes
13answers
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 ...
72
votes
63answers
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 ...
70
votes
27answers
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 ...
69
votes
79answers
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 ...
69
votes
13answers
12k 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 ...
68
votes
165answers
14k 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 ...
68
votes
47answers
7k 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 ...
66
votes
26answers
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 ...
65
votes
13answers
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: ...
59
votes
77answers
6k 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 ...
59
votes
54answers
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 ...
59
votes
18answers
6k 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
27answers
3k 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 ...
58
votes
43answers
7k 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 ...
58
votes
25answers
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 ...
57
votes
139answers
9k 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: ...
56
votes
11answers
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. ...
55
votes
146answers
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. ...
55
votes
33answers
6k views

Superstitious hotel elevator

Description Here's a very superstitious hotel elevator in Shanghai:                 It avoids the number 13, because ...
53
votes
10answers
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
47answers
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 ...
52
votes
42answers
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 LCM(A, B) after replacing every Ath ...
51
votes
78answers
9k views

Do n and n^3 have the same set of digits?

Given a number n (0 <= n <= 2642245), check if n and n3 have the same set of digits, and output a truthy or falsey value accordingly. For example, let's check the number 100. 1003 is 1000000. ...
51
votes
43answers
9k views

The Snail in the Well

Background There's a common riddle that goes something like this: A snail is at the bottom of a 30 foot well. Every day the snail is able to climb up 3 feet. At night when they sleep, they slide ...
51
votes
11answers
3k views

Bringing a pair of integers to equality

This was inspired by a math problem I saw somewhere on the internet but do not remember where (UPDATE: The original problem was found on the math riddles subreddit with a proof provided that it is ...
50
votes
233answers
14k 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 ...
50
votes
12answers
5k views

5, 2, 16, 3580, What comes next?

Consider the positive integer powers of five in decimal. Here are the first 25, right aligned: ...
49
votes
6answers
9k 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 ...
48
votes
30answers
6k 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, ...
48
votes
14answers
4k views

Fissile Numbers

I found this sequence while working on Evolution of OEIS, but never got around to posting it as an answer. After writing a reference implementation in Mathematica, I thought this is a fun exercise to ...
47
votes
41answers
17k 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: ...
47
votes
16answers
7k views

Attack, Decay, Sustain, Release

Sound synthesizers use envelope generators to control how certain parameters of the sound (such as overall loudness) change with time. In many synthesizers an envelope is defined by four parameters, ...
47
votes
3answers
4k views

Coding Around The Clock

Write a single line program two or more characters long that contains no line terminators and takes no input. For example, your program might be: MyProgram When ...

1
2 3 4 5
23