Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

# Questions tagged [integer]

For challenges involving the manipulation of integers.

284 questions
Filter by
Sorted by
Tagged with
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 ...
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 ...
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 ...
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] ...
18answers
6k views

### Count like Chuck Norris

As is well known, Chuck Norris counted to infinity. Twice Besides, Chuck Norris can count to infinity backwards. Also, although perhaps less known, Chuck Norris can speak a little Spanish 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 ...
121answers
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: ...
27answers
2k views

### Divisor skyline

For any positive integer k, let d(k) denote the number of divisors of k. For example, ...
20answers
4k views

### Greater than less than greater than something fishy

Given a length N string of less-than and greater-than signs (<, >), insert the integers 0 through N at the start and end ...
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 ...
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: ...
12answers
3k views

### Prime parity peregrination

The purpose of this challenge is to graphically depict a walk on the plane, where the direction of each step $k$ is determined by the primality of $k$ and the parity of its binary expansion. ...
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 ...
119answers
9k views

### Stay away from zero

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

### Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

Introduction: A few days ago I read this post with the same title when I came across it in the HNQ. In this question it is being discussed if the claim of president-candidate Bernie Sanders, who ...
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 ...
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-...
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 ...
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 ...
71answers
4k views

### As Easy as One-Two-Three

Write a program or function that takes in a positive integer. You can assume the input is valid and may take it as a string. If the number is any of ...
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 ...
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....
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: ...
65answers
3k views

### Interleave numbers from 1 to n, with the same numbers reversed

A simple one: Take a positive integer n less than 1000, and output the integers from 1 to n interleaved with the integers from n to 1. You must concatenate the numbers so that they appear without any ...
35answers
5k views

### Repeated! Factorials!

Not to be confused with Find the factorial! Introduction The factorial of an integer n can be calculated by $$n!=n\times(n-1)\times(n-2)\times(...)\times2\times1$$...
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 ...
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 ...
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 ...
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)...
41answers
5k views

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 ...
29answers
5k views

### Double it your way

There have been a couple of challenges involving doubling source code: here and here. The task we have here is a bit harder, but should be doable in almost every language. In this challenge, you will ...
42answers
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 ...
23answers
8k views

### Could you please stop shuffling the deck and play already?

Challenge: Input: A list of distinct positive integers within the range $[1, \text{list-size}]$. Output: An integer: the amount of times the list is riffle-shuffled. For a list, this means the ...
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 ...
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 ...
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 ...
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: ...