A competition to solve a particular problem through the usage and manipulation of arrays.
22
votes
22answers
3k views
Compute the kangaroo sequence
Backstory
Disclaimer: May contain made up information about kangaroos.
Kangaroos traverse several stages of development. As they grow older and stronger, they can jump higher and longer, and they ...
10
votes
12answers
303 views
Given a string, Return its Cumulative Delta [duplicate]
Related
Explanation
Given a string such as DCBA, convert it to ASCII ordinals, such as 68 67 66 65. Then, take the differences between each value, eg 67 - 68 = -1, 66 - 67 = -1... giving -1 -1 -1 ...
-3
votes
0answers
121 views
Split a list in chunks of n size without using “if-else” structures [closed]
Make a function that take a list and a number and output the same list splitted in chunk of n size.
For example:
[1,2,3,4,5,6], 2
=> [[1,2], [3,4], [5,6]]
[1,2,3,4,5,6], 3
=> [[1,2,3], [4,5,6]...
61
votes
28answers
5k views
2048-like array shift
Assume we want to shift an array like it is done in the 2048 game: if we have two equal consecutive elements in array, merge them into twice the value element.
Shift must return a new array, where ...
13
votes
11answers
784 views
The Woz Monitor
Challenge
I've recently gotten into 8-bit computers and are fascinated with the workings of them and others alike; thus the objective of this code golf, is to replicate a portion of the Woz Monitor, ...
9
votes
10answers
277 views
Interpret loose ranges
Interpret loose ranges
ListSharp is an interpreted programming language that has many features, one of those features is a 1 index based range creator that works like this:
You define a range as (...
18
votes
17answers
1k views
Multiple-Key Sorting
Given a list of indices and zero or more lists of integers, output the lists of integers, sorted in ascending order, with the key priority from the first input.
Example
Let the keys input be [1, 0, ...
27
votes
9answers
1k views
Build a nest
The challenge is simple: write a program or function that, when given a finite non-negative integer, outputs a nested array.
The rules
Your code must produce a unique valid nested array for every ...
11
votes
37answers
2k views
Output a string's cumulative slope
Challenge
Given a string such as Hello World!, break it down into its character values: 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33.
Then calculate the difference between each ...
9
votes
3answers
200 views
Pre-order + post-order to in-order
Task
Given the pre-order and post-order traversals of a full binary tree, return its in-order traversal.
The traversals will be represented as two lists, both containing n distinct positive integers,...
26
votes
22answers
2k views
Find the largest number n positions away from n
A sequel to this question.
Task
Given an array of positive integers, find the largest element k for which:
There exists some positive integer distance n, so that the element in the array located ...
18
votes
64answers
4k views
Invert a boolean array
A nice simple one
Input
Given a boolean array (Or an acceptable alternative), you can assume the array will never be more than 32 elements long.
[false, false, true, false, false]
Output
Invert ...
8
votes
14answers
726 views
Shuffle a mapping
We define a map as a set of key-value pairs. For this challenge, you need to take each of the values and assign them to a randomly chosen key.
You must randomly shuffle the values, and output the ...
2
votes
0answers
216 views
Where is your totem?
In the movie Inception we see the main star using a totem to check if he's in the real world or dreaming.
You seem to have misplaced your own totem, so you quickly draw inspiration from this movie ...
11
votes
42answers
2k views
Find the minimum and maximum integers in an array, without using builtins
Challenge
Given an array of integers, received from stdin, function arguments, program arguments, or some other method:
Output only the minimum and maximum numbers in the array, through a return ...
7
votes
2answers
332 views
How secure are my locks?
You have been assigned the task of installing new locks to the company's building. However, the locks you use are quite unusual: they require some combination of keys to open. Now, you want to figure ...
0
votes
1answer
144 views
Dyalog's International Problem Solving Competition (Phase I) – Code Golf Edition [closed]
Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. However, this is a multiple-holes (common theme is manipulation of data of any type and structure, ...
26
votes
21answers
2k views
Keep nonzeros and their neighbours
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.
The challenge
Given an array of integer values, remove all ...
28
votes
12answers
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
548 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
88 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 ...
34
votes
16answers
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)
...
11
votes
9answers
882 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-...
22
votes
56answers
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
979 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
969 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
431 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
299 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
666 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
258 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 numbers,...
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 and ...
36
votes
28answers
8k 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
796 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
776 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
896 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
717 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
192 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 ...
26
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
911 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 ...
4
votes
8answers
253 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
778 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
180 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,...
25
votes
23answers
3k 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];
...