-
-
Save waynejo/e396c6b52bf96be4f5f4c91e5cec4759 to your computer and use it in GitHub Desktop.
This file contains 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
import java.io.FileInputStream | |
import scala.io.StdIn | |
@main def solve3() = | |
def solve(trees: Vector[Vector[Char]], x: Int = 0, y: Int = 0, count: Int = 0): Int = { | |
if trees.size - 1 <= y then | |
count | |
else | |
val nextX = x + 3 | |
val nextY = y + 1 | |
val nextCount = if '#' == trees(nextY)(nextX % trees(nextY).size) then | |
count + 1 | |
else | |
count | |
solve(trees, nextX, nextY, nextCount) | |
} | |
val in = new FileInputStream("example3-1.in") | |
System.setIn(in) | |
val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null).map(_.toVector).toVector | |
println(solve(inputs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment