diff --git a/2019/20.cpp b/2019/20.cpp index ef2235b..fa7f882 100644 --- a/2019/20.cpp +++ b/2019/20.cpp @@ -1,19 +1,22 @@ #include +#include +#include #include -#include -#include #include +#include +#include #include -#include -#include +#include +#include +#include #include +#include +#include #include #include -#include -#include -#include -#include -#include +#include + +#include #include #include @@ -149,6 +152,129 @@ auto SolveMaze(Distances const& distances, bool const recursive) -> std::int64_t } // namespace +TEST_SUITE("2019-20 examples") { + TEST_CASE("part 1 a") { + std::istringstream in { + " A \n" + " A \n" + " #######.######### \n" + " #######.........# \n" + " #######.#######.# \n" + " #######.#######.# \n" + " #######.#######.# \n" + " ##### B ###.# \n" + "BC...## C ###.# \n" + " ##.## ###.# \n" + " ##...DE F ###.# \n" + " ##### G ###.# \n" + " #########.#####.# \n" + "DE..#######...###.# \n" + " #.#########.###.# \n" + "FG..#########.....# \n" + " ###########.##### \n" + " Z \n" + " Z \n" + }; + auto map = Grid::Parse(in); + auto portals = FindPortals(map); + auto distances = FindDistances(map, portals); + CHECK(SolveMaze(distances, false) == 23); + } + + TEST_CASE("part 1") { + std::istringstream in { + " A \n" + " A \n" + " #################.############# \n" + " #.#...#...................#.#.# \n" + " #.#.#.###.###.###.#########.#.# \n" + " #.#.#.......#...#.....#.#.#...# \n" + " #.#########.###.#####.#.#.###.# \n" + " #.............#.#.....#.......# \n" + " ###.###########.###.#####.#.#.# \n" + " #.....# A C #.#.#.# \n" + " ####### S P #####.# \n" + " #.#...# #......VT\n" + " #.#.#.# #.##### \n" + " #...#.# YN....#.# \n" + " #.###.# #####.# \n" + "DI....#.# #.....# \n" + " #####.# #.###.# \n" + "ZZ......# QG....#..AS\n" + " ###.### ####### \n" + "JO..#.#.# #.....# \n" + " #.#.#.# ###.#.# \n" + " #...#..DI BU....#..LF\n" + " #####.# #.##### \n" + "YN......# VT..#....QG\n" + " #.###.# #.###.# \n" + " #.#...# #.....# \n" + " ###.### J L J #.#.### \n" + " #.....# O F P #.#...# \n" + " #.###.#####.#.#####.#####.###.# \n" + " #...#.#.#...#.....#.....#.#...# \n" + " #.#####.###.###.#.#.#########.# \n" + " #...#.#.....#...#.#.#.#.....#.# \n" + " #.###.#####.###.###.#.#.####### \n" + " #.#.........#...#.............# \n" + " #########.###.###.############# \n" + " B J C \n" + " U P P \n" + }; + auto map = Grid::Parse(in); + auto portals = FindPortals(map); + auto distances = FindDistances(map, portals); + CHECK(SolveMaze(distances, false) == 58); + } + + TEST_CASE("part 2") { + std::istringstream in { + " Z L X W C \n" + " Z P Q B K \n" + " ###########.#.#.#.#######.############### \n" + " #...#.......#.#.......#.#.......#.#.#...# \n" + " ###.#.#.#.#.#.#.#.###.#.#.#######.#.#.### \n" + " #.#...#.#.#...#.#.#...#...#...#.#.......# \n" + " #.###.#######.###.###.#.###.###.#.####### \n" + " #...#.......#.#...#...#.............#...# \n" + " #.#########.#######.#.#######.#######.### \n" + " #...#.# F R I Z #.#.#.# \n" + " #.###.# D E C H #.#.#.# \n" + " #.#...# #...#.# \n" + " #.###.# #.###.# \n" + " #.#....OA WB..#.#..ZH\n" + " #.###.# #.#.#.# \n" + "CJ......# #.....# \n" + " ####### ####### \n" + " #.#....CK #......IC\n" + " #.###.# #.###.# \n" + " #.....# #...#.# \n" + " ###.### #.#.#.# \n" + "XF....#.# RF..#.#.# \n" + " #####.# ####### \n" + " #......CJ NM..#...# \n" + " ###.#.# #.###.# \n" + "RE....#.# #......RF\n" + " ###.### X X L #.#.#.# \n" + " #.....# F Q P #.#.#.# \n" + " ###.###########.###.#######.#########.### \n" + " #.....#...#.....#.......#...#.....#.#...# \n" + " #####.#.###.#######.#######.###.###.#.#.# \n" + " #.......#.......#.#.#.#.#...#...#...#.#.# \n" + " #####.###.#####.#.#.#.#.###.###.#.###.### \n" + " #.......#.....#.#...#...............#...# \n" + " #############.#.#.###.################### \n" + " A O F N \n" + " A A D M \n" + }; + auto map = Grid::Parse(in); + auto portals = FindPortals(map); + auto distances = FindDistances(map, portals); + CHECK(SolveMaze(distances, true) == 396); + } +} + + auto main(int argc, char** argv) -> int { auto map = Grid::Parse(*Startup(argc, argv)); auto portals = FindPortals(map);