99-haskell-problems/Problems 21-28/problem_27.hs

12 lines
408 B
Haskell
Raw Normal View History

import Data.List (groupBy, nub, permutations, sortBy)
2024-05-25 19:28:16 -05:00
group' :: [Int] -> [a] -> [[[a]]]
group' ln ls = map ((([([fst] <*>)] <*>) . groupBy grouper . sortBy sorter) . zip ls) (nub (permutations placers))
where
placers = concatMap (uncurry replicate) (zip ln [0 ..])
sorter (_, r1) (_, r2) = r1 `compare` r2
grouper (_, r1) (_, r2) = r1 == r2
group3 :: [a] -> [[[a]]]
group3 = group' [2, 3, 4]