Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.annotation.tailrec
- object day18 extends App {
- def nextRow(prev: String): String = {
- ('.' +: prev :+ '.').sliding(3).map(c => if (c.head != c.last) '^' else '.').mkString
- }
- def safeTiles(n: Int): Int = {
- @tailrec
- def countUp(row: String, acc: (Int, Int)): Int = acc match {
- case (x, y) if x == n => y
- case (x, y) => countUp(nextRow(row), (x + 1, y + row.count(_ == '.')))
- }
- val row1 = "......^.^^.....^^^^^^^^^...^.^..^^.^^^..^.^..^.^^^.^^^^..^^.^.^.....^^^^^..^..^^^..^^.^.^..^^..^^^.."
- countUp(row1, (0, 0))
- }
- safeTiles(40)
- safeTiles(400000)
- }
Advertisement
Add Comment
Please, Sign In to add comment