This challenge is intended to be solved by sorting, ordering, or otherwise organizing some set of data.

learn more… | top users | synonyms

34
votes
9answers
4k views

Eating Candy in the Correct Order

When it comes to eating candy, I hold myself to higher standards than the typical layperson. There is a delicate balance between "mixing it up" and "saving the best for last." In this challenge, you ...
21
votes
5answers
1k views

Sort a List With Swaps and Pops

Consider a randomized list of the integers 1 to N. You want to sort it using only the following actions: Swap the first and last list elements. (S) Pop off the first element and append it to the end ...
17
votes
3answers
779 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 ...
8
votes
6answers
309 views

Sort by custom alphabet

The challenge is to make a program that sorts a list of words, only that the words need to be in the order of a random alphabet. Your program will accept a string of comma-seperated words and a new ...
61
votes
13answers
5k views

Sort a list and write some English!

Your boss managed to read the secret hidden message. He didn't end up firing you, though, he just made you a secretary and forbade you from writing code. But you're a programmer. You need to write ...
8
votes
2answers
962 views

Put a list in order

With a window similar to the one pictured below, you are given a list of strings, which you want to put in alphabetical order. As shown, you have five operations: Move up [U] - moves the ...
-4
votes
4answers
193 views

The Golf (re)Sort [closed]

The Golf (re)Sort Everyone is sorting arrays these days, and so do we at our day jobs. But we like to go out golfing. When we do, we sure like to take our time. It is important to have a stress ...
5
votes
5answers
573 views

Convert binary search tree into ordered linked list

Write the shortest possible program that turns a binary search tree into an ordered doubly-linked list, by modifying the pointers to the left and the right children of each node. Arguments: a pointer ...
12
votes
1answer
684 views

Pathological Sorting

Pathological Sorting Your boss has demanded that you develop a sorting algorithm to improve the performance of your company's application. However, having written the application, you know that ...
3
votes
5answers
462 views

Golf the Pigeonhole sort

Implement the Pigeonhole sort. This is a variant of the Bucket sort, and its logic is very simple: index your items (by a given function) and then return all non-empty indexes' items. Your ...
3
votes
1answer
516 views

Duct Tape some sorting

Your job is to make a sorting algorithm. The catch, you must copy it from Stack Overflow. Your program will take an input array (or equivalency), and output a sorted permutation of the array. Your ...
4
votes
0answers
108 views

Using dictionaries, thesauruses, and similar databases, construct as large of a “See also” loop as possible [closed]

As I'm sure many of you know, synonyms can range from very similar to not-so-similar-but-I-can-see-how-it's-similar. It's common for dictionaries to use "See also" to denote occurrences of words that ...
8
votes
6answers
787 views

Shortest code to sort walking points

The challenge is to, given a list of points, sort in a way that, when they are connected in this order, they never intersect. Input format (read from stdin): X Y 1 2 3 4 5 6 ... Output should be ...
10
votes
21answers
1k views

Merge two sorted lists

Merge Sort In this challenge, you will implement the merge subroutine of merge sort. Specifically, you must create a function or program or verb or similar which takes two lists, each sorted in ...
18
votes
6answers
1k views

Tower of Hanoi Sort

Write a function/subroutine to sort a list of integers, Tower of Hanoi style. You will be given a stack of integers. This is the main stack. You are also given two more helper stacks. These helper ...
19
votes
29answers
3k views

Sort-a-number. Sorta

Inspired by the ill-fated sorting-a-numbers-digits-without-using-an-array, but I thought it made a better code golf than SO question. Given a positive integer, sort the digits in that integer. ...
11
votes
14answers
1k views

Golfed+Fast sorting in C

[Latest update: benchmark program and preliminary resuls available, see below] So I want to test the speed/complexity tradeoff with a classic application: sorting. Write an ANSI C function that ...
2
votes
2answers
168 views

Merging text files based on a prefix key

Imagine an ordered file set : file1, file2, ... fileN. Each file is a textual file that is made of lines that have the same format : A concatenation of a fixed-size key (the same among all the file ...
22
votes
47answers
3k views

Sort numbers by binary 1's count

Goal Write a function or program sort an array of integers by the number of 1's present in their binary representation. No secondary sort condition is necessary. Example sorted list (using 16-bit ...
3
votes
13answers
796 views

Sort an array only using recursion

Your task is to write a function that sorts an array. Your function: Cannot call other functions (excluding itself, of course); Must receive an array of integers as input, and it must return ...
13
votes
36answers
3k views

Shortest Program to Sort a List of numbers into Odd and Even Category

In the New Modern Times, when Charlie Chaplin encounters a computer, he is employed in the sorting Yard, as a validator to determine if the workers are correctly sorting the items. The Items in ...
7
votes
14answers
3k views

Sorting a list of strings without using any built-in sort method

The goal of this Code Golf is to create a program that sorts a list of strings (in ascending order), without using any built-in sort method (such as Array.Sort() in .NET, sort() in PHP, ...). Note ...
19
votes
10answers
2k views

Flipping pancakes

In pancake sorting the only allowed operation is to reverse the elements of some prefix of the sequence. Or, think of a stack of pancakes: We insert a spatula somewhere in the stack and flip all the ...
3
votes
2answers
330 views

Pseudosort a list in 2*n comparisons

Write a program that takes a list of n space-separated integers, and outputs a permutation of that list using a maximum of 2*n comparisons. It should loop this until an empty line is input. ...
11
votes
11answers
1k views

City names game

If you like, write a program which sorts cities according to the rules of city name game. Each name of the city should start from the last letter in the previous city name. E.g. Lviv -> v -> ...
-5
votes
13answers
560 views

Sort, with your hands tied behind your back

The problem is very simple: write a program that accepts a single unsigned integer from the command line, and prints out that many random numbers on the standard output, in ascending order. For ...
6
votes
3answers
376 views

Code Golf: Mix the nuts so that none of the same kind are touching

Input: Input is a randomized array of nuts (in your language), the possible nuts follow. Your program must have a way of representing each kind of nut, such as an integer code. Program must be able ...
-6
votes
1answer
300 views

Sort an array with values of integer

There is an array of integer values to be sorted.During the sorting process, the places of two numbers can be interchanged. Each interchange has a cost, which is the sum of the two numbers involved. ...
-4
votes
3answers
2k views

Descending Sort using Standard Ascending Sort Function [closed]

Taking an array of records. For example [ name: 'eventA', timestamp: '2011-08-27 15:34:00', name: 'eventB', timestamp: '2011-08-28 13:31:00', name: 'eventC', timestamp: '2011-08-29 10:34:00', name: ...
61
votes
23answers
8k views

Contest: fastest way to sort a big array of Gaussian-distributed data

Following the interest in this question, I thought it would be interesting to make answers a bit more objective and quantitative by proposing a contest. The idea is simple: I have generated a binary ...
20
votes
1answer
2k views

Implement QuickSort in BrainF***

As discussed in the Lounge room on Stack Overflow: if you can't implement the Quicksort algorithm given en.wikipedia.org/wiki/Quicksort in any language you have minimal knowledge of, you might ...
3
votes
1answer
384 views

Fastest alphabetical list sort given the following limitations:

Your function must have an input that takes in an array containing 10000 random names, and must sort these names in alphabetical order. Names have a random length of up to 128 characters. ISO/IEC ...
4
votes
11answers
971 views

Implement a sorting algorithm with no change.

In this task, you have to write a program, that reads a string with a length of up to 1024 characters and prints it out sorted. In order to make an interesting task from a boring one, I set a few ...
24
votes
31answers
3k views

Sort a list of numbers

About Code-Bowling: In golf, you try to get the lowest score (smallest application, most elegant, etc). In Bowling, you try to get the highest score. So if you follow, the goal of a Code-Bowling ...
12
votes
22answers
1k views

Implement Bogosort

Is solving Sudoku too hard? Even the brute force version? Here's a coding exercise that's a little easier. I hope. :-P Write the shortest function to implement bogosort. In specific, your function ...