Questions tagged [array]
A competition to solve a particular problem through the usage and manipulation of arrays.
839 questions
17
votes
18
answers
1k
views
Order a list by the difference of its elements
Task
Given an unsorted list of integers, order it in such a way that the absolute difference of every two adjacent elements will always be equal to 1:
\$|dx| = 1\$
There will be guaranteed one or more ...
11
votes
11
answers
788
views
Find a linear function such that if f(0), f(1), f(2), ⋯ are indices of the elements of the list, the sum must equal to its slope
Challenge:
Find integers \$a\$ and \$b\$ defining linear function \$f(x) = ax + b\$ with \$a > 0, b \ge 0\$ such that the sum of the elements of the input list \$l\$ located at the values of the ...
16
votes
16
answers
1k
views
Activate the Laser Gates
In a secret lab corridor, there are emitters and gates: A number represents a laser emitter with a certain frequency, a 0 represents an inactive gate. If two ...
18
votes
5
answers
1k
views
Hide from the "left-hand wall" robot
You need to hide in a maze from a robot which methodically follows the left hand wall rule. That is, it enters, immediately turns left, and will always move keeping its left hand on the wall. It only ...
5
votes
5
answers
364
views
Calculate the Squadrat "yard"
Write a program/function to calculate the squadrat "yard" from a collection of squadrats.
Squadrats is a platform that gamifies outdoor activities by recording which large (~1.6 km square) ...
9
votes
4
answers
664
views
Triangular Transposition Cipher
A text that can be arranged triangularly in some fashion can be read back in some other fashion effectively enciphering it.
Narrowing down a set of plausible triangular numberings allows to ...
13
votes
7
answers
980
views
Traverse the list
Update 2025-06-04: Thanks for the submissions everyone! It seems like a lot of the solutions are quite slow / timeout for the 100 length test case, so I don't think any will be able to do the 10k. ...
10
votes
6
answers
840
views
Optimal Assembly Jump Distance
In some forms of assembly, there are separate "short jump" and "long jump" instructions. However, these jumps can themselves have different lengths, which can affect the distance ...
4
votes
1
answer
287
views
Find the factor to use for shortest simple Brainfuck data initialization loop
I like writing answers using Brainfuck, since this language basically simulates a Turing machine, and it is pretty challenging to find the shortest answer for any problem, since there are a lot of ...
13
votes
9
answers
865
views
Output the symmetric inverse semigroup
The symmetric inverse semigroup is a very important object in the study of semigroups, for a number of reasons, but most obviously due to the Wagner-Preston theorem. In brief, for any set \$X\$, the ...
15
votes
14
answers
2k
views
Max Island Area
You are given a two-dimensional array consisting of 0s and 1s. The number of rows and columns can vary. For example, 10 by 20.
0 represents water.
1 represents land.
Your task is to find the area of ...
11
votes
13
answers
1k
views
Longest bitonic subarray
Solve this problem in the fewest number of bytes of code possible.
We have a data variable that contains user input data.
Data is a list of integers.
Write the code that finds the longest bitonic ...
37
votes
17
answers
2k
views
In what order will the downloads complete?
Background
Recently, I was installing updates on my pc with Pacman (I use arch btw) and noticed the order it downloaded files was like this
Start with the largest 4 downloads
When a download ...
9
votes
48
answers
2k
views
Calculate sum of self-exponentation
Given an array of positive integers, calculate the sum of each number raised to its own power. For example, given 4,6,7, the code needs to return \$4^4+6^6+7^7=...
28
votes
16
answers
2k
views
Is it a cartesian product?
The cartesian product of two multisets \$A\$ and \$B\$ is the multiset of all ordered pairs consisting of an element of \$A\$ and an element of \$B\$. For example, the cartesian product of \$\{1, 2, 7,...
24
votes
19
answers
2k
views
Emulate Jelly's tie-scan
The golfing language Jelly has a built-in ƭ called "tie", that cycles through a list of functions every time it's called. For example, ...
16
votes
15
answers
1k
views
Reconstruct a list of strings from its prefixes
emanresu A posted a challenge to reconstruct an ordered list of integers from its unordered set of unordered prefixes. Many users (beginning with xnor's answer) noticed that summing each unordered ...
12
votes
7
answers
2k
views
Contract a tensor
Introduction
Tensor contraction is an operation that can be performed on a tensor. It is a generalization of the idea of the trace of a matrix. For example, if we have a rank-2 tensor (a matrix) and ...
26
votes
23
answers
2k
views
Remove falsy rows and columns
Your challenge is to, given a matrix of nonnegative integers, remove all rows and columns that contain a 0.
For example, with this matrix:
...
7
votes
4
answers
449
views
Busy Letters & Evil CEOs
Imagine you are given an array/string containing \$5\$ letters of the English alphabet, with each letter having any value from A to Z (inclusive).
Every day, each letter will perform a job, which can ...
10
votes
6
answers
1k
views
Unnecessary Fluff
Following the great advice (what do you mean it's not advice?!) on Adding unnecessary fluff we can devise the following task:
Take a list of positive integers and a positive integer \$m\$ as input.
...
11
votes
8
answers
1k
views
Night hike partitioning
We want to go on a night hike with the youth group, but of course not everyone has their torch, even though we told them we planned to split up. What options are there for group formation if n teens ...
19
votes
24
answers
3k
views
Just another traffic jam!
One lane is closed, the vehicles have to thread their way in according to the zip-lock system: One car from one lane, the next car from the other lane, always taking turns.
Input: Two vehicle queues, ...
7
votes
2
answers
365
views
How many twisted corners?
Your challenge is to output the number of twisted corners given a 2x2 Rubik's Cube scramble.
For the purpose of this challenge, twisted corners are defined as corners where the colour of the top/...
30
votes
20
answers
4k
views
How many umbrellas to cover the beach?
You work at a beach. In the afternoon, the sun gets quite hot and beachgoers want to be shaded. So you put out umbrellas. When you put out umbrellas you want to shade the entire beach, with as few ...