better split in day 6
This commit is contained in:
parent
52f550dc86
commit
2dc820fc5b
11
day6.hs
11
day6.hs
@ -16,10 +16,7 @@ match as bs = (sort . nub) $ filter (`elem` bs) as
|
|||||||
|
|
||||||
split :: Eq a => a -> [a] -> [[a]]
|
split :: Eq a => a -> [a] -> [[a]]
|
||||||
split _ [] = []
|
split _ [] = []
|
||||||
split v as = split' v as [] []
|
split d as = chunk : (split d rest)
|
||||||
|
where
|
||||||
split' :: Eq a => a -> [a] -> [a] -> [[a]] -> [[a]]
|
chunk = takeWhile (/= d) as
|
||||||
split' _ [] a as = as ++ [a]
|
rest = drop 1 $ dropWhile (/= d) as
|
||||||
split' v (b:bs) a as
|
|
||||||
| b == v = split' v bs [] (as ++ [a])
|
|
||||||
| otherwise = split' v bs (a ++ [b]) as
|
|
||||||
|
Loading…
Reference in New Issue
Block a user