Skip to main content

Questions tagged [sorting]

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

17 votes
18 answers
2k views

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 ...
Glory2Ukraine's user avatar
8 votes
8 answers
821 views

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 ...
bigyihsuan's user avatar
  • 11.5k
8 votes
6 answers
1k views

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 ...
Sophia Antipolis's user avatar
36 votes
19 answers
3k views

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 ...
mousetail's user avatar
  • 14.4k
3 votes
1 answer
226 views

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 & ...
Kamila Szewczyk's user avatar
11 votes
5 answers
594 views

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 ...
Wheat Wizard's user avatar
  • 103k
24 votes
16 answers
3k views

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 ...
Bubbler's user avatar
  • 79.3k
9 votes
8 answers
1k views

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 ...
TruongVi's user avatar
  • 121
8 votes
3 answers
513 views

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 ...
Quuxplusone's user avatar
20 votes
32 answers
3k views

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: ...
pacman256's user avatar
  • 5,395
3 votes
6 answers
380 views

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 ...
pacman256's user avatar
  • 5,395
15 votes
17 answers
2k views

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 ...
Wheat Wizard's user avatar
  • 103k
19 votes
19 answers
2k views

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 ...
Bbrk24's user avatar
  • 3,863
14 votes
8 answers
2k views

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 ...
noodle person's user avatar
14 votes
10 answers
531 views

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 ...
Ginger's user avatar
  • 6,108

15 30 50 per page
1
2 3 4 5
15