2022 Developer Survey is open! Take survey.

Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
13 votes
9 answers
2k views

Magic: the Gathering - Colour Sorting

Related: Deck Names Friends or Foes Paying for Spells The Magic: the Gathering card game has five colours of magical mana: white (W), blue (U), black (B), red (R), and green (G). Cards can be any of ...
user avatar
9 votes
2 answers
310 views

Sorting passengers on a plane

A few days ago I made a puzzle about moving people on an airplane. Now I am interested in the general version of this puzzle and the shortest code golf for it. I will briefly summarise the puzzle here....
user avatar
20 votes
14 answers
1k views

Sort numbers in a ragged list

Given a ragged list, e.g. [[4, 7], [5, 3, [], [6, [2]]]] Your challenge is to sort only the numbers in it. For example, with the above, the result would be ...
user avatar
  • 27.2k
11 votes
7 answers
437 views

Sort musical pitches

Given an unordered list of musical pitches, write the shortest program/function (scored in bytes) to sort the list from lowest pitch to highest. Pitches will be given in scientific pitch notation, ...
user avatar
  • 10.3k
16 votes
16 answers
1k views

Sort every dimension

Given a multidimensional, rectangular array of nonnegative integers, sort it at every depth (lexicographically), starting from the innermost. For example, with this array: ...
user avatar
  • 27.2k
26 votes
28 answers
2k 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 ...
user avatar
17 votes
25 answers
1k views

Chunk Sort a Sequence

Your task is to input a sequence of integers and chunk sort it. You may assume the input list can always be chunked into groups of 1, 2, and 3. Definition Chunk sorting (a term I made up for the ...
user avatar
  • 3,053
2 votes
1 answer
805 views

An Scalable Event Scheduler That Can Handle Billions of Events [closed]

The event scheduler is a recurrent theme in event-driven architectures: something triggers an event that needs to be checked in the future one or more times. I has particular use in trading where you ...
user avatar
17 votes
13 answers
4k views

Worst case of Slowsort

Background Slowsort is an in-place, stable sorting algorithm that has worse-than-polynomial time complexity. The pseudocode for Slowsort looks like this: ...
user avatar
  • 62.1k
10 votes
2 answers
397 views

Branchless (MIPS) assembly code for median of 3

I was trying to write a short MIPS32 code for computing the median of three registers. The rules: Assume that some values are pre-loaded into $t0, ...
user avatar
  • 201
42 votes
17 answers
5k views

Recursive Stalin Sort [duplicate]

There is a "sorting" algorithm often called Stalin Sort, where instead of sorting an array, you just remove any items that are out of order. In this challenge, you'll implement part of a ...
user avatar
21 votes
16 answers
2k views

Largest Number with No Repeating Digit Pairs

Inspired by the problem with the same name on Puzzling SE by our very own Dmitry Kamenetsky. You are to find the largest number that only uses every digit pair once, in a given base. For example, in ...
user avatar
  • 1,921
8 votes
8 answers
561 views

Coordinate Connecting

Input: Ten unique integer coordinates, between (0,0) and (100,100). Output: The coordinates arranged in the order/an order such ...
user avatar
  • 1,184
19 votes
14 answers
2k views

NESCA: New English Stroke Count Alphabet

TLDR: Sort your input according to a new English alphabet somewhat based on Chinese stroke count methods. Background: In a Chinese glossary/index, finding terms that are contained within the book is ...
user avatar
  • 1,886
13 votes
19 answers
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 ...
user avatar
  • 2,850
3 votes
3 answers
279 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 ...
user avatar
  • 155
11 votes
14 answers
1k views

Is this a half-sort?

The problem over here introduces an new type of strings: if you split the string into equal halfs and swap the pairs, it produces the same output as sorting the string. We call that a half-sort. ...
user avatar
31 votes
35 answers
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 ...
user avatar
  • 6,657
19 votes
28 answers
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 ...
user avatar
7 votes
3 answers
487 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 ...
user avatar
20 votes
24 answers
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. ...
user avatar
  • 621
7 votes
2 answers
224 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 ...
user avatar
19 votes
17 answers
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 ...
user avatar
  • 2,813
26 votes
36 answers
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 ...
user avatar
  • 1,886
10 votes
3 answers
495 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 ...
user avatar
  • 4,163
8 votes
7 answers
239 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 ...
user avatar
  • 181
33 votes
17 answers
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 ...
user avatar
  • 6,740
-4 votes
1 answer
459 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 ...
user avatar
  • 537
21 votes
23 answers
3k 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 ...
user avatar
30 votes
28 answers
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 ...
user avatar
97 votes
45 answers
31k 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 ...
user avatar
  • 2,435
14 votes
3 answers
506 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 ...
user avatar
29 votes
48 answers
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 ...
user avatar
  • 27.1k
24 votes
26 answers
2k views

Sort by Largest Digit(s)

Challenge: Given a list of integer, sort descending by their single largest digit(s). The order for numbers with the same largest digit are then sorted by second largest digit, etc. We ignore ...
user avatar
34 votes
9 answers
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 <...
user avatar
  • 84.9k
18 votes
7 answers
2k views

Blind Random Sort

Here's a pretty common pattern for sorting algorithms: ...
user avatar
  • 41.3k
26 votes
19 answers
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 ...
user avatar
  • 6,657
18 votes
2 answers
9k 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 ...
user avatar
  • 12.6k
15 votes
22 answers
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 ...
user avatar
  • 12.6k
36 votes
9 answers
2k views

Indentation-based Sort

Given an ordered list of same-case letter strings (a-z XOR A-Z) where each string is preceded by 0 or more space ( ) characters, output the same list but with the strings sorted at each level of ...
user avatar
18 votes
22 answers
2k views

Sort by what the digit pairs describe

Given a positive integer, we can form a new number that's described by its digits taken pairwise (with a leading 0 added for numbers with odd number of digits). For eg.: 1234 can be read as one 2, ...
user avatar
  • 6,422
10 votes
8 answers
577 views

Codegolf Rainbow : Sorting Colors with Reflection

Introduction: After I posted two rainbow-related challenges: Codegolf Rainbow : Fun with Integer-Arrays 1 and Codegolf Rainbow : Draw in Black-and-White 2, the following comment was made by @ChrisM in ...
user avatar
14 votes
10 answers
2k 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 ...
user avatar
  • 166k
5 votes
4 answers
482 views

Einstein's Sorter

Challenge Given a list of integers and a velocity, \$v\$, implement a sorting algorithm which simulates a program sorting the list from smallest to biggest at the given velocity. Einstein's Theory ...
user avatar
  • 22.8k
21 votes
11 answers
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 ...
user avatar
  • 44.6k
21 votes
55 answers
6k 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 ...
user avatar
4 votes
1 answer
347 views

Pair and sort from two integer lists

You are given two arbitrary integer lists, e.g. [-10, 99, -6, 43], [100, 32, 44]. You are to pick one integer from each list and ...
user avatar
8 votes
1 answer
432 views

Implement Tyrant Sort [closed]

TL;DR Record (left-right)/length for each pair of consecutive elements. If they're 0 or negative, don't record it. Once this is done, take these actions. Don't update quotients: Increment right and ...
user avatar
  • 3,566
1 vote
0 answers
130 views

Sorting Algorithms for Physical Process [closed]

Not sure if this is the correct community to post this is. But as I see this problem as an interesting puzzle to solve, I'd thought to give it a shot... Problem Statement: Let`s say we have: N ...
user avatar
  • 11
17 votes
23 answers
2k views

Sort spelled-out serial numbers

Given a list of two or more spelled-out serial numbers of equal length greater than two, e.g. ...
user avatar
  • 27.1k