Questions tagged [integer]

For challenges involving the manipulation of integers.

20
votes
32answers
3k views

Swap the Endianness

As most of you probably know, (byte-addressable) hardware memories can be divided into two categories - little-endian and big-endian. In little-endian memories the bytes are numbered starting with 0 ...
23
votes
19answers
1k views

Reconstruct an arithmetic sequence

Given a finite arithmetic sequence of positive integers with some terms removed from the middle, reconstruct the whole sequence. The task Consider an arithmetic sequence: a list of positive integers ...
33
votes
32answers
4k 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 ...
26
votes
81answers
4k 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 ...
33
votes
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 ...
24
votes
23answers
3k views

Take a byte out of it!

Your task is to, given an unsigned integer n, find the largest number which can be created by removing a single byte (8 consecutive bits) of data. Example Given ...
27
votes
13answers
1k views

Seqindignot sequence

Title is made up, from 'Sequence Index Digit Not'. Challenge: Given an integer n which is >= 0, output the ...
23
votes
16answers
3k views

Take one to make one

Challenge Given a list of positive integers, find if there exists a permutation where taking up to one bit from each of the integers, a binary number consisting of all ...
28
votes
23answers
3k views

Basic sort, with annoying bug

Your input is a list/sequence/vector/array of 5-255 positive integers, not necessarily unique. You may assume whatever input format is most suitable, and that each integer (as well as the quantity of ...
28
votes
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 ...
4
votes
3answers
214 views

Solve the equation `a*x == b` with Int32 arithmetics [duplicate]

In this thread we use 32-bit signed integers (assuming the usual two's complement). For simplicity I shall call this type Int32. The range is from -2147483648 ...
28
votes
25answers
4k views

Smallest Zeroless Base

Given a positive integer n, output the smallest base b >= 2 where the representation of n ...
22
votes
28answers
2k views

Largest Prime Exponents

Given an integer n >= 2, output the largest exponent in its prime factorization. This is OEIS sequence A051903. Example Let ...
12
votes
15answers
783 views

Alternested numbers

Consider the array of positive integers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ... Then, concatenate them: ...
21
votes
6answers
863 views

Create a universal integer sequence

Definition Let's call an (infinite) integer sequence universal if it contains every finite integer sequence as a contiguous subsequence. In other words, the integer sequence (a1, a2, …) is universal ...
8
votes
22answers
895 views

Nth Ngonal Numbers

Most of us are probably familiar with the concept of triangular and square numbers. However, there are also pentagonal numbers, hexagonal numbers, septagonal numbers, octagonal numbers, etc. The Nth ...
-3
votes
3answers
164 views

Multi-Base Primes [closed]

For the purpose of this challenge, a multi-base prime is a prime which, when written in base 10, is prime in one or more bases smaller than 10 and larger than 1 as well. All single-digit primes are ...
9
votes
7answers
2k views

A train crosses a labeled bridge

Consider a bridge of length B formed by tiles labeled with the digits of the positive integers concatenated. For example, if B was 41, then it would look like this: -----------------------------------...
17
votes
14answers
1k views

Least integer as a product of given factors

There have been a lot of prime-/prime factorization-related challenges recently, so I thought it might be interesting to go the other way. Given: a positive integer ...
9
votes
17answers
1k views

Primes in the prime factorisation

I saw another prime challenge coming by in PPCG, and I do love me some primes. Then I misread the introductory text, and wondered what the creative brains here had come up with. It turns out the ...
14
votes
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). ...
16
votes
16answers
1k views

Prime Powers of Primes

For the purpose of this challenge, a Prime Power of a Prime (PPP) is defined as a number that can be defined as a prime number to the power of a prime number. For example, 9 is a PPP because it can ...
3
votes
2answers
432 views

A Slashy Dashy Spiral [duplicate]

Given a positive integer N, output the innermost N×N square of an ASCII art spiral made of -|/\ that spirals clockwise inward. The ...
5
votes
9answers
2k views

Back to the Basics of Math

Introduction: We all know these three basic arithmetic math tables I assume. ...
23
votes
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 ...
50
votes
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 ...
25
votes
29answers
2k views

Dizzy integer enumeration

Your challenge today is to output a given term of a sequence enumerating all of the integers. The sequence is as follows: If we have a 0-indexed function generating the sequence ...
14
votes
27answers
1k views

Pandigital Doubling

Inspired by this CMC Given a positive integer greater than 0, perform the following operation on it: If all ten single digits (1234567890) are in the number at ...
15
votes
17answers
2k views

Sort the points by linear distance in a 3D space

Specs You have a cubic 3D space x,y,z of size S integer units, such as 0 <= x,y,z <= S...
17
votes
21answers
1k views

Sum the deltas of my matrix

Background The deltas of an array of integers is the array formed by getting the differences of consecutive elements. For example, [1, 2, 4, 7, 3, 9, 6] has the ...
19
votes
45answers
2k views

Find the sum of the divisors of N

Write a program that displays on the screen the sum of the divisors of a number (1 ≤ N ≤ 100) entered by the user in the range of 1 to N. This is OEIS A000203. Examples: Input: 7 ...
28
votes
6answers
2k views

Help! My calculator malfunctions!

Introduction My calculator is behaving weird. Sometimes when I type in an 8 it displays a 2. And sometimes when I type in a <...
16
votes
24answers
673 views

Sum the rows of the concatenated triangle

Consider the following triangle. 1 23 456 7891 01112 131415 1617181 92021222 324252627 2829303132 33343536373 839404142434 4454647484950 51525354555657 585960616263646 5666768697071727 ...
2
votes
1answer
200 views

Collatz's First Conjecture [duplicate]

Background The Collatz Conjecture is quite well-known. Take any natural number. Triple and increment if odd; cut in half if even. Repeat, and it will reach 1 eventually. This famous conjecture, ...
9
votes
14answers
1k views

The Binary Binary Expansion

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term: ...
8
votes
14answers
528 views

Count the Palindromes [duplicate]

Given a number n, calculate the amount of bases in the range of [2, n) in which b(n) is a ...
7
votes
1answer
333 views

Playing Darts: become an amateur with the most efficient prioritizing

Introduction: I think most people will know how darts work. But since some might not, here are the rules of playing Darts in a nutshell: Amount of players: 2 Starting points: 501 Goal: Get your ...
24
votes
20answers
2k views

Circularly moving sum

Inspired by a question at Stack Overflow. Given a non-empty array of integers x and a positive integer n, compute the sum of ...
12
votes
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 ...
20
votes
25answers
1k views

Keep/Drop/Increase Sequence

Here is the sequence I'm talking about: {1, 4, 5, 9, 10, 11, 16, 17, 18, 19, 25, 26, 27...} Starting from 1, keep 1, drop the next 2, keep the next 2, drop 3, ...
0
votes
0answers
70 views

Turn an integer n into an N-DIMENSIONAL list [duplicate]

Inspired by this question. Given an integer n, create an n-dimensional list of "length" n in every dimension, where every element is n. Rules: If your language has a built-in that does this, you ...
15
votes
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 ...
34
votes
35answers
2k views

Undo a Range of Numbers

It is fairly simple to, given a number n, create a range from 0 to n-1. In fact, many ...
18
votes
16answers
2k views

It's a Bit of a Stretch․․․

Input: We take two inputs: An input b with two distinct values: Left and Right.† And a ...
2
votes
1answer
237 views

Syllables in a Number [closed]

Make a program/function which takes in an integer from 0 to 999999999999 (inclusive) as input and returns how many syllables it has when spoken in English. Make your code short. Specification A ...
20
votes
21answers
3k views

Fold the integer to save space!

The crazy mathematician owns a wide collection of numbers, and therefore the space he has left is quite limited. To save some, he must fold his integers, but unfortunately he is really lazy. Your task,...
31
votes
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 ...
14
votes
12answers
745 views

prepend,append-Sequence

Task The prepend,append-Sequence is defined recursively, like this a(1) = 1 a(n) = a(n-1).n , if n is even a(n) = n.a(n-1) , if n is odd where the . represents an integer concatenation. So the ...
22
votes
8answers
1k views

Products that equal a sum and vice versa

A fun pair of equivalences is 1 + 5 = 2 · 3 and 1 · 5 = 2 + 3. There are many like these, another one is 1 + 1 + 8 = 1 · 2 · 5 and 1 · 1 · 8 = 1 + 2 + 5. In ...
29
votes
20answers
2k views

Float 754 to Hamming

You will be given as input an integer k in the range from -4503599627370496 (−252) to ...