diff options
Diffstat (limited to 'day09')
-rw-r--r-- | day09/day09.hs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/day09/day09.hs b/day09/day09.hs index 0e03865..ca87b85 100644 --- a/day09/day09.hs +++ b/day09/day09.hs @@ -21,15 +21,15 @@ frag1 :: HDD -> HDD -> HDD -> HDD frag1 acc dt (Free _:rest) = frag1 acc dt rest frag1 acc (Data di dl:dr) p@(Data pi pl:_) - | di == pi = acc ++ [Data pi pl] - | otherwise = frag1 (acc ++ [Data di dl]) dr p + | di == pi = (Data pi pl:acc) + | otherwise = frag1 (Data di dl:acc) dr p frag1 acc (Free f:rest) (Data id d:pack) - | d < f = frag1 (acc ++ [Data id d]) (Free (f - d):rest) pack - | d == f = frag1 (acc ++ [Data id d]) rest pack - | d > f = frag1 (acc ++ [Data id f]) rest (Data id (d - f):pack) + | d < f = frag1 (Data id d:acc) (Free (f - d):rest) pack + | d == f = frag1 (Data id d:acc) rest pack + | d > f = frag1 (Data id f:acc) rest (Data id (d - f):pack) frag :: HDD -> HDD -frag hdd = frag1 [] hdd (reverse hdd) +frag hdd = reverse $ frag1 [] hdd (reverse hdd) checksum :: Int -> Int -> HDD -> Int checksum acc _ [] = acc |