Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created December 25, 2020 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynejo/e396c6b52bf96be4f5f4c91e5cec4759 to your computer and use it in GitHub Desktop.
Save waynejo/e396c6b52bf96be4f5f4c91e5cec4759 to your computer and use it in GitHub Desktop.
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