# Questions tagged [sorting]

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

71 questions
Filter by
Sorted by
Tagged with
7k views

### Sort an Integer List

The Challenge It's quite simple really, sort a list of numbers. Details You must sort a list of numbers in ascending order, without using any built-in sorting functions/libraries/etc (i.e. ...
4k 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 ...
• 18.6k
2k views

### Imitate an ordering

Given two lists of numbers, a source and a pattern, reorder the source to match the relative ordering of the pattern. Any two entries of the reordered source should compare the same way as the entries ...
• 145k
1k 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 ...
10k 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 ...
• 12k
2k views

### Ordering a list

Summary Given a list of integers, return the index each integer would end up at when sorted. For example, if the list was [0,8,-1,5,8], you should return ...
• 14.5k
2k views

### Implement a sorting algorithm with no change. [closed]

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 ...
• 10.1k
9k 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 ...
• 14.5k
7k views

### Implement QuickSort in BrainF*** [closed]

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 want ...
• 431
3k 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 ...
• 4,937
2k 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. ...
• 1,778
559 views

### Swaps to Sort an Array

You are given an array $A$, which may contain duplicate elements. In each swap, you may swap the value of any two indices $i, j$ (i.e. switch the values of $A_i$ and $A_j$). What is the least ...
6k views

### Xorting an array

Conceptually, this challenge is really simple. You're given a list of non-negative integers ai. If possible, find a non-negative integer ...
• 197k
4k views

### Vertically collapse text

Say I have text like this (each word on one line, with no spaces) Programming Puzzles & Code Golf That makes no sense! It totally defies the laws of physics. ...
• 1,702
5k views

### DropSort it like it's hot

As described in this question: 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 ...
• 1,723
22k views

### Sort numbers by binary 1's count

Goal Write a function or program sort an array of integers in descending order by the number of 1's present in their binary representation. No secondary sort condition is necessary. Example sorted ...
• 8,750
3k views

### Interleave strings

Inspiration.* I cannot believe we have not had this challenge before: Task Given one or more printable ASCII strings, interleave them by taking one character from each string, cyclically until out ...
• 30.4k
2k views

### Enumerate each series of identical numbers in-place

Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series. Examples ...
• 30.4k
3k views

### Unsort an array

Inspired by this StackOverflow post Given a list where each element appears a maximum of 2 times, we can define it's "sortedness" as the sum of the distances between equal elements. For ...
11k views

### Sort a list of numbers [closed]

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 ...
• 919
2k views

### Sort useless characters

This challenge is inspired by this very nice answer by TidB. In TidB's answer, every eight character is in the correct order: gnilwoB edoC (...
• 46.4k
3k views

### Rank a list of integers

You're given a non-empty list of positive integers, e.g. [6 2 9 7 2 6 5 3 3 4] You should rank these numbers by their value, but as is usual in leaderboards, if ...
• 197k
2k views

### Sort of numbers

Within the recesses of Unicode characters, there exists a Unicode block of (currently) 63 characters named "Number Forms", which consists of characters that have numerical values such as the roman ...
• 47.2k
3k views

### Bubble sorting in progress

Create a function or program that takes two inputs: A list of integers that shall be sorted (less than 20 elements) A positive integer, N, saying how many ...
• 46.4k
733 views

### Burrows, Wheeler and Back

Background The Burrows–Wheeler transform (BWT) is a reversible permutation of the characters of a string that results in large runs of similar characters for certain types of strings such as plain ...
• 210k
1k views

### The Strange Unsorting Machine for Nefarious Purposes

Good Evening Golfers! Your challenge is to completely unsort a series of numbers. Input Exactly 100 integers will be fed to your program. Your program may accept the input either as a file, or via ...
• 3,189
4k 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 ...
• 2,901
5k views

### Sign that word!

What is a Word Signature? The signature of a word are all of it's letters put in order - the signatures of this, hist and ...
2k views

### Advent Challenge 5: Move the presents to the transport docks!

<< Prev Next >> Thanks to the PPCG community, Santa has managed to remanufacture all of his presents and after the assembly line, the presents are now ready to be moved into the transport docks!...
• 42.4k
3k 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 ...
• 2,381
1 vote
4k views

### Sort an array only using recursion [closed]

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 the ...
• 4,431
421 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 free ...
• 179
4k views

### There are two new sheriffs in town – Identifying DJMcMego pairs!

We have some new sheriffs moderators in town, Mego and DJMcMayhem. We need a challenge to properly honour them for their new positions, so there we go. Here's something that has caught my attention ...
• 42.4k
3k views

### Perform gravity sort

Challenge Given a list of integers, show how gravity sort would be done. Gravity Sort In gravity sort, imagine the numbers as rows of asterisks. Then, everything falls, and the new rows will be ...
• 42.4k
5k 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 ...
• 29.1k
3k views

My first code golf post, apologies for any mistakes... Context In rock climbing (bouldering specifically), the V/Vermin (USA) climbing grades start at 'VB' (the easiest grade), and then go 'V0', 'V0+...
• 957
5k views

### Help, I've mixed my week up!

My dog ate my calendar, and now my days are all mixed up. I tried putting it back together, but I keep mixing up the days of the week! I need some help putting my calendar back together, with the days ...
• 6,897
3k views

### Numbers Increase While Letters Decrease

Inspired by this Stack Overflow question: Sorting a list: numbers in ascending, letters in descending. Your task is to solve the following problem and, as this is code-golf, you should do so in as few ...
• 7,219
3k views

### Visualize Merge Sort

Merge sort is a sorting algorithm which works by splitting a given list in half, recursively sorting both smaller lists, and merging them back together to one sorted list. The base case of the ...
• 26.2k
9k views

### Find the longest word in an array

Your challenge is to take an array of strings and output the longest string in the array. So for ["tiny", "small", "bigger", "biggest"] the output would be ...
• 465
5k views

### PronunciationSort™

We all know of different fancy sorting algorithms, but none of these give us numbers in a way that's easy to pronounce. To remedy this, I propose using PronunciationSort™, the most natural way to sort ...
• 6,897
3k views

### Fix my FizzBuzz

FizzBuzz is where a range of positive integers is taken, and numbers divisible by 3 are replaced with "Fizz", divisible by 5 with "Buzz" and divisible by 15 with "FizzBuzz&...
• 38.8k
2k views

### Old Spanish alphabetical order

Before 1994, Spanish dictionaries used alphabetical order with a peculiarity: digraphs ll and ch were considered as if they were ...
• 105k
964 views

### Sort these bond ratings

The task The credit rating agencies assign ratings to bonds according to the credit-worthiness of the issuer, and the "Big Three" credit rating agencies use a similar (though not identical) tiered ...
• 333
1k views

### Reverse odd runs

Inspiration. Task Reverse runs of odd numbers in a given list of 2 to 215 non-negative integers. Examples 0 1 → 0 1 ...
• 30.4k
1k views

### Fairly rank values

Task Given an input list of integers x1…xn, compute a list of ranks r1…rn (a permutation of {1…n}) so that xr1 ≤ xr2 ≤ … ≤ xrn. Then, for each xi, replace its rank by ...
• 68.8k
1k views

### Crazy Librarian's Amazing Sorting System

It's back to school season! So for a part-time job, you're helping out at the school's library. The problem is, the head librarian has never even heard the words "Dewey Decimal," let alone implemented ...
• 43.4k
2k views

### Hungarian alphabetical order

For those who wish a lot more challenge then the old Spanish alphabetical order, let's take a look at how the Hungarian alphabet is ordered. a, á, b, c, cs, d, dz, dzs, e, é, f, g, gy, h, i, í, j, k, ...
• 8,109
5k views

### Sort-a-number. Sorta [closed]

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. ...
• 738