From d26baeb75e7bb105eb23c7434832203dc2ce6cfa Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 26 Dec 2022 09:05:42 +0000 Subject: [PATCH] Bugfix --- advent25/Main.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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' -- 2.34.1