day4,5: update - use parser combinators

not the cleanest, im still learning parsing in hs

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-05 23:39:03 +05:30
parent eb9ae79611
commit 38201248c4
3 changed files with 47 additions and 52 deletions

17
Lib.hs
View File

@@ -1,17 +0,0 @@
module Lib (chunks, split) where
chunks :: Int -> [a] -> [[a]]
chunks n xs
| null xs = []
| otherwise = head : chunks n tail
where (head, tail) = splitAt n xs
split :: Eq a => a -> [a] -> [[a]]
split del =
foldr
( \c (x : xs) ->
if c == del
then [] : x : xs
else (c : x) : xs
)
[[]]