A competition to solve a particular problem through the usage and manipulation of arrays.
9
votes
1answer
116 views
Hilbert-Curvify a Matrix
Inspired by this question
Another way to unroll a 2D image into a 1D string is to use an Hilbert Curve.
There are many version of this curve, depending on the number of iterations used while ...
16
votes
2answers
356 views
Reconstruct a zigzagified matrix
As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction:
Your task is to take the unrolled vector along with the matrix ...
32
votes
10answers
2k views
Zigzagify a Matrix
As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction:
Your task is to take a matrix (not necessarily square) and ...
20
votes
5answers
769 views
Is this a submatrix?
This is the 2-dimensional generalisation of this challenge.
For our purposes, one matrix (or 2D array) A is considered a submatrix of another matrix B, if A can be obtained by completely removing a ...
-1
votes
0answers
58 views
Encoding decoding code challenge [closed]
Imagine an array of numbers 0 - 99
eg
var arrayOfNumbers = [ 0, 1, 2, 3..... ,98, 99 ];
Loop through every (x)th number and remove ( splice ) it from the original array and push it into a second ...
12
votes
8answers
498 views
How many steps did I walk?
A simple pedometer can be modeled by a pendulum with two switches on opposite sides—one at x=0 and one at x=l. When the pendulum contacts the far switch, the ambulator can be assumed to have taken ...
9
votes
2answers
157 views
Rotate every 2x2 block in a matrix
The Challenge
Given a n x m matrix with n > 1 and m > 1 filled with integers
1 2 3
4 5 6
and a list of integers with exactly as many values as 2x2 blocks in the matrix ((n-1)*(m-1) if you ...
28
votes
34answers
3k views
Yahtzee Small Straight Detection
In the game Yahtzee, players roll five six-sided dice, and attempt to create certain hands to score points. One such hand is a small straight: four consecutive numbers, not necessarily in order. The ...
18
votes
16answers
2k views
Center of Mass from a list of coordinates and their masses
Here is a quick Monday morning challenge...
Write a function or program in the least number of bytes that:
Takes as input a list of [x,y] coordinates
Takes as input a list of the [x,y] coordinates' ...
13
votes
2answers
152 views
Rotate every row and column in a matrix
The Challenge
Given a n x n matrix of integers with n >= 2
1 2
3 4
and a list of integers with exactly 2nelements
[1,2,-3,-1]
output the rotated matrix. This matrix is contructed in the ...
17
votes
15answers
672 views
Fluctuating ranges
Given a list with number, output the ranges like this:
Input: [0, 5, 0] would become [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0].
This is mapping a range through the array, so we first have to create the ...
15
votes
9answers
416 views
Block-diagonal matrix from columns
Inspired by Copied from this question at Stack Overflow.
Given a matrix A, create a matrix B such that the columns of A are arranged in a block-diagonal fashion. For example, given
1 2 3
4 5 6
the ...
-5
votes
15answers
634 views
Is the time linear?
I like patterns in time. My favorite is when the time lines up. For example, all of these line up:
3:45
12:34
23:45
3:21
6:54
This is because each digit in the hour/minute is increasing/decreasing ...
27
votes
15answers
880 views
Repair the ranges
Given an input of a list of positive integers with some replaced with 0,
output the list with the missing numbers that were changed to 0 replaced.
Characteristics of the input list:
The list will ...
22
votes
11answers
976 views
Leaving the Nest
Given a non-flat list of integers, output a list of lists containing the integers in each nesting level, starting with the least-nested level, with the values in their original order in the input list ...
19
votes
4answers
381 views
“Finish work” as early as possible
Background
Imagine for a moment that you have a mind-numbingly boring job.
Every morning, you are given a collection of tasks that you should work on that day.
Each task has a certain duration, and ...
18
votes
15answers
1k views
Compute minimax of an array
Inspired by this question
Consider an array x such as [1 5 3 4] and a number n, for example 2. Write all length-n sliding subarrays: [1 5], [5 3], [3 4]. Let the minimax of the array be defined as ...
-2
votes
11answers
194 views
Make a search engine
You need to make a program, that when giving a list and a string, searches on the list for items that contains the string.
Examples:
Input: th [thing, awesome, potato, example]
Output: thing ...
15
votes
13answers
852 views
Get the closest value to number
In this code golf, you need to get the closest number from another one in a list.
The output may be the closest number to the input.
Example:
value: (Input) 5 --- [1,2,3] --- 3
And, the program ...
24
votes
33answers
981 views
Remove leading and trailing zeroes
Given a non-empty list/array containing only non-negative integers like this:
[0, 0, 0, 8, 1, 4, 3, 5, 6, 4, 1, 2, 0, 0, 0, 0]
Output the list with trailing and leading zeroes removed.
The output ...
17
votes
11answers
464 views
Maximise the squared difference
Consider a permutation of the integer values from 1 to N. E.g. this example for N = 4:
[1, 3, 4, 2]
We'll consider this list to be cyclic, such that 1 and 2 are treated as adjacent. One quantity we ...
31
votes
27answers
3k views
Hollow out an array
The task
This challenge is very simple.
Your input is a rectangular 2D array of integers, sized at least 1×1.
It can be taken in any reasonable format.
Your output shall be the input array, but ...
24
votes
29answers
2k views
Determine the depth of an array
A simple challenge for your Monday evening (well, or Tuesday morning in the other half of the world...)
You're given as input a nested, potentially ragged array of positive integers:
[1, [[2, 3, ...
11
votes
15answers
2k views
Apply Kirchhoff's law
Kirchhoff's law says that when you sum up all the currents (positive for the currents going to a junction, and negative for current leaving a junction), you will always get as result 0.
Look at the ...
27
votes
32answers
3k views
Find the largest and the smallest number in an array
The Task
The task is very simple. Given an array containing only integers and strings, output the largest number and the smallest number.
Test Cases
Input: [1, 2, 3, 4, 5, 6, 7, 8]
Output: 1, 8
...
21
votes
4answers
287 views
Magnetic pull in an array
Background
I have a row of powerful magnets and a bunch of metal objects between them.
Where will the magnets pull them?
Input
Your input is an array of non-negative integers, which will contain at ...
14
votes
3answers
320 views
Check work periods
Introduction
Here in Germany the ruling on work times is very strict. If you work 6 or more hours a day, you have to take at least a 30 minute break. If you work 9 or more hours, you need to take a ...
24
votes
37answers
2k views
Consolidate an Array
The task is simple: consolidate an array of ints. Consolidating this array consists of the following:
All instances of 0 need to be moved to the end of the array.
There should be no 0s between the ...
15
votes
12answers
582 views
Remove specified non-numeric rows
In case there's any doubt: Nan = Non-numeric datatype for the purposes of this challenge.
Write a program or function that takes a matrix / array as input, as well as a list of column indices.
...
28
votes
14answers
2k views
Show the Top Five Comment Scores on a SE Post
A Stack Exchange script determines which five comments on questions or answers are initially seen on the main page of sites through the number of upvotes on them; the five comments with the highest ...
36
votes
20answers
3k views
Remove every N-th N
The task
In this challenge, your input is a non-empty list of positive integers, given in the native format of your language.
Your output is that same list, in the same format, with some elements ...
24
votes
7answers
1k views
Bouncing in an array
Introduction
Arrays can also be seen as a field for a bouncing ball. This of course sounds very vague, so here is an example of an input:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[9, 8, 7, 6, 5, 4, 3, 2, 1]
[1, ...
38
votes
32answers
9k views
Cheating a multiple choice test
Introduction
While studying, I tried to come up with several ways to cheat a multiple choice test. It basically is a compressed version of the multiple choice answers. The method goes as following:
...
36
votes
13answers
4k views
Look, up in the sky! It's a super duper array!
Inspired by this question from our rivals friends over at Code Review.
Definitions
A super array is an array where each new element in the array is larger than the sum of all the previous elements. ...
9
votes
1answer
197 views
Sort scrambled two-dimensional array filled with numbers by swapping adjacent numbers [closed]
A two-dimensional array of size n×n is filled with n*n numbers, starting from number 1. Those numbers are to be sorted per row in ascending order; the first number of a row must be greater than the ...
18
votes
7answers
879 views
Find the capacity of 2D printed objects
In a fictional 2D world, a set of 2D printing instructions for an object can be represented by a list of integers as follows:
1 4 2 1 1 2 5 3 4
Each number represents the height of the object at ...
25
votes
22answers
1k views
Find ranges of True values in a list
Challenge:
Write a function or program that accepts a list of boolean values and returns all of the ranges of True's.
Test Cases:
f [F] = []
f [T] ...
47
votes
9answers
3k views
Surrounded Countries
Countries own a series of territories on a 1D world. Each country is uniquely identified by a number. Ownership of the territories can be represented by a list as follows:
1 1 2 2 1 3 3 2 4
We ...
18
votes
1answer
368 views
Separate my integers
Introduction
In the field of mathematics known as topology, there are things called separation axioms.
Intuitively, you have a set X and a collection of subsets of X, which we can think of as ...
82
votes
15answers
3k views
Xorting an array
Conceptually, this challenge is really simple. You're given a list of non-negative integers ai. If possible, find a non-negative integer N, such that the list consisting of bi = ai XOR N is sorted. If ...
14
votes
2answers
212 views
Can the Array be Unshuffled?
Background
Very skilled card handlers are capable of a technique whereby they cut a deck perfectly in half, then perfectly interleave the cards. If they start with a sorted deck and perform this ...
31
votes
36answers
2k views
Cover up zeroes in a list
Inspired by this SO question
As input you will be given a non-empty list of integers, where the first value is guaranteed to be non-zero. To construct the output, walk from the start of the list, ...
33
votes
13answers
5k views
The sum is always 15
Write a program or function that takes an array of non-negative integers as input and outputs a set of vectors/arrays with the elements of the input array in order, split so that each vector sums up ...
23
votes
28answers
1k views
Separate a list into even-indexed and odd-indexed parts
Inspired by this question:
Make a function (or a full program) that receives a list of numbers and outputs the list rearranged, so that even-indexed numbers appear first, and odd-indexed numbers ...
26
votes
8answers
964 views
Rotate the anti-diagonals
Background
In most reasonable programming languages, it's very easy to rotate the rows or columns of a 2D array.
In this challenge, your task is to rotate the anti-diagonals instead.
Recall that the ...
14
votes
1answer
676 views
90° Self-Rotating Program
Introduction
Write a complete program that rotates a rectangular block of ASCII characters 90 degrees clockwise. When the program itself is rotated 90 degrees clockwise, it rotates a block of ASCII ...
19
votes
2answers
260 views
Are these trees isomorphic?
Introduction
In this challenge, your task is to write a program that decides whether two given trees are isomorphic.
A tree means a directed acyclic graph where every node has exactly one outgoing ...
34
votes
35answers
4k views
Lossy Sorting (Implement Dropsort)
Dropsort, designed by David Morgan-Mar, is an example of a linear-time "sorting algorithm" that produces a list that is, in fact, sorted, but contains only some of the original elements. Any element ...
18
votes
11answers
659 views
Calculate the bounded cumulative sum of a vector
The cumulative sum of a vector is calculated by simply taking the sum of all previous elements. For instance:
vec = [1 1 1 -1 -1 -1 -1 -1 1 1 1 1 -1]
cum_vec = [1 2 3 2 1 0 -1 -2 -1 0 ...
22
votes
24answers
1k views
Iterated partial sums
The partial sums of a list of integers [a1, a2, a3, ..., an] are
s1 = a1
s2 = a1 + a2
s3 = a1 + a2 + a3
...
sn = a1 + a2 + ... + an
We can then take the list of partial sums [s1, s2, s3, ..., sn] ...