A competition to solve a particular problem through the usage and manipulation of arrays.
27
votes
17answers
1k views
Superior Passtimes
Sometimes, when I'm really bored I like to take the sum of an array of non-negative integers. I only take the sum of arrays of lengths that are powers of two. Unfortunately I often make mistakes. ...
21
votes
6answers
512 views
Quandle Quandary Episode I: Identifying Finite Quandles
Write a program that will determine if a given matrix represents a quandle. A quandle is a set equipped with a single (non-commutative, non-associative) operation ◃ which obeys the following axioms:
...
5
votes
12answers
444 views
What's my question record?
There's a confusing factor in the 'Curious' badge. The "Positive question record".
(total questions - negative questions - closed - deleted)/total questions is the formula of the question record. (...
29
votes
4answers
567 views
Rotating a 2D Matrix
Let's say I have the following (2D) matrix:
[[1, 2, 3, 4 ],
[5, 6, 7, 8 ],
[9, 10, 11, 12],
[13, 14, 15, 16]]
Rotate the matrix counterclockwise R times (not in 90 degree increments, just ...
41
votes
32answers
5k views
N-dimensional N^N array filled with N
In: Enough memory and a positive integer N
Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by...
Examples:
1: [1] which is a 1D array (a list) of length ...
19
votes
8answers
866 views
Reverse Insertion sort
Objective
Generate the original scrambled list, from the movements that an Insertion Sort would do to sort it.
The original list will have all numbers from 0 to N-1(inclusive) where N is the size of ...
18
votes
28answers
2k views
Count My Change
Your task is to sort an array containing the strings "quarter", "dime", "nickel", and "penny" any number of times in no specific order and sort them so that they are in this order: quarter dime nickel ...
24
votes
12answers
2k views
Alternating Power Fibonacci Sequence
Definition
The Alternating Power Fibonacci Sequence is formed as follows.
Start with the empty sequence and set n to 1.
Compute fn, the nth non-negative Fibonacci number, with repetitions.
0 is the ...
22
votes
9answers
1k views
Hilbert's Grand Hotel
Introduction
Some of you may have heard of Hilbert's Grand Hotel. The manager there has lost his list of where the guests are staying but he still has the order in which they checked in. Each guest ...
10
votes
1answer
212 views
Split arrays and programs in half
Introduction
You have been tasked to write a program that splits a rectangular integer array evenly in half (for whatever reason).
This task is computationally intensive, but luckily you have a dual-...
19
votes
14answers
2k views
Neutralize data
To neutralize data, recursively replace all numbers (not digits!) with zeros and all characters (not strings!) with spaces.
You must accept any single number, character, or string, or possibly ...
0
votes
0answers
65 views
Total eclipse of the byte [duplicate]
This is my first attempt at code golfing. I wanted to make it as fun as I can. I hope you'll have fun while tinkering with this.
As the title suggests, task is to print out lyrics of Total Eclipse ...
27
votes
15answers
1k views
Is it an OVSF code?
Given a list of 1s and -1s, determine whether or not it is a valid OVSF code (by outputting a truthy or falsey value).
OVSF codes are defined as follows:
[1] is an OVSF code.
If X is an OVSF code, ...
38
votes
13answers
2k views
Zero sum covers
Introduction
Consider a nonempty list L of integers.
A zero-sum slice of L is a contiguous subsequence of L whose sum equals 0.
For example, [1, -3, 2] is a zero-sum slice of [-2, 4, 1, -3, 2, 2, -1, ...
42
votes
25answers
2k views
Sever-sort an array
Challenge
Given a non-empty array of integers, e.g.:
[5, 2, 7, 6, 4, 1, 3]
First sever it into arrays where no item is larger than the previous (i.e. non-ascending arrays):
[5, 2] [7, 6, 4, 1] [3]
...
32
votes
13answers
1k views
An Array of Challenges #2: Separate a Nested Array
Note: This is #2 in a series of array-manipulation challenges. For the previous challenge, click here.
Separating Nested Lists
To separate values in a nested list, flatten it, and then wrap each ...
20
votes
8answers
730 views
Wrap a seasonal present
Task
Given a wrapper element and a non-jagged 3D array, wrap the array top, bottom, and all-around. You must handle both character and numeric data, but the wrapper and the present will have the same ...
38
votes
33answers
2k views
An Array of Challenges #1: Alternating Arrays
Alternating Arrays
An alternating array is a list of any length in which two (not necessarily different) values are alternating. That is to say, all even-indexed items are equal, and all odd-indexed ...
29
votes
21answers
1k views
Generate a random derangement
Challenge description
A "derangement" of a sequence is a permutation where no element appears in its original position. For example ECABD is a derangement of ABCDE, but CBEDA is not:
ABCDE
| | &...
26
votes
21answers
939 views
Column-wise Sum
Given a nonempty list of nonempty rows of numbers, compute the column wise sum, which is another list that has the length of the longest input row. The first entry of the output list is the sum of all ...
15
votes
4answers
387 views
Help PPCG Claus Deliver his Presents!
Help PPCG Claus Deliver his Presents
Overview
PPCG Claus is running hella late delivering his gifts because nowadays we have so many odd little kiddos out there. This makes it much harder for PPCG ...
38
votes
21answers
1k views
Array alignment addition
Introduction
Consider two non-empty integer arrays, say A = [0 3 2 2 8 4] and B = [7 8 7 2].
To perform alignment addition on them, we do the following:
Repeat each array enough times to have total ...
23
votes
16answers
1k views
Shuffle a ragged array
A ragged array is an array where each element is an array of unknown number of positive integers.
For example, the following are ragged arrays:
[[1,2,3],[4],[9,10]] Shape: 3,1,2
[[1],[...
18
votes
24answers
2k views
Rank a list of integers
You're given a non-empty list of positive integers, e.g.
[6 2 9 7 2 6 5 3 3 4]
You should rank these numbers by their value, but as is usual in leaderboards, if there is a tie then all the tied ...
8
votes
7answers
290 views
Count the reviews!
Introduction and Credit
Imagine you're Amazon. Imagine you have a large number of products for which a lot of people have written reviews scoring 1-5 stars. Now you need to give your customers a ...
26
votes
7answers
663 views
Uniquely removable subsequences
Introduction
Consider a sequence of integers and one of its subsequences, say A = [4 2 2 4 4 6 5] and B = [2 4 5].
We want to remove the elements of B from A in order, and there are several ways of ...
20
votes
23answers
1k views
Reverse Deltas of an Array
Reverse Deltas of an Array
A continuation of Inverse Deltas of an Array
Your task is to take an array of signed 32 bit integers, recompile it with its deltas reversed.
Example
The List,
18 19 ...
32
votes
15answers
2k views
Who is the tallest?
N children, with no two sharing their exact size, are lined up in some order. Each can only compare heights with their immediate neighbours. When the teacher shouts "raise hands if you are the tallest"...
36
votes
31answers
3k views
Increment an Array
Given a nonempty array of positive integers, "increment" it once as follows:
If all the array elements are equal, append a 1 to the end of the array. For example:
[1] -> [1, 1]
[2] -> [2, 1]
[...
12
votes
11answers
907 views
Turn this array into a matrix
Take a not nested array in as input. Turn it into a matrix by:
Let's say my array is [1, 2, 3, 4, 5]
First, I repeat that array 5 times: (the length)
[[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, ...
10
votes
0answers
175 views
Group these cells!
This challenge is based on the game Layerz.
Given, on stdin or as a function argument, a 2D rectangular array of cells where each cell contains either a blank (you may choose to use 0s instead of ...
17
votes
14answers
761 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 its length (number of items contained) and the Recursive Size of a list containing any ...
4
votes
12answers
212 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 ...
9
votes
2answers
231 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 ...
23
votes
12answers
755 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 ...
12
votes
33answers
2k 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 ...
52
votes
42answers
3k 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 ...
22
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
131 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 ...
20
votes
29answers
791 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 ...
25
votes
24answers
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 ...
11
votes
12answers
329 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 ...
65
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 ...
16
votes
11answers
859 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, ...
14
votes
11answers
327 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 (...
19
votes
18answers
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, ...
29
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 ...
13
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
240 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,...
29
votes
23answers
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 ...