Questions tagged [integer]

For challenges involving the manipulation of integers.

Filter by
Sorted by
Tagged with
26
votes
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). ...
46
votes
27answers
2k views

Divisor skyline

For any positive integer k, let d(k) denote the number of divisors of k. For example, ...
9
votes
15answers
736 views

Implement Euler's method

The goal of this challenge is to use Euler's method to approximate the solution of a differential equation of the form f(n)(x) = c.† The input will be a list of integers in which the nth value ...
66
votes
5answers
5k views

Powerprogramming: O(1^N), O(N^1), O(2^N), O(N^2) all in one

Write a program (or function) that exhibits four common big O time complexities depending on how it is run. In any form it takes in a positive integer N which you may assume is less than 231. When ...
30
votes
21answers
2k 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 ...
42
votes
124answers
9k views

Stay away from zero

Task Given a non-negative integer n, output 1 if n is 0,...
15
votes
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 ...
40
votes
31answers
2k views

Moving modest minimum

Inspired by a question over at Stack Overflow. The title here is entirely my fault. The challenge Given a list of positive integers containing at least two entries, replace each number by the ...
16
votes
5answers
562 views

Do a BackFlip for ais523!

This challenge is a prize for ais523 for winning the "Rookie of the Year" category in "Best of PPCG 2016". Congratulations! BackFlip is an esoteric programming language made by user ais523, who has ...
26
votes
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 ...
41
votes
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: <...
10
votes
3answers
336 views

Mapping between integer and pronounceable word

Purpose The idea is to provide the code necessary to map a 32-bit integer to/from a pronouncable word of 9 characters maximum. That could be useful, for example, to make a serial number easier to ...
17
votes
13answers
998 views

Integer-Digits of the Arithmetic-Tables

Challenge: Output the 'integer-digits' of one of the following six arithmetic-tables based on the input: - addition (+); - subtraction (...
26
votes
25answers
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 ...
2
votes
0answers
80 views

Storing an array of Integers to WOM [closed]

Very few, if any, programs or applications have utilised the proposed spec for WOM which was initially thought up in the early 1970s as a polar opposite to ROM, so your task is to take a dataset of n ...
11
votes
18answers
645 views

Sort and Re-apply Deltas of an Array

It seems that any Simple Modification of deltas using a consistent function can almost always be done some other shorter way, Dennis. Thus, the only solution I can imagine to make this harder, is to ...
34
votes
68answers
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: ...
7
votes
10answers
454 views

How much does this Integer score?

The Challenge Given an integer, calculate its score as described below. The score is calculated by raising each digit of the input Integer to the power n, where <...
13
votes
3answers
457 views

Compute the most efficient binary function

Today, we'll be computing the most efficient binary function. More specifically, we'll be computing the function which, when an expression is created from applying the function to the constant input 0 ...
36
votes
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-...
29
votes
16answers
1k views

Fill in an increasing sequence with as many numbers as possible

A list of numbers is called monotonically increasing (or nondecreasing) is every element is greater than or equal to the element before it. For example, ...
27
votes
10answers
3k views

Solve an equation with (almost) any numbers you like

Given a string of the characters +=- where there is at least one =, insert positive integers between all the symbols and at the ...
63
votes
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: [1] ...
26
votes
11answers
2k views

Bitflip-resistant composite numbers

Sometimes, when writing a program, you need to use a prime number for some reason or other (e.g. cryptography). I assume that sometimes, you need to use a composite number, too. Sometimes, at least ...
17
votes
11answers
2k views

Find Recursively Prime Primes

The Recursively Prime Primes is are sequence of primes such that p(1) = 2 p(n) = the p(n-1)th prime Here is an example of how one might calculate the 4th ...
28
votes
20answers
2k views

A sequence of sums of integers that aren't in the sequence

Background Consider a sequence defined as follows: The first element is 0; The second element is 4; From the third element onwards, its value can be calculated by: Taking the set of integers from 0 ...
19
votes
12answers
1k views

Anagram Factors

On a recent episode of QI, the first 5 multiples of 142857 were described as anagrams of the original number. Of course, anyone with more than a passing knowledge of that number will know that those ...
35
votes
20answers
2k views

Sum the powers that be

A simple but hopefully not quite trivial challenge: Write a program or function that adds up the kth powers dividing a number n....
19
votes
8answers
3k views

Give me your tired, your poor, Your huddled masses yearning to breathe free

A bronze plaque in the pedestal of the Statue of Liberty displays the poem "The New Colossus" by Emma Lazarus, part of which reads: Give me your tired, your poor, Your huddled masses yearning to ...
28
votes
16answers
2k views

Output the Euler Numbers

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

Digital Hardness of Integers

To find the digital hardness of an integer, take its binary representation, and count the number of times both a leading and trailing 1 can be removed until it ...
22
votes
4answers
565 views

What did I just play? Translate guitar fingerings to chords

Related: Music: what's in this chord?, Notes to Tablature, Generating guitar tabs?, Translate number pairs to guitar notes Given a guitar fingering, output the chord it represents. You can use ...
28
votes
11answers
1k views

2016 Time Capsule String: Climb The Integer Ladder

Using the 74 characters from the 2016 time capsule string H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``#|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{% write N code snippets ...
35
votes
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 ...
23
votes
16answers
1k views

Golf a Numerical Growing Braid

Braid Description In this braid, when a strand crosses over the top of another strand it adds the other strand's value to itself and all other strand values pass through. The braid has three strands ...
36
votes
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 ...
68
votes
145answers
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 ...
45
votes
53answers
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 ...
31
votes
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 ...
41
votes
39answers
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 ...
34
votes
14answers
1k views

Generate n-ary numbers

A secondary number is a positive integer whose prime factors (without multiplicity) are all less than or equal to its square root. 4 is a secondary number, because ...
105
votes
34answers
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 ...
18
votes
16answers
1k views

Plus and Times, Ones and Nines

Implement this recurrence relation as a function or program that inputs and outputs a non-negative integer: F(0) = 0 F(N) = the smallest integer greater than F(N-1) such that the sum and/or product ...
23
votes
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, ...
20
votes
7answers
944 views

Numpad Word Search

Given an integer from 1 to 999 inclusive, output a truthy value if it appears horizontally, vertically, or diagonally, either forwards or backwards, anywhere in the 3x3 square of digits 1-9 on a ...
36
votes
24answers
3k views

Complex Binary Numbers

Let's create a simple, surjective mapping from positive integers to Gaussian integers, which are complex numbers where the real and imaginary parts are integers. Given a positive integer, for example ...
29
votes
43answers
2k views

The Squaring Sequence

Each term in the squaring sequence, xn, is created by taking xn-1, squaring it, and removing all but the first four digits. The sequence always begins with x1 = 1111. Squaring this yields 1234321, ...
19
votes
7answers
1k views

Alphabetize Integers

Alphabetize Integers For a given set of numbers, put them in alphabetical order when they are spelled out (i.e. 1: one, 2: two, 90: ninety, 19: nineteen). Your code should work for the range ...
44
votes
37answers
3k 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: ...
15
votes
9answers
817 views

All the Xenodromes

Introduction A xenodrome in base n is an integer where all of its digits in base n are different. Here are some OEIS sequences of xenodromes. For example, in base 16, ...