This commit is contained in:
Christian
2024-12-16 12:17:01 +01:00
parent 51b49018e4
commit f703a5f028
5 changed files with 214 additions and 1 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 =

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....#...........#.....#...................#.......#.........#...#.........#.....#.....#.......#...#.....#.....#...#...........#...#.......#
#############################################################################################################################################