projects
/
advent-of-code-22.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
248db89
)
Bugfix
author
Neil Smith
<NeilNjae@users.noreply.github.com>
Mon, 26 Dec 2022 09:05:42 +0000
(09:05 +0000)
committer
Neil Smith
<NeilNjae@users.noreply.github.com>
Mon, 26 Dec 2022 09:05:42 +0000
(09:05 +0000)
advent25/Main.hs
patch
|
blob
|
history
diff --git
a/advent25/Main.hs
b/advent25/Main.hs
index cc0a464c9fbd83ec28652aaedab4c7fe306ce08f..4e6cf876029e4dd73645a67d553b3688a8fadf58 100644
(file)
--- 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'