Questions tagged [integer]

For challenges involving the manipulation of integers.

Filter by
Sorted by
Tagged with
18 votes
34 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
  • 46.5k
17 votes
21 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,497
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
  • 5,817
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
  • 607
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.1k
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
  • 771
9 votes
11 answers
733 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
  • 104k
15 votes
16 answers
833 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
  • 11.8k
17 votes
25 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
  • 46.5k
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
  • 8,618
29 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
  • 987
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
15 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,707
13 votes
11 answers
765 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
  • 8,618
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
  • 17.8k
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
  • 96.5k
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
  • 34k
9 votes
4 answers
586 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
505 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
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,253
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.4k
14 votes
7 answers
984 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
  • 46.5k
24 votes
25 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.4k
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 ...
Somebody's user avatar
  • 1,140
8 votes
5 answers
911 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,497
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.3k
10 votes
13 answers
1k views

Smallest numbers whose square has even number of digits

...
AZTECCO's user avatar
  • 10.6k
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
  • 34k
4 votes
19 answers
572 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
  • 683
12 votes
3 answers
291 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
275 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
  • 197
32 votes
21 answers
3k views

How-many-bonacci-like is this sequence?

Inspired by @emanresu A's Is it a fibonacci-like sequence? Make sure to upvote that challenge as well! We say a sequence is Fibonacci-like, if, starting from the third term (\$1\$-indexed), each term ...
alephalpha's user avatar
  • 46.5k
10 votes
3 answers
332 views

Coordinates for a Heronian tetrahedron

Did you know that Heronian Tetrahedra Are Lattice Tetrahedra? A Heronian tetrahedron is a tetrahedron where the length of each edge is an integer, the area of each face is an integer, and the volume ...
Peter Kagey's user avatar
  • 8,659
19 votes
33 answers
1k views

Sum of the first n elements of the sequence of 9's complement

Let's consider the following sequence: $$9,8,7,6,5,4,3,2,1,0,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71...$$ This is the sequence of \$9\$'s complement of a number: that is, \$ a(x) = 10^...
sinvec's user avatar
  • 1,885
14 votes
15 answers
1k views

How many blocks make a "truncated square-pyramid garden"?

A truncated square-pyramid of height \$h\$ has \$h\$ square layers where each layer has a side \$1\$ greater than the one above it, apart from the top layer which is a square of blocks with a given ...
Jonathan Allan's user avatar
30 votes
35 answers
3k views

Is it a fibonacci-like sequence?

The Fibonacci Sequence is a sequence of positive integers where the first two elements are 1 and the rest are the sum of the previous two. It begins \$1, 1, 2, 3, 5, 8, 13\$ and continues forever. But ...
emanresu A's user avatar
  • 35.6k
21 votes
21 answers
1k views

Is given number a concat of two squares

Given a positive integer, determine if it can be represented as a concatenation of two square numbers. Concatenated numbers may not begin with 0 (except for 0). Any leading zeros in input should be ...
Jan's user avatar
  • 237
17 votes
27 answers
2k views

Prime a*b+c of N

Given an integer \$N\$, print or return integers \$a\$, \$b\$, and \$c\$ that satisfy all of the following conditions, if such integers exist: \$a \times b + c = N\$ \$a\$, \$b\$, and \$c\$ are all ...
drmosley's user avatar
  • 757
6 votes
1 answer
204 views

Represent any integer with an expression that uses no digit besides '4' [closed]

Fourward (Introduction) I have an unhealthy obsession with the number 4. I love it so much, in fact, that seeing any other digit is frustrating to me. I therefour wish to create a 'Fourier ...
Aos Sidhe's user avatar
  • 169
10 votes
6 answers
515 views

Mirror an integer... in NDos' way

NDos' Numeral System NDos' numeral system is a numeral system invented by me. It represents every nonnegative integer by a binary tree. Given a nonnegative integer \$n\$: If \$n=0\$, it is ...
Dannyu NDos's user avatar
  • 5,497
16 votes
15 answers
1k views

Encode integers with some others

Input a non-empty array of positive (greater than 0) integers. Output another non-empty array of positive integers which encode the input array. Output array does not use any numbers used in the input ...
tsh's user avatar
  • 34k
26 votes
34 answers
2k views

Even sum subarrays

Given an array of integers, count the number of contiguous subarrays with an even sum. You may assume that the array is non-empty, and contains only non-negative integers. This is code-golf, so the ...
dingledooper's user avatar
  • 22.3k

1
2 3 4 5
9