Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [integer]

For challenges involving the manipulation of integers.

Filter by
Sorted by
Tagged with
18 votes
8 answers
1k views

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 ...
Kevin Cruijssen's user avatar
15 votes
18 answers
1k views

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 <...
SquareFinder's user avatar
20 votes
31 answers
2k views

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 (...
SquareFinder's user avatar
12 votes
12 answers
743 views

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 ...
Fmbalbuena's user avatar
  • 5,085
10 votes
2 answers
368 views

Task: Your task is make a program to check if there exists integers \$a \ge 2, b \ge 2\$ such that \$a^b=i\$ where \$i\$ is the input integer at least 2. The catch is that your program must return a ...
Fmbalbuena's user avatar
  • 5,085
11 votes
11 answers
784 views

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 ...
Fmbalbuena's user avatar
  • 5,085
19 votes
29 answers
2k views

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
Steve Bennett's user avatar
13 votes
9 answers
2k views

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 ...
caird coinheringaahing's user avatar
2 votes
13 answers
676 views

Task: Write a code golf program that, given two positive integers n and m, returns a list of the distances between consecutive prime numbers in the range [n, m] ...
JuanCa's user avatar
  • 361
19 votes
12 answers
1k views

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 ...
Luis Mendo's user avatar
  • 107k
3 votes
1 answer
299 views

Challenge We define a Minsky machine as a program made of the following two instructions: +X which increments the register X and continues to the next instruction -Xn which simply continues if X is ...
malediscord kitten's user avatar
4 votes
4 answers
580 views

Your task is to find a boolean expression that uses AND (\$\land\$), OR (\$\lor\$), XOR (\$\oplus\$), and NOT (\$\lnot\$) operators and binary digit positions (\$d_1,d_2,d_3,d_4,d_5,d_6,d_7,d_8,d_9,d_{...
Fmbalbuena's user avatar
  • 5,085
-5 votes
4 answers
205 views

Determine if a rational number is also an integer, without any form of dividing. The input should be any pair of numerator and denominator. Don't forget to consider negative numbers, and division by ...
Gabriel Tellez's user avatar
7 votes
1 answer
355 views

We learned many identities involving addition, multiplication and exponentiation in highschool, for example: $$ \begin{aligned} (a+b)c &= ac + bc \\ (a b)^c &= a^c b^c \\ (a^b)^c &= a^{bc} ...
Trebor's user avatar
  • 805
16 votes
21 answers
2k views

ZigZag encoding is a method of encoding signed integers to unsigned integers. Non-negative integers are multiplied by two. Negative integers are equal to their absolute values multiplied by two, minus ...
Jordan's user avatar
  • 11.9k
33 votes
26 answers
9k views

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: ...
emanresu A's user avatar
  • 46.2k
18 votes
11 answers
2k views

One way to approximate π is the following: Start by drawing a 2x2 square with a quarter-circle in it. Then, the area of the quarter-circle is π. We can approximate this area by filling it with ...
emanresu A's user avatar
  • 46.2k
12 votes
12 answers
1k views

Similar question to my previous one, but in reverse. This time I want you to encode an integer into a VarInt. Background: I'm not going to assume everyone's seen my previous question, so here is a ...
ThePlaneGuy45's user avatar
20 votes
13 answers
3k views

If you look at the reverse-engineered Minecraft Java Edition server protocol, there is an interesting integer encoding method that is used quite often called VarInt. It works like this: You have an ...
ThePlaneGuy45's user avatar
13 votes
27 answers
1k views

Task is simple! Take an array of binary values (can be boolean, 0/1, etc.) and use those bits to construct an n-th bit long unsigned integer (return type does not need to be an unsigned integer, just ...
ThePlaneGuy45's user avatar
16 votes
27 answers
5k views

Given a positive integer n, output the "FizzFizzFizzBuzz" sequence for that number: print the decimal representations of the numbers 1 through ...
3-1-4-One-Five's user avatar
24 votes
19 answers
2k views

The golfing language Jelly has a built-in ƭ called "tie", that cycles through a list of functions every time it's called. For example, ...
emanresu A's user avatar
  • 46.2k
14 votes
14 answers
3k views

Objective Given an integer \$n\$ interpreted as two's complement binary, output two integers, namely the integer consisting of \$n\$'s bits at places of \$2^0, 2^2, 2^4, \cdots\$, and the integer ...
Dannyu NDos's user avatar
  • 7,371
2 votes
3 answers
256 views

In the poker game there are 1277 unique 'High Card' ranks. It's 1287 (13 over 5) if we include all straights. The challenge is to write a function which returns an integer value corresponding to the ...
Ziarek's user avatar
  • 123
14 votes
7 answers
2k views

If I want to type the string aaa, the least keystrokes I can type it in is 3: a a a. But if I want to type the string ...
emanresu A's user avatar
  • 46.2k
10 votes
5 answers
1k views

Objective Given a nonempty unordered list of positive integers, decide whether they can be added, negated, or multiplied to yield a single zero. Each given number must be used exactly once. There is a ...
Dannyu NDos's user avatar
  • 7,371
19 votes
26 answers
2k views

The tetration operation consists of repeated exponentiation, and it is written ↑↑. For instance, 3↑↑3 =3 ^(3^3) = 3^27 = 7,625,597,484,987 A tetrate of two is an ...
izzyg's user avatar
  • 42.3k
20 votes
25 answers
2k views

The task is simple, divide, get the quotient and the remainder, and if the remainder isn't 1 or 0, do the same thing (quotient divmod remainder) until the remainder is 1 or 0, then get the remainder. ...
Fmbalbuena's user avatar
  • 5,085
13 votes
14 answers
2k views

Given two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ with integer coordinates, calculate the number of integer points (excluding the given points) that lie on the straight line segment joining these two ...
vengy's user avatar
  • 2,309
4 votes
1 answer
678 views

Consider an \$n \times n\$ grid of integers. The task is to draw a straight line across the grid so that the part that includes the top left corner sums to the largest number possible. Here is a ...
Simd's user avatar
  • 3,167
18 votes
39 answers
3k views

The Rudin-Shapiro sequence is a sequence of \$1\$s and \$-1\$s defined as follows: \$r_n = (-1)^{u_n}\$, where \$u_n\$ is the number of occurrences of (possibly overlapping) \$11\$ in the binary ...
alephalpha's user avatar
  • 51.9k
17 votes
23 answers
2k views

Provided that the input is a monotone sequence of three or more integers: Output -2 if the sequence strictly decreases. Example: [7,4,3,2] Output -1 if the ...
Dannyu NDos's user avatar
  • 7,371
11 votes
8 answers
2k views

Given two natural numbers (less than 100) as input print the sequence of intermediate results obtained when computing the sum of the two numbers using only the following operations1: ...
bsoelch's user avatar
  • 6,095
17 votes
14 answers
2k views

Introduction This question is inspired by this great question. Challenge Given a number \$N>0\$, output the largest integer \$a^b\$ that is smaller or equal to \$N\$, and the smallest integer \$c^d\...
Dmitry Kamenetsky's user avatar
15 votes
16 answers
2k views

Introduction Finding the closest power to a number is a common enough problem. But what if you need both the next-highest and next-lowest power? In this challenge you must find the closest powers to a ...
calvenable's user avatar
6 votes
7 answers
4k views

The Brits aren't exactly known for being good at memorizing stuff. That's why scientists need newspaper articles to find those who are, and that's why it shouldn't be a surprise that they forget more ...
leo848's user avatar
  • 637
15 votes
14 answers
1k views

Given a number \$n\$, you are to compute the sequence of positive numbers where for each number \$a\$, the \$n\$-times multiple \$n\cdot a\$ is missing. Example We always start with the sequence of ...
Laikoni's user avatar
  • 26.4k
25 votes
29 answers
3k views

Description Given a list of positive integers, write the shortest code to find the number count of the longest consecutive sequence of numbers within the list. Input A list of positive integers. You ...
aitzazisstuffed's user avatar
23 votes
14 answers
2k views

Related. Given a positive integer \$n\$, output all integers \$b\$ (such that \$1<b<n-1\$) where \$n\$ can be written as the sum of any number of consecutive powers of \$b\$. Example: Let's say \...
MTN's user avatar
  • 793
9 votes
11 answers
907 views

Brief description of the game In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. ...
Luis Mendo's user avatar
  • 107k
15 votes
16 answers
997 views

This sequence is defined as Starts with 1, 2, 3 The next element of the sequence is the first number greater than the previous three that is co-prime with each of the previous 3 elements in the ...
mousetail's user avatar
  • 14.4k
23 votes
31 answers
3k views

A powerful number is a positive integer \$n\$ such that for every prime \$p\$ that divides \$n\$, \$p^2\$ also divides \$n\$. Or equivalently, \$n\$ is powerful if and only if it can be written in the ...
alephalpha's user avatar
  • 51.9k
13 votes
15 answers
2k views

Hertzprung's Problem (OEIS A002464) is the number of solutions to a variant of the Eight Queens Puzzle, where instead of placing \$n\$ queens, you place \$n\$ rook-king fairy pieces (can attack like ...
bigyihsuan's user avatar
  • 11.4k
30 votes
10 answers
4k views

Consider the following spiral of positive integers: We now define grambulation as a binary operation \$\lozenge : \mathbb N \times \mathbb N \to \mathbb N\$, using this grid. Some example inputs and ...
caird coinheringaahing's user avatar
23 votes
9 answers
3k views

In this challenge, you're given a list of overlapping waves. Each wave is a finite list with n truthy values, then n falsy ...
Peter's user avatar
  • 1,067
13 votes
4 answers
1k views

Challenge: A Frog List is defined by certain rules: Each frog within a Frog List has an unique positive digit [1-9] as id (any 0...
Kevin Cruijssen's user avatar
13 votes
17 answers
1k views

The ubiquitous Catalan numbers \$C_n\$ count the number of Dyck paths, sequences of up-steps and down-steps of length \$2n\$ that start and end on a horizontal line and never go below said line. Many ...
Parcly Taxel's user avatar
  • 4,749
14 votes
11 answers
885 views

Given an atomic number in the inclusive range [1,118], write the shortest program/function that outputs one of {2,8,18} if the ...
bigyihsuan's user avatar
  • 11.4k
22 votes
27 answers
3k views

Your task Given a integer input, \$ n \$ (such that \$ n > 1 \$), decide whether it can be written as the sum of (at least 2) consecutive square numbers. Test cases Truthy: ...
The Thonnu's user avatar
  • 18.7k
22 votes
17 answers
3k views

In this challenge you will be tasked with implementing a sequence of natural numbers such that: Each number appears a natural number of times No two numbers appear the same number of times No two ...
Wheat Wizard's user avatar
  • 103k

1
2 3 4 5
10