Questions tagged [integer]

For challenges involving the manipulation of integers.

Filter by
Sorted by
Tagged with
33
votes
26answers
3k views

Find the nearest greater number

The task Given any array of integers, e.g.: [-1,476,578,27,0,1,-1,1,2] and an index of that array (this example uses 0 based indexing, though you can use 1 based ...
24
votes
31answers
3k views

"-rot" transform

Background -rot transform (read as "minus-rot transform") is a sequence transformation I just invented. This transform is done by viewing the sequence as a stack in Forth or Factor (first ...
23
votes
37answers
2k views

Generate this number table

Given an integer \$1 < n < 10 \$ generate a table like below. For \$n = 5\$, 1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5 For \$n = 8\$, ...
81
votes
175answers
8k 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 ...
17
votes
10answers
1k views

Minimally prepend numbers to get a symmetric Young diagram

Background A Young diagram is a diagram that represents a nonincreasing sequence of positive integers using left-justified rows of squares. As an example, 5, 4, 1 ...
2
votes
7answers
207 views

Bijective mapping from integers to a variable number of trits

This challenge is a harder version of this one. A variable number of trits is an array of 0 or more trits (a trit is a ternary digit). So [0, 2, 2, 1] is a ...
37
votes
34answers
6k views

Reduce a number by its largest digit

Task: Given an integer number in decimal number system, reduce it to a single decimal digit as follows: Convert the number to a list of decimal digits. Find the largest digit, D Remove D from the ...
21
votes
39answers
2k views

Print a conversion table for (un)signed bytes

Your task: Print or return a conversion table with every byte from 00 to ff's value as an unsigned integer, to its value as a ...
21
votes
22answers
3k views

Longest Zero Sum Sub-array

Given an array of integers. Find out its longest sub-array (contiguous subsequence) whose sum is 0. The sub-array for output may be an empty array. Input Input an array of integers. Output Output the ...
10
votes
8answers
904 views

Boustrophedon transform

Related: Boustrophedonise, Output the Euler Numbers (Maybe a new golfing opportunity?) Background Boustrophedon transform (OEIS Wiki) is a kind of transformation on integer sequences. Given a sequence ...
64
votes
52answers
6k views

N-dimensional N^N array filled with N

In: Enough memory and a positive integer N Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by... Examples: 1: [1] ...
15
votes
33answers
2k views

2 factors factorization

Given a natural number n write a program or function to get a list of all the possible two factors multiplications that can be used to achieve ...
18
votes
24answers
2k views

Find the Serialized Integer

Task Write a program that will take (as input) a positive integer. It will then count up from 0, appending each integer to a ...
14
votes
25answers
2k views

Make an array of 128 bit integers

Given an input value \$n\$, construct an array of \$n\$ random 128 bit (unsigned) integers. The integers should be uniformly random. Your code can use any in built random number generation function ...
7
votes
4answers
306 views

Hexagonal section numbers

Introduction Let's draw some regular hexagons formed by hexagonal tiles, marking the vertices of the tiles with dots. Then we will count the number of dots. ...
22
votes
23answers
2k views

Complete a sequence using its distances

Given \$A = (a_1,\dots,a_k)\ k\ge2 \$ a sequence of positive integers, in which all elements are different. Starting from \$i=2\$, while \$a_i\in A:\$ (until the last element) If \$d=|a_i-a_{i-1}|\$ ...
36
votes
15answers
2k views

Maximum number of squares touched by a line segment

Consider a square grid on the plane, with unit spacing. A line segment of integer length \$L\$ is dropped at an arbitrary position with arbitrary orientation. The segment is said to "touch" ...
37
votes
50answers
3k views

(RGS 1/5) Binary multiples

A binary multiple of a positive integer k is a positive integer n such that n is written ...
17
votes
4answers
532 views

Calculate the integer square root of a matrix

Let \$A\$ be a square matrix that is at least \$2 \times 2\$ where each element is an integer. \$A^2 = A \times A\$ will then have the same dimensions as \$A\$, and will have integer elements. For ...
28
votes
27answers
3k views

Pigeonhole Principle & Code Golf

The pigeonhole principle states that If N items are put into M boxes, with N > M, then at least one box must contain more than one item. For many, this principle has a special status compared to ...
51
votes
33answers
7k views

Conway's Monster

This challenge is in honor of mathematician John Conway who passed away April 11, 2020 due to COVID-19. He was famous for coming up with the Game of Life cellular automaton and many other mathematical ...
15
votes
19answers
1k views

Compare positions of integers in this sequence

A001057 is one way to represent an integer as a natural number. It lists them according to the following pattern: 0, 1, -1, 2, -2, 3, -3, 4, -4, ... In this ...
5
votes
5answers
205 views

Potential nonzero entries in an irregular sequence

Background A338268 is a sequence related to a challenge by Peter Kagey. It defines a two-parameter function \$T(n,k)\$, which counts the number of integer sequences \$b_1, \cdots, b_t\$ where \$b_1 + \...
24
votes
65answers
6k 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 ...
47
votes
52answers
7k views

Is this number an integer power of -2?

There are clever ways of determining whether a number is a power of 2. That's no longer an interesting problem, so let's determine whether a given integer is an integer power of -2. For example: <...
19
votes
3answers
366 views

Decompress an integer, Jelly style

Jelly has compressed string literals, using the “...» delimiters. The way these work is by interpreting the ... as a base-250 ...
5
votes
3answers
147 views

Is this an ordinal transform? [duplicate]

Related: What's my telephone number? which asks to calculate the terms of A000085, the number of possible ordinal transforms of length n. Background Ordinal transform is a transformation on an integer ...
26
votes
68answers
5k views

How long is my number?

Challenge Given an integer \$Q\$ in the range \$-2^{100} ≤ Q ≤ 2^{100}\$, output the number of digits in that number (in base 10). Rules Yes, you may take the number as a string and find its length. ...
19
votes
29answers
1k views

Inverse Deltas of an Array

Your task is to, given an array of signed 32 bit integers, recompile it with its inverse deltas. For example, the list 1 3 4 2 8 holds the deltas: ...
50
votes
47answers
5k views

Increment an Array

Given a nonempty array of positive integers, "increment" it once as follows: If all the array elements are equal, append a 1 to the end of the array. For example: ...
19
votes
26answers
2k views

A bit of a digital XOR

Here are the first 100 numbers of a sequence: ...
21
votes
40answers
3k views

X Steps Forward, 1 Step Back

Here the first 100 numbers of an easy sequence: ...
21
votes
23answers
3k views

Rotated Position of Integers

Challenge: Input: A sorted list of positive integers. Output: The amount of integers which are still at the exact same index, after rotating the digits in each integer its index amount of times ...
11
votes
6answers
769 views

Golf this Thumb-2 Constant!

One thing that is constantly frustrating when golfing ARM Thumb-2 code is generating constants. Since Thumb only has 16-bit and 32-bit instructions, it is impossible to encode every immediate 32-bit ...
62
votes
150answers
9k 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: ...
27
votes
38answers
3k views

Is this a Permutation of 1..n

Input a non-empty array with \$n\$ positive integers. Test if the input array contains every integer in \$1\cdots n\$. In case you prefer 0-indexed numbers, you may choose to input an array of non-...
37
votes
80answers
4k views

Output the missing integer

You will be given a string. It will contain 9 unique integers from 0-9. You must return the missing integer. The string will look like this: ...
26
votes
17answers
2k views

Give me odd, even, square, cube, prime and composite 3-digit numbers

Given a string which is guaranteed to be either odd, even, square, ...
17
votes
20answers
882 views

Binomial transform

Background Binomial transform is a transform on a finite or infinite integer sequence, which yields another integer sequence. The binomial transform of a sequence \$\{a_n\}\$ is given by $$s_n = \sum_{...
27
votes
22answers
1k views

Consecutive Distance Rating

We'll call the consecutive distance rating of an integer sequence the sum of the distances between consecutive integers. Consider 2 9 3 6 8 1. ...
25
votes
12answers
2k views

Collatz's ice cream cone factory

The Collatz sequence Given a positive integer \$a_1\$, the Collatz sequence with starting value \$a_1\$ is defined as \begin{equation} a_{n+1} = \begin{cases} a_n/2 & \mathrm{if}\ a_n\ \mathrm{is}\...
18
votes
45answers
2k views

Generate list of numbers and their negative counterparts

A recent SO question asks for a convenient one-liner to generate a list of numbers and their negative counterparts in Python. Given two integers \$1≤a≤b\$, generate all the integers \$x\$ such that \$...
26
votes
82answers
5k views

Is it a whole number?

A number is whole if it is a non-negative integer with no decimal part. So 0 and 8 and ...
18
votes
20answers
2k views

Gödel numbering of a string

Background Gödel numbers are a way of encoding any string with a unique positive integer, using prime factorisations: First, each symbol in the alphabet is assigned a predetermined integer code. Then, ...
47
votes
142answers
9k views

Stay away from zero

Task Given a non-negative integer n, output 1 if n is 0,...
23
votes
41answers
4k views

Round up my number

Sandbox Given two positive integers a and b, return the smallest multiple of b that is greater than or equal to a. Examples Definitions: true = ...
30
votes
31answers
2k views

Ken Iverson’s Favourite APL Expression?

Ken Iverson, 1920–2020 Let's implement his favourite expression: Given a row of Pascal's triangle, compute the next row. This can for example be computed by taking the input padded with a zero on the ...
16
votes
34answers
2k views

Implement a zipwith function

zipwith is a functional construct that takes three arguments: one binary function and two lists of the same length, and returns a single list where each element is ...
17
votes
10answers
2k views

Reciprocal copycats

Let \$A\$ be a positive integer consisting of \$n\$ decimal digits \$d_1,d_2,...,d_n\$. Let \$B\$ be another positive integer. For the purpose of this challenge, we call \$A\$ a copycat of \$B\$ if ...
36
votes
59answers
6k views

Is my barcode valid?

An EAN-8 barcode includes 7 digits of information and an 8th checksum digit. The checksum is calculated by multiplying the digits by 3 and 1 alternately, adding the results, and subtracting from the ...

1
2 3 4 5
8