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
| otherwise = (1, (snafuRep (d' - 5) : acc))
where d' = d + carry
-
snafuRep :: Int -> Char
snafuRep 2 = '2'
snafuRep 1 = '1'