Questions tagged [number]

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

Filter by
Sorted by
Tagged with
55 votes
10 answers
12k 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 ...
38 votes
15 answers
3k views

{Curly Numbers};

In the esoteric programming language Curly, programs consist solely of curly braces {} and semicolons ;. Despite this humble ...
34 votes
59 answers
5k views

Sum every second digit in a number

I have a number like this: n = 548915381 The output should be the sum of every second digit of that number. In this case 26: ...
24 votes
61 answers
3k views

Subtract my odds from my evens

Given a non-negative integer, return the absolute difference between the sum of its even digits and the sum of its odd digits. Default Rules Standard Loopholes apply. You can take input and provide ...
32 votes
29 answers
2k 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, ...
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 ...
86 votes
226 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 ...
34 votes
84 answers
4k views

Swap the parity

Task Given a positive integer n, output n+1 if n is odd, and output ...
27 votes
22 answers
8k views

1, 2, 4, 8, 16, ... 33?

Challenge Write a function/program that outputs either the n'th element, or the first n elements, in the well known number ...
23 votes
36 answers
2k views

Output "Fit" numbers

"Fit Numbers" Sam has a "brilliant" idea for compression! Can you help? Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller ...
41 votes
81 answers
5k views

As Easy as One-Two-Three

Write a program or function that takes in a positive integer. You can assume the input is valid and may take it as a string. If the number is any of ...
49 votes
25 answers
5k views

Ginormous number

Output this 1364-digit base-10 number: ...
24 votes
24 answers
2k views

Decipher a squashed sequence

Given a string containing a sequence of ascending consecutive positive integers, but with no separators (such as 7891011), output a list of the separated integers. ...
26 votes
44 answers
3k views

X Steps Forward, 1 Step Back

Here the first 100 numbers of an easy sequence: ...
150 votes
335 answers
44k 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 ...
60 votes
268 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 ...
23 votes
11 answers
3k views

Highly composite numbers

A highly composite number is a positive integer that has more divisors than any smaller positive integer has. This is OEIS sequence A002182. Its first 20 terms are ...
22 votes
26 answers
2k views

Borders of a Rectangular Matrix

Although it's done a few times as sub-challenge of a larger challenge, and we also have a challenge to remove the borders of a square matrix, I couldn't find a challenge to output the borders of a ...
45 votes
77 answers
7k views

Is this number triangular?

Challenge Given a positive integer, determine whether it is a triangular number, and accordingly output one of any two constant, distinct values. Definition A triangular number is a number that can be ...
57 votes
136 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 ...
235 votes
368 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 ...
12 votes
26 answers
2k views

Calculate all the squares up to x using only addition and subtraction

The goal is to calculate all the squares up to x with addition and subtraction. Rules: The code must be a function which takes the total number of squares to ...
11 votes
4 answers
625 views

Doors and guards

Related but noticeably different You are the leader of the guard in the dungeon of an ancient castle. There are N doors in the dungeon and ...
55 votes
160 answers
10k views

Stay away from zero

Task Given a non-negative integer n, output 1 if n is 0,...
26 votes
26 answers
3k views

How far from binary?

Given a decimal integer n as input, output the smallest (in terms of absolute value) decimal integer m such that the absolute ...
39 votes
26 answers
2k views

Basic ASCII Tallies

Alternate Title: Tally Your Prison Sentence on the Wall Given a number n, output tallies grouped into the traditional 5-per-group and 50 per row. Examples 1 ...
23 votes
64 answers
4k views

count ones in range

Challenge : Count the number of ones 1 in the binary representation of all number between a range. Input : Two non-decimal positive integers Output : The sum of ...
21 votes
34 answers
2k views

Reversed Squares

Given an integer n, your task is to determine whether it is a perfect square that when reversed, is still a perfect square. You may assume n is always positive. When numbers such as 100 (10x10) are ...
29 votes
39 answers
4k views

Convert a string of digits from words to an integer

Convert a string containing digits as words into an integer, ignoring leading zeros. Examples "four two" -> 42. ...
169 votes
73 answers
25k 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 ...
192 votes
180 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 ...
15 votes
16 answers
1k views

Pretty Palintiples

Imagine you have a positive integer number \$n\$. Let \$m\$ be the number obtained by reversing \$n\$'s digits. If \$m\$ is a whole multiple of \$n\$, then \$n\$ is said to be a reverse divisible ...
84 votes
193 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 ...
67 votes
165 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: ...
16 votes
54 answers
5k views

Find the minimum and maximum integers in an array, without using builtins

Challenge Given an array of integers, received from stdin, function arguments, program arguments, or some other method: Output only the minimum and maximum numbers in the array, through a return value,...
26 votes
47 answers
8k views

Distance between two points in n-dimensional space

Here is another simple one: The Challenge Given two points in an n-dimensional space, output the distance between them, also called the Euclidean distance. The coordinates will be rational numbers; ...
35 votes
54 answers
4k views

Generating a random alphanumeric string of length N

What is the shortest way of generating a random string with a given length and with only alphanumeric characters allowed? example of a random string: with N = 9 output would be ...
13 votes
72 answers
3k views

Summing the Digits of a Number

Challenge Given a non-negative integer, find the sum of its digits. Rules Your program must take a non-negative integer as input. Your program should output the sum of the digits of the input ...
42 votes
51 answers
5k views

Numbers that are actually letters

Given a non-negative integer input, write a program that converts the number to hexadecimal and returns a truthy value if the hexadecimal form of the number contains only the characters ...
144 votes
93 answers
32k 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 ...
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 ...
35 votes
28 answers
8k views

Could you please stop shuffling the deck and play already?

Challenge: Input: A list of distinct positive integers within the range \$[1, \text{list-size}]\$. Output: An integer: the amount of times the list is riffle-shuffled. For a list, this means the list ...
45 votes
45 answers
5k views

Find the largest number that's adjacent to a zero

Challenge: Take a vector / list of integers as input, and output the largest number that's adjacent to a zero. Specifications: As always, optional input and output format You may assume that there ...
7 votes
7 answers
443 views

Floating point numbers... dar nu-mă, nu-mă iei!

When you leave, my challenges fade to grey, 0A0AE16, 0A0A0AE16... A while ago, I made this programming language (https://esolangs.org/wiki/Dragostea_din_tei) which uses an interesting number system. ...
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 ...
100 votes
92 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: ...
14 votes
12 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 ...
24 votes
20 answers
2k views

Output two numbers (Cops' thread)

This is the cops' thread to a cops-and-robbers challenge. Click the link to find the robbers' thread. The challenge here is very simple. Create two programs of the same size, in the same language, ...
6 votes
2 answers
338 views

Compact Binary Representation

Background Often, when storing a number in binary with some maximum, we simply round the maximum to the next power of two then allocate the number of bits nececairy to store the whole range. Lets call ...
33 votes
34 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. ...

1
2 3 4 5
27