From fa1bf6c2eac1c9f7969ff29504c9f51b9ba48008 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 29 May 2017 01:11:20 -0400 Subject: finish vol 3 --- 21-28/28.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 21-28/28.hs (limited to '21-28/28.hs') diff --git a/21-28/28.hs b/21-28/28.hs new file mode 100644 index 0000000..dd9270d --- /dev/null +++ b/21-28/28.hs @@ -0,0 +1,16 @@ +import Data.List (sortBy, foldl', groupBy) +import Data.Ord (comparing) + +lsort :: [[a]] -> [[a]] + +lsort = sortBy (comparing length) + +lfsort :: [[a]] -> [[a]] + +lfsort l = + [a | (a, b) <- sortBy (\x y -> (snd x) `compare` (snd y)) zipped] + where larr = map length l + count l e = foldl' (\acc x -> acc + (if x == e then 1 else 0)) 0 l + zipped = zip l (map (count larr) larr) + +lfsort2 = concat . lsort . groupBy (\x y -> length x == length y) . lsort -- cgit v1.2.3