Questions tagged [sorting]
This challenge is intended to be solved by sorting, ordering, or otherwise organizing some set of data.
220 questions
17
votes
18
answers
1k
views
Order a list by the difference of its elements
Task
Given an unsorted list of integers, order it in such a way that the absolute difference of every two adjacent elements will always be equal to 1:
\$|dx| = 1\$
There will be guaranteed one or more ...
8
votes
6
answers
1k
views
Ranking of binary trees
Let N = [0,1,2,...n-1] be the initial segment of the natural
numbers of length n, then all permutations of N can be sorted
lexicographically, starting with the identity. The index into this
sorted ...
3
votes
1
answer
226
views
How comparison-heavy is this list? [closed]
Given a list of strings in any convenient format display the amount of comparisons between individual characters that a merge sort algorithm would perform.
The merge-sort algorithm is a divide & ...
24
votes
16
answers
3k
views
Sorting with a deque
You're given an array of positive integers. Your job is to sort them using an initially empty deque (double-ended queue) by the following procedure:
Take a number from the front of the array, and ...
8
votes
3
answers
513
views
Stably sort N elements in this restricted "cmov" language
The following problem is taken from the real world — but indubitably code-golf!
In this puzzle, the programming language is fixed, and your job is to write the most ...
3
votes
6
answers
378
views
Pseudo-Quantum Bogosort [closed]
Pseudo-Quantum Bogosort
Quantum Bogosort is as follows:
Quantumly randomise the list, such that there is no way of knowing what order the list is in until it is observed. This will divide the ...
19
votes
19
answers
2k
views
"Sort" by element duplication
Inspired by one of many bugs I ran into while implementing selection sort in trilangle.
Given a non-empty list of non-negative integers, "sort" the list using the following procedure:
Find ...
14
votes
10
answers
530
views
CGAC2022 Day 17: Present Heap
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Inspired by https://xkcd.com/835
In the midst of his mid-life crisis, Santa has impulsively purchased a Sports ...
26
votes
7
answers
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&...
5
votes
0
answers
271
views
Sort my Cups︎︎︎︎︎︎︎︎︎︎ [closed]
I have a set of colored plastic cups. They come in four colors: green, yellow, pink, and blue. When I put them on my shelf, I like to stack them in a certain pattern. Your job is, given a list of any ...
9
votes
2
answers
395
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....
10
votes
9
answers
640
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, ...
28
votes
30
answers
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 ...
2
votes
1
answer
1k
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 ...
12
votes
2
answers
779
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, ...
21
votes
16
answers
3k
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 ...
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 ...
3
votes
3
answers
338
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 ...
34
votes
37
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 ...
8
votes
3
answers
631
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 ...
20
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 ...
12
votes
4
answers
898
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 ...
34
votes
20
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
...
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 ...
102
votes
47
answers
33k
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 ...