Questions tagged [number]

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

Filter by
Sorted by
Tagged with
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 ...
Dennis's user avatar
  • 210k
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 ...
C. K. Young's user avatar
  • 4,917
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 ...
Vereos's user avatar
  • 4,433
30 votes
8 answers
3k views

crossed out 44 is still regular 44 ;(

Introduction On March 24th, 2015 @isaacg golfed his Pyth answer from 44 to 42 bytes. Since a crossed out 44 (44) looks a lot like a regular 44, @Optimizer made the following comment: striked out ...
Kevin Cruijssen's user avatar
33 votes
33 answers
3k 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. ...
HeyLlama's user avatar
  • 461
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 ...
vrwim's user avatar
  • 2,499
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 ...
GarethPW's user avatar
  • 1,299
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 ...
Shaggy's user avatar
  • 41.6k
16 votes
9 answers
2k views

Base Conversion With Strings

Introduction We've have a few base conversion challenges here in the past, but not many designed to tackle arbitrary length numbers (that is to say, numbers that are long enough that they overflow the ...
Mwr247's user avatar
  • 3,574
47 votes
35 answers
14k views

XOR multiplication

You goal is to implement the operation of XOR (carryless) multiplication, defined below, in as few bytes as possible. If we think of bitwise XOR (^) as binary ...
xnor's user avatar
  • 144k
11 votes
7 answers
799 views

Determine the position of a non-negative number in the infinite spiral

Definition The infinite spiral used in this question has 0 on the position (0,0), and continues like this: ...
Leaky Nun's user avatar
  • 49.6k
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, ...
Stewie Griffin's user avatar
37 votes
43 answers
8k 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 ...
mbomb007's user avatar
  • 23.3k
35 votes
20 answers
9k 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. ...
user avatar
25 votes
29 answers
3k views

Different Way Forward

Given a list of integers produce a Forward Difference at a specified order/depth. For the list of integers: (10, 18, -12, 4, 8, -3, -5, 67, 9, 14) The Forward ...
MickyT's user avatar
  • 12.2k
26 votes
6 answers
2k views

The Coin Problem

Background The official currency of the imaginary nation of Golfenistan is the foo, and there are only three kinds of coins in circulation: 3 foos, 7 foos and 8 foos. One can see that it's not ...
Zgarb's user avatar
  • 42.5k
25 votes
11 answers
4k views

Generate a Kolakoski sequence [duplicate]

Definition1 A Kolakoski sequence is a self-describing infinite sequence {kn} of alternating blocks of 1's and 2's, given by the following rules: k0 = 1 kn = the length of the (n+1)'th ...
ardnew's user avatar
  • 2,329
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 ...
Arandur's user avatar
  • 1,939
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 ...
Stewie Griffin's user avatar
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 ...
user avatar
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 ...
Adám's user avatar
  • 29.9k
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 ...
PyRulez's user avatar
  • 7,197
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: ...
Nicole's user avatar
  • 643
44 votes
68 answers
8k views

I reverse the source code, you negate the input!

Blatant rip-off of a rip-off. Go upvote those! Your task, if you wish to accept it, is to write a program/function that outputs/returns its integer input/argument. The tricky part is that if I ...
Adám's user avatar
  • 29.9k
44 votes
90 answers
7k views

Notcalc (Calculate the wrong answer)

Goal: Given two natural numbers (integers from 0 to infinity), output a number that is not the sum of those numbers, but is a natural number. Example solutions (TI-Basic): ...
Julian Lachniet's user avatar
37 votes
29 answers
6k views

Find the number in the Champernowne constant

Introduction In base 10, the Champernowne constant is defined by concatenating representations of successive integers. In base 10: 0.1234567891011121314151617... ...
Adnan's user avatar
  • 44.3k
36 votes
49 answers
5k views

Generate Monday Numbers

Monday numbers, as defined by Gamow in this question over on Puzzling, are positive integers N with the following three properties: The decimal representation of N does not contain the digit 0 The ...
AdmBorkBork's user avatar
  • 43.3k
17 votes
105 answers
8k views

Turn an integer n into a list containing it n times [closed]

Given an integer n as input, return a list containing n, repeated n times. For example, the ...
Bruno E's user avatar
  • 425
13 votes
7 answers
2k views

Mixed Base Conversion

Background Most people on here should be familiar with several base systems: decimal, binary, hexadecimal, octal. E.g. in the hexadecimal system, the number 1234516 would represent ...
Martin Ender's user avatar
11 votes
21 answers
997 views

Return each number from a group of numbers

The challenge The program must return all numbers included into a group (comma and hyphen separated sequence) of numbers. Rules s is the sequence string; all ...
BernaMariano's user avatar
11 votes
5 answers
3k views

Implement t9-like functionality

Your challenge today is to implement a t9-like functionality. You will implement a function that will only have 2 parameters. You will receive 1 phone number in a string and the content of a text ...
Ismael Miguel's user avatar
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. ...
Ypnypn's user avatar
  • 10.8k
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: ...
Fatalize's user avatar
  • 38.4k
36 votes
11 answers
3k views

Encode an integer

Given positive integer n > 2. We convert it to an array as follows: If it is equal to 2 return an empty array Otherwise ...
user avatar
30 votes
144 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 ...
anna328p's user avatar
  • 6,336
29 votes
26 answers
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, ...
Luis Mendo's user avatar
  • 104k
28 votes
18 answers
3k views

Generate a pair of integers from a non-negative one

You should write a program or function which takes a non-negative integer N as input and outputs or returns two integers (negative, zero or positive) ...
randomra's user avatar
  • 20.8k
28 votes
9 answers
3k views

Spell out numbers in French

There was a challenge to convert a number to its numeral in English, but that was too straightforward. Given a number 0–100, your task is to output the corresponding numeral in French. The French ...
NinjaBearMonkey's user avatar
26 votes
11 answers
4k views

Flipping pancakes

In pancake sorting the only allowed operation is to reverse the elements of some prefix of the sequence. Or, think of a stack of pancakes: We insert a spatula somewhere in the stack and flip all the ...
daniero's user avatar
  • 18.6k
22 votes
26 answers
10k views

List Prime Numbers [duplicate]

Introduction Prime numbers are simple, right? Well, now you get your chance to find out! Challenge You must write a program or function that takes an input n and ...
Elliot A.'s user avatar
  • 454
21 votes
10 answers
2k views

Prime factors buddies

Given an integer N > 1, output all other numbers which prime decompositions have the same digits as the prime decomposition of ...
Fatalize's user avatar
  • 38.4k
19 votes
2 answers
873 views

Dames, do some math!

The order of operations, PEMDAS, is a basic rule in mathematics telling us which order operations should be performed: "Parentheses, Exponents, Multiplication and Division, and Addition and ...
Stewie Griffin's user avatar
12 votes
10 answers
684 views

New Order #1: How does this feel?

Introduction Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. ...
agtoever's user avatar
  • 2,881
2 votes
8 answers
1k views

Compute the number of ways how you can express a number as a sum [closed]

For a given natural number n, compute the number of ways how one can express n as a sum of positive natural numbers. For example,...
Petr's user avatar
  • 4,362
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 ...
Calvin's Hobbies's user avatar
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 ...
Calvin's Hobbies's user avatar
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 ...
Adám's user avatar
  • 29.9k
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 ...
Martin Ender's user avatar
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>, <...
user avatar
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 ...
Amphibological's user avatar

1
2 3 4 5
9