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

learn more… | top users | synonyms

6
votes
5answers
295 views

Average Out Two Lists [duplicate]

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 ...
41
votes
23answers
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, ...
15
votes
8answers
916 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 ...
19
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
669 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 ...
9
votes
12answers
877 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, ...
4
votes
2answers
228 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 ...
6
votes
5answers
591 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: ...
11
votes
3answers
619 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
214 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 ...
14
votes
21answers
511 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 ...
21
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 ...
23
votes
17answers
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
265 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
197 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 ...
14
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
162 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 ...
21
votes
32answers
4k 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
444 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 ...
36
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 ...
12
votes
2answers
562 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 ...
20
votes
10answers
862 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
288 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 ...
14
votes
8answers
922 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 ...
28
votes
18answers
3k views

Unflatten an Array

This challenge was inspired by a question on Mathematica.SE. Say you've got a nested list/array of some arbitrary structure (the lists at each level don't necessarily have the same length). For ...
17
votes
6answers
1k views

Time Travelling Stock Trader

Story Long time ago Bobby created a Bitcoin wallet with 1 Satoshi (1e-8 BTC, smallest currency unit) and forgot about it. Like many others he later though "Damn, if only I invested more back then...". ...
32
votes
28answers
2k views

At least h with at least h

Input A list of nonnegative integers. Output The largest nonnegative integer h such that at least h of the numbers in the list are greater than or equal to h. Test Cases [0,0,0,0] -> 0 ...
14
votes
24answers
2k views

Shorter than a Split Second!

Challenge You task for this question is to split an input array of integers on the second occurrence of every integer in that array. Not clear enough ? Here is an example to help Input array: [2 1 ...
18
votes
37answers
2k views

Create an array with repeated numbers

Challenge Your task in this question is to write a program or a named function which takes a positive integer n (greater than 0) as input via STDIN, ARGV or function arguments and outputs an array ...
16
votes
23answers
3k views

Most common number

Calculate the most common number in a list. You should use an expression that fits on one line (the record is just 18 characters). d = [4,3,1,0,6,1,6,4,4,0,3,1,7,7,3,4,1,1,2,8] winner = ... # TODO: ...
3
votes
2answers
475 views

Shortest Code to Translate a PHP array

NOTE: This question was migrated from http://stackoverflow.com/q/27134588/1442685 PHP QUESTION Almost purely out of curiousity, how can I take an array like this: array( 'fruit' => 'banana', ...
5
votes
4answers
582 views

Shortest program to split special array

Background Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance: | A | [0 0 0 ...
18
votes
2answers
888 views

Book Stack Sort

When stacking books you usually want to put the largest ones at the bottom and the smallest ones at the top. However, my latent OCD makes me feel very uneasy if I've got two books where one is shorter ...
0
votes
2answers
93 views

Approximated (unsorted) square from a set of values [closed]

So a colleaque came with this problem lately and I want to challange you to solve the problem in the code-golf style, shortest solution in any language wins. The Problem: Given is a random set of ...
-2
votes
7answers
181 views

Create an array of unique ints in a set range

Goal: Write a piece of code that produces a array containing all integer values in a set range in random order (upper and lower bounds included). Use any language you like, but use as little built-in ...
9
votes
1answer
253 views

Golfscript Diagonal Array

Is there a way in Golfscript to bring all of the diagonals of an array into a single array? For example, for the array [[1 2 3][4 5 6][7 8 9]] return [[7][4 8][1 5 9][2 6][3]] (not necessarily ...
22
votes
33answers
3k views

Generating a single string with an Oxford comma from a list

What are some clever (brief and idiomatic) approaches to taking a list of strings and returning a single properly punctuated string built from the list, with each element quoted. This came up for me ...
2
votes
6answers
504 views

Programming Praxis - Survive like Flavius Josephus [duplicate]

Here's a challenge inspired by Programming Praxis: http://programmingpraxis.com/2009/02/19/flavius-josephus/ Write a function josephus(n,m) that returns a list of n people, numbered from 0 to ...
7
votes
15answers
712 views

Rank a list of scores with “skips”

Given a list of scores (non-negative integers) pre-sorted from greatest to least: [ 10, 10, 6, 6, 4, 0] Assign each score an integer rank, beginning with 1 and ascending, such that equal scores ...
1
vote
4answers
2k views

Rotate 2D Array [duplicate]

Given an input of a 2 dimensional array of integers, rotate the array 90 degrees clockwise. It should work for rectangular arrays of all sizes and proportions. The rotated array should be printed at ...
3
votes
2answers
409 views

Deplane! Deplane! (Or: RGBRGBRGB => RRRGGGBBB?)

Imagine bytes in memory for an RGB image--R and G and B represented by bytes in sequence. If an image is NxM then the memory layout will be M repetitions for vertical scanlines of 3*N bytes in ...