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

learn more… | top users | synonyms

8
votes
1answer
166 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 ...
18
votes
30answers
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
323 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
672 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 ...
3
votes
2answers
452 views

Find the closest pair of integers which will be neighbors when sorting an array

An integer V lies strictly between integers U and W if U < V < W or if U > V > W. A non-empty zero-indexed array A consisting of N integers is given. A pair of indices (P, Q), where 0 <= P ...
1
vote
4answers
610 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
383 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 ...
12
votes
5answers
484 views

Stack the deck!

Alice and Bob like to play a card game, with a deck of cards numbered with consecutive nonnegative integers. Alice has a very particular way of shuffling the deck, though. First, she takes the top ...
5
votes
20answers
1k views

Rotate An Integer Array with an O(n) algorithm

Write a function that rotates an integer array by a given number k. k elements from the end should move to the beginning of array, and all other elements should move to right to make the space. The ...
0
votes
0answers
223 views

Change the innermost element type of a jagged array — any .NET language: C#, F#, VB.NET, MSIL, C++/CLI, etc

Write a class containing a method with the signature System.Array ChangeElementType(System.Array jaggedArray) (you may rename identifiers ChangeElementType, jaggedArray and shorten the type ...
1
vote
10answers
1k views

Convert JSON string to Key / Value Arrays

Convert JSON (key/value pairs) to a native arrays of keys & values, in your language. var X = '{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}'; The value array could be ...
16
votes
15answers
2k views

Javascript: Create a 10x10 array of 1s

Obviously this challenge would be trivial with separate functions and libraries, so they aren't allowed. Your code must conform to an ECMAscript specification (any spec will do), so no ...
-2
votes
1answer
224 views

Merge working time periods

You have an array of working time period pairs (from, till) received from user input and written according 24-hour clock format convention. You have to merge these periods if the intersect each ...
7
votes
8answers
602 views

Array Sandwiches

(Adapted from Problem C of the first qualifier of the ACM Programming Contest of 2012/2013) You have several arrays, named A1, A2, ... , An, each sorted in ascending order. Every item in the array ...
4
votes
13answers
423 views

Create a hash from an array of arrays of key|value pairs

Starting from an array of sub-arrays, each sub-array is a 2 elements key|value pair. Example input = [["A", 5], ["B", 2], ["A", 12], ["B", -2], ["C", 7]] Convert this into a hash that has distinct ...
3
votes
5answers
244 views

Operations with Lists

Inspired by this question. Given a list containing numbers, print: The sum and product of the numbers in the list The average and median The differences between each term in the list (e.x. [1,2,3] ...
0
votes
1answer
180 views

Reduce the amount of loops when finding if an element is stored only once in the array? [closed]

I was amazed to find that there is a way to reduce the times you loop on an array to find if a element is contained once. One would think that the only way would be to loop through the whole array, ...
2
votes
3answers
337 views

Polynomial extrapolation

Task Given a list of integers a1, a2, …, ak (k ≥ 2) and a positive integer m, write a function or a complete program that calculates the next m numbers of the list. Assume that ai = P(i) ...
10
votes
15answers
2k views

Shuffle a deck without local variables

The object of this puzzle is to take a deck of 52 cards and shuffle it so that each card is in a random position. Given: An array, deck, of 52 distinct integers representing the cards. When you ...