Created
December 21, 2025 13:01
-
-
Save ritesh/7de3951b64a8b1fbfdcd4109d3a1e111 to your computer and use it in GitHub Desktop.
day2.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @main def main(): Unit = { | |
| val path = os.Path("/tmp/1.txt") | |
| val lineStream: geny.Generator[String] = os.read.lines.stream(path) | |
| println("Num zeroes: " + turn_dial_part2(lineStream)) | |
| } | |
| def turn_dial_part2(gen: geny.Generator[String]): Int = { | |
| var dialPos = 50 | |
| gen | |
| .map(input => { | |
| val direction = if input.head == 'L' then -1 else 1 | |
| (0 until input.tail.toInt) | |
| .map(i => { | |
| // println("Dial is moving by " + i) | |
| dialPos = (dialPos + direction) % 100 | |
| // println("Dial pos is now " + dialPos) | |
| if dialPos == 0 then 1 else 0 | |
| }) | |
| .sum | |
| }) | |
| .sum | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be day 1 part 2 not day 2