We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6b11e5f commit b36962dCopy full SHA for b36962d
src/main/scala/AdventOfCode2022/Day25.scala
@@ -11,14 +11,14 @@ object Day25:
11
5 * total + digit
12
}
13
14
- def toSnafu(i: Long, s: String = ""): String = if i == 0 then s else
15
- val (digit, prefix) = i % 5 match
16
- case 0 => (0, "0")
17
- case 1 => (1, "1")
18
- case 2 => (2, "2")
19
- case 3 => (-2, "=")
20
- case 4 => (-1, "-")
21
- toSnafu((i - digit) / 5, prefix + s)
+ def toSnafu(i: Long): String = if i == 0 then "" else
+ val suffix = i % 5 match
+ case 0 => "0"
+ case 1 => "1"
+ case 2 => "2"
+ case 3 => "="
+ case 4 => "-"
+ toSnafu((i + 2) / 5) + suffix
22
23
def part1(input: Seq[String]): String = toSnafu(input.map(fromSnafu).sum)
24
0 commit comments