Compare commits

..

4 Commits

Author SHA1 Message Date
Christian
f703a5f028 Day 16 2024-12-16 12:17:01 +01:00
Christian
51b49018e4 Revert "Day 11 (Make fast when hot)"
This reverts commit 7bd424d1f9.
2024-12-15 12:42:06 +01:00
Christian
558b9f33be More pretty 2024-12-15 12:33:30 +01:00
Christian
7bd424d1f9 Day 11 (Make fast when hot) 2024-12-15 12:31:08 +01:00
6 changed files with 228 additions and 7 deletions

View File

@@ -11,6 +11,9 @@ case class Point(x: Int, y: Int):
def *(n: Int): Point = Point(n * x, n * y)
def reduce: Point = { val g = gcd(x.abs, y.abs); Point(x / g, y / g) }
val directions =
Seq(Direction.Up, Direction.Right, Direction.Down, Direction.Left)
object Direction:
def from(c: Char): Direction =
c match
@@ -43,6 +46,7 @@ enum Direction:
case Left => Right
case class Pose(pos: Point, dir: Direction):
def turnLeft: Pose = Pose(pos, dir.turnLeft)
def turnRight: Pose = Pose(pos, dir.turnRight)
def step: Pose = Pose(dir(pos), dir)
def step(n: Int): Pose = Pose(dir.applyN(pos, n), dir)

View File

@@ -17,7 +17,8 @@ val solvers = Map[Int, Solver](
12 -> Day12,
13 -> Day13,
14 -> Day14,
15 -> Day15
15 -> Day15,
16 -> Day16
)
def runSolver(solver: Solver, input: os.Path): Unit =
@@ -27,15 +28,22 @@ def runSolver(solver: Solver, input: os.Path): Unit =
println(solution.p1)
println(solution.p2)
case None =>
println(f"Preprocessing: ${timings.prep}%24s μs")
println(f"Part 1: ${solution.p1}%15s ${timings.p1}%15s μs")
println(f"Part 2: ${solution.p2}%15s ${timings.p2}%15s μs")
println(f"==============================================")
println(f"Day ${solver.day}%02d ---------------------------------------")
println(f"Prep ${timings.prep}%38s μs")
println(f"Part 1 ${solution.p1}%20s ${timings.p1}%15s μs")
println(f"Part 2 ${solution.p2}%20s ${timings.p2}%15s μs")
println(f"----------------------------------------------")
println(f"Total ${timings.total}%37s μs")
println(f"==============================================")
@main def main(day: String, input: String): Unit =
val num = """(\d+)""".r
day match
case "all" =>
solvers.foreach { case (day, solver) =>
solvers.toList.sortBy(_._1).foreach { case (day, solver) =>
runSolver(solver, os.Path(input, os.pwd) / f"$day%02d.in")
}
case num(_) =>

View File

@@ -1,10 +1,11 @@
package dev.ctsk.aoc
case class Timings(prep: Long, p1: Long, p2: Long)
case class Timings(prep: Long, p1: Long, p2: Long):
def total: Long = prep + p1 + p2
case class Solution(p1: Object, p2: Object)
abstract class Solver(day: Int):
abstract class Solver(val day: Int):
def run(input: os.ReadablePath): (Timings, Solution)
def timed[A](solution: => A): (Long, A) =

View File

@@ -0,0 +1,65 @@
package dev.ctsk.aoc.days
import dev.ctsk.aoc.{Direction, *}
import scala.collection.mutable
object Day16 extends Solver(16):
override def run(input_ : os.ReadablePath): (Timings, Solution) =
val (pre_time, grid) = timed {
Grid(os.read.lines(input_).map(_.toArray).toArray)
}
val start = grid.findFirst(_ == 'S').get
val end = grid.findFirst(_ == 'E').get
case class State(distance: Int, pose: Pose)
implicit def ord: Ordering[State] = Ordering.by(-1 * _.distance)
Direction.Up.ordinal
def search(start: Pose): (Map[Pose, Int], Map[Pose, List[Pose]]) =
val distance = mutable.Map(start -> 0)
val ancestor = mutable.Map.empty[Pose, List[Pose]]
val heap = mutable.PriorityQueue(State(0, start))
inline def relax(u: Pose, v: Pose, vDist: Int): Unit =
val oldDist = distance.getOrElse(v, 1_000_000)
if vDist == oldDist then ancestor(v) +:= u
if vDist < oldDist then
ancestor(v) = List(u)
distance(v) = vDist
heap.enqueue(State(vDist, v))
while heap.nonEmpty do
val State(uDist, u) = heap.dequeue()
if uDist == distance(u) then
if !grid(u.step.pos).contains('#') then relax(u, u.step, uDist + 1)
for (v <- Seq(u.turnLeft, u.turnRight)) do relax(u, v, uDist + 1000)
(distance.toMap, ancestor.toMap)
val (p1_time, (distance, ancestor)) = timed {
search(Pose(start, Direction.Right))
}
val endPose = directions.map(Pose(end, _)).minBy(distance(_))
val p1 = distance(endPose)
val (p2_time, p2) = timed {
val all = mutable.Set(endPose)
var cur = Set(endPose)
println(start)
while cur.nonEmpty do
cur = cur.filter(_ != Pose(start, Direction.Right)).flatMap(ancestor(_))
all.addAll(cur)
all.map(_.pos).size
}
(
Timings(0, p1_time, p2_time),
Solution(Int.box(p1), Int.box(p2))
)

2
data/16.ans Normal file
View File

@@ -0,0 +1,2 @@
106512
563

141
data/16.in Normal file
View File

@@ -0,0 +1,141 @@
#############################################################################################################################################
#.....#.....#.....#.........#.....#.......#...#.........#.....#.....#...........#...#.............#.....#.....#...........#.....#..........E#
#.###.#.###.#.###.#####.#.#.#.###.#.#####.#.#.#.###.###.#.#.###.###.#.#######.###.#.#.###.#######.###.#.###.###.###.#####.#.###.#.#####.###.#
#.#.....#.#.#.#.....................#.....#.....#...#...#.#.......#.#...#...#.....#.#.#.#.....#.#.....#...#...#.#.#...#.....#...#...#...#...#
#.#######.#.#.#######.###.#.###.###.#.#.###.#####.#.#.###.#######.#.###.#.#.#######.#.#.#####.#.#########.###.#.#.###.#######.###.###.###.###
#...........................#...#...#.#.#...........#.#...#.#...#.#.#...#.#.....#...........................#.......#...#...#...#.#...#.....#
#.###.#.#.#.###.#.#.#######.#####.#.#.#.#.###.###.#.#.#.###.#.#.###.#.###.#####.#.#.#####.#.###.###.#######.###########.#.#.###.#.#.###.#####
#.#...#.#.#.#...#.#...#...........#.........................#.#...#.#.#...#...#.#.#...#...#.#.......#.#...#.........#...#.#.#...#.#.#...#...#
#.#.###.#.#.#.###.#####.#####.#####.#.###.###.#.#.#.#########.###.#.#.#####.#.#.#.###.#.###.#.#######.#.#.#########.#.#####.#.###.#.#####.#.#
#.#...#.#...#.#.......#.#.....#...#.#...#.....#...#...........#.#.#.........#...#...............................#...#...#...#.#...#...#...#.#
#.###.#.#####.#######.#.#.#######.#.#.#.#######.#.#.#.###.#####.#.###.#.#######.#######.#.#.#####.###.#.#.#.#.#.#.#####.#.###.#######.#.###.#
#.#.#.#.......#.......#...#.#.....#.#.#.......#.#.#.#.#...#...#.....#.#.....#...#.........#.#...#.....#.................#.......#...#...#...#
#.#.#.#########.#####.#####.#.#.###.#.#.#######.#.#.#.#.###.#.#####.#.#####.#.#########.#.#.###.###.###.#.#.###.#.#.#.#########.#.#.#####.#.#
#...#.#.........#.......#...#.#.....#.#.....#...#...........................#.........#...#.............#.#...#...#.#.....#...#...#.......#.#
###.#.#.#####.###.###.#.#.#.#.#######.#####.#.###.###.###.#.#####.#.#.###########.###.#.#####.#.#.###.###.###.#####.#####.#.#.#############.#
#...#.#.....#.....#...#...#.......#.....#...#.#.....#.#...#.#...#.#...#.............#.#...#...#.....#...#...#.#...#.#...#...#.#.............#
#.#.#.#####.#######.#.###########.#.#####.#.#.#.###.#.#####.#.###.###.#######.#.#.###.###.#.#######.#.#####.#.#.#.#.#.#.#####.###.#.#######.#
#...#...#.#...#.....#.........#...#...#...#.#.#.#...#.......#...#.#.#.#.....#.#...#.......#.......#.#.#.....#.#.#.....#.....#...#.#.....#...#
#.#####.#.###.#####.#########.#.###.#.#.###.#.###.#############.#.#.#.#.###.#.#.###.###########.#.#.#.#.#####.#.###########.###.#####.#.#.###
#.#.....#...#.....#.........#...#.#...#...#.#...#...#...........#.#...#.#.#.#.#.....#.#.......#.#.....#.#...#.#...#...#.....#.#.....#.#...#.#
#.#.#.#####.###.#.#####.#########.###.###.#.###.#.#.#.###.#####.#.#.###.#.#.#####.###.#.#####.#########.#.#.#.#.###.#.#.#####.#####.#.#####.#
#.#.#.#...#.....#.....#...............#...#.#.#.#...#.#.#...#.#.#.#.#...#.#.....#.....#.#...#.....#.....#.#.#.#.#...#.#.#.....#.....#.#.....#
#.#.###.#.#.#########.#.###############.###.#.#.#.###.#.###.#.#.#.#.#.###.#####.#######.#.#######.#.#######.#.###.###.#.#.#.###.#####.#.###.#
#.#.....#.#.......#...#...#...........#...#...#.#...#.#...#.#.#.#.#...#.........#.......#.......#.#.#.......#.....#.#.#.#.#.#.......#.#.#...#
#.#######.#####.###.#####.#.#.#######.###.#####.###.#.#.#.#.#.#.#.#############.#.#########.###.#.#.###.###########.#.#.#.###.###.#.#.#.###.#
#.#.....#.#...#.#...#...#.#.#.#.....#.#.#.....#...#.....#...#.#.#...#.........#...........#...#.....#...#.........#...#.#...#.#...#.#.#...#.#
#.#.#####.#.#.#.#.###.###.###.#.###.#.#.#####.###.###.#####.#.#.###.#.#######.#.#######.#.###########.###.#######.#.###.#.#.#.###.###.###.#.#
#...#.....#.#...#...#...#.....#...#.........#.......#.#...#.#.....#.........#.#.#.....#.#.......#.....#.....#...#.#.#...#.#.#...#...#.....#.#
###.#.#####.###.###.###.#.###############.#######.#.###.#.#.#.#############.#.#.#.###.#########.#.#####.#####.#.#.#.###.###.###.#.#.#######.#
#.#.#.#.......#.#.#...#...#.............#.#.......#...#.#...#.#...........#.#.#...#.#...........#.........#...#...#...#.....#...#...........#
#.#.#.#.#.#.#.#.#.###.#.#.#.#####.#.###.###.#####.###.#.#####.#.#.#######.###.#.###.#############.#########.#.#######.#.#####.###.#.###.#####
#...#.#.#...#.#.....#.#...#.......#.#...#...#...#...#...#...#.#...#.....#.#...#...........#.....#...#.......#.#.....#...#.....#...#...#.#...#
#.###.#.#####.###.###.#.#######.#.#.#.###.###.#####.#####.###.#.#.#.###.#.#.###.###.#######.###.###.#.#######.#.###.#.#.#.###.#####.#.#.###.#
#...#.#.#...#.#.#.#...#...#.#...#...#.#...#...........#.....#...#.#...#.#...#...#.#.#.......#.#...#.#.......#.....#...#.#...#.#.....#.#...#.#
###.#.###.#.#.#.#.#.#####.#.#.#######.#.###.#########.#####.###.#.###.#.#####.###.#.#.#######.###.#.#######.#####.#########.###.###.#.###.#.#
#...#.#...#...#...#...#.....#...#...#.#...#.....#...#.....#.....#...#.#...#.......#.#.....#...#...#.#.....#.......#...........#...#.#.......#
#####.#.#.###.#######.#.#######.#.###.#.#.#######.#.#####.#######.#.###.#.#.#######.#####.#.#.#.###.#####.#########.#.###.#.#.#.###.#######.#
#...#.#.#.....#...#...#.#.......#.....#.#.......#.#...#...#.....#.#...#.#.#...........#.#.#.#.#...#.#.....#...#.....#.#.#.#.#.......#...#...#
#.#.#.#.#.#####.#.#.#####.###.###.#####.#.#####.#.###.###.#.###.#####.#.#####.#.#####.#.#.###.###.#.#.###.###.#.###.#.#.#.#######.#.#.#.#.###
#...............#.........#...........#.#.....#.#...#...#...#...#.....#.......#.#...#.#.#...#...#.....#...#...#.#.....#.#...#.....#...#.#...#
#.#####.#.#################.#########.###.###.#.###.###.#####.###.###.#.#.#####.#.#.#.#.###.#.#.#####.#.###.#.#.#.#####.###.#.###.#.###.###.#
#...#.#...#...#...#.....#...#.......#...#...#...#...#.#.....#.#...#.#.........#.#...#.......#.#.......#.#...#.#.#.........#.#.............#.#
###.#.###.#.#.#.#.###.###.###.#####.###.###.###.#.###.#####.#.#.###.#.#.#######.#.###.#####.###.#######.###.###.#.#####.###.#.#####.#.###.#.#
#...#...#...#.#.#...#.......#.#...#.#...#.....#.#.#...#.....#...#.....#.........#.....#.....#...#.....#...#.....#.....#.....#.#.......#.#.#.#
#.###.#.#.###.#.###.#.#.#####.#.#.#.###.#.#.#.#.#.#.#.#.#########.#####.#########.#####.#####.###.###.###.#.#########.#.#####.#.###.###.#.###
#...#.#.......#...#...#.#.....#.#.#...#...#.....#.#.#.#.#...#.......#...#.........#.....#.....#...#.#...#.#.......#.#.#...#.....#.......#...#
#.#.#####.#.#.#.#.###.###.#####.#.###.#####.#####.#.#.#.#.###.#######.###.###.#.###.#######.#.#.###.###.#.#######.#.#.###.#.#######.#.#.###.#
#.#.......#...#...#.#...#.....#.....#.#...#...#...#.#.#.#.....#.......#...#...#...#.#.......#...#.....#...#.#.......#.#...#.#.......#.#.#.#.#
#.#######.###.#.###.###.#####.#.###.#.#.#.###.#.#####.#.#######.###########.#.#####.###.#####.#.#.#.#######.#.#####.#.#.###.#####.#.#.#.#.#.#
#.....#.#.............#.#...#...#...#.#.#...#.#...#...#.#.....#...#...#...#...#...#.....#.....#.#.#.#...#...#.#...#.#.#.#...#.....#.#.#...#.#
#.###.#.#.###.#######.#.#.#.#.#.#####.#.###.#.###.#.#.#.#.###.###.#.#.#.#.#.#.#.#.#######.#####.#.###.#.#.#.#.#.#.###.#.#.#.#.#####.#.#####.#
#.............#...#...#...#.....#.....#...#.........#.#...#.#.#...#.#...#...#...#...#.....#.....#.....#...#.#.#.#...#.#...#...#...#...#.....#
#.###########.#.#.###############.#######.#############.###.#.#.#.#.###############.#.#.#.#.#####.#########.#.#.#.#.#.###.#####.###.#.#.###.#
#.#.....#.....#.#...........#...#.......#.#...#.......#.....#.#.#.#.#...#.....#...#...#.#.#.....#.........#...#.#.#...#.........#.....#.#.#.#
###.###.#.#.#.#.###.#######.#.#.#######.#.#.###.#####.#####.#.#.#.#.###.#.#.#.#.#.#####.#.#####.#########.#####.#.#####.###.###.#.#####.#.#.#
#...#...#.#.....#.......#.#...#...#...#.#.....#.#...#.....#.#.#.#.#...#.#.#.#...#.#...#.#.#.....#...#...........#...#...#.....#.#.#.....#.#.#
#.#####.#.###.###.#####.#.#######.#.#.#.#.#.#.#.#.#.#####.###.#.#####.#.#.#.#####.###.#.#.#.#####.#.#######.#######.#.###.#####.#.#.#####.#.#
#.....#.#.......#.#...#.....#...#...#.#.#.#...#.#.#.....#...#.#.......#...#.#.........#.#.#.#.....#...#...#.#.....#...#...#...#...#...#.#...#
#.###.#.#######.#.#.#.#.#####.#.###.#.#.#.#.###.#.#####.#.#.#.###.#########.#.#######.#.#.#.###.#.###.#.#.#.#.###.#.#####.#.#.#.#####.#.#.###
#...#.#.#...#...#.#.#...#...#.#.............#...#.#...#.....#...#...........#...#.....#.#.#...#.#...#...#.#.....#.#.#...#.#.#.#.....#.#.....#
#####.#.#.#.#.###.#######.#.#.#############.#.###.###.#########.###############.#.#####.#.###.#.###.###.#.#####.#.#.#.#.###.#.###.###.#####.#
#.....#...#.#.#.#.........#...#.#...#.......#...#...#.....#.....#.........#...#.#.#.....#.#...#.#...#...#...#.#.#.#...#.....#...#.#...#...#.#
#.#####.###.#.#.#.#.###########.#.#.#.#########.###.#.###.#.#.###.#######.#.#.#.#.#.#####.#.#####.###.#.###.#.#.#.#############.#.#.#.#.#.#.#
#.............#.#.....#.........#.#...#.....#.#...#...#.#.#.#...#...#...#...#.#.........#.#.......#.........#...#.....#.........#.#.#.#.#.#.#
#.###########.#.#####.###.#####.#.#####.#.#.#.###.#####.#.#.###.#.###.#.#.###.#.#######.#######.#.#########.#.#######.#########.###.###.#.#.#
#.#.......#...#.....#.#...#.#...#.#...#.#.......#.#...#...#.#...#.#...#.#.#...#.#.....#.......#.#.#...#...#.#.......#...#.....#.....#...#.#.#
#.#.#####.#.#.#.#.#.#.#.###.#.#.#.#.#.#.#.#.#####.#.#.#.#####.###.#.###.###.###.###.#####.#####.#.#.#.#.#.#.###########.#.###.#.#####.###.#.#
#...#...#.#.#.#.#.#.#.#.#.......#...#.#.#.#.#.....#.#.#.......#...#.#.....#.#.......#.....#.....#...#...#.#...........#...#...#.#.....#.#.#.#
#.###.#.#.###.#.#.###.#.#.###########.#.#.###.#####.#.#######.#.###.#####.#.#########.###.#.#########.###.###########.###.#.###.#.#####.#.###
#.....#.#...#...#.....#.#.#.........#.#.#.#...#.....#.....#...#.........#.#.........#...#...........#...#.#.........#...#.#.#.#.#.#.........#
#######.###.#.#####.###.###.#######.#.###.#.###.#######.#.#.#####.#####.#.#.#######.#.#.###########.#####.#.###.#######.#.#.#.#.#.#.###.###.#
#.....#.#...#...#...#.#.............#.....#.#.....#...#.#.#.....#.#...#.#.#.#.#...#.#.....................#...#...#.....#.#.#...#.#.#...#.#.#
#.###.###.#.###.#.#.#.#.###########.#####.#.#####.#.###.#.#####.#.###.###.#.#.#.#.#.#########.###########.#######.#.#####.#.#.###.###.#.#.#.#
#.#.#...#.....#...#.#...#...........#.....#...#...#...#.#.....#.#.....#...#...#.#.#.....#...#...#...#.....#.....#.#.....#.#.#.#...#...#.#.#.#
#.#.###.###.#.#####.#####.#######.###.#.#.###.#.#####.#.#######.###.#.#.#######.#.###.#.#.#.###.#.#.#######.###.#.#####.###.#.#.###.###.#.#.#
#.#.........#...#.#...#...#.....#.#...#.....#.#.......#...#...#.#.#.#.#.........#...#.#.#.#.#...#.#...#.....#...#...#...#...#.#...#.#...#.#.#
#.#########.###.#.###.#.#.#.###.###.#########.###########.#.#.#.#.#.#.###########.#.#.#.#.#.###.#.###.#.#####.#####.#.###.###.###.#.#.###.#.#
#.#.....#.#.#...#.....#.#.#...#...#.....#...#.#.........#.....#...#...#.......#...#.#.#.......#.#.#.#...#.....#...#...#...#.....#...#.#...#.#
#.#.###.#.#.#.###.#.###.#.###.###.###.#.#.#.#.#.#######.#####.#.#.###.#.#####.#.#.#.###.#####.###.#.#####.#####.#.#.###.#####.#######.#.#.#.#
#...#...#...#...#...#...#...#.#.#.......#.#.#.#.#.....#.#.....#.#.#.#.#.....#...#.#...#.#...............#.....#.#.#.....#...................#
#####.###.#.#.#.#.#####.#.###.#.#####.#.#.#.#.#.#.###.#.#.###.#.#.#.#.#.###.###.#####.###.#.###########.#####.#.#.#######.###############.#.#
#.....#.#...#.#...#.....#.#...#.........#.#...#.......#...#.#...#...#.#...#...#.#...#.....#.....#...#...#.#...#.#...#.....#.......#...#...#.#
#.#####.###.#.#.###.#.#####.###.#####.###.#####.#.#.###.###.###.#.###.###.###.###.#.###########.#.#.#.###.#.###.#.#.#.###########.#.#.###.#.#
#.#...#...#...#.#.#.#.....#.#...#.......#.#.....#.#.......#.....#.....#.#...#.....#.......#.....#.#.........#.....#...............#.#...#.#.#
#.#.#.#.#.#.###.#.#.#####.#.###.#.#####.#.#.#####.#.###.###.#####.#.###.###.#############.#.#############.#.#.#####.#########.#.###.###.###.#
#...#.#.#.....#.#...#.....#...#.....#...#.#.#.#...#.#.#.....#.....#.#.........#.......#.............#...#.#...#.........#...#.#.#...#.#.....#
#.###.#####.###.#.###.#######.#######.#.#.#.#.#.###.#.#######.#####.#.#######.#.#####.#.#.#########.#.#.#.###.#.###.#####.#.#.#.#.###.#######
#.#.#.....#.....#...#.......#.#.....#...#.#...#...#...#.......#.#...#...#...#.#...#.....#.......#...#.#.#.#...#.....#.....#.#.#.#...#.......#
#.#.#####.#.#.###.#########.#.#.###.###.#.###.###.###.#.#######.#.#######.#.#####.###############.###.#.#.#.#####.#.#.#####.#.#.###.#.###.#.#
#.#.....#...#.#...#.......#.#.#.#.#...#.#.#.....#...............#.#.....#.#.......#.....#.......#.#...#.....#...#.#.#.#.#...#.#.#...#...#.#.#
#.#.#.#.###.#.###.#.#####.#.#.#.#.###.#.#.###.#####.#####.#####.#.###.#.#.#.#####.#.###.#.#####.#.#.#########.#.#.#.#.#.#.#.#.#.#.###.#.#.###
#.#.#.#.........#.#...#.....#.#.#...#.#.#...#.#...#.#...#.#...#.#.#...#...#.....#.#...#...#.#...#.#.#.....#...#.#.#.#.#.#.......#...#...#...#
#.#.###.#######.#####.#######.#.#.#.#.#.###.###.#.###.#.###.#.#.#.#.#######.###.#####.#####.#.###.#.#.###.#.###.#.#.#.#.###########.#.#####.#
#...........#.#.......#.....#.#.#.#.#.#...#.....#...#...#...#.#.#.#.#...#...#.#.....#.....#.#...#.....#.#.#.#.......#.#.#...........#...#...#
#.###.#.###.#.#.#.###.#.###.#.#.#.#.#.#.###########.#.#.#.#.#.###.#.#.#.#.###.#####.#####.#.###.#######.#.#.#######.#.#.#.###########.#.#.#.#
#...............#.#...#.#.#...#.#.#...#.........#.#...#...#.#.....#.#.#...#.......#.......#...#.......#...#.......#.#...#.......#.....#...#.#
#####.#.#####.###.#.###.#.#####.###.#####.#####.#.#########.#######.#.#######.#.#.###########.#.#######.#########.###.###.#.###.#.###.#####.#
#...#.#...#.......#.#...#.........#.....#...#.#...#...........#.....#.....#...#.#.#...........#...#...#.#.......#.....#...#.#.....#.......#.#
#.###.#.#.#######.###.###.#######.#.###.###.#.###.#.#####.#.#.###.#.#####.#.###.#.#.###.#.#######.#.#.#.#.#####.#####.#.###.#######.#.###.#.#
#...#...#.......#.#...#.......#...#...#.....#.#...#...#.#...#...#.#.....#.#...#.#.#.#.#.#.......#...#.#...#...#.......#.......#.......#.#.#.#
#.#.###.#######.#.#.#####.#####.###.#########.#.#####.#.###.###.#.###.###.#.#.#.#.#.#.#.#.#####.#####.#####.#.#####.#.#.#####.#.#####.#.#.###
#.#...#.....#...#.#.....#.......#.....#.......#.#...#.....#.#...#...#.....#.#...#.....#.......#.#.........#.#.......#.#.....#...........#...#
#.#.#.#.###.#.###.#####.###.#####.###.#.#####.#.#.#####.###.#.###.#####.#.#.#.#.#.###########.#.#.#######.#.###.#.###.#####.###.#.#.#.#####.#
#.#.#.#.....#...#.....#.#...#.....#...#.#...#...#.....#.#...#...#.#.....#.#.#.#.#...#.....#.#.#.#.......#.#...#.#.#.......#.................#
#.#.###.#######.#.#####.#.###.#####.#.#.#.###########.#.#.#####.###.#####.###.#.#####.###.#.#.#.#######.#.#.#.#.#.###########.#.#.#####.#.#.#
#.#...#.......#.#.#.........#.#...#.#.#.#...........#.#.#.#...#...#.....#.....#.......#.......#...#.....#.#.#.#.#.............#.#.#...#...#.#
#.###.#.###.#.#.###.#######.#.#.###.#.#.#.#####.###.#.#.#.###.###.#.###.#####.#########.#########.#.#####.###.#.###############.#.#.#.#####.#
#...#...#.....#...#...#.....#...#...#.#.#.#.#...#.......#...#.....#.#.#.......#...#...#.#.....#...#.#...#.....#.....#.......#...#...#.#.#...#
###.#.###.#.#####.###.#.#######.#.#####.#.#.#.#########.###.#.#####.#.#########.#.#.#.#.#.###.#.###.#.#.#######.#.#.#.#####.#.#####.#.#.#.###
#...#.#...#.........#...#.....#.#...#...#.#.#.............#.#.....#.....#.......#...#.#...#.#.#.#...#.#.......#.#.#.#.....#.......#.#.......#
#.###.#.###.#######.#######.#.#####.#.###.#.#############.#.#####.#######.###########.#####.#.#.#.###.#####.###.#.#.###.#########.#.#.#.#.#.#
#.................#...#.....#.....#.#.#.#...#.......#...#.#.....#.....#...#.........#...#...#...#...#...#...#...#.#.....#.....#.#...#.#.#.#.#
###.#####.#.#.###.###.###.#######.#.#.#.#.###.#####.#.#.#.#####.#####.#.###.###.#######.#.#.#.#.###.###.#.###.###.#######.###.#.###.#.#.#.#.#
#.#.......#.....#...#...#.#.....#...#.....#...#...#.#...#.....#...#.....#.#.#.#.........#.#...#...#.#...#.#...#...#...#...#...#.....#.#.....#
#.###.#####.###.###.###.#.#.###.###.#.#####.###.#.#.#.#.#####.###.#######.#.#.###########.#.#####.#.#.###.#.###.###.#.#.###.###.###.#.#.#####
#...#.#...........#.#.....#...#.#...#.......#.....#...#.#.....#...#...#...............#...#.......#.#.#.#.#.#.#...#.#...#.#...#.#.....#.#...#
#.###.#.###.#######.#######.###.#.#############.#.#####.#######.#.#.#.#######.#######.#.###########.#.#.#.#.#.#.###.#####.###.###.#.#####.#.#
#.....#...#.....#...#.......#...#.....#.........#.....#.#.......#.#.#.....#.....#.....#.....#.......#.#.#...#...#.....#.....#...#...#.....#.#
#########.#.#.#.#.###.#.#.###.###.#####.#.#####.#######.#.#########.#####.#.#.###.#######.###.#####.#.#.#########.#.#.#.###.###.###.#.#####.#
#.........#...#.#.....#.#...#...#.#.....#...........#...#.#...#...#.#...#.#.#.......#.....#...#...#...#.........#...#.....#...#...#.....#...#
#.#########.#.#.#.#####.###.###.#.#.#.#############.#.###.#.#.#.#.#.###.#.#########.#.#.###.#.#.#.###.#####.###.#.#.#.###.###.###.#.#.###.#.#
#.#.........#...#.....#.#...#.#...#...#.........#.....#.#...#.#.#...#...#.........#...#...#.#.#.#...#.#.....#...#.#.#.......#...#.........#.#
#.###.#####.#.#########.###.#.#######.#.#######.#.###.#.#.###.#.#####.#######.###.#######.#.###.###.#.#.#####.#####.#######.#.#.###.#######.#
#...#.#.....#...#.....#...#...#.....#.#.......#.#.....#...#...#...#...#.......#.#...#.#.....#...#...#.#...#.#.....#.......#.#.#.........#.#.#
###.###.###.###.#.###.###.###.#####.#.#########.#######.###.#####.###.#.#.###.#.###.#.#.#####.###.###.###.#.#####.#.#####.###.#.###.###.#.#.#
#...#...#.#...#...#.#.....#...#.....#.........#.......#.#.#.....#...#...#...#...#...#.....#...#...#.#.....#...#...#.#.....#...#.#.....#...#.#
#.###.###.###.#####.#######.###.###.#######.#.#.###.###.#.#####.###.###.###.#####.#.#####.#.###.###.#######.###.###.#.#####.###.#.#.#.#####.#
#...........#.#.....#.#.....#...#.#.#.#.......#.......#.#.....#...........#.....#.#.#.........#...#...#.....#...#...#.......................#
#.#####.###.#.#.###.#.#.#######.#.#.#.#.#######.#####.#.#####.#########.#.#####.#.###.###.#######.#.#.#.###.#.#.#####.#.#.#.#####.#.###.#.###
#.......#...#.#.#.....#...#.....#.#...#.#.....#...#.#.......#...#...#...#.#.....#...........#...#.#.#.#.#.#...#.......#.#.#.......#...#.#.#.#
#########.###.#.#####.###.#.#####.###.#.###.#.###.#.#######.###.#.#.#.#.#.#.###.###########.#.#.#.#.#.#.#.#####.#######.#.###########.#.#.#.#
#.....#...#...#.....#...#.#.#.....#...#...#.#.......#.....#.....#.#.#.......#.....#.....#...#.#...#.#.#.#...#.....#.....#.#...........#...#.#
#.#####.###.#####.#.###.#.#.#####.#.#####.#.#######.#.###.#######.#.###.#########.#.###.###.#.#######.#.#.#.###.#.#.###.#.#.###.#####.#####.#
#.#.......#.#...#.#.#...#...#...#.......#.#.#...#.#.#.#...#.......#...#...#.....#.#.#.#.......#.......#...#...#...#.#.#.#.#.................#
#.#.#######.#.#.###.#####.###.#.#####.###.###.#.#.#.#.###.#.#########.#.#.#.###.###.#.#####.###.#####.#######.#.###.#.#.#.#.#.###.#.#####.#.#
#...#.....#.#.#...#.......#...#.....#.#...#...#.#...#...#...#.......#...#.#...#.....#.....#.....#.....#.......#.#.....#.#.#.#...#.#.....#.#.#
#.###.#.#.#.#.###.###.#####.#######.###.###.###.#.#####.#.#####.#######.#.###.#######.###.#.###.#######.#######.#.#####.#.#####.#.###.#.#.#.#
#.#...#.#.................#.......#.....#...#...#.#...#.......#.#...#...#.#...#.....#.#.#.#.#.#.....................#...#.....#.#...#.#.#.#.#
#.###.#.#####.#.###.###.#.#######.#.#######.#.#####.#.###.###.#.#.#.#.#.###.###.###.#.#.#.#.#.###.#.#.#.#.###.#.#.#.#.#######.#.###.#.###.#.#
#S....#...........#.....#...................#.......#.........#...#.........#.....#.....#.......#...#.....#.....#...#...........#...#.......#
#############################################################################################################################################