Questions tagged [integer]
For challenges involving the manipulation of integers.
463 questions
9
votes
4
answers
230
views
Finding Chord Segments with Integer Length
A math teacher wants to give his students an interesting geometry problem.
He has the following idea (Fig. 1):
Let \$AB\$ and \$CD\$ be two chords of a circle with center \$M\$, intersecting
...
14
votes
13
answers
632
views
Find the outcome of a Cortex Prime dice roll
In the Cortex Prime roleplaying game system, successes and failures are determined by rolling a pool of polyhedral dice of different sizes. After rolling the dice:
First, the player chooses two of ...
16
votes
25
answers
2k
views
Rebase Until Inert
This is a sequel to Numbers Interpreted in Smallest Valid Base.
Let us define the operation of rebasing a number as writing out its digits in decimal form, then interpreting them in the smallest base <...
18
votes
32
answers
2k
views
Add Y to X to get a palindrome
Given X>0, return the smallest Y>=0 such that X+Y is a palindrome. Code golf.
Tests:
5 => 0
14 => 8
200 => 2
819 => 9
1100 => 11
1122 => 99
20
votes
31
answers
2k
views
Numbers Interpreted in Smallest Valid Base
Let us define the operation of rebasing a number as writing out its digits in decimal form, then interpreting them in the smallest base N possible (...
90
votes
201
answers
12k
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 ...
18
votes
8
answers
1k
views
English to Dutch number order conversion
Introduction:
When saying numbers out loud, the order is slightly different in Dutch than in English. For a number like \$1234\$:
in English you'd say: one thousand, two hundred and thirty-four
in ...
12
votes
12
answers
809
views
Recursive cumulative sum [duplicate]
Challenge:
Given inputs \$i\$ and \$n\$, calculate \$R_i(n)\$ where:
$$R_0(n)=n \\
R_i(n)=\sum_{j=0}^nR_{i-1}(j)$$
Note that \$R_1\$ is triangular function, and \$R_2\$ is tetrahedral function.
This ...
35
votes
98
answers
9k
views
iHateOddNumbers
Task
Given a non-negative number, check if it's odd or even. In case it's even, output that number. Otherwise, throw any exception/error that your language supports, and stop the program.
Example with ...
11
votes
11
answers
965
views
Find a linear function such that if f(0), f(1), f(2), ⋯ are indices of the elements of the list, the sum must equal to its slope
Challenge:
Find integers \$a\$ and \$b\$ defining linear function \$f(x) = ax + b\$ with \$a > 0, b \ge 0\$ such that the sum of the elements of the input list \$l\$ located at the values of the ...
72
votes
177
answers
13k
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:
...
57
votes
172
answers
13k
views
Stay away from zero
Task
Given a non-negative integer n, output 1 if n is 0,...
12
votes
9
answers
2k
views
Pennies to Dollars
Over on Puzzling a couple years ago, Hermant Agarwal proposed the following question:
In a certain country the following coins are in circulation: 1 cent, 2 cents, 5 cents, 10 cents, 20 cents, 50 ...
33
votes
26
answers
9k
views
Print 4 billion if statements
Recently (okay, December 2023, I'm a little late) there's been a meme going around about a program checking if a 32-bit unsigned integer is even or odd using four billion if statements:
...
19
votes
12
answers
1k
views
Print Dyck paths
Definition
A Dyck path of length \$2n\$ can be defined as a two-dimensional path such that:
The path consists of straight lines of equal length.
The path goes left to right while moving either up or ...