A competition to solve a particular problem through the usage and manipulation of arrays.
14
votes
2answers
172 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, ...
32
votes
13answers
4k 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 ...
24
votes
8answers
704 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 ...
13
votes
1answer
642 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
251 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 ...
17
votes
11answers
622 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] ...
24
votes
15answers
1k views
Illustrate the square of a binomial
Given (by any means) two different natural numbers (of any reasonable size), output (by any means) the square of their sum as in the examples below:
Given 4 and 3, output:
12 12 12 12 9 9 9
12 12 ...
12
votes
12answers
1k views
Play the elimination game
Introduction
In this challenge, your task is to simulate a certain type of elimination game.
In the game, the participants stand in a circle, and everyone is holding an integer.
On each round of the ...
19
votes
1answer
191 views
One goes up, the other comes down
Introduction
In this challenge, your task is to decide whether a given sequence of numbers can be separated into two subsequences, one of which is increasing, and the other decreasing.
As an example, ...
17
votes
34answers
2k views
Non Unique Elements
Write a program which finds the non-unique elements of an array of signed integers. The resulting array can be in any order.
Your answer may be a snippet which assumes the input to be stored in a ...
1
vote
3answers
205 views
Transpose columns in table
Let's say you've got a table of data:
meter_id date 0000 0600 1200 1800
0 030915 10 20 30 40
1 030915 15 7 49 2
where the last four columns are meter readings at ...
13
votes
5answers
278 views
Is it L-convex?
Background
A polyomino is called L-convex, if it's possible to travel from any tile to any other tile by an L-shaped path, that is, a path that goes in the cardinal directions and changes direction ...
15
votes
12answers
582 views
Integer Percentify
Write a function which takes in a list of positive integers and returns a list of integers approximating the percent of total for the corresponding integer in the same position.
All integers in the ...
7
votes
4answers
506 views
Average Out Two Lists
Average out two lists
Challenge
Given two lists of positive integers, determine whether it is possible to rearrange the elements into two new lists such that the new lists have the same arithmetic ...
31
votes
12answers
4k views
The Will Rogers Phenomenon
The so-called Will Rogers phenomenon describes a way to tweak statistics by raising the average in two (multi)sets when one element is moved between the two sets. As a simple example, consider the two ...
21
votes
16answers
1k views
Calculating waves
I've been scrolling around this site for a while, but just recently got really interested in actually trying out some of the challenges. I was intending to try my hand at some of the existing ...
47
votes
25answers
5k views
First code golf decathlon
Tasks
All competitors try to solve the following list of 10 tasks:
math
Read a positive integer n from input and return the sum of the cubes of the first n non-negative integers.
For input 1, ...
16
votes
8answers
938 views
Analyzing Earthquakes
Background
The Random Domino Automaton is a toy model for earthquakes, inspired by cellular automata.
In this challenge, your task is to simulate a simplified version of this model, and collect data ...
20
votes
16answers
3k views
Bitstring Physics
Background
Yes, bitstring physics is a real thing.
The idea is to construct a new theory of physics using only strings of bits that evolve under a probabilistic rule... or something.
Despite reading ...
19
votes
13answers
1k views
Refined Partitions
Consider an array of integers:
[1, 0, 9, 1, 3, 8]
There are a lot of ways to partition this list into consecutive sublists. Here are three:
A: [[1, 0, 9], [1, 3, 8]]
B: [[1], [0, 9], [1, 3], [8]]
...
9
votes
4answers
1k views
Calculate a probability exactly
This task is about writing code to compute a probability exactly. The output should be a precise probability written as a fraction in its most reduced form. That is it should never output 4/8 but ...
19
votes
9answers
1k views
Sum in each dimension
You are given a multi-dimensional array of integers. Each dimension has a fixed size (so that it would be always rectangular if it is 2D). Your program should calculate the sums in each dimension and ...
20
votes
15answers
2k views
Generalised Array Riffle
A simple golf to start the week! You're given three arrays: the base array B, the value array V and the index array I. You should produce another array where the values from V are inserted into B at ...
15
votes
10answers
691 views
Undirect a Graph
Introduction
In this challenge, you are given a directed graph with self-loops, and your task is to convert it to an undirected graph without self-loops.
Input
Your input is a directed graph with ...
8
votes
12answers
931 views
Rearranging a set of numbers into order
The Question
Given a set of 9 numbers, m[], which contains only numbers 1 through 9 in a random order, with no two numbers being the same, create a program in any language which rearranges the number ...
15
votes
9answers
2k views
Compute the Hausdorff Distance
Introduction
The Hausdorff distance measures the difference between two subsets of a metric space.
Intuitively, a metric space is just some set with a built-in distance function; in this challenge, ...
5
votes
2answers
234 views
Remove boxes under preservation of shape
This challenge is specific to languages of the APL family. Although it might be solvable in other languages, please do not expect this to be easy as it depends on some specific concepts of this ...
7
votes
5answers
638 views
IPV4 subnet list cleaner (in CIDR notation)
We have a lot of IPV4 address, to group into subnets, so we need a tool for doing this:
Our list is very ugly, not ordered and sometime in subnet notation, sometime in simple address.
Sample:
...
12
votes
3answers
637 views
Un-Merge a List
Introduction
Most of you are familiar with the merge sort algorithm for sorting a list of numbers.
As part of the algorithm, one writes a helper function called merge that combines two sorted lists ...
8
votes
3answers
226 views
Identifying Sequences for Cellular Automata
Background
For the purposes of this challenge, an n-state cellular automaton is simply a binary function f that takes two numbers from the state set {0, 1, ..., n-1} as inputs, and returns another ...
15
votes
21answers
561 views
Bookkeeping for the Sex Bob-ombs (check if a running sum ever gets too low)
Believe it or not, the Sex Bob-ombs have become a world famous band and are currently on world tour! As their bookkeeper you must oversee their day to day finances and provide regular reports.
Every ...
22
votes
22answers
1k views
Home on the Range of Lists
This challenge is simply to return a list of lists of integers, similar to the Python range function, except that each successive number must be that deep in lists.
Rules:
Create a program or a ...
25
votes
18answers
2k views
Construct a Ladder
Introduction
I want to build a ladder.
For this, I have scavenged from the junkyard two long boards with holes in them, and I want to place the steps into these holes.
However, the holes are not ...
7
votes
2answers
281 views
Paeth-transform arrays
One of the key parts of PNG's compression algorithm is the Paeth transformation, which transforms the image in a way that makes it compress better (usually). In this challenge, your task is to write a ...
7
votes
5answers
205 views
Almost Lexicographical List Comparison
Input
Two lists A and B of nonnegative integers.
Output
Either 1, 0, or -1, depending on whether A is larger than, equal to, or smaller than B with respect to the twisted lexicographical ordering ...
15
votes
16answers
2k views
Different Way Forward
Given a list of integers produce a Forward Difference at a specified order/depth.
For the list of integers:
(10, 18, -12, 4, 8, -3, -5, 67, 9, 14)
The Forward Differences at the various ...
23
votes
24answers
2k views
Print a Block-Diagonal Matrix
Here is a simple, bite-sized (byte-sized?) code golf: given a non-empty list of positive integers less than 10, print a block-diagonal matrix, where the list specifies the size of the blocks, in ...
2
votes
2answers
166 views
Array combinatoric comparison
Introduction
You may remember sudoku, where there can only be one of each number in each row, column and block of nine.
The general idea is that if the array contains but one element, you can submit ...
27
votes
33answers
5k views
Random Golf of the Day #1: Shuffle an Array
About the Series
I will be running a little series of code-golf challenges revolving around the theme of randomness. This will basically be a 9-Hole Golf Course, but spread out over several ...
11
votes
12answers
1k views
Complexity-free Kolmogorov(-Smirnov)
In statistics, sometimes it's useful to know whether two data samples come from the same underlying distribution. One way to do this is to use the two-sample Kolmogorov-Smirnov test.
Your task will ...
8
votes
9answers
452 views
Ordering an array of negatives, zero and positives integers with one iteration
Take an array of integers containing negative numbers, positive numbers and zeros. Group it with one iteration and in place such that all of the negative numbers come first, followed by all of the ...
37
votes
14answers
5k views
Into how many pieces can you cut this string?
Consider a piece of string (as in "rope", not as in "a bunch of characters"), which is folded back and forth on the real line. We can describe the shape of the string with a list of points it passes ...
13
votes
2answers
625 views
Score a game of Kingdom Builder
I want to try a new form of code golf here. Similar to bonuses, not all parts of the challenge have to be completed, but each answer has to implement a subset of certain size (and there is a core that ...
21
votes
10answers
867 views
0-1 Maximal Phase Counter
Consider an array of bits, say
1 1 1 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0
We call a contiguous subarray of length ≥ 5 a phase if at least 85% of the bits are the same and the first/last bits are both ...
5
votes
3answers
321 views
Compute the Join and Meet of Partitions
Background
In this challenge, a partition of a set S means a collection of nonempty subsets of S, which are mutually disjoint and whose union is S. We say that a partition p is finer than another ...
15
votes
8answers
952 views
Jump the Array!
Let's play a one-player game called jump the array. To play, you only need an array of integers, say a. You start at some position i, and on each turn, you jump to a new position. On turn n,
if n is ...