From 0a48ed023ea65d75851ba2a4151100602695a2fd Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 22 Oct 2015 14:05:21 +1100 Subject: Cleaning up source a bit --- sort/pancakesort.hs | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 sort/pancakesort.hs (limited to 'sort/pancakesort.hs') diff --git a/sort/pancakesort.hs b/sort/pancakesort.hs deleted file mode 100644 index 30993ba..0000000 --- a/sort/pancakesort.hs +++ /dev/null @@ -1,30 +0,0 @@ - - - -pancakeSort :: Ord a => [a] -> [a] -pancakeSort [] = [] -pancakeSort cakeStack = - let selectedCake = indexOfLargest cakeStack - cakeStack' = (doFlip (length cakeStack)) . (doFlip selectedCake) $ cakeStack - in (pancakeSort (init cakeStack')) ++ [last cakeStack'] - - - -indexOfLargest :: Ord a => [a] -> Int -indexOfLargest (x:xs) = - let f m i j y = if length y == 0 - then i - else if (head y) > m - then f (head y) j (j+1) (tail y) - else f m i (j+1) (tail y) - in f x 0 1 xs - - - -doFlip :: Int -> [a] -> [a] -doFlip depth list = - let prefix = take (depth + 1) list - rest = drop (depth + 1) list - in (reverse prefix) ++ rest - - -- cgit