Questions tagged [integer]

For challenges involving the manipulation of integers.

Filter by
Sorted by
Tagged with
12
votes
1answer
192 views

Calculate the integer square root of a matrix

Let \$A\$ be a square matrix that is at least \$2 \times 2\$ where each element is an integer. \$A^2 = A \times A\$ will then have the same dimensions as \$A\$, and will have integer elements. For ...
5
votes
5answers
169 views

Potential nonzero entries in an irregular sequence

Background A338268 is a sequence related to a challenge by Peter Kagey. It defines a two-parameter function \$T(n,k)\$, which counts the number of integer sequences \$b_1, \cdots, b_t\$ where \$b_1 + \...
14
votes
18answers
1k views

Compare positions of integers in this sequence

A001057 is one way to represent an integer as a natural number. It lists them according to the following pattern: 0, 1, -1, 2, -2, 3, -3, 4, -4, ... In this ...
14
votes
23answers
2k views

Make an array of 128 bit integers

Given an input value \$n\$, construct an array of \$n\$ random 128 bit (unsigned) integers. The integers should be uniformly random. Your code can use any in built random number generation function ...
6
votes
3answers
275 views

Hexagonal section numbers

Introduction Let's draw some regular hexagons formed by hexagonal tiles, marking the vertices of the tiles with dots. Then we will count the number of dots. ...
19
votes
21answers
2k views

Longest Zero Sum Sub-array

Given an array of integers. Find out its longest sub-array (contiguous subsequence) whose sum is 0. The sub-array for output may be an empty array. Input Input an array of integers. Output Output the ...
5
votes
3answers
139 views

Is this an ordinal transform? [duplicate]

Related: What's my telephone number? which asks to calculate the terms of A000085, the number of possible ordinal transforms of length n. Background Ordinal transform is a transformation on an integer ...
36
votes
13answers
2k views

Maximum number of squares touched by a line segment

Consider a square grid on the plane, with unit spacing. A line segment of integer length \$L\$ is dropped at an arbitrary position with arbitrary orientation. The segment is said to "touch" ...
26
votes
38answers
2k views

Is this a Permutation of 1..n

Input a non-empty array with \$n\$ positive integers. Test if the input array contains every integer in \$1\cdots n\$. In case you prefer 0-indexed numbers, you may choose to input an array of non-...
26
votes
17answers
2k views

Give me odd, even, square, cube, prime and composite 3-digit numbers

Given a string which is guaranteed to be either odd, even, square, ...
17
votes
20answers
861 views

Binomial transform

Background Binomial transform is a transform on a finite or infinite integer sequence, which yields another integer sequence. The binomial transform of a sequence \$\{a_n\}\$ is given by $$s_n = \sum_{...
26
votes
22answers
1k views

Consecutive Distance Rating

We'll call the consecutive distance rating of an integer sequence the sum of the distances between consecutive integers. Consider 2 9 3 6 8 1. ...
25
votes
12answers
2k views

Collatz's ice cream cone factory

The Collatz sequence Given a positive integer \$a_1\$, the Collatz sequence with starting value \$a_1\$ is defined as \begin{equation} a_{n+1} = \begin{cases} a_n/2 & \mathrm{if}\ a_n\ \mathrm{is}\...
23
votes
36answers
2k views

Generate this number table

Given an integer \$1 < n < 10 \$ generate a table like below. For \$n = 5\$, 1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5 For \$n = 8\$, ...
24
votes
65answers
6k views

iHateOddNumbers

Task Given a non-negative number, check if it's odd or even. In case it's even, output that number. Otherwise, throw any exception/error that your language supports, and stop the program. Example with ...
18
votes
20answers
2k views

Gödel numbering of a string

Background Gödel numbers are a way of encoding any string with a unique positive integer, using prime factorisations: First, each symbol in the alphabet is assigned a predetermined integer code. Then, ...
7
votes
14answers
566 views

Calculate \$ \lfloor n \log_2(n) \rfloor \$, exactly

Given an integer \$ n \ge 2 \$, you need to calculate \$ \lfloor n \log_2(n) \rfloor \$, assuming all integers in your language are unbounded. However, you may not ignore floating-point errors - for ...
17
votes
9answers
1k views

Dimensional Chess positions

Task Any one of these two: Determine if a given position (an ordered non-empty collection of integers in the range ‒8 to 8, or ‒7 to 7 if you want) is a valid Dimensional Chess position. List all the ...
7
votes
2answers
356 views

Gelatin integer metagolf

Gelatin is a worse version of Jelly. It is a tacit programming language that always takes a single integer argument and that has 7 (or maybe 16) commands. Gelatin Gelatin programs will always match ...
28
votes
39answers
2k views

Implement an Over function

Over is a higher-order function in multiple languages such as APL (). It takes 2 functions and 2 values as arguments, applies the first function to both values, ...
16
votes
7answers
766 views

Minimal number of banknotes to pay a bill

Suppose denominations of banknotes follow the infinity Hyperinflation sequence: \$ $1, $2, $5, $10, $20, $50, $100, $200, $500, $1000, $2000, $5000, \cdots \$. How many banknotes are required, at ...
16
votes
5answers
722 views

Dominate a zero-sum game

Consider a zero-sum game with 2 contestants. Each round, each contestant chooses, independently of each other, one of \$n \ge 2\$ different choices. Depending on the two chosen choices, one player is ...
-1
votes
1answer
123 views

Print all digits of an integer [duplicate]

Challenge Given a positive integer, find the fastest way to iterate over its digits. Bytecode size doesn't matter as much as speed of execution. Examples For 6875, the program would output ...
17
votes
19answers
3k views

Fibonacci Encoding

Fibonacci coding is a universal code, which can encode positive integers of any size in an unambiguous stream of bits. To encode an integer \$ n \$: Find the largest Fibonacci number less than or ...
17
votes
3answers
309 views

Decompress an integer, Jelly style

Jelly has compressed string literals, using the “...» delimiters. The way these work is by interpreting the ... as a base-250 ...
20
votes
9answers
573 views

Zeroes at end of \$n!\$ in base \$m\$

Related: Zeroes at the end of a factorial Today, we are going to calculate how many zeroes are there at the end of \$n!\$ (the factorial of \$n\$) in base \$m\$. Or in other words: For given integers \...
11
votes
6answers
763 views

Golf this Thumb-2 Constant!

One thing that is constantly frustrating when golfing ARM Thumb-2 code is generating constants. Since Thumb only has 16-bit and 32-bit instructions, it is impossible to encode every immediate 32-bit ...
15
votes
8answers
729 views

Close(st) Binary Boxes

Challenge: Given a list of non-negative integers, determine by how much you should increase each item to create the closest binary box with the resulting integer-list. What is a binary box? A binary ...
16
votes
34answers
2k views

Implement a zipwith function

zipwith is a functional construct that takes three arguments: one binary function and two lists of the same length, and returns a single list where each element is ...
20
votes
37answers
2k views

Print a conversion table for (un)signed bytes

Your task: Print or return a conversion table with every byte from 00 to ff's value as an unsigned integer, to its value as a ...
22
votes
18answers
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 ...
1
vote
1answer
144 views

Twist on words to numbers [closed]

The Goal The goal of this question is to put a twist on this question. Your answer should be able to convert an array of words associated with integers into those integers. As an extra challenge, ...
12
votes
7answers
646 views

Generalised Taxicab Numbers

\$\newcommand{T}[1]{\text{Ta}(#1)} \newcommand{Ta}[3]{\text{Ta}_{#2}^{#3}(#1)} \T n\$ is a function which returns the smallest positive integer which can be expressed as the sum of 2 positive integer ...
30
votes
31answers
2k views

Ken Iverson’s Favourite APL Expression?

Ken Iverson, 1920–2020 Let's implement his favourite expression: Given a row of Pascal's triangle, compute the next row. This can for example be computed by taking the input padded with a zero on the ...
30
votes
50answers
4k views

Multiply or Divide by n

Here's a simple challenge, so hopefully lots of languages will be able to participate. Given a positive integer \$n\$, output \$A076039(n)\$ from the OEIS. That is, start with \$a(1)=1\$. Then for \$n&...
34
votes
23answers
3k views

Narcissistic loop lengths

A narcissistic number is a natural number which is equal to the sum of its digits when each digit is taken to the power of the number digits. For example \$8208 = 8^4 + 2^4 + 0^4 + 8^4\$, so is ...
11
votes
14answers
867 views

Prefix divisibility

Inspiration Given a positive integer \$1 \le n \le 9\$, output all positive \$n\$-digit integers \$i\$ for which the following is true: Each digit from \$1\$ to \$n\$ appears exactly once in \$i\$. ...
25
votes
29answers
2k views

Not so triangular numbers

Let's consider the sequence \$S\$ consisting of one \$1\$ and one \$0\$, followed by two \$1\$'s and two \$0\$'s, and so on: $$1,0,1,1,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,0,...$$ (This is A118175: Binary ...
23
votes
17answers
2k views

A Portuguese sequence of integers

Context Consider the following sequence of integers: $$2, 10, 12, 16, 17, 18, 19, ...$$ Can you guess the next term? Well, it is \$200\$. What about the next? It is \$201\$... In case it hasn't become ...
15
votes
23answers
2k views

We're all unique in our own way

This is an answer-chaining challenge where every part of your answer should aim to be unique from every other answer. This question will work in the following way: I will post the first answer. The ...
22
votes
44answers
3k views

Converting Strings to Decimals (Gone Wrong)

What? Many programming languages, both practical and esoteric, have functions, methods, etc to convert a given string to a decimal number. This is how the process might work: For each character in ...
20
votes
14answers
1k views

Find all integer pairs that produce a given Loeschian number

Inspired by and drawns from Is this number Loeschian? A positive integer \$k\$ is a Loeschian number if \$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers. For example, ...
14
votes
4answers
455 views

Bad matrix multiplication that gives the right answer

Executive summary: Print NxN matrices \$A\$ and \$B\$ where \$ AB = 10A + B \$. Largest N wins! Details: Entrants in this challenge should choose an N. Submit a program that takes an input integer '...
11
votes
1answer
399 views

Amount Of Potential Keys That'll Fit The Lock

Introduction: You're a key maker, and want to access something from a safe that has a lock. Unfortunately, the key to that lock is lost, so you'll have to make a new one. You have access to a bunch of ...
25
votes
17answers
3k views

A long long time ago, in a galaxy … right here

Task Given a positive integer return the geologic era and period it was that many million years ago. Input/output The input is a string or integer; the output is a string. Eras and periods are ...
19
votes
16answers
2k views

Find the discrete logarithm

Task Write a program/function that when given 3 positive integers \$a, b\$ and \$m\$ as input outputs a positive integer \$x\$ such that \$a^x\equiv b\ (\text{mod}\ m)\$ or that no such \$x\$ exists. ...
5
votes
5answers
267 views

Divide into 2 isosceles triangles

Given the measures of two of the interior angles of a triangle (x and y; the other angle can be easily calculated with ...
21
votes
6answers
2k views

The matrix has U

Given a matrix of size at least 3×3 formed by positive integers, determine if it contains at least one "U" pattern, defined as ...
12
votes
3answers
740 views

Metagolf the OEIS

We've had Meta Regex Golf and Display OEIS Sequences. Now, it is time for Meta OEIS Golf. Challenge Given a sequence of integers, your program/function should output a program/function in the same ...
0
votes
2answers
190 views

Remove each integer from a string and multiply them all! [closed]

Goal: Get every integer from the string (not a number, but integer) Multiply them Output the result Input: 5 kilograms of food eaten, 10 liters of water drank, 20 plates dirty, 40 mugs dirty, and ...

1
2 3 4 5
8