Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [integer]

For challenges involving the manipulation of integers.

Filter by
Sorted by
Tagged with
10 votes
19 answers
723 views

Construct a uInt from an array of bits

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
15 votes
24 answers
5k views

FizzFizzFizzBuzz!

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
18 votes
13 answers
1k views

Emulate Jelly's tie-scan

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
  • 38.4k
14 votes
14 answers
2k views

Break an integer into even- and odd-indexed bits

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
  • 5,951
2 votes
3 answers
192 views

Rank poker High Card hands [closed]

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

How quickly can you type this unary string?

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
  • 38.4k
10 votes
5 answers
953 views

Manipulate integers to zero

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
  • 5,951
18 votes
26 answers
2k views

Is it a tetrate of two?

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 ...
isaacg's user avatar
  • 42k
15 votes
21 answers
2k views

Divmod continuously until the remainder is 1 or 0, then get the remainder

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
  • 3,847
10 votes
12 answers
1k views

Counting Collinear Points

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,163
4 votes
1 answer
593 views

Which line is best?

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
  • 2,926
18 votes
39 answers
2k views

Rudin-Shapiro sequence

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
  • 48.2k
17 votes
23 answers
2k views

Monotone sequence beatitude

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
  • 5,951
11 votes
8 answers
2k views

Add two natural numbers

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,015
17 votes
14 answers
2k views

Finding the power sandwich version 2

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

Finding the power sandwich

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
3k views

Help, I can't bloody well memorize this number!

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

The multiples are missing

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.2k
24 votes
28 answers
3k views

Longest Consecutive Sequence

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 ...
Aitzaz Imtiaz's user avatar
23 votes
14 answers
2k views

Sum of consecutive nth powers

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
  • 783
9 votes
11 answers
742 views

Otteretto Classic game scoring method

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
  • 105k
15 votes
16 answers
840 views

Output the smallest increasing sequence where each term is coprime to preceding 3 terms

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
  • 12.6k
23 votes
31 answers
3k views

Is this a powerful number?

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
  • 48.2k
12 votes
15 answers
1k views

The number of solutions to Hertzsprung's Problem

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
  • 9,438
30 votes
10 answers
3k views

Implement grambulation

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 coinheringaahin g's user avatar
21 votes
8 answers
3k views

How many xor'ed waves?

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,007
13 votes
4 answers
1k views

Is it a Frog List?

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

A Fine sequence with fine interpretations

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
  • 3,737
14 votes
11 answers
772 views

Determine the Octet(/Duplet/18-electron) Rule

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
  • 9,438
22 votes
27 answers
3k views

Sum of Consecutive Squares

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.1k
22 votes
17 answers
3k views

Don't repeat yourself

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
  • 98.8k
23 votes
36 answers
2k views

Smallest Bit Rotation

For a given positive integer, try to find out the smallest possible rotation resulted by rotating it 0 or more bits. For example, when the given number is 177, whose binary representation is \$...
tsh's user avatar
  • 34.9k
9 votes
4 answers
597 views

RADD decomposition of an integer

Introduction The \$RADD(n)\$ operation is defined as the sum of \$n + [\$ the number whose decimal representation are the decimal digits of \$n\$ in reverse order \$]\$, see A004086. After reversal, ...
Hugo Pfoertner's user avatar
14 votes
4 answers
507 views

Find a matrix whose sliding sum is the input

Given a matrix like this: 1 1 3 -2 3 -4 1 -1 1 1 1 0 0 -1 0 0 By taking a 2×2 "sliding sum", where the sum of every 2×2 region of the matrix is ...
Rydwolf Programs's user avatar
16 votes
11 answers
1k views

Carryless factors

Carryless multiplication is an operation similar to binary long multiplication, but with XOR instead of addition: ...
Rydwolf Programs's user avatar
19 votes
25 answers
2k views

Carry-less sum given a base b

Given a list of positive integers \$\mathcal I=I_1,I_2,I_3,...,I_n\$ and a base \$b>1\$ return their "carry-less sum", i.e. represent \$\mathcal I\$ in base \$b\$ and sum digit-by-digit ...
loopy walt's user avatar
  • 16.7k
1 vote
5 answers
212 views

Find number components with lowest distribution

Let us assume that we have number X. Let us assume that we have positive integer "components" (C) of this ...
vpas's user avatar
  • 143
19 votes
9 answers
1k views

Cryptic Multiplications

Given two non-negative integers e.g. 27, 96 their multiplication expression would be 27 x 96 = 2592. If now each digits is ...
Domenico's user avatar
  • 2,273
22 votes
45 answers
2k views

Shifted auto-sum

Let’s take a positive integer such as 123. We define the shifted auto-sum of this integer as follows: 123 has 3 digits. We thus consider 3 copies of 123. We stack ...
Fatalize's user avatar
  • 38.7k
14 votes
7 answers
996 views

Exponential transform of an integer sequence

The exponential generating function (e.g.f.) of a sequence \$a_n\$ is defined as the formal power series \$f(x) = \sum_{n=0}^{\infty} \frac{a_n}{n!} x^n\$. When \$a_0 = 0\$, we can apply the ...
alephalpha's user avatar
  • 48.2k
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 ...
Fatalize's user avatar
  • 38.7k
10 votes
27 answers
2k views

Find the nth Fibonacci number, where n is the mth Fibonacci number

Introduction If \$\newcommand{\fib}{\operatorname{fib}}\fib(x)\$ calculates the \$x\$th Fibonacci number, write a program that calculates \$\fib(\fib(m))\$ for any integer value of \$m \ge 0\$. (Of ...
Someone's user avatar
  • 1,580
8 votes
5 answers
914 views

Spell out an integer... in NDos' way

Objective Given a positive integer, spell it out in the conlang I made. Specification Let \$n\$ be the inputted integer. \$n\$ shall be spelled out in the following specification. The entire spelling ...
Dannyu NDos's user avatar
  • 5,951
19 votes
6 answers
2k views

Is it 1089-able?

\$ 1089 \$ is a very special number. To prove why, select any 3-digit number whose first and last digits differ by at least 2. Then, reverse the digits, and take the difference of these two numbers. ...
dingledooper's user avatar
  • 22.7k
10 votes
13 answers
1k views

Smallest numbers whose square has even number of digits

...
AZTECCO's user avatar
  • 10.8k
13 votes
17 answers
1k views

The interstice of two binary numbers

Given two integers, compute the two numbers that come from the blending the bits of the binary numbers of equal length(same number of digits, a number with less digits has zeros added), one after the ...
LWS SWL's user avatar
  • 420
21 votes
26 answers
2k views

Randomly Rounding

Input a decimal number and round it to an integer, randomly rounding up or down with a probability based on its fractional part, so the expected value of the output equals to the input value. If ...
tsh's user avatar
  • 34.9k
4 votes
19 answers
573 views

Double bit rotation to the right [closed]

Given a positive integer as input, output that integer, but with its bits rotated two times to the right. Also, think of the number as a donut of bits, eg. ...
Joao-3's user avatar
  • 1,123
12 votes
3 answers
296 views

Line Islands in a Word Search

My third word search related challenge in a row. :) Challenge: Brief explanation of what a word search is: In a word search you'll be given a grid of letters and a list of words. The idea is to cross ...
Kevin Cruijssen's user avatar
4 votes
3 answers
277 views

Find All Digitroot Cyclic Sequences With Length Greater Than One

Digital sum, DR, Digit root is the iterative process of summing digits of a number until you end up with a single digit root number: e.g. digit root of 12345 is 6 since 1 + 2 + 3 + 4 + 5 = 15 = 1+5. ...
jixperson's user avatar
  • 195

1
2 3 4 5
9