Questions tagged [array]

A competition to solve a particular problem through the usage and manipulation of arrays.

Filter by
Sorted by
Tagged with
12 votes
10 answers
987 views

Convert J brackets back to 2-D list

Let's say we have a 2-D list, like the following one: \$ \begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4} \\ \color{blue}{5} & \color{blue}{6} & \...
  • 12.7k
20 votes
13 answers
3k views

Shuffle an array, a little bit

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array ...
  • 43.4k
16 votes
16 answers
1k views

Damerau-Damerau distance

Given a list of the integers from \$1\$ to some \$n\$, give the minimum number of adjacent swaps required to put the list in ascending order. You will receive a list as input and should output a non-...
  • 93.8k
17 votes
11 answers
824 views

Find the J twin

For a 2 dimensional array we will define the elements in either the first row or the last column to be the largest "J-Bracket" of the array. For example in the following array elements in ...
  • 93.8k
18 votes
19 answers
1k views

Removed J-brackets

For a 2 dimensional array we will call the elements in either the first row or the last column the "J-Bracket" of the array. For example in the following array elements in the J-bracket are ...
  • 93.8k
10 votes
6 answers
589 views

Fourth Time's the Triple Tap

The sci-fi shooter Destiny 2 contains guns which have the ability to regenerate ammunition directly into the magazine if, and only if x (precision) shots are landed ...
40 votes
13 answers
5k views

Recreate Minecraft's lighting

Minecraft has a fairly unique lighting system. Each block's light value is either one less than the brightest one surrounding it, or it is a light source itself. Your task is to write a method that ...
  • 691
21 votes
14 answers
2k views

Sort numbers in a ragged list

Given a ragged list, e.g. [[4, 7], [5, 3, [], [6, [2]]]] Your challenge is to sort only the numbers in it. For example, with the above, the result would be ...
7 votes
13 answers
1k views

Complex permutation

Given an array of integers as input(including negative integers), find all (can include duplicates) permutations that do not have the same number next to each other, then print them all out. If no ...
  • 465
19 votes
28 answers
2k views

Zip uneven lists

In this challenge you will take two lists as input and you will zip them. The zip can be defined with this recursive expression: \$ \mathrm{zip}(a,b) = \begin{cases} \left[\,\,\right] & a = \left[...
  • 93.8k
10 votes
7 answers
455 views

Sort musical pitches

Given an unordered list of musical pitches, write the shortest program/function (scored in bytes) to sort the list from lowest pitch to highest. Pitches will be given in scientific pitch notation, ...
  • 10.9k
29 votes
34 answers
2k views

Repeat List Until Longer

The Challenge The challenge is simple: given an input list a and another list b, repeat a ...
  • 5,153
3 votes
5 answers
329 views

The Nineteenth Bakery [duplicate]

Yes, this is very similar to this question. However, that concerns infinite linked lists, and you do not need to handle out of bounds indexes in that question. You are in a strange city, looking for ...
  • 5,153
15 votes
3 answers
357 views

What was my Wordle play?

Task Given a winning Wordle play results (clues), the target ("secret") word and a list of words, output a possible sequence of words leading to such results. The words in the list will be ...
  • 13.7k
25 votes
30 answers
2k views

Fill in the next numbers

Given a list of integers, output a list where the \$ i \$th element of the list equals the first number in the input list which is \$ \ge i \$, until there are no such numbers. For example, if the ...
  • 23.3k
14 votes
14 answers
1k views

Lexicographically Smallest Decreasing Integer Partition

For a given number n, output an strictly decreasing array whose sum is n and its lexicographical order is the smallest for any ...
  • 4,937
6 votes
6 answers
602 views

Crate art stacking

Your task is, given a array of numbers, that is strictly increasing, output the crate stack. The input is an array of positive integers which represents which layer has how many crates there are. So ...
  • 4,937
19 votes
27 answers
2k views

Is it a tower permutation?

A tower is made out of layers, each one being one unit shorter than the one below it. Every layer is completely on top of the previous layer. For example, here is a tower along with it's height map: <...
  • 6,785
12 votes
8 answers
1k views

Wiggle the tower

Your input is the height map of a tower. The tower is made out of layers, each one being one unit shorter than the one below it. Every layer is completely on top of the previous layer. For example <...
  • 6,785
21 votes
10 answers
1k views

Pretty print my arrays

I like to pretty print multidimensional arrays, like this: [ [ [1, 2, 3], [4, 5, 6] ], [ [7, 8, 9], [6, 4, 2] ] ] But it's a pain to do by hand and it'd ...
11 votes
10 answers
960 views

Smallest maximal rectangle in a skyline

A skyline is an array of positive integers where each integer represents how tall a building is. For example, if we had the array [1,3,4,2,5,3,3] this would be the ...
  • 6,785
24 votes
11 answers
3k views

"Defuse" the bombs

You've been hired by a bomb defusing company to perform some "controlled" demolition of un-exploded ordnance. You are given a list of bombs represented by non-negative integers. ...
  • 93.8k
12 votes
5 answers
907 views

Simulating Bombs

More advanced version of this The aim of this puzzle is to simulate the impact of the shock wave of bombs on a square grid. The grid initially contains cells labelled ...
  • 4,937
7 votes
1 answer
319 views

Heart Point Generator

It's mentioned last time that, in Hearts, Each round every player gets a non-negative amount of points. The sum of the points is 26, and at least one player gets 13 or more points. Actually, it's ...
  • 17k
16 votes
21 answers
3k views

Largest rectangle in a skyline

A skyline is an array of positive integers where each integer represents how tall a building is. For example, if we had the array [1,3,4,2,5,3,3] this would be the ...
  • 6,785
25 votes
9 answers
946 views

Generate all groupings

Let's define a grouping as a flat list, which is either: just 0 2 groupings followed by the literal integer 2 3 groupings ...
  • 23.3k
21 votes
19 answers
2k views

Rolling a ball over a list

Starting with a binary list (just 1s and 0s) we are going to roll a ball over it. The ball has a position and a direction. At ...
  • 93.8k
20 votes
1 answer
508 views

Can I wall glitch to there?

Background In a 2d game that I play, each screen is a 2d grid of tiles with walls and walkable tiles, with the player only able to travel on walkable tiles, and being stopped by walls. When the player ...
  • 11.2k
5 votes
3 answers
215 views

Cubax Folding Game

Your task is to solve a new puzzle called Cubax. This toy is actually a Chinese puzzle whose expected “final” state is a simple cube. During the festivities, Cubax unfolded, because it cannot move ...
  • 4,937
17 votes
6 answers
941 views

Retaining Water

Your task is to check the volume of water in a pool. Your have to create a program that takes in a input that is represented by an 10 by 10 grid of integers, with ...
  • 4,937
22 votes
6 answers
790 views

Check if a matrix is Zarankiewicz-maximal

My final-year project at the National University of Singapore is on Zarankiewicz's problem: What is the maximum number of 1s in an \$m×n\$ binary matrix (\$m\$ rows and \$n\$ columns) with no \$a×b\$ ...
  • 2,927
3 votes
1 answer
315 views

Bracket Depth List

Challenge Your challenge is simple, calculate the depth of each matching brackets in the given input e.g. (()()(()))->...
  • 4,937
22 votes
23 answers
1k views

How many laps around the permutation?

Your input is an array of numbers: a permutation of \$\{1, 2 \dots n\}\$ for some integer \$n \geq 2\$. How many times must you repeat this list before you can "pick out" the numbers \$[1, 2 ...
  • 67k
17 votes
3 answers
1k views

Solve Rubik's Clock

Rubik's Clock is a round(ish) puzzle with two flat sides. On each side, front and back, there are 9 clock faces, arranged on a 3x3 grid. In addition, there are 4 pegs (switches) in between the clock ...
  • 6,786
12 votes
8 answers
523 views

Is there a stable way to stack these?

If we have a binary matrix then we will say that a \$1\$ is stable if it is in the bottom row or it is directly adjacent to a \$1\$ which is stable. In other words there must be a path to the bottom ...
  • 93.8k
18 votes
18 answers
999 views

One pair or fewer

Given a list of positive integers, give the longest contiguous sublist which contains at most 1 pair of identical items. In the case of a tie return any of the solutions. This is code-golf so the ...
  • 93.8k
15 votes
15 answers
1k views

Animate finding the middle (hypercube edition)

1d version Given a multidimensional array of positive integers where all dimensions are the same length, animate finding the centre of it. Simply output the array, then remove the first and last items ...
14 votes
14 answers
785 views

SuperSquares NxN

Given an integer N from 1-9, you must print an NxN grid of NxN boxes that print alternating 1s and Ns, with each box having an alternating starting integer. Examples ...
  • 747
23 votes
18 answers
2k views

Print a NxN integer involute

Given an integer \$N\$, you must print a \$N\times N\$ integer involute with the numbers increasing in a clockwise rotation. You can start with either 0 or 1 at the top left, increasing as you move ...
  • 431
8 votes
8 answers
451 views

Count the ways to transform

A rigid transformation of a square array is a mapping from square arrays of a certain size to square arrays of the same size, which rearranges the elements of the array such that the distance to each ...
  • 93.8k
23 votes
12 answers
4k views

Squishy vectors

If we have a list of integers we can "squish" one of them by: decrementing it replacing adjacent values with its new value For example in this list: ...
  • 93.8k
18 votes
17 answers
2k views

Sort every dimension

Given a multidimensional, rectangular array of nonnegative integers, sort it at every depth (lexicographically), starting from the innermost. For example, with this array: ...
21 votes
14 answers
1k views

Build a list from a depth map

You will be given as input a non-empty list of positive integers. For example: [1,2,2,2,1] You want to produce a ragged list as output which has this as its "...
  • 93.8k
30 votes
21 answers
3k views

How many times can I skip a stone?

Let's have a list of positive integers [6,1,9,3,7,4,6,3,2,7,6,6] this will represent a river. We would like to skip a stone across this river. We can throw the ...
  • 93.8k
30 votes
9 answers
675 views

Predicting pumpkin planting plans' potential problems

You are going to be planting pumpkins soon, and you are preparing your supplies. Pumpkins come in all sorts of sizes and have their sizes written on the seed bag. A pumpkin that is size n will grow ...
  • 93.8k
12 votes
21 answers
935 views

Move to Right and left

Task Your task is to take an array of numbers as input, and produce a new one where each number has been shifted both right and left, leaving 0s if no number fills ...
  • 2,861
20 votes
36 answers
2k views

Implement an argwhere function

The \$\text{argwhere}\$ function takes a list of values and a predicate/boolean function as arguments and returns a list of indices where the predicate function returns true in the input list. For ...
  • 16.8k
21 votes
53 answers
2k views

Remove odd indices and double the even indices

Your task is simple, just remove the odd indices and double the even indices Example the input is Hello, World! and we get indices ...
  • 2,861
15 votes
9 answers
845 views

Array depth of a ragged list

This is not a duplicate of this challenge. Here by an array, I mean a nested list that is "not ragged", i.e., it is either a list of elements, or a list of arrays of the same shape. For ...
  • 41.9k
14 votes
13 answers
970 views

Compare shapeless lists

Let's have a ragged list containing no values, only more lists. For example: [[[],[[]],[],[]],[],[[],[],[]],[]] And the list will be finite, meaning that ...
  • 93.8k

1
2
3 4 5
16