Skip to content

Commit f978e3d

Browse files
committed
Simplify 2022 day 25 to not use branching
1 parent a92a67c commit f978e3d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/main/scala/eu/sim642/adventofcode2022/Day25.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ object Day25 {
3030
if (int == 0)
3131
None
3232
else {
33-
val (q, r) = int /% 5
34-
if (r <= 2)
35-
Some((r, q))
36-
else
37-
Some((r - 5, q + 1)) // subtract from carried instead
33+
// shift by 2 to avoid carrying
34+
val (q, r) = (int + 2) /% 5
35+
Some((r - 2, q))
3836
}
3937
})
4038
.view

0 commit comments

Comments
 (0)