A competition to solve a particular problem through the usage and manipulation of arrays.
8
votes
10answers
432 views
Find the “Recursive Size” of a List
Inspired by Find the “unwrapped size” of a list.
Define the Recursive Size, RS, of a list containing no lists as it's length (number of items contained) and the Recursive Size of a list containing ...
4
votes
11answers
170 views
Make an inversedict
Input
A dictionary with string keys and string values.
Output
The 'inversedict' of this dictionary.
How to make an inversedict
An inversedict is a dictionary with string keys and string array ...
5
votes
1answer
180 views
Check if rectangles fill a rectangular space without gaps or overlaps
This challenge is based on another similar challenge. Because finding the most efficient packing of rectangles is NP-hard (that is, its solution is easy to check but hard to find), this challenge is a ...
-1
votes
0answers
73 views
Print an array with maximum density of local maxima [closed]
You are given a mxn matrix of numbers, that have two possible integer entries
a and b, that might be freely chosen. A quadratical sliding window of size cxc is moving over the array and the following ...
20
votes
10answers
699 views
Array unification
Introduction
Consider two arrays of the same length, say A = [0,1,0,2] and B = [-1,1,2,2].
Suppose we know that their contents are equivalent in some sense, item by item:
0 is equivalent to -1,
1 is ...
9
votes
32answers
1k views
Find the “unwrapped size” of a list
Let's define the "unwrapped size" function u of a nested list l (containing only lists) by the following rules:
If l is empty, then u(l) is 1.
If l is non-empty, u(l) is equal to the sum of the ...
49
votes
34answers
2k views
Count trailing truths
Inspired by, and in memory of, my dear friend and colleague,
Dan Baronet, 1956 – 2016.
He found the shortest possible APL solution to this task:
Task
Given a Boolean list, count the number of ...
21
votes
10answers
1k views
Simplificate an array
Input
An array that can contain arrays or positive, consecutive, ascending integers. The arrays can have any number of arrays inside of them, and so on and so forth. No arrays will be empty.
Output
...
2
votes
2answers
126 views
N in a row (or column)! [closed]
N in a row
Input:
The character and a 2-Dimensional array.
The array with a size of N x N where 1 <= N <= 26, it will be filled randomly like so:
N = 1
A
N = 2
B | A
-----
A | B
N = 3
A ...
11
votes
24answers
668 views
Find the maximum deviation
This problem is "inspired" from a question that was originally asked on Quora (not for code golfing). I just want to make it a challenge for you guys (and my first problem submission here).
Given an ...
24
votes
23answers
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
317 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 ...
62
votes
28answers
6k 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 ...
14
votes
11answers
798 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
286 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, ...
28
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
215 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
65answers
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 ...
9
votes
15answers
756 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
227 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
3k 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
341 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
148 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 ...
25
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
549 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
92 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)
...
14
votes
12answers
1k 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
982 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
970 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
319 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
673 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
264 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,...
19
votes
15answers
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-...
30
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
803 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
781 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
905 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
718 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 | ...