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

learn more… | top users | synonyms

25
votes
10answers
2k views

Array Escape - get out of there

One day you awake only to find yourself caught in an array. You try to just walk out of there, taking one index at the time, but it seems there are other rules: The array is completely filled with ...
24
votes
28answers
1k views

Substring Sum Set

Introduction Let's observe this array: [3, 2, 4, 1, 1, 5, 1, 2]. Each element displays the length of the substring which must be summed up. Let's take a look at the first element of the above array: ...
13
votes
12answers
517 views

Inverting lists of lists of indices

Inspired by this StackOverflow post. Introduction Bob's job is to create spreadsheets and organize them. The way he organizes them is known to very few except for Bob, but he creates a list of each ...
18
votes
8answers
1k views

Generate the Rummy Sequence

Your task is to take an input n and output element n of the Rummy Sequence, a sequence which I made (looking on OEIS will not help you). Definition Each element of the Rummy Sequence is a set of ...
1
vote
1answer
69 views

JSON tips: filter objects from array of objects where object name is alpha [closed]

I did this using a javascript library underscore which says filtered_obj = _.where(obj, { name: "Alpha" }); What could be the sortest code for filtering the following array in Javascript without any ...
29
votes
13answers
2k views

Stock Time Machine

Stock Time Machine You've gained access to a dataset, tomorrowStocks, which contains the stock prices from your favorite business on the NASDAQ. This dataset is a container indexed by minutes past ...
22
votes
21answers
1k views

Post-determined Array Sorting

Input: An array containing three integers: 0, 1 and 2 in any order (i.e. [2, 0, 1]) And a string of length >= 2 only containing alphabetic letters (both lower- and uppercase) and digits (i.e. a1B2c3)...
10
votes
9answers
851 views

Is it a max-heap?

A heap, also known as a priority-queue, is an abstract data type. Conceptually, it's a binary tree where the children of every node are smaller than or equal to the node itself. (Assuming it's a max-...
21
votes
54answers
3k views

Implement Takewhile

Introduction and Credit Today without a fancy prelude: Please implement takewhile. A variation of this (on a non-trivial data structure) was an assignment at my university functional programming ...
10
votes
32answers
952 views

Groups of repeating items

Challenge description Given a list / array of items, display all groups of consecutive repeating items. Input / output description Your input is a list / array of items (you can assume all of them ...
17
votes
22answers
949 views

Distinct Sieves

Given a list of integers, create a boolean mask such that the true indices can be used to filter the distinct values from the list. Which index is selected as the true one does not matter as long as ...
12
votes
8answers
419 views

Autonest an array

Everybody loves nested lists! However, sometimes it's hard to make a nested list. You have to decide if you want to nest it deeper, or if you need to nest it shallower. So for your challenge, you must ...
6
votes
3answers
269 views

Flood-fill a 2D grid

Challenge description Let's call a two-dimentional, rectangular array (meaning its every subarray has the same length), a grid. Every unit of a grid is either an empty space or a border. In a grid of ...
14
votes
8answers
651 views

Alternating sign matrix verification

An alternating sign matrix is an n by n matrix consisting of the numbers -1, 0, 1, such that: The sum of each row and column is 1 The nonzero entries in each row and column alternate in sign These ...
18
votes
26answers
2k views

Count Up, Replace, Repeat!

Definition Define the nth array of the CURR sequence as follows. Begin with the singleton array A = [n]. For each integer k in A, replace the entry k with k natural numbers, counting up from 1 to k....
7
votes
4answers
236 views

Count, Replace, Add Up! [duplicate]

Definition Define the nth term of the CRAU sequence as follows. Begin with the singleton array A = [n]. Do the following n times: For each integer k in A, replace the entry k with k natural ...
17
votes
14answers
1k views

Bit-Reversal Permutations

Your goal is to create a function or a program to reverse the bits in a range of integers given an integer n. In other words, you want to find the bit-reversal permutation of a range of 2n items, zero-...
29
votes
37answers
2k views

Difference of the square of the sum

Find the difference between the square of the sums and sum of the squares. This is the mathematical representation: (∑n)^2-∑n^2 Your program/method should take two inputs, these are your lower ...
35
votes
28answers
7k views

Weapons of Math Instruction

Last time when I tried to come up with something easy that wasn't a duplicate, it ended up being way too hard.. So hopefully this time it's indeed something newcomers can try as well. Input: An ...
7
votes
24answers
760 views

Same length sub arrays

Background: Here's a little simple challenge. You want to be able to find out whether the arrays inside an array have the same length. Input: Your input should consist of exactly one array (this is ...
11
votes
8answers
771 views

N-chotomize a list

Given a list of integers L, and an integer N, output L splitted in N sublists of equal lenghts. Non-divisible lengths If N does not divide the length of L, then it is not possible that all sublists ...
16
votes
10answers
775 views

Jam don't add like that

Background Jelly's arithmetic atoms vectorize automatically. In fact, x + y is well-defined whenever x and y are numbers or ragged arrays of numbers. Jelly's source code implements this behavior ...
15
votes
11answers
706 views

Oneliner to merge lines with same first field

This is my first codegolf question, so I apologize in advance if it's not appropriate, and I welcome any feedback. I have a file with this format: a | rest of first line b | rest of second line b | ...
10
votes
4answers
189 views

Minimum cost block diagonalisation

Consider binary block diagonal matrices which have square blocks of 1s on the main diagonal, and are 0 everywhere else. Let's call such matrices "valid" matrices. For example, here are some valid 4x4 ...
25
votes
15answers
2k views

Falsify brief truths

Find the longest run of true in a list of booleans. Return the same list, with all other trues falsified. Input, output A list; any usual format (e.g., a delimited list as a string). Details True ...
8
votes
12answers
893 views

Maximum Maxima!

Inspired by this question and refined by Luis Mendo. Challenge Given a 2D matrix of integers, each row has a maximum value. One or more elements of each row will be equal to the maximum value of ...
8
votes
26answers
2k views

The Nine Pattern

Introduction I stumbled across this (useless) pattern the other day while I was watching TV. I named it "the 9 pattern" because the first number to use it was 9. The gist of it is, you enter a number ...
3
votes
7answers
193 views

Randomly Assign People to Tasks

The challenge is to assign people to tasks randomly~. From stdin you get 2 lines. Line one is a comma-separated list of names. Line 2 is a comma-separated list of jobs. The output required is one line ...
27
votes
23answers
5k views

Flatten the Array!

In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] should output [10,20,30,40,50]. ...
10
votes
11answers
737 views

Discrete Convolution or Polynomial Multiplication

Given two non empty lists of integers, your submission should calculate and return the discrete convolution of the two. Interestingly, if you consider the list elements as coefficients of polynomials, ...
6
votes
6answers
178 views

Find how many pair elements sums up to N [closed]

Based on a recent question in StackOverflow Write a program/function that takes in one ARRAY/list and returns the number of pair-values which sums up to a given TOTAL. Explaining TOTAL=4, ARRAY=[1,...
22
votes
20answers
2k views

Index of a multidimensional array

Lower level languages, such as C and C++ actually have no concept of multidimensional arrays. (Other than vectors and dynamic arrays) When you create a multidimensional array with int foo[5][10]; ...
13
votes
8answers
563 views

Find a maximal rectangle of 1s

Background I want to buy an plot of land and build my house on it. My house should be rectangular, and as large as possible; however, the available plots have lots of rocky areas that I cannot build ...
17
votes
17answers
2k views

Counting in bijective base 62

The task is to generate all the strings from 'a' to '999' including upper case characters like so: 'a', 'b', 'c' ... 'y', 'z', 'A', 'B', 'C' ... 'Y', 'Z', '0', '1', 2' ... '8', '9', 'aa', 'ab', 'ac' ...
-22
votes
20answers
408 views

Reverse a 1-dimensional array

Note: This challenge is not the same. Challenge Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays (although we've got one for n-dimensional ones)! This should ...
14
votes
13answers
605 views

Smallest groups in an array

Introduction Let's observe the following array: [1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1] A group consists of the same digits next to each other. In the above array, there are 5 different ...
13
votes
18answers
728 views

Run through an array

We all often hear the idiom "walk through the array" to mean "map the function over the following array". However, I need it done (now!), so I want you to run through the array. How do I run? ...
5
votes
1answer
121 views

Swap Pairs or Remove

Specification For this challenge you will: Take an array of positive integers. For each overlapping pair in the array, calculate the difference of it's integers. If the difference is a common ...
22
votes
28answers
1k views

Reverse positive runs

Input Your input is a list of single-digit numbers in any reasonable format, including a string of digits. The input will not be empty. Output Your output shall be the input list, but with each ...
14
votes
1answer
336 views

Generate a looping array

Introduction A pointer array is an array L of nonzero integers where 0 ≤ L[i]+i < len(L) holds for all indices i (assuming 0-based indexing). We say that the index i points to the index L[i]+i. ...
16
votes
15answers
2k views

Diamondize a Matrix

Given a matrix, output a representation of the matrix where the top left element is on top, the anti-diagonal is the central row and the bottom right element is at the bottom. For example, consider ...
12
votes
6answers
1k views

Who's the king of the tournament?

Background Consider a round-robin tournament, in which each contestant plays one game against every other contestant. There are no draws, so every game has a winner and a loser. A contestant A is a ...
13
votes
16answers
789 views

Sorting rectangular matrices

Given a matrix A, we can say that it is "sorted" if each row and column of A is sorted (ascending left-to-right for rows and top-to-bottom for columns). Thus, this matrix is sorted: [ 1 2 3 4 5 ] [ 2 ...
11
votes
9answers
1k views

A classic sorting code-golf question

This is a code-golf question. Input A list of non-negative integers in whatever format is the most convenient. Output The same list in sorted order in whatever format is the most convenient. ...
22
votes
9answers
1k views

Sort a nested list

You must write a program or function that sorts a nested list. Here are the rules for sorting a nested list: Let's take this list as an example: ((5, 2), 2, 7, (2, 1, (3, 4)), 9) Each element in ...
10
votes
5answers
603 views

Print arrays from the middle out

This is a code-golf question. Given integers s and n the task is to output all arrays of length n which take values from -s to s. The only twist is that you must output them in the following order. ...
16
votes
6answers
331 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
412 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 ...
33
votes
10answers
3k 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
814 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 ...