blob: dd9270d4e602b2581aa3e120aa96dcfe6056bf32 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
|