From 8dbb6391db593bd2f29d4dd99c8cad8164498ea6 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 20 Dec 2024 20:57:46 +1100 Subject: [PATCH] day 20 --- 20/input_20 | 141 ++++++++++++++++++++++++++++++++++++++++++++++ 20/twenty.go | 89 +++++++++++++++++++++++++++++ util/grid/grid.go | 8 +++ 3 files changed, 238 insertions(+) create mode 100644 20/input_20 create mode 100644 20/twenty.go diff --git a/20/input_20 b/20/input_20 new file mode 100644 index 0000000..00720d6 --- /dev/null +++ b/20/input_20 @@ -0,0 +1,141 @@ +############################################################################################################################################# +#...#...###...#####...#...#.......#####.....#...#.........###...###...#.....#...#.......#.....#...#...###...#.......#...........#.....#.....# +#.#.#.#.###.#.#####.#.#.#.#.#####.#####.###.#.#.#.#######.###.#.###.#.#.###.#.#.#.#####.#.###.#.#.#.#.###.#.#.#####.#.#########.#.###.#.###.# +#.#.#.#.#...#...#...#.#.#.#.....#...#...#...#.#...#.......#...#.#...#.#.#...#.#.#...#...#...#...#...#.#...#.#...#...#.#.........#...#.#...#.# +#.#.#.#.#.#####.#.###.#.#.#####.###.#.###.###.#####.#######.###.#.###.#.#.###.#.###.#.#####.#########.#.###.###.#.###.#.###########.#.###.#.# +#.#.#.#.#.....#...#...#.#.#.....#...#...#.#...#.....#...###.#...#...#.#.#...#.#.###.#.#...#.....#.....#...#.#...#.....#.....#...#...#...#.#.# +#.#.#.#.#####.#####.###.#.#.#####.#####.#.#.###.#####.#.###.#.#####.#.#.###.#.#.###.#.#.#.#####.#.#######.#.#.#############.#.#.#.#####.#.#.# +#.#...#.......#.....#...#.#.....#...#...#.#.#...#.....#...#.#.#...#.#.#.#...#.#.#...#.#.#.#...#.#...#...#.#.#.#.............#.#...#.....#.#.# +#.#############.#####.###.#####.###.#.###.#.#.###.#######.#.#.#.#.#.#.#.#.###.#.#.###.#.#.#.#.#.###.#.#.#.#.#.#.#############.#####.#####.#.# +#.#...#...#...#...###.#...#...#.#...#...#...#...#...#.....#.#.#.#.#.#.#.#...#.#...#...#.#.#.#.#.#...#.#.#.#.#.#.....#...###...#.....#...#.#.# +#.#.#.#.#.#.#.###.###.#.###.#.#.#.#####.#######.###.#.#####.#.#.#.#.#.#.###.#.#####.###.#.#.#.#.#.###.#.#.#.#.#####.#.#.###.###.#####.#.#.#.# +#...#.#.#...#...#...#.#.#...#.#.#.#...#...#.....#...#...###.#.#.#.#.#...#...#.#.....#...#...#.#.#.....#...#...#...#.#.#...#...#.......#...#.# +#####.#.#######.###.#.#.#.###.#.#.#.#.###.#.#####.#####.###.#.#.#.#.#####.###.#.#####.#######.#.###############.#.#.#.###.###.#############.# +#...#.#.###...#.#...#.#.#...#.#.#.#.#.#...#...#...#.....#...#...#.#.....#...#.#.#...#.....#...#.#.....#.........#...#...#.....#...#...#.....# +#.#.#.#.###.#.#.#.###.#.###.#.#.#.#.#.#.#####.#.###.#####.#######.#####.###.#.#.#.#.#####.#.###.#.###.#.###############.#######.#.#.#.#.##### +#.#...#.#...#...#.....#...#.#.#.#.#.#.#...#...#...#.....#.......#.###...#...#.#...#...###.#.###.#.###.#.....#...#...###.#.......#...#...#...# +#.#####.#.###############.#.#.#.#.#.#.###.#.#####.#####.#######.#.###.###.###.#######.###.#.###.#.###.#####.#.#.#.#.###.#.###############.#.# +#.......#.........#.....#.#.#...#...#.###.#.#...#.....#...###...#.....#...###...#.....#...#...#...#...#...#...#...#.#...#.#...#...#...###.#.# +#################.#.###.#.#.#########.###.#.#.#.#####.###.###.#########.#######.#.#####.#####.#####.###.#.#########.#.###.#.#.#.#.#.#.###.#.# +#.................#.#...#.#.....#.....#...#...#...#...#...#...#.....#...###...#.#.....#.#...#.###...#...#...#.....#.#...#.#.#...#...#.....#.# +#.#################.#.###.#####.#.#####.#########.#.###.###.###.###.#.#####.#.#.#####.#.#.#.#.###.###.#####.#.###.#.###.#.#.###############.# +#.........#.........#...#.......#.###...#.........#...#.###...#.#...#.#...#.#...#.....#...#.#.#...#...#####...#...#.#...#...#.....#...#.....# +#########.#.###########.#########.###.###.###########.#.#####.#.#.###.#.#.#.#####.#########.#.#.###.###########.###.#.#######.###.#.#.#.##### +#.......#...#...#...#...#...#...#...#...#.........#...#.....#...#...#.#.#.#.....#...#...#...#...#...#...#...###.....#.#...#...###...#.#.#...# +#.#####.#####.#.#.#.#.###.#.#.#.###.###.#########.#.#######.#######.#.#.#.#####.###.#.#.#.#######.###.#.#.#.#########.#.#.#.#########.#.#.#.# +#.#...#.###...#...#...#...#...#...#.....#.........#.....#...###...#.#...#...###.#...#.#.#.....#...#...#.#.#...#...#...#.#...#.....#...#...#.# +#.#.#.#.###.###########.#########.#######.#############.#.#####.#.#.#######.###.#.###.#.#####.#.###.###.#.###.#.#.#.###.#####.###.#.#######.# +#...#.#.....#...#...#...###...###.......#.......#...#...#...#...#.#.......#.....#.#...#...###.#...#.#...#.#...#.#.#.#...#...#.#...#.#.....#.# +#####.#######.#.#.#.#.#####.#.#########.#######.#.#.#.#####.#.###.#######.#######.#.#####.###.###.#.#.###.#.###.#.#.#.###.#.#.#.###.#.###.#.# +###...#.......#...#...#...#.#.#.......#.#.......#.#.#.#.....#...#.###...#.#.......#.....#.....#...#.#...#.#.....#...#...#.#...#...#...###...# +###.###.###############.#.#.#.#.#####.#.#.#######.#.#.#.#######.#.###.#.#.#.###########.#######.###.###.#.#############.#.#######.########### +#...#...#.......#.......#.#.#.#...#...#.#.#...#...#.#.#.#.....#.#.#...#...#.....#...#...#.......###.#...#.#...........#...#.....#.....#.....# +#.###.###.#####.#.#######.#.#.###.#.###.#.#.#.#.###.#.#.#.###.#.#.#.###########.#.#.#.###.#########.#.###.#.#########.#####.###.#####.#.###.# +#...#.###.....#.#.......#...#.....#...#.#.#.#.#...#.#.#.#...#.#.#.#.......#.....#.#.#.#...#...#...#.#.#...#.........#.#.....###...#...#.#...# +###.#.#######.#.#######.#############.#.#.#.#.###.#.#.#.###.#.#.#.#######.#.#####.#.#.#.###.#.#.#.#.#.#.###########.#.#.#########.#.###.#.### +#...#.#.......#.......#...#.........#.#.#.#.#.#...#.#.#...#.#.#.#...#...#.#.#...#.#.#.#...#.#.#.#.#.#...#.....#...#.#.#.....#...#...#...#...# +#.###.#.#############.###.#.#######.#.#.#.#.#.#.###.#.###.#.#.#.###.#.#.#.#.#.#.#.#.#.###.#.#.#.#.#.#####.###.#.#.#.#.#####.#.#.#####.#####.# +#.....#.........#...#...#.#.###.....#...#.#.#.#...#.#...#.#.#.#...#.#.#.#.#.#.#.#.#.#.#...#.#.#.#.#.#...#...#...#...#.#...#.#.#...#...#.....# +###############.#.#.###.#.#.###.#########.#.#.###.#.###.#.#.#.###.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#.#.#.#.###.#########.#.#.#.#.###.#.###.##### +#.....#.......#...#...#.#...#...#.......#...#...#.#.#...#...#...#.#...#...#.#.#.#.#.#.#...#.#.#.#.#.#.#.....#.......#...#...#.#...#.#...#...# +#.###.#.#####.#######.#.#####.###.#####.#######.#.#.#.#########.#.#########.#.#.#.#.#.###.#.#.#.#.#.#.#######.#####.#########.#.###.#.###.#.# +#...#.#.....#.#...#...#.......#...#.....#...###.#.#.#...###...#.#.........#.#.#...#...###...#.#.#.#.#.#.....#...#...#.....#...#.....#.....#.# +###.#.#####.#.#.#.#.###########.###.#####.#.###.#.#.###.###.#.#.#########.#.#.###############.#.#.#.#.#.###.###.#.###.###.#.###############.# +#...#.....#.#...#...#...#...#...###.......#...#.#.#.#...#...#...#...#.....#.#...#.............#.#.#.#...#...###.#...#...#.#.#.........#.....# +#.#######.#.#########.#.#.#.#.###############.#.#.#.#.###.#######.#.#.#####.###.#.#############.#.#.#####.#####.###.###.#.#.#.#######.#.##### +#.......#.#.....#...#.#...#.#.#.............#.#...#.#...#...#...#.#.#.....#...#.#.....#.....#...#.#.#.....#...#.#...#...#...#.......#...#...# +#######.#.#####.#.#.#.#####.#.#.###########.#.#####.###.###.#.#.#.#.#####.###.#.#####.#.###.#.###.#.#.#####.#.#.#.###.#############.#####.#.# +#.......#.......#.#...###...#.#.#.........#.#.#.....#...#...#.#.#.#.#.....###.#.#.....#.###...###...#.......#...#...#.#.............#...#.#.# +#.###############.#######.###.#.#.#######.#.#.#.#####.###.###.#.#.#.#.#######.#.#.#####.###########################.#.#.#############.#.#.#.# +#.........#.......#.....#.....#...#.......#...#.....#...#.#...#.#.#.#.###...#...#.....#.#.......#...#...............#.#.#...#...#.....#...#.# +#########.#.#######.###.###########.###############.###.#.#.###.#.#.#.###.#.#########.#.#.#####.#.#.#.###############.#.#.#.#.#.#.#########.# +#.........#.#.....#...#.###...###...#...#...###...#.....#...#...#.#.#.....#...#.......#.#.#...#.#.#.#.....#...#.......#...#...#...#.........# +#.#########.#.###.###.#.###.#.###.###.#.#.#.###.#.###########.###.#.#########.#.#######.#.#.#.#.#.#.#####.#.#.#.###################.######### +#...#...#...#...#.....#.....#...#.....#...#.....#.........###...#.#.#...#.....#.........#...#.#.#.#.#...#...#...#...#.........#...#.....#...# +###.#.#.#.#####.###############.#########################.#####.#.#.#.#.#.###################.#.#.#.#.#.#########.#.#.#######.#.#.#####.#.#.# +###...#.#.#.....#...#.........#.......#...........#.....#.....#.#.#...#.#.###.........#...#...#...#...#.......#...#...###...#...#.....#...#.# +#######.#.#.#####.#.#.#######.#######.#.#########.#.###.#####.#.#.#####.#.###.#######.#.#.#.#################.#.#########.#.#########.#####.# +#...#...#.#.....#.#.#.#.....#...#...#...###...###.#...#.#...#.#.#.#.....#.#...#.....#...#.#...#...#...#...###.#...........#.......###.....#.# +#.#.#.###.#####.#.#.#.#.###.###.#.#.#######.#.###.###.#.#.#.#.#.#.#.#####.#.###.###.#####.###.#.#.#.#.#.#.###.###################.#######.#.# +#.#.#.....#.....#.#.#.#...#.....#.#.........#...#.....#...#...#...#...#...#...#.#...#...#.....#.#.#.#...#...#.#...#.....#...#...#.....###.#.# +#.#.#######.#####.#.#.###.#######.#############.#####################.#.#####.#.#.###.#.#######.#.#.#######.#.#.#.#.###.#.#.#.#.#####.###.#.# +#.#.#...###.....#.#...###...#.....#.....#...#...#...#...#...#.......#...###...#.#...#.#.#.......#.#.#.......#...#.#...#.#.#.#.#.......#...#.# +#.#.#.#.#######.#.#########.#.#####.###.#.#.#.###.#.#.#.#.#.#.#####.#######.###.###.#.#.#.#######.#.#.###########.###.#.#.#.#.#########.###.# +#.#.#.#.#...###...#...#...#...###...###...#.#.....#...#...#...#.....#...#...#...#...#.#.#.###...#...#...........#...#.#...#.#...#.....#.#...# +#.#.#.#.#.#.#######.#.#.#.#######.#########.###################.#####.#.#.###.###.###.#.#.###.#.###############.###.#.#####.###.#.###.#.#.### +#.#...#...#.#...#...#...#...#...#.......###...#...#...#.........#.....#.#...#.###.....#...#...#.................###...#...#...#...#...#...### +#.#########.#.#.#.#########.#.#.#######.#####.#.#.#.#.#.#########.#####.###.#.#############.###########################.#.###.#####.######### +#.........#.#.#...#.....#...#.#.###.....#...#...#.#.#.#...#.....#.....#...#...#...#...#...#.............................#...#.#...#...#...### +#########.#.#.#####.###.#.###.#.###.#####.#.#####.#.#.###.#.###.#####.###.#####.#.#.#.#.#.#################################.#.#.#.###.#.#.### +#.......#.#.#.#.....#...#.....#.....###...#...###...#.....#...#...###.#...###...#...#...#.....#.....#...#.......#.....#.....#.#.#...#...#...# +#.#####.#.#.#.#.#####.#################.#####.###############.###.###.#.#####.###############.#.###.#.#.#.#####.#.###.#.#####.#.###.#######.# +#...#...#.#.#...#.....#.....#...........#...#...###...###...#...#.#...#.....#...............#.#...#...#.#.....#...###.#.....#...###...#.....# +###.#.###.#.#####.#####.###.#.###########.#.###.###.#.###.#.###.#.#.#######.###############.#.###.#####.#####.#######.#####.#########.#.##### +#...#...#.#.#...#.#...#...#.#.#...........#...#.....#...#.#.#...#...#.......#...............#.....#...#.......#.....#.......#...#...#...#...# +#.#####.#.#.#.#.#.#.#.###.#.#.#.#############.#########.#.#.#.#######.#######.#####################.#.#########.###.#########.#.#.#.#####.#.# +#.....#...#...#.#...#...#.#.#.#.....#...#...#.#...#...#...#.#.......#.#.....#.................#.....#.#...###...#...#...###...#...#.......#.# +#####.#########.#######.#.#.#.#####.#.#.#.#.#.#.#.#.#.#####.#######.#.#.###.#################.#.#####.#.#.###.###.###.#.###.###############.# +#...#.........#.#...###...#...#...#...#.#.#.#...#...#.#.....#.......#...#...#.....#...#.......#...#...#.#...#.#...###.#...#.#...............# +#.#.#########.#.#.#.###########.#.#####.#.#.#########.#.#####.###########.###.###.#.#.#.#########.#.###.###.#.#.#####.###.#.#.############### +#.#...........#...#.#...###...#.#.....#...#...###...#.#.....#.....#.....#.###...#...#.#.#...#.....#...#.#...#.#.#...#.#...#.#.......###...### +#.#################.#.#.###.#.#.#####.#######.###.#.#.#####.#####.#.###.#.#####.#####.#.#.#.#.#######.#.#.###.#.#.#.#.#.###.#######.###.#.### +#...#...#...#.....#...#.#...#.#.....#.......#...#.#.#.......###...#...#...#.....#...#.#...#...###...#...#.#...#...#...#.....#.....#.....#...# +###.#.#.#.#.#.###.#####.#.###.#####.#######.###.#.#.###########.#####.#####.#####.#.#.###########.#.#####.#.#################.###.#########.# +###...#...#...###.#...#.#...#.....#.......#...#.#.#...#.....#...#.....#...#.......#.#.#.......#...#.......#.#.........#...#...###...........# +#################.#.#.#.###.#####.#######.###.#.#.###.#.###.#.###.#####.#.#########.#.#.#####.#.###########.#.#######.#.#.#.################# +#.................#.#.#...#.....#.........#...#...#...#.#...#...#.#...#.#...#...#...#...#.....#.............#.......#...#.#...#...#...#...### +#.#################.#.###.#####.###########.#######.###.#.#####.#.#.#.#.###.#.#.#.#######.#########################.#####.###.#.#.#.#.#.#.### +#...................#...#.#...#...........#.....#...#...#...###.#.#.#.#...#.#.#.#.......#...#...#...#.......#.......#...#.....#.#...#...#...# +#######################.#.#.#.###########.#####.#.###.#####.###.#.#.#.###.#.#.#.#######.###.#.#.#.#.#.#####.#.#######.#.#######.###########.# +#...###.................#...#.............#.....#.....#.....#...#...#...#.#.#.#.###...#...#.#.#...#...#...#...#...###.#.#.....#.#.......#...# +#.#.###.###################################.###########.#####.#########.#.#.#.#.###.#.###.#.#.#########.#.#####.#.###.#.#.###.#.#.#####.#.### +#.#.....#.........#...#.....#...........###.............#...#.......#...#.#.#.#.#...#...#.#.#.#.......#.#.....#.#...#.#.#...#...#.....#.#...# +#.#######.#######.#.#.#.###.#.#########.#################.#.#######.#.###.#.#.#.#.#####.#.#.#.#.#####.#.#####.#.###.#.#.###.#########.#.###.# +#.........#.......#.#.#.#...#.#.........#.....#...###.....#.#######.#...#.#.#.#.#.....#.#.#.#...#...#.#.#...#...#...#.#.###.#.........#...#.# +###########.#######.#.#.#.###.#.#########.###.#.#.###.#####.#######.###.#.#.#.#.#####.#.#.#.#####.#.#.#.#.#.#####.###.#.###.#.###########.#.# +#...###.....#...#...#...#.....#.....#...#.#...#.#...#...#...#####...#...#.#.#.#.#.....#...#.....#.#.#.#.#.#.......###.#.#...#.....#.....#...# +#.#.###.#####.#.#.#################.#.#.#.#.###.###.###.#.#######.###.###.#.#.#.#.#############.#.#.#.#.#.###########.#.#.#######.#.###.##### +#.#.#...#...#.#.#.#.............###...#...#...#...#...#.#...#####..S#...#.#...#.#.#.......#.....#.#.#...#...#.........#...#...#...#.#...#...# +#.#.#.###.#.#.#.#.#.###########.#############.###.###.#.###.###########.#.#####.#.#.#####.#.#####.#.#######.#.#############.#.#.###.#.###.#.# +#.#...#...#...#...#...........#.#.............###...#.#.#...#########...#.....#.#...#...#.#.###...#...#.....#.#.....#.....#.#.#.....#.....#.# +#.#####.#####################.#.#.#################.#.#.#.###########.#######.#.#####.#.#.#.###.#####.#.#####.#.###.#.###.#.#.#############.# +#...#...#.....................#.#...#.....#.....#...#.#.#...#########.#...#...#.....#.#.#.#...#.....#.#.......#...#...###...#...............# +###.#.###.#####################.###.#.###.#.###.#.###.#.###.#########.#.#.#.#######.#.#.#.###.#####.#.###########.########################### +#...#.###...........#...#.....#.....#.#...#.#...#.#...#.#...#########.#.#.#.....#...#.#.#.#...#...#.#.###...#...#.....#...#.................# +#.###.#############.#.#.#.###.#######.#.###.#.###.#.###.#.###########.#.#.#####.#.###.#.#.#.###.#.#.#.###.#.#.#.#####.#.#.#.###############.# +#...#...#.......###...#...#...#.....#.#...#.#...#.#.#...#.###########.#.#.....#.#...#.#.#.#.#...#.#.#...#.#.#.#.#...#...#...#.....#...#.....# +###.###.#.#####.###########.###.###.#.###.#.###.#.#.#.###.###########.#.#####.#.###.#.#.#.#.#.###.#.###.#.#.#.#.#.#.#########.###.#.#.#.##### +###.....#.....#.#.......###.#...#...#.#...#...#...#.#.#...#########...#.#.....#...#.#.#.#.#.#...#...###.#.#.#.#.#.#...#.......#...#.#...#...# +#############.#.#.#####.###.#.###.###.#.#####.#####.#.#.###########.###.#.#######.#.#.#.#.#.###.#######.#.#.#.#.#.###.#.#######.###.#####.#.# +#.........#...#...#...#.....#...#.....#.#.....###...#.#...#########.....#.#...#...#...#.#.#...#...#.....#.#...#...#...#.....###...#.......#.# +#.#######.#.#######.#.#########.#######.#.#######.###.###.###############.#.#.#.#######.#.###.###.#.#####.#########.#######.#####.#########.# +#.......#.#...#.....#.....#.....#.......#.......#...#.#...###########.....#.#.#.#.......#...#...#.#.....#.........#...#...#.....#.#.....#...# +#######.#.###.#.#########.#.#####.#############.###.#.#.#############.#####.#.#.#.#########.###.#.#####.#########.###.#.#.#####.#.#.###.#.### +###.....#.....#.#.........#.#.....#.....#.......###.#.#...###########.....#.#...#.#...#...#...#...#.....#.........#...#.#.#.....#.#.###.#...# +###.###########.#.#########.#.#####.###.#.#########.#.###.###############.#.#####.#.#.#.#.###.#####.#####.#########.###.#.#.#####.#.###.###.# +#...#.....#...#.#...#...#...#.....#.###.#.###.....#...###.###.....#.......#...#...#.#.#.#.#...#...#.....#...#...#...#...#.#.....#.#...#.#...# +#.###.###.#.#.#.###.#.#.#.#######.#.###.#.###.###.#######.###.###.#.#########.#.###.#.#.#.#.###.#.#####.###.#.#.#.###.###.#####.#.###.#.#.### +#...#...#...#...###...#.#.###.....#.#...#...#...#...#...#.#E#.#...#...#...#...#...#.#...#.#.#...#.......#...#.#.#.#...###.#...#.#.#...#...### +###.###.###############.#.###.#####.#.#####.###.###.#.#.#.#.#.#.#####.#.#.#.#####.#.#####.#.#.###########.###.#.#.#.#####.#.#.#.#.#.######### +###.....#...#...###...#.#.#...#...#.#.#...#.....#...#.#...#...#.#...#...#.#.#.....#.#.....#.#.......#...#.....#.#.#.....#...#...#.#.........# +#########.#.#.#.###.#.#.#.#.###.#.#.#.#.#.#######.###.#########.#.#.#####.#.#.#####.#.#####.#######.#.#.#######.#.#####.#########.#########.# +###.......#...#.....#...#.#...#.#.#.#...#.#.....#.###.....#...#...#...###...#.....#.#.#...#.#.......#.#...#.....#.#.....#.......#.#...#.....# +###.#####################.###.#.#.#.#####.#.###.#.#######.#.#.#######.###########.#.#.#.#.#.#.#######.###.#.#####.#.#####.#####.#.#.#.#.##### +#...#.......#...#.....#...#...#.#...###...#...#...#.......#.#...#...#...........#...#...#.#.#.#...#...#...#.....#.#.......#...#.#.#.#.#.#...# +#.###.#####.#.#.#.###.#.###.###.#######.#####.#####.#######.###.#.#.###########.#########.#.#.#.#.#.###.#######.#.#########.#.#.#.#.#.#.#.#.# +#...#.#...#.#.#...###.#.#...#...#.......#...#.....#.....#...#...#.#.#...#...#...###...#...#.#.#.#.#.###.#...#...#.......#...#.#.#...#.#...#.# +###.#.#.#.#.#.#######.#.#.###.###.#######.#.#####.#####.#.###.###.#.#.#.#.#.#.#####.#.#.###.#.#.#.#.###.#.#.#.#########.#.###.#.#####.#####.# +#...#.#.#...#.###.....#.#.....#...#.....#.#.#.....#.....#.###.....#.#.#...#...#.....#...#...#.#.#.#...#...#.#.......###...###...#.....#...#.# +#.###.#.#####.###.#####.#######.###.###.#.#.#.#####.#####.#########.#.#########.#########.###.#.#.###.#####.#######.#############.#####.#.#.# +#...#.#...#...#...#.....###.....#...#...#.#.#.....#.#...#.........#.#...###...#.......#...#...#.#...#.#.....#...#...#.......#...#...#...#...# +###.#.###.#.###.###.#######.#####.###.###.#.#####.#.#.#.#########.#.###.###.#.#######.#.###.###.###.#.#.#####.#.#.###.#####.#.#.###.#.####### +#...#...#.#.#...#...#.......#...#...#.....#...#...#.#.#...#.....#.#...#...#.#...#.....#...#.#...###...#...#...#.#.....#...#...#...#.#.###...# +#.#####.#.#.#.###.###.#######.#.###.#########.#.###.#.###.#.###.#.###.###.#.###.#.#######.#.#.###########.#.###.#######.#.#######.#.#.###.#.# +#...#...#.#.#...#...#.....#...#.#...###...###.#...#.#.#...#.###.#...#...#...#...#.#.....#.#...###.........#...#...#.....#.....#...#.#.....#.# +###.#.###.#.###.###.#####.#.###.#.#####.#.###.###.#.#.#.###.###.###.###.#####.###.#.###.#.#######.###########.###.#.#########.#.###.#######.# +#...#...#.#.#...#...#.....#.###.#.#.....#.....#...#.#.#...#...#...#.#...#...#.###...###.#...#...#.......#.....#...#.........#.#...#...#...#.# +#.#####.#.#.#.###.###.#####.###.#.#.###########.###.#.###.###.###.#.#.###.#.#.#########.###.#.#.#######.#.#####.###########.#.###.###.#.#.#.# +#.#...#.#.#.#...#.#...#...#.#...#.#.#...#...#...#...#...#...#...#.#.#...#.#.#.........#.#...#.#.........#.....#...#...#...#.#.#...#...#.#.#.# +#.#.#.#.#.#.###.#.#.###.#.#.#.###.#.#.#.#.#.#.###.#####.###.###.#.#.###.#.#.#########.#.#.###.###############.###.#.#.#.#.#.#.#.###.###.#.#.# +#...#...#...###...#.....#...#.....#...#...#...###.......###.....#...###...#...........#...###.................###...#...#...#...###.....#...# +############################################################################################################################################# \ No newline at end of file diff --git a/20/twenty.go b/20/twenty.go new file mode 100644 index 0000000..78f3eb4 --- /dev/null +++ b/20/twenty.go @@ -0,0 +1,89 @@ +package main + +import ( + "fmt" + + "github.com/cdlewis/advent-of-code/util" + "github.com/cdlewis/advent-of-code/util/aoc" + "github.com/cdlewis/advent-of-code/util/grid" +) + +func main() { + input := grid.ToByteGrid(aoc.GetInput(20, false, "")) + + var start, end grid.Point + for idx, i := range input { + for jdx, j := range i { + if j == 'S' { + start = grid.Point{idx, jdx} + input[idx][jdx] = '.' + } + + if j == 'E' { + end = grid.Point{idx, jdx} + input[idx][jdx] = '.' + } + } + } + + cheatLength := 20 + minSavings := 100 + + shortestWithoutCheating, _ := grid.ShortestUnweightedPath( + input, + start, + func(p grid.Point) bool { return p == end }, + func(p1, p2 grid.Point) bool { return input.Get(p2) != '#' }, + ) + + toStart := calculateDistsFrom(start, input) + toEnd := calculateDistsFrom(end, input) + + results := 0 + for p1, p1Dist := range toStart { + for p2, p2Dist := range toEnd { + p1p2Dist := util.Abs(p1[0]-p2[0]) + util.Abs(p1[1]-p2[1]) + if p1p2Dist > cheatLength { + continue + } + + totalDist := p1Dist + p1p2Dist + p2Dist + + if shortestWithoutCheating-totalDist >= minSavings { + results++ + } + } + } + + fmt.Println(results) +} + +func calculateDistsFrom(start grid.Point, maze grid.Grid[byte]) map[grid.Point]int { + q := []grid.Point{start} + dist := 0 + result := map[grid.Point]int{} + + for len(q) > 0 { + var newQ []grid.Point + + for len(q) > 0 { + curr := q[0] + q = q[1:] + + if _, ok := result[curr]; ok { + continue + } + result[curr] = dist + + for _, newPos := range maze.GetAdjacent(curr) { + if maze.Get(newPos) != '#' { + newQ = append(newQ, newPos) + } + } + } + dist++ + q = newQ + } + + return result +} \ No newline at end of file diff --git a/util/grid/grid.go b/util/grid/grid.go index cd164f4..d4a4044 100644 --- a/util/grid/grid.go +++ b/util/grid/grid.go @@ -58,6 +58,14 @@ func (g Grid[T]) Get(point Point) T { return g[point[0]][point[1]] } +func (g Grid[T]) GetOrElse(point Point, orElse T) T { + if !g.ValidPoint(point) { + return orElse + } + + return g.Get(point) +} + func (g Grid[T]) Set(point Point, val T) { g[point[0]][point[1]] = val }