Questions tagged [integer]

For challenges involving the manipulation of integers.

120 questions
Filter by
Sorted by
Tagged with
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:  ...
3k 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 ...
7k views

Turn an integer n into a list containing it n times [closed]

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

Mountain range numbers

Mountain range number A number is a mountain range number if the inequalities satisfied by their consecutive digits alternate. In a way, looking at the number's digits should exhibit a ...
9k 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: ...
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 ...
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 ...
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 ...
944 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: ...
2k 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. ...
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 ...
586 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 ...
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 ...
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. ...
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 ...
2k views

Divisor skyline

For any positive integer $k$, let $d(k)$ denote the number of divisors of $k$. For example, $d(6)$ is $4$, because $6$ has $4$ divisors (namely $1, 2, 3, 6$). Given a positive integer \...
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 ...
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: <...
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 ...
1k 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 ...
10k views

Stay away from zero

Task Given a non-negative integer n, output 1 if n is 0,...
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 $\text{lcm}$$(A, B)$ ...
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 ...
3k 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 ...
4k 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 ...
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 ...
3k views

Swap Two Values in a List

Introduction: Although we have a lot of challenges where swapping two items in a list is a subtask, like Single swaps of an array; Swap to Sort an Array; $n$ swaps into a nop; etc., we don't have ...
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-...
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 ...
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 ...
3k 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:...
2k views

Enumerate each series of identical numbers in-place

Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series. Examples ...
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: ...
2k views

Computing a specific coefficient in a product of polynomials

Generator functions This gives the context for why this challenge came to life. Feel free to ignore. Generator functions are a nice way of encoding the solution to a problem of combinatorics. You ...
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 ...
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 ...
3k 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 ...
1k views

Interpret Interval Notation

Interval notation is a way to write complicated range bounds more conveniently and concisely than writing an inequality. The challenge, should you choose to accept it, is to write a program or ...
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 ...
216 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 ...
12k 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 permutations. Choose your ...
8k views

Historical difference between / and ÷ in mathematical expressions

Introduction: Inspired by a discussion that is already going on for many years regarding the expression $6÷2(1+2)$. With the expression $6÷2(1+2)$, mathematicians will quickly see that ...
5k 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: ...
3k views

Make The Finest Magic Code Square

In math a magic square is an N×N grid of numbers from 1 to N2 such that every row, column, and diagonal sums to the same total. For example here's a 3×3 magic square: In this challenge we'...
5k views

How many petals around the rose

How many petals around the rose How many petals around the rose is a dice game you can play with your friends. Similar to "can I join the music box", there is a person that knows how the ...
Given a non-negative integer $n ,$ output the $n^{\text{th}}$ Euler number (OEIS A122045). All odd-indexed Euler numbers are $0 .$ The even-indexed Euler numbers can be computed with the ...