From: Neil Smith Date: Mon, 26 Dec 2022 09:05:42 +0000 (+0000) Subject: Bugfix X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-22.git;a=commitdiff_plain;h=d26baeb75e7bb105eb23c7434832203dc2ce6cfa Bugfix --- diff --git a/advent25/Main.hs b/advent25/Main.hs index cc0a464..4e6cf87 100644 --- a/advent25/Main.hs +++ b/advent25/Main.hs @@ -33,7 +33,10 @@ toBase5R n = (r : (toBase5R k)) where (k, r) = n `divMod` 5 packSnafu :: [Int] -> String -packSnafu = snd . foldl' packSnafuDigit (0, "") +packSnafu digits + | carry == 0 = shown + | otherwise = (snafuRep carry) : shown + where (carry, shown) = foldl' packSnafuDigit (0, "") digits packSnafuDigit :: (Int, String) -> Int -> (Int, String) packSnafuDigit (carry, acc) d @@ -41,7 +44,6 @@ packSnafuDigit (carry, acc) d | otherwise = (1, (snafuRep (d' - 5) : acc)) where d' = d + carry - snafuRep :: Int -> Char snafuRep 2 = '2' snafuRep 1 = '1'