# Questions tagged [sorting]

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

181 questions
Filter by
Sorted by
Tagged with
2k views

### Interviewer's Room

You are James and four of your friends (Bjarne, Eich, Rossum, Ada) are called for an interview. There are n interviewers, and they can each serve one person at a time, alphabetically. Each round of ...
2k views

### Sign that word 2!

Sign that word 2! Not that long ago, I posted a challenge called Sign that word!. In the challenge, you must find the signature of word, which is the letters put in order (e.g. The signature of ...
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 ...
8k 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 ...
2k views

### Integer Interpretator

The Challenge Given a finite list of integers, split it into the fewest partitions possible such that no partition contains a number more than once. Rules Input can be in any format and any order. ...
253 views

### Too much lines for me! [closed]

The problem You just got a new job, hurray! You expect to be given various interesting tasks, and be able to learn a lot in the next few months. Good news, your boss gave you your first work this ...
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 ...
1k views

### Minimally sort a list into a matrix

Given an unsorted list of unique strictly positive integers, minimally sort it into a 2D matrix. The input list is guaranteed to be of composite length, which means the output matrix is not ...
29k views

### Implement the Thanos sorting algorithm

The sorting algorithm goes like this: While the list is not sorted, snap half of all items (remove them from the list). Continue until the list is sorted or only one item remains (which is sorted by ...
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 ...
366 views

### Filesystem-sort my directory please

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

### Pendulum Encoding

Given a string as an input (which can be any acceptable/convenient format in your language), implement pendulum encoding. The test cases are split into individual items (which aren't quoted) for a ...
3k views

### Roll for Initiative!

Roll for Initiative! Introduction In tabletop games like Dungeons and Dragons, when you begin a battle, all involved parties roll for initiative. In DnD 5e, this is ...
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: ...
2k views

### Rubik-sorting a matrix (a.k.a. the torus puzzle)

The idea for this code-challenge is simple: given a matrix of integers, let's sort it by applying Rubik-style movements. This means that you can select a single row or column and rotate its elements ...
5k 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. ...
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 (...
373 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 ...
203 views

### Two stack sorting

This challenge is inspired by the same task I read some time ago in CACM. There are many ways to sort stuff. Most attempt to sort in as few operations as possible (= as fast as possible). However, it ...
8k 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 element ...
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 ...
2k views

### Sort and Table a Sentence by Word Lengths

In as few bytes as possible, sort the input, a delimited string OR list/vector/array of words, words contain printable ASCII except space (ASCII values 33-126) into a numbered list, table, or ...
5k views

### Sort odd numbers first

Rearrange a given list such that all the odd numbers appear before all the even numbers. Besides for this requirement, the output list may be in any order. The input will only contain integers, but ...
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 ...
421 views

### North Korean dictionary order

The objective Given a string of Hangul syllables, sort the characters in North Korean dictionary order. Introduction to Hangul syllables Hangul(한글) is the Korean writing system invented by Sejong ...
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 ...
718 views

### Stack the Christmas Gifts

Someone has been hastily stacking the Christmas presents, and it's quite a mess: ...
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, ...
218 views

### Dropsort with a Twist

This is my first attempt at a Code Golf question. If it needs obvious edits, please feel free to make them. Below is a description of the basic Dropsort algorithm. Dropsort is run on a list of ...
2k views

### Tell me how to flop

As computer scientists, you're probably all familiar with the basic list operations of pop and push. These are simple operations that modify a list of elements. However, have you ever heard of the ...
981 views

### Let's practice the scoring rules of 421!

421 is a rather popular dice game in France and some other European countries. It is mostly played in bars and pubs to determine who's going to buy the next round of drinks. The full game is usually ...
431 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. ...
3k views

### A quine of sorts

Given a string x, output the characters in x sorted according to the order of appearance in your source code. Examples ...
395 views

### Write the shortest O(n^2) sorting algorithm [closed]

Write a sorting algorithm for a list of integers that has an average performance of O(n^2). This is code-golf, so the shortest code in bytes wins. RULES: The characters wasted for the declaration of ...
2k views

### Block-sorting rows and columns in a 2D array

Given a 2D array of integers, let's sort its rows and columns in blocks. This means that you only have to sort a given row or column, but applying the transformations needed for sorting it to every ...
2k views

### Rotated Position of Integers

Challenge: Input: A sorted list of positive integers. Output: The amount of integers which are still at the exact same index, after rotating the digits in each integer its index amount of times ...
871 views

### Sort a list of numbers on the λ-calculus

Write a term on the pure untyped lambda calculus that, when applied to a church-encoded list of numbers, returns it with its numbers sorted in ascending or descending order. Church lists and numbers ...
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 ...
4k views

### Arrow those variables!

Challenge Robin likes having his variables declaration in the shape of an arrow. Here's how he does it: Input any number of strings Order them by ascending length Output them ordered by the middle ...
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 ...
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 ...
440 views

### Matrix rotation sort

Lets define a non-empty, unsorted and finite matrix with unique numbers as follow: $$N = \begin{Bmatrix} 4&5&7\\1&3&6 \end{Bmatrix}$$ Lets define 4 matrix moves as: ↑* (up): Moves a ...
5k views

### A “Sorting” algorithm

There is a "sorting algorithm" sometimes called Stalin sort in which in order to sort a list you simply remove elements from the list until it is sorted in increasing order. For example the list <...
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: ...
294 views

### Sort a list without builtin functions

Sorting a list would make a pretty fun code-golf challenge, but all the builtins make it boring! Its no fun when you spend all of your time golfing a function and then you see that someone else has a ...
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. ...
8k 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 ...
189 views

### Organize Your Christmas Party!

Christmas is coming up, and this year you have been charged with organizing your family's christmas get-together. You have a list of foods you want be there, but before you assign foods to people, you ...