Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [integer]

For challenges involving the manipulation of integers.

11
votes
11answers
1k views

Codegolf Rainbow : Fun with Integer-Arrays

Introduction: (Source: Wikipedia) When we look at a rainbow it will always have the colors from top to bottom: Red; orange; yellow; green; blue; indigo; violet If we look at these individual rings, ...
15
votes
21answers
1k views

Fill up to duplicate ranges

Let \$L\$ be a list of positive integers with no particular ordering, and which can contain duplicates. Write a program or function which outputs a list of positive integers \$M\$ (whose ordering is ...
25
votes
15answers
2k views

Toggle some bits and get a square

Given an integer \$N>3\$, you have to find the minimum number of bits that need to be inverted in \$N\$ to turn it into a square number. You are only allowed to invert bits below the most ...
17
votes
34answers
905 views

Calculate power series result [duplicate]

Related: Calculate Power Series Coefficients Given a positive integer \$X\$ and a max exponent (Also a positive integer too) \$N\$ calculate the result of a power series. Example: $$X^0+X^1+X^2+\...
18
votes
8answers
699 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: ...
13
votes
12answers
2k views

Small Ramsey Numbers

Background: the Ramsey number \$R(r,s)\$ gives the minimum number of vertices \$v\$ in the complete graph \$K_v\$ such that a red/blue edge coloring of \$K_v\$ has at least one red \$K_r\$ or one blue ...
17
votes
7answers
604 views

Stacked digit staircases

Given positive integers \$w\$ and \$h\$ output \$w\$ columns and \$h\$ rows of text as described below. The first row begins with 11 0s, the second row with 10 <...
-1
votes
7answers
373 views

Calculate the sum of all odd digits of pi in range [duplicate]

Introduction In the not so distant future with the AI revolution, we will need a way to solve their captchas to prove we're not humans. This challenge was inspired by CommitStrip. Challenge One ...
7
votes
10answers
511 views

How many bytes is it

This time, we want render the count of bytes in a human readable way to user. Let's write a program (a full one or a function or other acceptable formats) to do this. Input An non-negative integer, ...
25
votes
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 ...
21
votes
28answers
2k views

Replace me by the sum of my cyclic successors!

I have a simple challenge for you this time. Given an array of positive integers A (or the equivalent in your language), replace each entry Ai with the sum of the next Ai elements of A, cycling back ...
16
votes
8answers
539 views

Classify a region by its slope

Definitions The kth ring of a square matrix of size N, where 1 ≤ k ≤ ceiling(N/2) is the list formed by the elements of the kth and (N-k+1)th rows and columns, but without the first and last k-1 ...
21
votes
39answers
3k views

X Steps Forward, 1 Step Back

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

Up and down, up and down

Challenge: Given a positive integer input n, create a vector that follows this pattern: 0 1 0 -1 -2 -1 0 1 2 3 2 1 0 -1 -2 -3 -4 -3 -2 -1 ... ±(n-1) ±n ...
3
votes
0answers
155 views

Make Three from One [duplicate]

Given a single digit integer and a three digit integer, output a mathematical formula that uses only the single digit and a given list of operators to equal the three digit integer. Input: A one ...
24
votes
10answers
2k views

Knight Distance

In Chess, a Knight on grid (x, y) may move to (x-2, y-1), (x-2, y+1), (x-1, y-2), (x-1, y+2), (x+1, y-2), (x+1, y+2), (x+2, y-1), (x+2, y+1) in one step. Imagine an infinite chessboard with only a ...
3
votes
2answers
67 views

Generate lowest degree polynomial from sequence [duplicate]

Introduction A sequence of numbers is passed in as the input. The program has to generate the lowest degree polynomial possible. This was my first programming project in college and it would be ...
13
votes
13answers
1k views

Arithmetic Cycle

Input: Integer n which is >=0 or >=1 (f(0) is ...
12
votes
8answers
745 views

Digit Occurrences

Input: A list of integers (which will never contain a zero) Output: A list of the same size with counts based on the following: If the current item is negative: Look at all items before this item, ...
21
votes
16answers
1k views

Interval Notations

Challenge: Input: Two integer parameters a and b (where a<b and the difference is at ...
23
votes
15answers
2k views

Not Quite Roman Ternary

Given an integer n ≥ 0 , output it in a non-positional base-3 notation, using digits 139ABCDE… and a 1-character separator. Every digit is a consecutive power of 3 ...
31
votes
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:...
30
votes
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 ...
20
votes
14answers
1k views

Is this a truncated triangular number?

Related OEIS sequence: A008867 Truncated triangular number A common property of triangular numbers is that they can be arranged in a triangle. For instance, take 21 and arrange into a triangle of <...
11
votes
3answers
809 views

Crazy but Rational Bases

We have many challenges based on base 10, base 2, base 36, or even base -10, but what about all the other rational bases? Task Given an integer in base 10 and a rational base, return the integer in ...
12
votes
5answers
172 views

Reduced Factorization Leader Changes

tl;dr: Output the values where the reduced prime factorization leader changes. Every positive integer has a unique prime factorization. Let's call the reduced prime factorization just the list of ...
15
votes
19answers
1k views

Make Zero From First 'n' Numbers

Challenge The challenge is to write a code that takes a positive integer 'n' as an input and displays all the possible ways in which the numbers from 1 - n can be written, with either positive or ...
14
votes
9answers
1k views

Find The Local Maxima And Minima

Definition The maxima and minima of a given function are the largest and smallest values of the function either within a given range or otherwise within the entire domain of the function. Challenge ...
32
votes
8answers
762 views

Can square tree rings be generated from primes?

Apparently yes! In three easy steps. Step 1 Let f(n) denote the prime-counting function (number of primes less than or equal to n). Define the integer sequence s(n) as follows. For each positive ...
28
votes
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. Input One positive integer N. Output The smallest number of ones that must ...
14
votes
4answers
869 views

Bottom part of the Hourglass

Challenge: Input: Three integers: bottom-edge length; starting amount of grains of sand; index Output: Output the state of the bottom part of an hourglass at the given index, based on the given ...
19
votes
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 ...
18
votes
12answers
2k views

Olympic Rings Sequence

Challenge: Given an index integer n, either output the n'th item in this sequence, or output the sequence up to and including ...
24
votes
61answers
3k views

The Non-Zero Digital Product Challenge

Originally the Multiplicative digital root Challenge Basically do what the title says Method Given a positive integer 1 <= N <= 100000000 through one of our standard input methods, multiply ...
12
votes
14answers
977 views

Minimise the count of prime factors through insertion

Given two positive integers A and B, return the position p that minimises the number of prime factors (counting multiplicities) of the resulting integer, when B is inserted in A at p. For example, ...
16
votes
32answers
2k views

Find the largest number of distinct integers that sum to n

The Task Given an input positive integer n (from 1 to your language's limit, inclusively), return or output the maximum number of distinct positive integers that ...
26
votes
18answers
2k views

Am I a 'Redivosite' Number?

Redivosite is a portmanteau word invented for the sole purpose of this challenge. It's a mix of Reduction, Division and Composite. Definition Given an integer N > 6: If N is prime, N is not a ...
13
votes
20answers
1k views

Compute the Optimal Square Matrix

The optimal matrix (for the rather narrow scope of this challenge) is obtained by "zipping" the elements from the corresponding rows and columns of a square matrix and getting the maximum of each pair....
11
votes
4answers
317 views

Balanced ternary logic

Balanced ternary logic Ternary is normally another name for base 3, that is to say, each digit is 0, 1, or ...
19
votes
23answers
2k views

Single swaps of an array

Inspired by Taken from a question at Stack Overflow. The challenge Given an integer n>1, output all arrays that can be obtained by swapping exactly two entries ...
26
votes
35answers
2k views

Output the hours at 90 degrees

Today while playing with my kids I noticed that an apparently simple toy in the park hid a challenge. The wheel has a triangle that points to a number, but also has three circles that point to the ...
42
votes
16answers
4k views

How small can it get?

Starting with a positive integer N, find the smallest integer N' which can be computed by repeatedly dividing N by one of its digits (in base-10). Each selected digit must be a divisor of N greater ...
10
votes
6answers
328 views

Is it a Satisfying Number?

inspired by this chat conversation A satisfying number is a number whose decimal representation is of the form abx, with the following properties: ...
14
votes
11answers
547 views

N-bit Variation on Subset-Sum

For another challenge I am writing, I need to verify that test cases are solveable with bounded integers. Specifically, I need to verify the following, for a non-empty array of integers ...
23
votes
22answers
2k views

Frequency Distribution of Mixed Dice Rolls

A follow-up to this challenge Given a set of mixed dice, output the frequency distribution of rolling all of them and summing the rolled numbers on each die. For example, consider ...
23
votes
11answers
1k views

The sequence of self-contained numbers

Let's define a self-contained number as a positive integer, whose digits appear in runs of length equal to themselves only. In other words, any decimal digit d (excluding 0) occurs only in runs of ...
24
votes
25answers
2k views

Find a Fixed Point

Given an integer x1 and some black box function f: ℤ → ℤ find a fixed point of f in the ...
14
votes
31answers
1k 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 ...
33
votes
30answers
6k views

Find the smallest positive integer which ends in n, is divisible by n and whose digits sum to n

It's all in the title... Take as input a positive integer n>=12 and... do what the title says. Yes, this is on OEIS A187924. Some test cases ...
20
votes
10answers
1k views

Minimal sparse rulers

A standard ruler of length n has distance marks at positions 0, 1, ..., n (in whichever units). A sparse ruler has a subset of those marks. A ruler can measure the distance k if it has marks at ...