Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sorting]

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

30
votes
17answers
2k views

Show the Top Five Comment Scores on a SE Post

A Stack Exchange script determines which five comments on questions or answers are initially seen on the main page of sites through the number of upvotes on them; the five comments with the highest ...
9
votes
1answer
296 views

Sort scrambled two-dimensional array filled with numbers by swapping adjacent numbers [closed]

A two-dimensional array of size n×n is filled with n*n numbers, starting from number 1. Those numbers are to be sorted per row in ascending order; the first number of a row must be greater than the ...
9
votes
1answer
429 views

Help me fill my wallet!

A while ago I purchased a new wallet which is able to hold 8 cards (4 on both side). However, I seem to have way more cards than that and I need to make choices on which ones I want to carry with me. ...
38
votes
37answers
4k views

The Rien Number

The Champernowne constant is a number that is constructed by concatenating the first n numbers, with n tending to infinity. It ...
104
votes
17answers
5k views

Xorting an array

Conceptually, this challenge is really simple. You're given a list of non-negative integers ai. If possible, find a non-negative integer ...
10
votes
4answers
219 views

Title Keywords in Context

This challenge is based on a problem described in D. Parnas, On the criteria to be used in decomposing systems into modules, and elaborated upon in J. Morris, Real Programming in Functional Languages. ...
12
votes
8answers
499 views

Typesetting multidimensional labels

In a steam-punk multidimensional world, our boss wants to affix printed index labels to each drawer in our conglomerate's multidimensional file cabinet. The boss wants to typeset the entire label ...
24
votes
20answers
2k views

Imitate an ordering

Given two lists of numbers, a source and a pattern, reorder the source to match the relative ordering of the pattern. Any two entries of the reordered source should compare the same way as the entries ...
27
votes
24answers
3k views

Sort this, quick!

Well... there are 59 (now 60) questions tagged sorting, but no simple quicksorts. That must be fixed. For those unfamiliar with quicksort, here is a breakdown, courtesy of Wikipedia- Pick an ...
-1
votes
2answers
124 views

Epcot World Reorder

Intoroduction If you've ever been to Epcot at Disney World, you've probably been to the world showcase: a lake surrounded by various country-themed locations. One thing that's always bothered me ...
57
votes
54answers
7k 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 ...
2
votes
0answers
119 views

Anagram Bubble Sorter [closed]

The Challenge A bubble sort takes a list of non-repeating integers and sorts them in ascending order, with only the use of one operation: switching two numbers which are next to eachother. However ...
1
vote
1answer
299 views

The Truck Problem [closed]

I am a teacher who was given a problem a few years ago. Every year since I have given it to my advanced students as a bonus assignment, but in ~10 years only 8 solved it, each with a slightly ...
20
votes
8answers
1k views

Crazy Librarian's Amazing Sorting System

It's back to school season! So for a part-time job, you're helping out at the school's library. The problem is, the head librarian has never even heard the words "Dewey Decimal," let alone implemented ...
7
votes
3answers
779 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 ...
85
votes
28answers
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. ...
17
votes
24answers
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 ...
12
votes
43answers
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 ...
32
votes
6answers
1k views

Sort the Textbooks

Sort the Textbooks School is starting soon (if it hasn't already) and so it's time to get our textbooks in order. You need to sort your books in alphabetical order but that takes too long so you ...
14
votes
3answers
607 views

Burrows, Wheeler and Back

Background The Burrows–Wheeler transform (BWT) is a reversible permutation of the characters of a string that results in large runs of similar characters for certain types of strings such as plain ...
8
votes
2answers
605 views

Sorting for Bozos

Introduction This challenge is about three (bad) sorting algorithms: Bogosort, and two others variants that I came up with (but have probably been thought of by ...
15
votes
14answers
2k views

CodeGolf - Ignore the noise #1

Instructions Barry is a not so good backend developer in charge of a small API that should give you information about purchases made in a client's shop. However, he hasn't done a great job and your ...
8
votes
12answers
1k views

Rearranging a set of numbers into order

The Question Given a set of 9 numbers, m[], which contains only numbers 1 through 9 in a random order, with no two numbers being the same, create a program in any ...
12
votes
3answers
345 views

Books on a Shelf

I have some books and a bookshelf. I would like to put as many books on the shelf as possible but I have a rule. All dimensions of the books (height, width and depth) should form a non-increasing ...
8
votes
5answers
382 views

Decide existence of total orderings

In this task, we consider arrays of positive integers such as this: 3 18 321 17 4 4 51 1 293 17 The input comprises a pair of such arrays both of arbitrary, ...
-1
votes
3answers
117 views

Detect the main order based on sub-lists [closed]

The question is simple but the answer maybe not! suppose that you have the following lists that all of them are ordered (not consecutive): ...
8
votes
6answers
2k views

Sort all the pixels of an image by the number of occurrences

Input The name of a file in the raster graphics format of your choice. The chosen format must support at least 8 bits per channel and 3 channels. Output A file in the same format, with the same ...
14
votes
3answers
825 views

Un-Merge a List

Introduction Most of you are familiar with the merge sort algorithm for sorting a list of numbers. As part of the algorithm, one writes a helper function called ...
8
votes
5answers
283 views

Almost Lexicographical List Comparison

Input Two lists A and B of nonnegative integers. Output Either 1, ...
9
votes
9answers
521 views

Ordering an array of negatives, zero and positives integers with one iteration

Take an array of integers containing negative numbers, positive numbers and zeros. Group it with one iteration and in place such that all of the negative numbers come first, followed by all of the ...
-4
votes
2answers
430 views

Implement slow sorting algorithm [duplicate]

All good coders know some good sorting algorithms like quicksort or merge sort. There is also slow sorting algorithms, e.g. bubble sort and insertion sort. But those are such easy to implement and so,...
19
votes
8answers
628 views

Stack the Christmas Gifts

Someone has been hastily stacking the Christmas presents, and it's quite a mess: ...
36
votes
9answers
5k views

Eating Candy in the Correct Order

When it comes to eating candy, I hold myself to higher standards than the typical layperson. There is a delicate balance between "mixing it up" and "saving the best for last." In this challenge, you ...
22
votes
5answers
7k views

Sort a List With Swaps and Pops

Consider a randomized list of the integers 1 to N. You want to sort it using only the following actions: Swap the first and last list elements. (S) Pop off the first element and append it to the end ...
21
votes
2answers
1k views

Book Stack Sort

When stacking books you usually want to put the largest ones at the bottom and the smallest ones at the top. However, my latent OCD makes me feel very uneasy if I've got two books where one is shorter ...
9
votes
7answers
843 views

Sort by custom alphabet

The challenge is to make a program that sorts a list of words, only that the words need to be in the order of a random given alphabet. Your program will accept a string of comma-separated words and a ...
97
votes
20answers
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 ...
8
votes
2answers
1k views

Put a list in order

With a window similar to the one pictured below, you are given a list of strings, which you want to put in alphabetical order. As shown, you have five operations: Move up [U] - moves the selected ...
-2
votes
4answers
388 views

The Golf (re)Sort [closed]

The Golf (re)Sort Everyone is sorting arrays these days, and so do we at our day jobs. But we like to go out golfing. When we do, we sure like to take our time. It is important to have a stress free ...
6
votes
5answers
2k views

Convert binary search tree into ordered linked list

Write the shortest possible program that turns a binary search tree into an ordered doubly-linked list, by modifying the pointers to the left and the right children of each node. Arguments: a pointer ...
15
votes
2answers
1k views

Pathological Sorting

Pathological Sorting Your boss has demanded that you develop a sorting algorithm to improve the performance of your company's application. However, having written the application, you know that you'...
5
votes
6answers
800 views

Golf the Pigeonhole sort

Implement the Pigeonhole sort. This is a variant of the Bucket sort, and its logic is very simple: index your items (by a given function) and then return all non-empty indexes' items. Your program/...
4
votes
1answer
690 views

Duct Tape some sorting

Your job is to make a sorting algorithm. The catch, you must copy it from Stack Overflow. Your program will take an input array (or equivalency), and output a sorted permutation of the array. Your ...
4
votes
0answers
118 views

Using dictionaries, thesauruses, and similar databases, construct as large of a “See also” loop as possible [closed]

As I'm sure many of you know, synonyms can range from very similar to not-so-similar-but-I-can-see-how-it's-similar. It's common for dictionaries to use "See also" to denote occurrences of words that ...
8
votes
6answers
1k views

Shortest code to sort walking points

The challenge is to, given a list of points, sort in a way that, when they are connected in this order, they never intersect. Input format (read from stdin): ...
14
votes
24answers
4k views

Merge two sorted lists

Merge Sort In this challenge, you will implement the merge subroutine of merge sort. Specifically, you must create a function or program or verb or similar which takes two lists, each sorted in ...
21
votes
6answers
3k views

Tower of Hanoi Sort

Write a function/subroutine to sort a list of integers, Tower of Hanoi style. You will be given a stack of integers. This is the main stack. You are also given two more helper stacks. These helper ...
19
votes
29answers
5k views

Sort-a-number. Sorta

Inspired by the ill-fated sorting-a-numbers-digits-without-using-an-array, but I thought it made a better code golf than SO question. Given a positive integer, sort the digits in that integer. ...
11
votes
14answers
2k views

Golfed+Fast sorting in C

[Latest update: benchmark program and preliminary resuls available, see below] So I want to test the speed/complexity tradeoff with a classic application: sorting. Write an ANSI C function that ...
2
votes
2answers
208 views

Merging text files based on a prefix key

Imagine an ordered file set : file1, file2, ... fileN. Each file is a textual file that is ...