# Questions tagged [integer]

For challenges involving the manipulation of integers.

84 questions
Filter by
Sorted by
Tagged with
47answers
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:  ...
97answers
6k views

### Turn an integer n into a list containing it n times

Given an integer n as input, return a list containing n, repeated n times. For example, the ...
120answers
7k 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: ...
42answers
2k views

### Least Common Multiple

The least common multiple of a set of positive integers A is the smallest postive integer B such that, for each ...
46answers
4k views

### Sort an Integer List

The Challenge It's quite simple really, sort a list of numbers. Details You must sort a list of numbers in ascending order, without using any built-in sorting functions/libraries/etc (i.e. ...
141answers
7k 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 ...
69answers
8k views

### Check whether an integer is a power of 2 without using +,- operations [closed]

Write a program that checks if the integer is a power of 2. Sample input: 8 Sample output: Yes Sample input: ...
39answers
4k views

### Smallest palindrome divisible by the input

Given a positive integer N, output the smallest positive integer such that this number is a palindrome (i.e. is its own reverse) and is divisible by ...
15answers
2k views

### All the single eights

Given a non-empty rectangular array of integers from 0 to 9, output the amount of cells that are ...
8answers
521 views

### Bijective mapping from integers to a variable number of bits

A variable number of bits is an array of 0 or more bits. So [0, 1] is a variable number of bits, but so is []. Write a function ...
36answers
3k views

### Find the unique twins

You will be given two Arrays / Lists / Vectors of non-negative integers A and B. Your task is to output the highest integer N that appears in both A and B, and is also unique in both A and B. You ...
11answers
5k views

### Is this number an exact power of -2: (Very) Hard Mode

This is a version of the recent challenge Is this number an integer power of -2? with a different set of criteria designed to highlight the interesting nature of the problem and make the challenge ...
56answers
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). ...
26answers
2k views

### Divisor skyline

For any positive integer k, let d(k) denote the number of divisors of k. For example, ...
40answers
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: <...
27answers
4k views

### Cops: The Hidden OEIS Substring

This is a Cops and Robbers challenge. This is the cop's thread. The robber's thread is here. As a cop, you must pick any sequence from the OEIS, and write a program p that prints the first integer ...
8answers
2k views

### Find number of ones to get a number using + and *

Introduction Your goal is to find the least number of ones you need to add or multiply together to get the input value, this is A005245. Input One positive integer N. Output The smallest number ...
50answers
3k views

### Output integers in negative order, increase the maximum integer everytime

Main task Your task is to print out integers in descending order, starting from 1, and increasing as you keep hitting 1 again, up until the given input is reached, then, print out the rest until you ...
39answers
2k views

### An Array of Challenges #1: Alternating Arrays

Alternating Arrays An alternating array is a list of any length in which two (not necessarily different) values are alternating. That is to say, all even-indexed items are equal, and all odd-indexed ...
34answers
3k views

### Is it a Mersenne Prime?

A number is a Mersenne Prime if it is both prime and can be written in the form 2n-1, where n is a positive integer. Your task is to, given any positive integer, determine whether or not it is a ...
47answers
4k views

### Which Card is it?

Introduction Long ago, when I used to code card games with usual playing cards, I used to specify a number for each card and call a function with some number to get a card. This somewhat inspired me ...
12answers
1k views

### Polynomialception

Given two polynomials f,g of arbitrary degree over the integers, your program/function should evaluate the first polynomial in the second polynomial. ...
57answers
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 ...
33answers
2k views

### Digits in their lanes

Input: A list of integers Output: Put each digit (and the minus sign) in its own lane, in the order -0123456789, ignoring any duplicated digits. Example: Input:...
4answers
4k views

### The happy Ender problem

The happy ending problem (actually a theorem) states that Any set of five points in the plane in general position has a subset of four points that form the vertices of a convex quadrilateral. The ...
8answers
766 views

### Spiral neighbourhoods

If we take the natural numbers and roll them up counter clock-wise into a spiral we end up with the following infinite spiral: ...
24answers
1k views

### Inverse Deltas of an Array

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 ...
13answers
2k views

### Skip like a frog!

Given an array of non-negative integers, your task is to only keep certain elements of it, as described below. Let's say the array is ...
26answers
5k views

### Oddly Even, Positively Negative

Given N, output the Nth term of this infinite sequence: -1 2 -2 1 -3 4 -4 3 -5 6 -6 5 -7 8 -8 7 -9 10 -10 9 -11 12 -12 11 ... etc. N may be 0-indexed or 1-...
41answers
3k views

### Find the sum of all numbers below n that are a multiple of some set of numbers

Almost equivalent to Project Euler's first question: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find ...
3answers
2k views

### The Path Of The Wildebeest

Golf a program or function which gives the $n^{\text{th}}$ location of the wildebeest who starts at square $1$ on an infinite chessboard which is numbered in an anti-clockwise square spiral, where ...
8answers
1k views

### Decompose a number into triangles

Given an integer n, decompose it into a sum of maximal triangular numbers (where Tm represents the mth triangular number, or the sum of the integers from 1 to m) as follows: while n > 0, find the ...
5answers
161 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 ...
32answers
11k views

### What are the five most powerful characters in your language?

Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 ...
22answers
2k views

### Frequency Distribution of Multiple Dice Rolls

Given two positive integers a and b, output the frequency distribution of rolling a b-sided ...
17answers
2k views

### Find Integral Roots of A Polynomial

Challenge The challenge is to write a program that takes the coefficients of any n-degree polynomial equation as input and returns the integral values of x for which the equation holds true. The ...
64answers
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: ...
34answers
4k views

### Make a Spiky Box

Given two positive integers, W and H, output an ASCII-art box whose border is made of slashes (/ and \) with W "spikes" on the ...
30answers
2k views

### Let's design a digit mosaic

Challenge Given a positive integer $N$, repeat each of its digits $d_1, d_2, d_3, \cdots, d_n$ a number of times corresponding to its position in $N$. In other words, each digit $d_k$ should ...
25answers
2k views

### Reverse Deltas of an Array

Reverse Deltas of an Array A continuation of Inverse Deltas of an Array Your task is to take an array of signed 32 bit integers, recompile it with its deltas reversed. Example The List, ...
29answers
4k views

### Find the closest palindromic number

Given a number N, output/return X so that N+X is a palindrome, where |X| has to be as small as possible. Palindrome: A number is a palindrome, if its sequence of digits is the same when reading them ...
18answers
5k views

### Simplistic Lava Lamp

Introduction: I think everyone knows what a Lava Lamp is, but in case they do not: (Image source) They're basically glass tubes that contain wax in a translucent liquid. The bottom part is heated ...
33answers
2k views

### How many unique primes?

One way to represent a natural number is by multiplying exponents of prime numbers. For example, 6 can be represented by 2^1*3^1, and 50 can be represented by 2^1*5^2 (where ^ indicates exponention). ...
3answers
536 views

### Summation under Zeckendorf Representation

Zeckendorf's theorem shows that every positive integer can be uniquely represented as a sum of non-adjacent Fibonacci numbers. In this challenge, you have to compute the sum of two numbers in ...
42answers
3k views

### Illustrate the Least Common Multiple

Given two positive integers, A and B, illustrate their least common multiple by outputting two lines of dashes (-) with length LCM(A, B) after replacing every Ath ...
32answers
6k views

### Never tell me the odds

Input A integer n ( ≥ 1) and a digit d (an integer such that 0 ≤ d ≤ 9). In either order; from stdin or parameters or whatever; to a program or function; etc. ...
14answers
1k views

### An Array of Challenges #2: Separate a Nested Array

Note: This is #2 in a series of array-manipulation challenges. For the previous challenge, click here. Separating Nested Lists To separate values in a nested list, flatten it, and then wrap each ...
61answers
5k views

### Find the highest unique digit

Surprisingly we haven't had a simple "find the highest digit" challenge yet, but I think that's a little too trivial. Given input of a non-negative integer, return the highest unique (ie not repeated)...
13answers
3k views

### Valid Badminton Score?

Introduction: I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. ...
19answers
2k views

### The Written Digits Sequence

Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences. Start with an empty sequence then define each term as the number of characters required to write out,...