Questions tagged [array]

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

Filter by
Sorted by
Tagged with
16 votes
25 answers
1k views

Alternating sums of multidimensional arrays

Given a multidimensional array, find the recursive alternating sum. An alternating sum is simply the sum of an array, where every other item (starting with the second) is negated. For example, the ...
user avatar
7 votes
2 answers
229 views

Write a (simplified) BitCycle interpreter

Implement a function or program that can run simplified BitCycle code. The functions you must implement are: <^>v: Change the direction of a bit to the ...
user avatar
  • 1,130
10 votes
15 answers
308 views

center a matrix [closed]

The words "center a" probably give flashbacks to any decent HTML developer. Luckily, we are not working with divs, we are working with matrices. Given a matrix where w=h, and given a "...
user avatar
  • 691
15 votes
7 answers
1k views

Euler characteristic of a binary matrix

A binary matrix represents a shape in the plane. 1 means a unit square at that position. 0 means nothing. The background is <...
user avatar
  • 32.6k
12 votes
5 answers
422 views

Unshuffle my poker chips

This part is somewhat detached from the actual array manipulation side of the challenge, scroll down for an explanation that is much more array-based You've been learning how to shuffle poker chips ...
user avatar
12 votes
7 answers
1k views

Is Wally there?

Inpired by recent Stand-up Maths' video. Task Wrapping a list x can be seen as inserting "line-breaks" into x every <...
user avatar
  • 10.7k
21 votes
16 answers
1k views

Get the trends of an array

For our purposes, a trend is a contiguous subsequence of an array that falls into one of three categories: increasing, e.g. [1,2,3,10,239] decreasing, e.g. ...
user avatar
  • 8,538
12 votes
10 answers
938 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} & \...
user avatar
  • 3,408
20 votes
13 answers
2k views

Shuffle an array, a little bit

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array ...
user avatar
  • 42.9k
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-...
user avatar
  • 84.4k
17 votes
11 answers
775 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 ...
user avatar
  • 84.4k
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 ...
user avatar
  • 84.4k
10 votes
6 answers
550 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 ...
user avatar
40 votes
13 answers
4k 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 ...
user avatar
  • 691
20 votes
14 answers
1k 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 ...
user avatar
  • 26.8k
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 ...
user avatar
20 votes
26 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[...
user avatar
  • 84.4k
11 votes
7 answers
437 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, ...
user avatar
  • 10.3k
28 votes
29 answers
2k views

Repeat List Until Longer

The Challenge The challenge is simple: given an input list a and another list b, repeat a ...
user avatar
  • 2,488
3 votes
5 answers
319 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 ...
user avatar
  • 2,488
15 votes
3 answers
334 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 ...
user avatar
  • 10.7k
25 votes
27 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 ...
user avatar
  • 18.2k
14 votes
14 answers
989 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 ...
user avatar
  • 3,031
6 votes
5 answers
557 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 ...
user avatar
  • 3,031
21 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: <...
user avatar
  • 6,645
13 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 <...
user avatar
  • 6,645
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 ...
user avatar
  • 26.8k
11 votes
10 answers
949 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 ...
user avatar
  • 6,645
22 votes
10 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. ...
user avatar
  • 84.4k
12 votes
5 answers
888 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 ...
user avatar
  • 3,031
6 votes
0 answers
192 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 ...
user avatar
  • 12.7k
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 ...
user avatar
  • 6,645
23 votes
9 answers
870 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 ...
user avatar
  • 18.2k
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 ...
user avatar
  • 84.4k
19 votes
1 answer
441 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 ...
user avatar
  • 3,772
5 votes
3 answers
196 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 ...
user avatar
  • 3,031
17 votes
6 answers
876 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 ...
user avatar
  • 3,031
22 votes
6 answers
754 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\$ ...
user avatar
2 votes
0 answers
205 views

Bracket Depth List

Challenge Your challenge is simple, calculate the depth of each matching brackets in the given input e.g. (()()(()))->...
user avatar
  • 3,031
22 votes
22 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 ...
user avatar
  • 65.5k
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 ...
user avatar
  • 6,090
12 votes
8 answers
511 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 ...
user avatar
  • 84.4k
18 votes
18 answers
972 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 ...
user avatar
  • 84.4k
16 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 ...
user avatar
  • 26.8k
15 votes
14 answers
764 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 ...
user avatar
  • 757
24 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 ...
user avatar
  • 431
8 votes
8 answers
448 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 ...
user avatar
  • 84.4k
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: ...
user avatar
  • 84.4k
16 votes
16 answers
1k 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: ...
user avatar
  • 26.8k
20 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 "...
user avatar
  • 84.4k

1
2 3 4 5
15