Skip to content

Instantly share code, notes, and snippets.

@kmizu
Last active November 27, 2019 04:47
Show Gist options
  • Save kmizu/a229857d15a3d14b50416c2efec266af to your computer and use it in GitHub Desktop.
Save kmizu/a229857d15a3d14b50416c2efec266af to your computer and use it in GitHub Desktop.
CS Study 2019/11/27
case class Point(x: Int, y: Int)
def traverse(p: Point): Int = p match {
case Point(3, 3) =>
1
case Point(x, y) if x <= 3 && y <= 3 =>
traverse(p.copy(x = p.x + 1)) +
traverse(p.copy(y = p.y + 1))
case Point(_, _) =>
0
}
traverse(Point(1, 1)) // 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment