# Questions tagged [sorting]

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

173 questions
Filter by
Sorted by
Tagged with
1k views

### What type are my suffixes?

Intro So I've been wasting my time again researching suffix sorting algorithms, evaluating new ideas by hand and in code. But I always struggle to remember the type of my suffixes! Can you tell me ...
390 views

### Rate my sorting

Introduction So my boss is making me do some manual labor...urgh...I have to take a part out a box of parts, process it and put it back in the box. To make this more interesting I try to sort the ...
2k 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 ...
1k views

### Swap indices and values

The task Write a program or function whose input is a list/array X of integers, and whose output is a list of sets of integers Y, such that for each element e in each set Y[i], X[e] = i, and such ...
2k views

### Sort digits by their first occurrence in pi

Given a non-negative number n, sort the digits of n by their first occurrence in pi. Input can be taken via function cli ...
891 views

### Optimize sorting, using “Sub-vector reversals”

This is a fewest-operations challenge where the objective is to sort a vector into ascending order using the fewest reversals. Your algorithm can only sort the vector using "sub-vector reversals"1, ...
450 views

### Line up for golf!

Alice, Bob, Carol, Dave, and Eve are going out for a nice game of golf and need your help to decide in what order they will play. Your program will input some statements, which are defined as a ...
645 views

### Sort and Re-apply Deltas of an Array

It seems that any Simple Modification of deltas using a consistent function can almost always be done some other shorter way, Dennis. Thus, the only solution I can imagine to make this harder, is to ...
3k views

### This is the sort of challenge that bytes

I need to stop thinking of punny names Your task is to create as many snippets (programs that have input and output built-in), functions or full programs as possible that sorts whatever your language'...
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 (...
499 views

### Back-To-Front Permutation Index

The Challenge Given the number of items, n, in a non-empty, sorted list output the index, i(n), at which its "Back-To-Front ...
4k views

### Output numbers up to 2^n-1, “sorted”

Take a positive integer n as input, and output (some of the) decimal numbers that can be created using n bits, ordered in the following way: First list all the numbers that can be created with only ...
2k views

### Count My Change

Your task is to sort an array containing the strings "quarter", "dime", "nickel", and "penny" any number of times in no specific order and sort them so that they are in this order: ...
327 views

Sometimes lexicographical sorting of strings may cut it, but when browsing the filesystem, you really need better sorting criteria than just ASCII indices all the time. For this challenge, given a ...
495 views

### Golf Me A Bubble Sort [duplicate]

Your task is to create a program that performs a bubble sort on a given array until it is sorted. Algorithm In order to qualify as a bubble sort, the program must operate as follows: Each pass goes ...
68 views

### Code Golf - Print all unique ways of writing a number as a sum with a lexical order [duplicate]

I found about Code Golf after writing this program and decided to post the rules here so you can try it out too. I saw this, which is a less restrictive version of my question. I've got a bit more ...
3k views

### Sort a string, sort of

If you sort a string you'll typically get something like: ':Iaaceeefggghiiiiklllllmnnooooprrssstttttuuyyyy Yes, that was the first sentence sorted. As ...
3k views

### Sever-sort an array

Challenge Given a non-empty array of integers, e.g.: [5, 2, 7, 6, 4, 1, 3] First sever it into arrays where no item is larger than the previous (i.e. non-...
2k 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 ...
2k 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 ...
1k views

### Alphabetize Integers

Alphabetize Integers For a given set of numbers, put them in alphabetical order when they are spelled out (i.e. 1: one, 2: two, 90: ninety, 19: nineteen). Your code should work for the range ...
624 views

### Blueprint a sestina

A sestina is a format of poem that follows an interesting pattern that we can generate. It has six stanzas of six lines each, where the last words of each line in the first stanza make up the line ...
1k views

### Visualize sorting

Say I have a list such as [3, 0, 4, 2, 1], and I use selection sort to sort it, I could visualize it like this: ...
1k views

### Multiple-Key Sorting

Given a list of indices and zero or more lists of integers, output the lists of integers, sorted in ascending order, with the key priority from the first input. Example Let the keys input be ...
1k views

### Make An ASCII Poker Chip Stack Arrangement

Poker has etiquette in how you arrange your chips, often enforced in tournaments - your chips may not be "hidden" from your opponents by being behind others, mostly to not hide some large denomination ...
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 ...
259 views

### “Cut and Paste Sorting”

The Challenge Given a string containing a random sequence of unique characters A to Z (all upper case, no duplicates), determine the cut-and-paste" sort and output the sort sequence to a specific ...
107 views

### Numeric to Alphabetic Organization [closed]

I have a list of images grouped numerically (YI0.png, YI1.png...YI20479.png). I want them ...
1k views

### The Burnt Pancake Problem

This challenge is related to Flipping Pancakes. You may have heard of pancake sorting, where a stack of pancakes is sorted by size by inserting spatula into the stack and flipping all of the pancakes ...
293 views

### Extendable Train Swapping Problem

Extended Train Swapping Problem Part 1: Normal Train Swapping Problem In the 1996 CCC (Canadian Computing Competition), the first Stage 2 problem was a Train Swapping Problem. You can visit the link ...
8k views

### List of possible birth years of living humans

The Challenge Output a list of years that starts with the current year and ends 120 years ago. The birth year of every living human would be included in this list. Details The list should be in ...
478 views

### Fun with strings and string lengths

Introduction Inspired by Dyalog Ltd.'s 2016 student competition. The challenge there is to write good APL code, but this is a code-golf and it is open to all languages. Derived from this closed ...
2k views

### Sort the months of the year

Write a function or program that takes string inputs, fully-spelled, English month names in title case: January, February, ...
2k views

### Sort band names

Challenge description You have a music library with many tracks recorded by many bands, each of which has a name, like Queen, ...
631 views

### Collect and place items

The goal of this challenge is to collect selected items in a list and move them to a certain location in the list. As a visual example, take the input values (represented by black boxed integers) and ...
333 views

### Sort a list of unknown values with the least amount of comparisons

In this optimization challenge you will write a program that sorts a single array by only comparing elements through asking the user on stdout to input comparison results on stdin. The below protocol ...
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 ...
2k views

### Post-determined Array Sorting

Input: An array containing three integers: 0, 1 and 2 in any order (i.e. ...
2k views

### Rearrange a number into alphabetical order

Given a non-negative integer (n), create a function that returns n in alphabetical order, according to the literal spelling of ...
944 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...
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 ...
444 views

### QWERTY Quine Creation

Challenge Create a quine, that instead of outputting it's source, output's it's source QWERTY-sorted. What is QWERTY sorting? QWERTY sorting is sorting code by the QWERTY keyboard. Anything higher ...
3k views

### Driftsort an array

Driftsort is a simple way to "sort" an array. It works by "sliding" or "rotating" the elements over in the array until the array is sorted, or until the array fails to be sorted. Let's walk through ...
4k 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. ...
343 views

### Insert semi-sorted into unsorted array

Welcome to your first day at PPCG Inc. As our newest junior assistant document sorter, you are responsible for making sure all documents we sent down to you are archived in alphabetical order. It's so ...
1k views

### Sorting rectangular matrices

Given a matrix A, we can say that it is "sorted" if each row and column of A is sorted (ascending left-to-right for rows and top-...
1k views

### A classic sorting code-golf question

This is a code-golf question. Input A list of non-negative integers in whatever format is the most convenient. Output The same list in sorted order in whatever format is the most convenient. ...
2k views

### Sort a nested list

You must write a program or function that sorts a nested list. Here are the rules for sorting a nested list: Let's take this list as an example: ...