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
2k
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
8
answers
821
views
The steps of sorting a stack of disks on three pegs
You have a Tower of Hanoi-esque set of 3 pegs.
There is a stack of unsorted disks labelled from 1 to n (inclusive) on one of these pegs. The other two pegs are ...
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 ...
36
votes
19
answers
3k
views
In what order will the downloads complete?
Background
Recently, I was installing updates on my pc with Pacman (I use arch btw) and noticed the order it downloaded files was like this
Start with the largest 4 downloads
When a download ...
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 & ...
11
votes
5
answers
594
views
Double dequer sort
In this challenge Bubbler describes sorting a list by inserting its elements left to right into a double ended queue or "deque".
Take a number from the front of the array, and push it into ...
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 ...
9
votes
8
answers
1k
views
Sort Number Array
Given array \$A\$ \$(a_0, a_1,... , a_n) \$ as a permutation of \$(0, 1,...,n)\$ where \$n ≥ 2\$. Sort array \$A\$ into array \$(0, 1,...,n\$) with \$2\$ caveats:
\$1\$ swap is counted when swapping ...
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 ...
20
votes
32
answers
3k
views
Iteratively sort a list
Given a list of Integers greater than zero, Sort each of the unique values in ascending order, then repeat the process on the remaining duplicate values and append.
Example:
...
3
votes
6
answers
380
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 ...
15
votes
17
answers
2k
views
How long to carry sort?
Carry sort is an \$O(n)\$ "sorting" algorithm. Here's how it works. The algorithm moves left to right along a list. As it traverses a list it "carries" a single item, the largest ...
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
8
answers
2k
views
Change the subject
Sometimes I feel like the conversation is going down the wrong path and take it upon myself to steer it in another direction. And this conversation is going wrong real fast, so I need to change the ...
14
votes
10
answers
531
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 ...