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

learn more… | top users | synonyms

14
votes
14answers
2k views

QuickGolf - Ignore the noise #1

Instructions Barry is a not so good backend developer in charge of a small API that should give you information about purchases made in a client's shop. However, he hasn't done a great job and your ...
9
votes
12answers
853 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 ...
11
votes
3answers
225 views

Books on a Shelf

I have some books and a bookshelf. I would like to put as many books on the shelf as possible but I have a rule. All dimensions of the books (height, width and depth) should form a non-increasing ...
8
votes
5answers
316 views

Decide existence of total orderings

In this task, we consider arrays of positive integers such as this: 3 18 321 17 4 4 51 1 293 17 The input comprises a pair of such arrays both of arbitrary, possibly distinct, positive length. ...
-1
votes
3answers
90 views

Detect the main order based on sub-lists [closed]

The question is simple but the answer maybe not! suppose that you have the following lists that all of them are ordered (not consecutive): x = ['one', 'two', 'four'] y = ['two', 'three', 'five'] z ...
6
votes
6answers
569 views

Sort all the pixels of an image by the number of occurrences

Input The name of a file in the raster graphics format of your choice. The chosen format must support at least 8 bits per channel and 3 channels. Output A file in the same format, with the same ...
11
votes
3answers
612 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 ...
7
votes
5answers
194 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 ...
8
votes
9answers
437 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 ...
-4
votes
2answers
188 views

Implement slow sorting algorithm [duplicate]

All good coders know some good sorting algorithms like quicksort or merge sort. There is also slow sorting algorithms, e.g. bubble sort and insertion sort. But those are such easy to implement and ...
15
votes
2answers
436 views

Stack the Christmas Gifts

Someone has been hastily stacking the Christmas presents, and it's quite a mess: ======================== | | ======================== ...
35
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 ...
22
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 ...
18
votes
2answers
878 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
326 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 ...
70
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
994 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 ...
-3
votes
4answers
245 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
687 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
726 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
482 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
521 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
110 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
837 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 ...
18
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
175 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
958 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
2k 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
4k 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
1k 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
335 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
569 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
390 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 ...
-7
votes
1answer
313 views

Sort an array with values of integer [closed]

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: ...
63
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 ...
21
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
402 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
1k 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 ...
25
votes
32answers
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 ...
13
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 ...