2024-05-26 00:36:26 -05:00
|
|
|
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]
|