Skip to main content

Questions tagged [integer]

For challenges involving the manipulation of integers.

Filter by
Sorted by
Tagged with
34 votes
4 answers
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'...
Calvin's Hobbies's user avatar
5 votes
16 answers
3k views

Move my liquid to make me equal

You are given 4 positive integers: volume of the first container (v1), volume of the second container (v2), volume of the liquid ...
user avatar
20 votes
9 answers
2k views

Proportion of self-avoiding walks on a square lattice

The challenge Given a positive integer N, compute the proportion of N-step walks on a plane that don't intersect themselves. ...
Luis Mendo's user avatar
  • 105k
25 votes
44 answers
5k views

Round up my number

Sandbox Given two positive integers a and b, return the smallest multiple of b that is greater than or equal to a. Examples Definitions: true = ...
user avatar
16 votes
16 answers
1k views

Find the length of a number's "base-jumping" path

Consider a positive integer N written in base b. A sequence is generated from this number by finding the largest digit ...
Arcturus's user avatar
  • 7,387
25 votes
7 answers
2k views

Inverse Look-and-Say

Background The Look and Say Sequence is built up by reading off the digits of previous entries in the sequence, counting the number of digits in groups of the same digit. For example: ...
Uri Granta's user avatar
  • 2,959
1 vote
0 answers
84 views

Making Fibonacci Cry [duplicate]

Introduction The Fibonacci sequence is a mathematical sequence in which each term is the sum of the \$2\$ terms before it; the first two terms are \$0\$ and \$1\$. The first few terms are \$0, 1, 1, ...
sugarfi's user avatar
  • 2,203
1 vote
20 answers
633 views

Quine in Bytes, not Characters [duplicate]

Introduction A quine is a program that takes no input and produces a copy of its own source code as output. Writing a quine is a standard test of a programming language. Most quines operate using ...
sugarfi's user avatar
  • 2,203
19 votes
25 answers
4k views

Visualize a large int

Convert a large int (e. g. 1234567890) into a string containing the usual decimal prefixes k, M, G, T, etc. for kilo, mega, giga, tera, etc. The result shall be groups of three digits, interspersed ...
Alfe's user avatar
  • 307
14 votes
35 answers
2k views

Determine the Winner of a Game of Australian Football

In Australian Football, goals are worth 6 points and behinds are worth 1 point. Scores may include the number of goals and behinds, as well as the total score. Given the number of goals and behinds ...
Stephen's user avatar
  • 14k
33 votes
29 answers
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 ...
GammaFunction's user avatar
29 votes
18 answers
4k views

Infinitely many primes

Since Euclid, we have known that there are infinitely many primes. The argument is by contradiction: If there are only finitely many, let's say \$p_1,p_2,...,p_n\$, then surely \$m:=p_1\cdot p_2\cdot.....
flawr's user avatar
  • 43.8k
27 votes
29 answers
5k views

Count the number of triangles

Given a list of positive integers, find the number of triangles we can form such that their side lengths are represented by three distinct entries of the input list. (Inspiration comes from CR.) ...
flawr's user avatar
  • 43.8k
20 votes
30 answers
2k views

Numbers Decrease while Letters Increase

Randomly inspired by Numbers Increase While Letters Decrease Given a list of mixed letters and integers (e.g., ['a', 2, 3, 'b']) increase the letters by one ...
AdmBorkBork's user avatar
  • 43.4k
30 votes
30 answers
3k views

Output with the same length always

With challenges like Output with the same length as the code and Create output twice the length of the code, I thought of a separate, but similar challenge. The task is to produce an output. It can ...
maxb's user avatar
  • 6,897
16 votes
1 answer
400 views

Decompose Commutators

A theorem in this paper1 states that every integral n-by-n matrix M over the integers with trace M = 0 is a commutator, that means there are two integral matrices A,B of the same size as M such that M ...
flawr's user avatar
  • 43.8k
39 votes
41 answers
6k 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$$...
Jitse's user avatar
  • 7,324
29 votes
30 answers
4k views

Inverse Colombian Function

Let's define a sequence: The n digit summing sequence (n-DSS) is a sequence that starts with n. If the last number was k, then the next number is k + digit-sum(k). Here are the first few n-DSS: ...
DJMcMayhem's user avatar
  • 59.3k
8 votes
4 answers
720 views

Find X,Y,Z coordinates from index

Introduction I began studying the Collatz Conjecture And noticed these patterns; 0,1,2,2,3,3...A055086, and 0,1,2,0,3,1...A082375, in the numbers that go to 1 in one odd step, 5,10,20,21,40,42......
PrincePolka's user avatar
27 votes
27 answers
3k views

Robbers: The Hidden OEIS Substring

This is a Cops and Robbers challenge. This is the robber's thread. The cop's thread is here. The cops will pick any sequence from the OEIS, and write a program p that prints the first integer from ...
DJMcMayhem's user avatar
  • 59.3k
42 votes
30 answers
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 ...
DJMcMayhem's user avatar
  • 59.3k
33 votes
68 answers
6k views

Integer Lists of Noah

Introduction: I think we've all heard of it, but here a very brief summary: Noah gathered two of every species of animal on the planet, male and female, to save in his Ark during a great flood. The ...
Kevin Cruijssen's user avatar
3 votes
3 answers
170 views

Sum of multiples of powers of ten of an integer [duplicate]

Write a function to produce, for a non-negative integer, a string containing a sum of terms according to the following: ...
Ray Toal's user avatar
  • 659
-7 votes
4 answers
294 views

Is this number a palindrome? [closed]

Input A single integer in your language's preferred format, e.g int or an array of digits are all acceptable. Output A truthy or falsely value, depending on ...
Geza Kerecsenyi's user avatar
42 votes
34 answers
15k 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. It asks if this claim of US presidential candidate Bernie Sanders is true or not: Today the world's ...
Kevin Cruijssen's user avatar
46 votes
12 answers
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. ...
Luis Mendo's user avatar
  • 105k
9 votes
0 answers
266 views

Fastest way to iterate over sublattice of discrete lattice

I need to construct a functor that iterates over the linear representation of a sub-lattice of size \$d_x,d_y,d_z,d_q\$ embedded in a lattice of size \$n_x,n_y,n_z,n_q\$. The sub-lattice corner is ...
user3646557's user avatar
22 votes
6 answers
1k views

Subtract the Folded Matrix

Challenge: Given an NxN matrix where \$N\geq2\$ and one of eight distinct 'folding options', output a 2D array/list with the subtracted values. The eight folding options are: left-to-right; right-to-...
Kevin Cruijssen's user avatar
12 votes
6 answers
1k views

Group Integers by Originality

Introduction: I collect twisty puzzles. Most twisty puzzles are produced and sold by Chinese companies. Most well-known companies ask permission from puzzle designers to produce their designs and work ...
Kevin Cruijssen's user avatar
21 votes
23 answers
3k views

Rotated Position of Integers

Challenge: Input: A sorted list of positive integers. Output: The amount of integers which are still at the exact same index, after rotating the digits in each integer its index amount of times ...
Kevin Cruijssen's user avatar
9 votes
4 answers
663 views

Leading and Suffering Numbers

Introduction: In Dutch, the words leading and suffering, being 'leiden' and 'lijden' respectively, are pronounced the same way. One is written with a "short ei", and one with a "long ij&...
Kevin Cruijssen's user avatar
21 votes
9 answers
1k views

Warped chessboard

This challenge is about building a chessboard in which the square size, instead of being constant across the board, follows a certain non-decreasing sequence, as described below. The board is defined ...
Luis Mendo's user avatar
  • 105k
32 votes
21 answers
2k views

A ​Note ​on ​N!

J. E. Maxfield proved following theorem (see DOI: 10.2307/2688966): If \$A\$ is any positive integer having \$m\$ digits, there exists a positive integer \$N\$ such that the first \$m\$ digits of \$N!...
flawr's user avatar
  • 43.8k
-3 votes
6 answers
273 views

Map values to any multidimensional array [closed]

Codegolf challenge - mapping values in a multidimensional array [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ] This 2D array is sick of being so false, and wants to ...
Jack Hales's user avatar
23 votes
21 answers
2k views

Maximum summed subsequences with non-adjacent items

Introduction: Inspired by these two SO questions (no doubt from the same class): print the elements in the subarray of maximum sum without adjacent elements java and Maximum sum of non adjacent ...
Kevin Cruijssen's user avatar
11 votes
6 answers
5k views

Area of a 2D convex hull

You are given an array/list/vector of pairs of integers representing cartesian coordinates \$(x, y)\$ of points on a 2D Euclidean plane; all coordinates are between \$−10^4\$ and \$10^4\$, duplicates ...
Vladimir Reshetnikov's user avatar
27 votes
13 answers
3k views

Valid Badminton Score?

Introduction: I saw there was only one other badminton related challenge right now. Since I play badminton myself (for the past 13 years now), I figured I'd add some badminton-related challenges. Here ...
Kevin Cruijssen's user avatar
26 votes
22 answers
2k views

The Digit Triangles

Challenge: Input: A positive integer \$n\$ Output: Create a list in the range \$[1,n]\$, and join it together to a string (i.e. \$n=13\$ would be the string ...
Kevin Cruijssen's user avatar
35 votes
28 answers
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 list ...
Kevin Cruijssen's user avatar
15 votes
11 answers
1k views

Source permutation

A permutation of a set \$S = \{s_1, s_2, \dotsc, s_n\}\$ is a bijective function \$\pi: S \to S\$. For example, if \$S = \{1,2,3,4\}\$ then the function \$\pi: x \mapsto 1 + (x + 1 \mod 4)\$ is a ...
ბიმო's user avatar
  • 16.8k
12 votes
31 answers
2k views

Sum integers in a string [duplicate]

Input A string. Output The sum of all integers in the line. Constraints 1≤Length of line≤500 Sample test Case Input the 5is 108 seCONd4 a Output ...
Karandeep Singh's user avatar
36 votes
5 answers
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 ...
Kevin Cruijssen's user avatar
10 votes
10 answers
814 views

Check type of an integer

You will receive an integer less than 2000000000 and bigger than -2000000000 and you have to test what type(s) of number this is out of: ...
SimpleBinary's user avatar
4 votes
9 answers
408 views

Floating over the integers

As you may know, the typical binary floating point numbers in a computer language are quite different than the typical integer numbers in a computer language. Floating point numbers can represent a ...
don bright's user avatar
  • 1,315
21 votes
17 answers
2k views

Square Root Distance from Integers

Given a decimal number k, find the smallest integer n such that the square root of n is ...
Stephen's user avatar
  • 14k
20 votes
25 answers
3k views

The Highest Dice

Challenge: Here we have the first 100 items of a sequence: ...
Kevin Cruijssen's user avatar
24 votes
3 answers
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 ...
Jonathan Allan's user avatar
25 votes
15 answers
3k views

Matrix Jigsaw Puzzles

Input: An integer n Two equal-sized square matrices (with their width/height being a multiple of n) Output: One of two ...
Kevin Cruijssen's user avatar
30 votes
49 answers
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 ...
Adám's user avatar
  • 30.4k
25 votes
20 answers
2k views

Collapsing numbers

Let's define the a function on natural numbers \$n\$, written as base 10 digits \$d_k\; d_{k-1}\; \dotsc\; d_1\; d_0\$, as follows: As long as there are equal adjacent digits \$d_i\;d_{i-1}\$, ...
ბიმო's user avatar
  • 16.8k

1 2 3
4
5
9