# Sort a list of numbers [closed]

In golf, you try to get the lowest score (smallest application, most elegant, etc). In Bowling, you try to get the highest score. So if you follow, the goal of a Code-Bowling challenge is to make the biggest, most bastardized, hardest to maintain piece of code that still meets the requirements of the challenge. However, there's no point in making source longer just for the sake of it. It needs to seem like that added length was from design and not just padding.

The Challenge:

Create a program that sorts a list of numbers in ascending order.

Example:

Input: 1, 4, 7, 2, 5

Output: 1, 2, 4, 5, 7

Code: Obviously this wouldn't be a good answer, since there aren't many WTFs in there

function doSort(array $input) { sort($input);
return $input; }  Rules: There are no real rules. As long as the program functions, have at it! Remember: This is code-bowling, not golf. The objective is to make the worst, most bastardized code that you can! Bonus points for code that looks good, but is actually deceptively evil... • I wish I still had the calendar queue code I wrote once... Feb 17, 2011 at 20:21 • sort(sort(sort(sort(sort(sort(myarray)))))) Guarantees perfect sorting! Mar 12, 2011 at 22:55 • Apr 15, 2016 at 12:44 ## 33 Answers # Perl not so long but self-explained: if (my @list = (2,5,4,1)) { do { @list = sort @list and print @list} if("you want to sort it") }  # Radix Sort in Haskell I have tried to do some optimization using Data.Sequence but it probably needs some more around assingBuckets method. import qualified Data.Sequence as Seq import qualified Data.Foldable as Fold import System.Environment digit :: Int -> Int -> Int digit x pos = if pos >= 0 && pos < xlength then read [xstr !! (xlength - 1 - pos)] else 0 where xlength = length xstr xstr = show x assignBuckets :: [Int] -> Int -> [[Int]] assignBuckets xs dig = map Fold.toList . Fold.toList$
assign xs dig
(Seq.fromList $take 10$ repeat (Seq.empty :: Seq.Seq Int))
where assign :: [Int] -> Int -> Seq.Seq (Seq.Seq Int) -> Seq.Seq (Seq.Seq Int)
assign []     _   seq = seq
assign (x:xs) dig seq = assign xs dig $Seq.update idx ((Seq.index seq idx) Seq.|> x) seq where idx = digit x dig radixSort :: [Int] -> [Int] radixSort [] = [] radixSort xs = sort xs 0 (length . show . maximum$ xs)
where sort xs n m = if n >= m
then xs
else sort buckets (n+1) m
where buckets = (concat $assignBuckets xs n) main = do args <- getArgs print . radixSort . map (read :: String -> Int)$ args


This sort (if done properly I haven't checked the asymptotic runtime 100%) should run i O(kN) where k is the number of digits in the largest number which is good if k is constant.

oh lawd

<?php

$input = "1, 4, 7, 2, 5";$array = explode(', ', $input);$max = '';

$min = ''; foreach ($array as $value) { if (is_numeric($value) === true) {

$max = ($max < $value ?$value : $max);$min = ($min >$value ? $value :$min);
}
}

$output = ''; for ($i == $min;$i <= $max;$i++) {

if (in_array($i,$array) === true) {

$output .=$i . ', ';
}
}

echo trim(\$output, ', ');

?>