Add solution day 16
This commit is contained in:
parent
65b0a425d2
commit
e6488986e5
15
day_16/example_1.txt
Normal file
15
day_16/example_1.txt
Normal file
@ -0,0 +1,15 @@
|
||||
###############
|
||||
#.......#....E#
|
||||
#.#.###.#.###.#
|
||||
#.....#.#...#.#
|
||||
#.###.#####.#.#
|
||||
#.#.#.......#.#
|
||||
#.#.#####.###.#
|
||||
#...........#.#
|
||||
###.#.#####.#.#
|
||||
#...#.....#.#.#
|
||||
#.#.#.###.#.#.#
|
||||
#.....#...#.#.#
|
||||
#.###.#.#.#.#.#
|
||||
#S..#.....#...#
|
||||
###############
|
17
day_16/example_2.txt
Normal file
17
day_16/example_2.txt
Normal file
@ -0,0 +1,17 @@
|
||||
#################
|
||||
#...#...#...#..E#
|
||||
#.#.#.#.#.#.#.#.#
|
||||
#.#.#.#...#...#.#
|
||||
#.#.#.#.###.#.#.#
|
||||
#...#.#.#.....#.#
|
||||
#.#.#.#.#.#####.#
|
||||
#.#...#.#.#.....#
|
||||
#.#.#####.#.###.#
|
||||
#.#.#.......#...#
|
||||
#.#.###.#####.###
|
||||
#.#.#...#.....#.#
|
||||
#.#.#.#####.###.#
|
||||
#.#.#.........#.#
|
||||
#.#.#.#########.#
|
||||
#S#.............#
|
||||
#################
|
141
day_16/input.txt
Normal file
141
day_16/input.txt
Normal file
@ -0,0 +1,141 @@
|
||||
#############################################################################################################################################
|
||||
#.....#.........#.......#.....................#.....#...#.........#.#.....#.......#.........#.........#.......#...#.........#...#.....#...#E#
|
||||
#.#.#.#.#####.###.#.#####.###.#.#.#.#.#######.#.###.#.#.###.#.###.#.#.#.###.###.#.###.#.###.#.#######.###.###.#.#.#.#.#####.#.#.#.#.#.#.#.#.#
|
||||
#.#.#.#.....#...#.#.#.......#.#.#.#.#.#.....#...#.#...#...#.................#...#.....#.#...#.#.....#...#...#.#.#...#.#.....#.#...#.#...#...#
|
||||
#.#.#######.###.#.#.#.#######.#.#.#.#.#.###.#.###.#######.###.#.#.###########.#######.#.#.###.#.#######.###.#.#######.#.#####.#####.#######.#
|
||||
#.#.#.....#...#...#.......#...#...#...#...#.......#.....#.....#.#.....#.......#.......#.#.#...#.......#.....#.#.......#...#.#.#...#.....#...#
|
||||
###.#.#.#####.#############.###############.#.###.#.###.#######.###.#.#.###########.###.#.###.#####.#########.#.#########.#.#.#.#.#.###.#.#.#
|
||||
#...#.#...........................#...#...#...................#.....#.#...........#.....#.#...#.....#.......#...#.....#...#...#.#.#...#...#.#
|
||||
#.#.#.###.#.#.#.#####.#.#####.###.#.#.#.#.#.#.#####.#####.#.#.#.###.#.#########.#.#.#####.#.###.#####.#.#########.#####.#######.#.#########.#
|
||||
#...................#.#.#...#.#...#.#...#...#.....#.....#.#.#...#.#...#.......#.#.#.....#...#...#...#.#.....................................#
|
||||
#.###.#.#.###.###.#.#.###.#.#.#.###.###.#####.###.#.###.###.###.#.#####.#####.###.#.###.#####.###.#.#.###############.#######.#.###########.#
|
||||
#.#...#.#.....#...#...#...#...#...#.......................#.......#.....#...#...............#.....#...#.....#.....#.#.................#.....#
|
||||
#.#.#.#.###.###.#####.#.#########.#.#.###.###.#.#.#######.#####.#.#####.###.#.#.#.###.#####.#.###########.#.###.#.#.#######.#.#.#.#####.###.#
|
||||
#...#.#.......#.....#.#.#.....#...#.#.....#.....#...........#...#.......#...#.#.#.#...#.......#.....#...#.#.....#.......#...#...#.....#.....#
|
||||
#.###.#.#.#.#.#####.###.###.###.#####.#####.#.#############.#.#.#########.###.#.###.###.#####.#.###.#.#.#.#####.#########.#######.###.#####.#
|
||||
#.#.....#.#...#...#...#...#.#...#...#.....#.........#.......#.....#...#.....#.#.....#...#.....#...#...#...#.#...#.........#.........#.#.....#
|
||||
#.#.#.###.#.###.#.###.###.#.#.#.#.#.#####.#########.#.#######.###.#.#.###.#.#.#.#####.###.#######.#########.#.###.#########.#########.#.###.#
|
||||
#.#.......#.....#.#.....#.....#.#.#.#.........#.....#.........#.#...#...#.#.#.#...#...#...#.......#.......#.....#.........#.#...#.....#.....#
|
||||
#.#.#.#####.#######.###.###.#.#.#.#.###.#######.###############.#######.###.#.#####.###.###.###.###.###.#.#.#############.#.###.#.###.#.###.#
|
||||
#.#.#.......#.......#.#.#.#.#.#.#.#...#.#.......#...............#.....#.....#.#.....#...#...#...#.....#.#.#.#...........#.#...........#...#.#
|
||||
#.#.#.#####.#.#######.#.#.#.#.###.###.###.#######.#######.#.#####.###.#.#####.#.#####.###.###.###.###.#.###.#.#########.#.###.#.#.#.###.#.#.#
|
||||
#...#.#.....#.....#.......#.#.......#.#...#.......#.......#.#.......#...#.....#...#...#...#...#.#...#.#...#.#.....#.#...#.#...#.............#
|
||||
###.#.#.###.#####.#.#######.#########.#.#.#.#######.###.#.###.###########.#######.#.#######.###.###.#.###.#.#####.#.#.###.#.###.#.#.#.#.#####
|
||||
#.............#...#.#.......#...#.#...#...#...#...#.#.#.#.....#.#.........#...#...#.#.....#.#.......#...#...#.....#.#.....#.#...#.#...#.#...#
|
||||
###.#.#.###.#.#.#.#.#.#######.#.#.#.#####.#####.#.#.#.#.###.###.#.#########.#.#.#.#.#.###.#.#.#########.#####.#####.#.###.#.#.#.#.#####.#.#.#
|
||||
#...#.....#.#.#.#...#.......#.....#.....#.......#.....#...#.....#.#.........#...#.#...#.#...#...#.............#.....#.#...#.#.#.#.......#.#.#
|
||||
#.#.#.###.#.#.#.###########.#.#.#.#####.#.###########.###.#####.#.###.#.#########.#####.#######.#.#######.#.#######.#.#.#.#.#.###.#####.#.#.#
|
||||
#.#.#...#.#...#.#...#...#...#.#...#.....#.#.....#...#...#...#...#.#...#.#...........#.......#.....#.....#.#...#...#.#.#.#...#.............#.#
|
||||
#.#.#.#.#.#####.#.#.#.#.#.###.#####.#####.#.###.#.#.#######.#####.#.###.#.#######.#.#.###.###.#####.###.#####.#.#.#.#.#.#.#####.###########.#
|
||||
#.#.#.#.#.......#.#...#...#.....#...#.#...#.#.#...#.......#.#.....#...#.#.#.#.....#...#.#.#.....#...#.#...#...#.#...#...#.......#.........#.#
|
||||
#.#.###.#######.#.###.#########.#.###.#.###.#.###########.#.#.#######.#.#.#.#.#####.###.#.#.#####.###.###.#.###.#######.#.#######.#########.#
|
||||
#.#.....#.......#...#...........#.#...#...#.#...#.......#.#.#...#...........#.#.......#...#.#.#...#.#...#...#.#...........#.........#.......#
|
||||
#.#.###############.#.#########.#.###.###.#.#.###.#.#####.#.###.#.#.#######.#.###.#.###.###.#.#.###.#.#.#####.#.###########.#######.#.#######
|
||||
#...#.............#...#.....#...#...#.#...#.#.....#.....#.#.#...#.#.......#.#...#.#...#.#.#.....#.....#.........#.....#...#.#.....#.#...#...#
|
||||
###.#.#########.#.#####.#.###.#####.#.#.###.###.#######.#.#.#.###.###.###.###.#.#####.#.#.###.#.#.#######.#######.###.#.#.#.#####.#.###.#.#.#
|
||||
#...#.#.....#...#...#...#.#...#.#...#...#.#...#.#.....#.....#.....#...#.#...#.#.#.....#...#.#.#.#.#.....#.#.....#...#...#...#...#.#...#...#.#
|
||||
#.#.#.#.#####.#####.#.#####.###.#.###.###.###.###.###.#############.###.###.###.#.#######.#.#.#.###.###.###.###.###.#########.#.#.###.#####.#
|
||||
#.#...#.....#...#.....#.....#...#.#.#.#.....#...#.#.#.......#.......#.......#...#.......#...#.#.......#.#...#.#.....#.........#.#...#.....#.#
|
||||
#.#.###.###.###.#####.#.#.#####.#.#.#.#.#######.#.#.#######.#.#.#####.#######.###.###.#####.#.#########.#.###.#######.###.#####.#.#.###.#.#.#
|
||||
#.#...#...#...#.....#.#.#...#.......#.#.......#.#.#.......#...#.#...#...#.....#.....#.#.....#.....#.....#.#.....#.......#...#...#.#...#.#.#.#
|
||||
#.###.###.#.#.#####.#.#.#.#.#.#.#.#.#.###.#.#.#.#.#.#.###.#####.###.###.#.###.#####.#.#.#########.#.#.###.#.#.#.#.#####.###.#.###.###.#.#.#.#
|
||||
#...#...#.#.....#.#.#.#...#...#...#.#...#.#.#.#.#.#.#.#...#...#...#...#...#...#...#.#.#.....#.#...#.#.#...#...#...#.....#...#.#...#.#.#.#...#
|
||||
###.###.#.###.#.#.#.#.#####.###.###.###.#.#.#.#.#.###.#.#####.###.#.#.#####.#.#.#.###.#####.#.#.###.###.###.#.#####.#.###.###.###.#.#.#.###.#
|
||||
#...#.....#.#.#...#.#.#.....#...#...#...#.#.#.#...#...#.#.......#.#.#.........#.#...#.........#...#...#...#.#...#...#.....#.#...#.#.#.#.#...#
|
||||
#.#.#.###.#.#.###.#.###.#####.###.#.#.#####.#.#####.###.#.###.###.#############.###.#.###.###.###.###.###.#####.###.#######.#.#.#.#.#.#.#.###
|
||||
#.#.#.#.#...#...#.#.........#.#...#.#.#.............#.....#.#.#.............#...#.#.#...#...#...#...#...#...#...#.....#.....#.#.#.#.#.#...#.#
|
||||
#.#.#.#.###.###.#.#########.#.#.###.#.#.###.#######.#######.#.#.###.#######.#.###.#.#####.#.#######.#.#####.#.###.#.###.#.#.#.#.#.#.#.#####.#
|
||||
#.#.#.#.......#.#.....#...#.#.#.#...#...#...#...#...#.....#...#.#...#.....#...#...#.....#.#...#.....#.......#...#.#.#...#.#...#.#.#.#.......#
|
||||
#.###.#.#######.#######.#.#.#.#.###.#####.###.#.#.###.#.#.#####.#.#####.#########.#####.#.###.#.###############.#.#.#.###.###.#.#.#.###.#####
|
||||
#.....#...#.....#.......#.#.#.#...#.#.....#...#...#...#.#.#.....#.....#...........#...#...#.#...#.#.....#.......#.....#.#.#...#.#.....#.....#
|
||||
###########.#####.###.#.#.###.###.#.###.#.#.#######.###.#.#.###.#####.#######.###.###.#####.#####.#.#.###.#.#####.#####.#.#.###.###########.#
|
||||
#.#.........#...#.#...#.#.....#...#.#...#.#.#...#...#...#...#.#.....#.......#...#.............#.....#.....#.#...#.......#.#...#.....#...#...#
|
||||
#.#.###.#####.#.#.#.###.###.###.###.#.###.#.#.###.###.#######.#.#.#########.#.#.#####.#######.###.#########.#.###.#####.#.###.#####.#.#.#.#.#
|
||||
#.............#...#.....#...#...#.....#...#...#...#.............#.....#.....#.#.#.....#.....#...#.#.....#...#...#.......#.#.......#.#.#...#.#
|
||||
#.###.#.#.#.#.###########.#.#.#.#############.#.###.#########.###.#.###.#######.#.#####.###.###.#.###.#.#.#####.#######.#.#.###.###.#.#####.#
|
||||
#...#.#...#.#.......#.....#.#.#...........#...#.#...#.#.....#.....#...#.........#...#...#.#.....#...#.#.#.#...#.........#.#.#.........#...#.#
|
||||
#.#.#.#####.#######.#.#####.#.###########.#.###.#.###.#.###.#.#######.#######.#.#.#.#.###.#########.#.#.#.#.#.#.#########.#.#.#.#.#####.#.#.#
|
||||
#.#.#.#...#.............#...#.........#...#...#.#.....#.#.#...#.....#.......#...#.#.#.....#...#...#.#.#.#...#.#.#.....#...#.#...#.....#.#...#
|
||||
#.#.#.#.#####.#.#.#.###.#.###########.#.#.#.#.#.#####.#.#.#########.#####.#.#####.#.#####.#.#.#.###.#.#.#####.#.#.###.#.#.#.###.#####.#.#####
|
||||
#.#.#.#.....#...#.#.#...#.#...........#.#.#...#...#...#.........#.....#...#.#.....#.....#.#.#...#...#.#.#...#.#...#...........#.............#
|
||||
#.###.#####.###.#.#.#.###.#.#.#########.###.#####.#############.#.###.#.#####.#####.#####.#.###.#.###.#.#.#.#.#####.#########.#.#.#######.#.#
|
||||
#.....#...#...#.#.#...#.#.#.#.........#.#...#.....#.....#.....#...#...#.........#.#.#.....#...#.....#.#.#.#...#.#...#.#.....#.#.#...#...#...#
|
||||
#.#.###.#.###.#.###.#.#.#.#.#####.#####.#.###.#####.#.#.#####.#####.#######.###.#.#.#.#####.#.#####.#.#.#.#####.#.###.#.#.#.#.#.###.#.#.###.#
|
||||
#.#...............#...#.#.#.......#...#.....#...#...#.#.....#...#.......#...#.#...#...#...#.#.....#.#.#.#.#.....#...#...#.#.#...#.#.#.#.....#
|
||||
#.#.#.#####.#.###.#####.#.#.#######.#.#########.#.###.#####.#.###.#######.#.#.###.#######.#.###.#.#.###.#.#.###.###.#####.#.###.#.#.#.#######
|
||||
#...#...#.#.....#.......#.#.#.......#.........#...#...#...#...#.....#.......#.....#.....#.......#.#.#...#.#.#.....#...#...#.....#.#.#.......#
|
||||
#.#####.#.#.###########.#.#.#.#########.#####.#####.###.#.#####.#####.#####.#.#######.#.#.###.#####.#.#.#.###.#######.#.#######.#.#.###.#.#.#
|
||||
#.......#...#.......#...#.#.#.#.......#...#...#...#...#.#.......#...#.#.....#.#.......#.#...#.......#...#...#.#.....#.#.#.........#.........#
|
||||
#########.#.#.#####.#.#.#.#.#.#.#.###.#.#.#.#.#.#.#.#.#.#########.#.#.#.#.###.#.#.#.###.#########.###.#####.#.#.#.###.#.#####.#.#####.#.###.#
|
||||
#.....#.#.#...#...#...#...#.#.#.#...#...#...#.#.#.#.#.#.........#.#...#.....#...#...#.#.........#.#.......#.#...#.....#.#...#...............#
|
||||
#.#.#.#.#.#.###.#.###.#.###.#.#.###.#.#####.###.#.###.#.#.#######.#########.#########.#########.#.###.###.#.#######.###.#.#.###.###.#.#####.#
|
||||
#...#...#.#...#.#...#.#...#.#.....#.#.......#...#...#.#.#.#.....#.......#...#.......#...#.....#.#.....#...#.#.......#...#.#.....#...#.....#.#
|
||||
###.#.###.#.#.#.#####.###.#####.###.#########.#####.#.#.#.#.###.#########.###.###.#.#.#.#.#.###.#####.#.###.#.###.#.###.#.#######.#.#.#####.#
|
||||
#...#.#.....#.#.......#.#.......#...#...#.....#...#.#.....#...#...........#...#...#...#.#.#.#.........#...#.#.#.#.#...#.........#.#.#.#.....#
|
||||
#.#.#.#.###.#.#.#######.#########.#.#.#.#.#####.#.#.#########.###############.#.#.#####.#.#.#.###.###.###.#.#.#.#.###.#######.###.#.#.#.#####
|
||||
#.............#.............#.....#.#.#...#...#.#...........#.#.......#.......#.#.#...#...#.#.......#.....#.....#...#.#...#...#...#.#.#...#.#
|
||||
###.#.###.#.#.#############.#.#####.#.#####.#.#.#.#.###.#.#.#.#.#####.#.#.#.#.#.#.#.#.#####.#######.#########.#####.#.#.#.#.###.#.###.###.#.#
|
||||
#.........#...#.......#.....#.#.....#.......#...#.#.....#...#.#.#...#...#.#.#.#.#.#.#.#...#.#.....#.#.......#.#.....#.#.#.#.#...#.#.....#.#.#
|
||||
#.#.#.#####.###.#.#####.#####.###.###############.#.#.#.#.###.#.#.#.#####.#.#.#.###.#.#.#.#.#.#.#.#.#.#####.#.#.#.#.#.#.#.###.###.#.###.#.#.#
|
||||
#.#.....#.......#.#.....#...#...#.#.............#...#...#.....#...#...#...#.#.#.....#.#.#.#.....#.#.#.#.....#.#.#...#...#.#...#.#.#.#...#...#
|
||||
#.#.#.#.#######.###.#####.#.###.#.#.#####.###########.#################.###.#.#######.#.#.#.#######.#.#.#####.#.#########.#.###.#.#.#######.#
|
||||
#...#...#...#...#...#.#...#.#...#.#...#.#...........#.#.....#...........#.#.#.#.......#.#.#.#.......#.#...#...#.#...#...#.#...#.#.#.........#
|
||||
#.#.#.###.#.#.###.###.#.#.###.###.###.#.#######.#####.#.#.#.#.###########.#.#.#.#######.#.#.#.#######.###.#####.#.#.#.#.#.###.#.#.#.#.#######
|
||||
#...#.#...#.......#.....#...#.#...#...#.......#.......#.#.#...#.....#.......#.#.#.....#.#...#...#.......#.......#.#.#.#.#...................#
|
||||
###.#.#.###.#.#.###.#######.#.#.###.#########.#.#########.#####.###.#.#########.#.#.###.#######.#######.###########.#.#.#######.#.#.###.#.#.#
|
||||
#.#.#...#...#.#.#...#.....#.#.#.#...#.......#.............#...#...#.............#.#.#...#...#...#.......#...#.......#.#.........#.#.....#.#.#
|
||||
#.#.#.###.###.#.#####.###.#.#.###.###.#####.#####.###.###.#.#.###################.###.###.#.#.###.#.#.###.#.#.###.#.#.#.###.#####.###.#.#.#.#
|
||||
#...#.#...#...#.......#.#...#.....#.....#.........#...#.....#...#.....#.........#.....#...#...#.......#...#.#.#...#.#.....#.......#.#.....#.#
|
||||
#.###.#.###.#########.#.#.#############.###########.###.###.#.#.#.###.#####.#####.#####.#######.###.###.###.#.#.###.#####.#########.#.#.#.#.#
|
||||
#.....#...#...............#.............#...#.....#.#...#...#.#.....#...#...#...#.#.....#.....#.#.....#.#...#.#.#...#.#...#.....#.........#.#
|
||||
#####.###.###.#############.#######.#.###.#.###.###.#.###.#.###########.#.###.#.#.#.###.#.#.#.#.#######.#.#####.#.###.#.###.###.#.###.#.#.#.#
|
||||
#...#...#...#.#.......#...#...#...#.#.#...#...#...#.#...#.#...........#.#.#...#...#.#.....#.#...#.....#.#.....#.#...#.#.#.....#.......#.#...#
|
||||
#.#.#.#.#.#.#.#.#####.#.#.###.###.#.###.#####.#.#.#.###.#.###.#######.#.#.#.#######.#.#####.#####.###.#.#####.#.#.#.#.#.#.###.#.#.###.#.#.#.#
|
||||
#.#...#.#.#.#.#.#.#...#.#...#.#...#.....#...#.#.#.#.#...#...#.#.....#...#.....#...#.#.....#.....#...#...#...#.#...#...#.#.....#.#...#.....#.#
|
||||
#.###.#.#.#.#.#.#.#.#####.#.#.#.#.#######.#.#.###.#.#.#####.###.###.#########.#.###.#####.#.#.#.###.#####.#.#.###.###.#.###.#.#.#.#.#.#.#.#.#
|
||||
#.#.............#.......#...#.#.#.........#.#...#.#.#.#...#.....#.#.#.....#.#.#.#...#...#.#...#.#...#.....#.#.#.......#...#.#.#.#.#.....#...#
|
||||
#.###.#####.#####.#####.#.###.#.#####.#####.###.#.#.#.#.#.###.###.#.#.###.#.#.#.#.###.###.#####.#.###.#######.#.#####.###.#.#.###.###.#.#.###
|
||||
#...#.....#.#.#...#.......#...........#.......#.#...#.#...........#...#...#...#.#.#.....#.....#.......#...#...#.....#...#.#.#.#.....#...#...#
|
||||
#.#.#####.#.#.#.#.#.#######.###.#######.#######.#.###.#########.#.#####.#####.#.#.#####.###.#.#########.#.#.#######.#####.#.#.#.#####.#.#.#.#
|
||||
#.#.#.....#.#...#...#.#.....#.........#.#...#...#...#...#.....#.#...#...........#.....#.....#.....#.....#...#.....#.#.....#.#.....#...#...#.#
|
||||
#.#.###.###.#.#######.#.#############.#.#.#.#.#########.#.###.#.#.#.#.#####.#########.###.###.###.#.#########.#.#.#.#.#########.###.#.#.#.#.#
|
||||
#.#...#.#...#...#.....#.....#.......#.#...#.#.........#...#.#.#.#...#.....#.........#...#.#...#...#.#.......#.#.#...#.#.......#.#...#...#...#
|
||||
#.###.#.#.#####.#.###.#####.#.#####.#.#####.#######.#.#####.#.#.###.#####.#####.###.###.#.#.#.#####.#.###.###.#.###.#.#####.#.###.###.#.#.###
|
||||
#.#...#.#.#...#.#...#.#.....#...#...#...#.......#.#.#.....#.......#.#...#.#...#...#...#.#.#.#.#.....#.........#.#...#...#...#...............#
|
||||
#.#.###.#.#.#.#.###.#.#.#######.#.#####.#.#####.#.#.###.###.#####.#.#.#.#.#.#.###.#####.#.#.#.#.#######.#######.###.###.#.#######.#.#.#.#.#.#
|
||||
#.#...#...#.#.#...#.#.#.#.......#.....#.#.....#...#.#...#.........#...#...#.#.....#.....#...#.#.....#...#.....#...#...#...#.........#...#.#.#
|
||||
#####.#######.###.#.###.#.#.#########.#.###.#.#.###.#####.#####.#######.###.#####.#.###############.#####.###.#.#.###.#####.#########.###.#.#
|
||||
#.....#.......#...#...#.#.#.#.....#...#.#...#...#...#.....#...#.#...........#...#.#...#...........#.......#...#.#...#.#...........#...#...#.#
|
||||
#.#######.#.###.#####.#.#.#.#.###.#.###.#.#####.#.###.#####.#.###.###########.###.###.###.#######.###.#####.###.###.###.#########.###.#.###.#
|
||||
#.#.....#.#...#.......#...#.#.#.#.......#.....#.#.#...#...#.#...#.....#.....#.....#...#...#.....#...#.#...#.#...#.#...#.....#...#.......#...#
|
||||
#.#.###.#.#.#.#.#####.#####.#.#.#####.#######.#.#.#.###.###.#.#.#####.#.#####.#####.###.###.#######.#.#.#.#.#.###.###.#####.#.###########.#.#
|
||||
#.#...#.#...#...#...#.#.....#.#.......#.....#.#.#.#...#...#...#.......#...#.....#...#.....#.........#.#.#.#.#...#...#.....#.#.............#.#
|
||||
#.###.#.###.#####.#.#.#.#.###.#.#####.###.#.#.#.#.###.#.#.###.###########.#.#####.###.###.#.#########.###.#.###.#.#.#####.#.###.#.#########.#
|
||||
#.....#.....#...#.#.#...#.....#.#...#.....#.#.#.#...#.#.#...#...#.......#.#...#...#...#.#.#...#.#...#.....#...#...#.#...#.#...#.#.#.#.......#
|
||||
#.#########.#.#.#.#.#.###.#####.#.#.#########.#.###.#.#####.###.#.#####.#.###.#.###.###.#.###.#.#.#.#####.###.#####.#.#.#.###.#.#.#.#.#####.#
|
||||
#...#.....#.#.#...#.#.#...#.......#.........#...#...#.......#.#...#.....#.....#.#.......#.#...#...#...#.....#.#...#.#.#.#.#...#.#.#...#...#.#
|
||||
###.#.#####.#.#####.###.###.###############.#.###.#.#######.#.#####.#########.#.#########.#.#######.#.#.#####.###.#.#.#.#.#.###.#.#####.#.###
|
||||
#.#.#...#...#...#...#...#...#...#...#...#...#.#.....#.....#.#...#.#.........#.#.....#...#.#.......#.#.....#...#...#...#.#...#...#...#...#...#
|
||||
#.#.###.#.#.###.#.###.###.#.#.#.#.#.#.#.#.###.#.#.###.###.#.#.#.#.###.#####.#.#####.#.#.#.#####.#.###.#.###.###.#######.#######.###.#.#####.#
|
||||
#.#...#.#.....#.#...#.#...#.#.#...#...#.#.#.....#.#...#.#.#...#...#.........#.....#...#...#.....#...#.#.#...#.......#...#.....#...#...#...#.#
|
||||
#.###.#.###.###.###.#.#.#.#.#.###.#######.#.###.###.###.#.#######.###.#.###.#####.#########.###.###.#.#.#.#######.###.###.#.#.#.#####.#.###.#
|
||||
#...#...#...#...#.#.#.#...#.#...#.#...#.......#...#.....#.........#...#.#.....#.....#.......#.#.#.#.#...#.......#.....#...#.#.#.#...#...#...#
|
||||
#.#####.#.#.#.###.#.#.###.#.###.###.#.#.###.#.###.#####.###########.#.#.#.###.#.###.#######.#.#.#.#.###.#######.#.#######.#.#.###.#.###.#.###
|
||||
#.......#...#...#.#.#.#...#...#.....#.....#.#...#...#...#.....#.....#.#...#.#.#.....#...#...#.....#.#...#.....#.........#.#.#.....#...#.#...#
|
||||
#.#########.###.#.#.#.#.#####.#.###.#.###.#.#.###.###.###.###.#.#.#########.#.#.#####.#.#.###.#####.#.###.###.#.#######.#.#.###.#.###.###.#.#
|
||||
#...#.#...#...#.#.#...#.#...#...#.....#...#.#...#...#...#.#.....#.#.........#.#.....#.#.#...#.#...#.#.#.#...#.#.#.....#.#.#.#.#...#.........#
|
||||
###.#.#.#.#.###.#.#####.###.###.#.###.#.#######.###.###.#.#.###.#.#.#.#######.#####.#.#.###.#.#.#.#.#.#.###.#.#.#.#.###.#.#.#.###.#.###.###.#
|
||||
#...#.#.#...#...#.....#...#...#...#...#.........#...............#...#.......#.....#.#.#.....#.#.#...#...#...#...#.#.....#.#.#.........#...#.#
|
||||
#.###.#.#.###.###.#######.#.#.#####.#.#.#######.#.#####.#.###.###.#########.#.###.#.#.###.###.#.#######.#.#######.#########.#.#.#.#######.#.#
|
||||
#.....#.#.....#.........#.#.#...#...#.........#...............#...#.....#...#...#.#...#...#.....#.....#.#.......#.#.........#.#...#.....#...#
|
||||
#####.#.#.#####.#.###.#.#.#####.#.###.#.###.#########.#.###.#.#.#.#####.#.#.#.#.#.#####.###.#########.#.#######.#.#.###.#####.###.#.###.###.#
|
||||
#.#...#...#.#.........#.#.#.....#.....#.#...#.....#.#...#...#...#.......#.#.#.#...#.#...#...#.......#.......#...#.............#...#...#.....#
|
||||
#.#.#####.#.#.#####.#.###.#.###.#####.#.#.#.#.#.#.#.###.#.#######.#.###.#.#.#.#####.#.###.###.###.#.#####.###.###.#.###.#####.#.#.###.#######
|
||||
#.#.#.......#.......#.......#.......#...........#...#...#...#.....#.#...#.#.#.#...#.....#.#...#...#...#...#...#.#.....#.....#.#.#.#...#.....#
|
||||
#.#.###.#.#.###.#####.###############.#.#.#.#.#.#####.#.###.#######.#.###.#.#.#.#.#.#####.#.###.#####.###.#.###.###.#.#####.###.#.#.###.#.###
|
||||
#.....................#.........#.....#...#.#.#.....#...#...........#...#.#.#.#.#...#...............#...#.#.#.......#.....#.#...#...#...#...#
|
||||
#.###.###.#.###.#.#.###.#######.#.###.#.###.#.#####.###.#################.#.#.#.#####.#####.#.###.#####.###.#.#.###.#####.#.#.###.#######.#.#
|
||||
#...#.....#.....#.#...#...#...#.#.#...#...#...#...#...#...........#.......#.#.#...#...#.......................#.#.......#...#.#...#.........#
|
||||
#.#.#####.#######.###.###.#.###.#.#.#.#.#.#######.#.#############.#.#######.#.#####.###.#######.#.#.#########.#.#.#.###.#####.#.#####.#.###.#
|
||||
#S#...............................................#.................#.......#...........#.........#...........#.......#...............#.....#
|
||||
#############################################################################################################################################
|
100
day_16/solve_1.ts
Normal file
100
day_16/solve_1.ts
Normal file
@ -0,0 +1,100 @@
|
||||
import { BinaryHeap } from "jsr:@std/data-structures/binary-heap";
|
||||
|
||||
export type Map = string[][];
|
||||
|
||||
export async function readMap(path: string): Promise<Map> {
|
||||
const text = await Deno.readTextFile(path);
|
||||
return text.trim().split("\n").map((line) => line.trim().split(""));
|
||||
}
|
||||
|
||||
export function displayMap(map: Map): void {
|
||||
console.log(map.map((line) => line.join("")).join("\n"));
|
||||
}
|
||||
|
||||
export type Position = [number, number];
|
||||
export type Face = 0 | 1 | 2 | 3;
|
||||
export type RotateDir = "clockwise" | "counter-clockwise";
|
||||
export function rotateFace(face: Face, dir: RotateDir): Face {
|
||||
if (dir === "clockwise") {
|
||||
return ((face + 1) % 4) as Face;
|
||||
} else {
|
||||
return ((face + 3) % 4) as Face;
|
||||
}
|
||||
}
|
||||
export function faceToStr(face: Face): string {
|
||||
return ["E", "S", "W", "N"][face];
|
||||
}
|
||||
export function strToFace(str: string): Face {
|
||||
const face = ["E", "S", "W", "N"].indexOf(str);
|
||||
if (face === -1) {
|
||||
throw new Error(`Invalid face: ${str}`);
|
||||
}
|
||||
return face as Face;
|
||||
}
|
||||
export function moveForward([x, y]: Position, face: Face): Position {
|
||||
switch (face) {
|
||||
case 0: return [x + 1, y];
|
||||
case 1: return [x, y + 1];
|
||||
case 2: return [x - 1, y];
|
||||
case 3: return [x, y - 1];
|
||||
}
|
||||
}
|
||||
|
||||
// S is start
|
||||
// E is end
|
||||
// # is wall
|
||||
// first face the east
|
||||
|
||||
export class Solver {
|
||||
readonly map: Map;
|
||||
|
||||
constructor(map: Map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public minCost([x,y]: [number, number], face: Face): number {
|
||||
const heap = new BinaryHeap<[Position, Face, number]>(
|
||||
([, , cost1], [, , cost2]) => cost1 - cost2
|
||||
);
|
||||
const visited = new Set<string>();
|
||||
heap.push([[x, y], face, 0]);
|
||||
while (heap.length > 0) {
|
||||
const [[x, y], face, cost] = heap.pop()!;
|
||||
if (this.map[y][x] === "E") {
|
||||
return cost;
|
||||
}
|
||||
if (this.map[y][x] === "#") {
|
||||
continue;
|
||||
}
|
||||
const key = `${x},${y},${face}`;
|
||||
if (visited.has(key)) {
|
||||
continue;
|
||||
}
|
||||
visited.add(key);
|
||||
for (const dir of ["clockwise", "counter-clockwise"] as RotateDir[]) {
|
||||
heap.push([[x, y], rotateFace(face, dir), cost + 1000]);
|
||||
}
|
||||
heap.push([moveForward([x, y], face), face, cost + 1]);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
findStart(): Position {
|
||||
for (let y = 0; y < this.map.length; y++) {
|
||||
for (let x = 0; x < this.map[y].length; x++) {
|
||||
if (this.map[y][x] === "S") {
|
||||
return [x, y];
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("No start found");
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const map = await readMap("input.txt");
|
||||
displayMap(map);
|
||||
const solver = new Solver(map);
|
||||
const start = solver.findStart();
|
||||
console.log(solver.minCost(start, strToFace("E")));
|
||||
}
|
123
day_16/solve_2.ts
Normal file
123
day_16/solve_2.ts
Normal file
@ -0,0 +1,123 @@
|
||||
import { BinaryHeap } from "jsr:@std/data-structures/binary-heap";
|
||||
import {
|
||||
displayMap,
|
||||
Face,
|
||||
moveForward,
|
||||
Position,
|
||||
readMap,
|
||||
RotateDir,
|
||||
rotateFace,
|
||||
Solver,
|
||||
strToFace,
|
||||
} from "./solve_1.ts";
|
||||
|
||||
function moveBackward([x, y]: Position, face: Face): Position {
|
||||
switch (face) {
|
||||
case 0:
|
||||
return [x - 1, y];
|
||||
case 1:
|
||||
return [x, y - 1];
|
||||
case 2:
|
||||
return [x + 1, y];
|
||||
case 3:
|
||||
return [x, y + 1];
|
||||
}
|
||||
}
|
||||
|
||||
class Solver2 extends Solver {
|
||||
public getPathBlocks(
|
||||
[x, y]: [number, number],
|
||||
face: Face,
|
||||
): Position[][] {
|
||||
const heap = new BinaryHeap<[Position, Face, number]>(
|
||||
([, , cost1], [, , cost2]) => cost1 - cost2,
|
||||
);
|
||||
const costMap = new Map<string, number>();
|
||||
const visited = new Set<string>();
|
||||
heap.push([[x, y], face, 0]);
|
||||
let endY = -1, endX = -1, endCost = -1, endFace = -1 as Face;
|
||||
while (heap.length > 0) {
|
||||
const [[x, y], face, cost] = heap.pop()!;
|
||||
const key = `${x},${y},${face}`;
|
||||
if (this.map[y][x] === "E") {
|
||||
endY = y;
|
||||
endX = x;
|
||||
endCost = cost;
|
||||
endFace = face;
|
||||
costMap.set(key, cost);
|
||||
visited.add(key);
|
||||
break;
|
||||
}
|
||||
if (this.map[y][x] === "#") {
|
||||
continue;
|
||||
}
|
||||
if (visited.has(key)) {
|
||||
continue;
|
||||
}
|
||||
visited.add(key);
|
||||
costMap.set(key, cost);
|
||||
for (
|
||||
const dir of ["clockwise", "counter-clockwise"] as RotateDir[]
|
||||
) {
|
||||
heap.push([[x, y], rotateFace(face, dir), cost + 1000]);
|
||||
}
|
||||
heap.push([moveForward([x, y], face), face, cost + 1]);
|
||||
}
|
||||
if (endY === -1) {
|
||||
return [];
|
||||
}
|
||||
// find the path back to the start
|
||||
let curX = endX;
|
||||
let curY = endY;
|
||||
let curFace = endFace;
|
||||
let curCost = endCost;
|
||||
const getPathes = (pos: Position, face: Face, cost: number) => {
|
||||
const key = `${pos[0]},${pos[1]},${face}`;
|
||||
if (costMap.get(key) !== cost) {
|
||||
return [];
|
||||
}
|
||||
if (cost < 0) {
|
||||
return [];
|
||||
}
|
||||
if (cost === 0) {
|
||||
return [[pos]];
|
||||
}
|
||||
const pathes: Position[][] = [];
|
||||
for (
|
||||
const dir of ["clockwise", "counter-clockwise"] as RotateDir[]
|
||||
) {
|
||||
const r = getPathes(pos, rotateFace(face, dir), cost - 1000);
|
||||
if (r.length > 0) {
|
||||
pathes.push(...r);
|
||||
}
|
||||
}
|
||||
const ba = getPathes(moveBackward(pos, face), face, cost - 1);
|
||||
pathes.push(...ba.map((p) => [pos, ...p]));
|
||||
return pathes;
|
||||
};
|
||||
return getPathes([curX, curY], curFace, curCost);
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const map = await readMap("input.txt");
|
||||
displayMap(map);
|
||||
const solver = new Solver2(map);
|
||||
const start = solver.findStart();
|
||||
const pathes = solver.getPathBlocks(start, strToFace("E"));
|
||||
for (const path of pathes ?? []) {
|
||||
for (const [x, y] of path) {
|
||||
map[y][x] = "O";
|
||||
}
|
||||
}
|
||||
displayMap(map);
|
||||
let count = 0;
|
||||
for (const row of map) {
|
||||
for (const cell of row) {
|
||||
if (cell === "O") {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(count);
|
||||
}
|
Loading…
Reference in New Issue
Block a user