diff options
Diffstat (limited to '2018')
-rw-r--r-- | 2018/input/20.txt | 1 | ||||
-rw-r--r-- | 2018/src/day20.rs | 118 | ||||
-rw-r--r-- | 2018/src/main.rs | 4 |
3 files changed, 122 insertions, 1 deletions
diff --git a/2018/input/20.txt b/2018/input/20.txt new file mode 100644 index 0000000..6fa41f5 --- /dev/null +++ b/2018/input/20.txt @@ -0,0 +1 @@ +^NWSWNWSSSENESESSEENWNENW(NNNEESWSEENENNENWNNWSWSES(WWWWSWWWNNNWSWWNNNWNEESS(ENESESENNWNEENWWWNNWNWSWWWNNWSSSWSESWWNWWSESSSSSENNESEESE(NNWWNE(N(WWSWNSENEE|)NNEEN(WW|EES(SEWN|)W)|E)|EESE(N|SSSSWWWNWNENN(ESSE(SWEN|)N|WWW(NEWS|)SSWNWN(WSSWWSEESWWWWWNWSWSWWWSEESESSESEENWNWNENEN(WWSWENEE|)ESESWS(WNSE|)ESWSSWSSESWSESSENNENWNEEEENENESSEESSESESENENNWSWNWNNNNEEESEENWNNWSWNNNN(EESE(N|S(WWNSEE|)EEEENNNEESSSW(SWSWWN(E|WWSESSESEENN(EEENN(WSWENE|)NEENWNNEEEENWWWNNENWNNNESES(SENNNESEEENEESWSEENNNWNNESESEESESSWSWW(SWWSWWNWWNEN(WWSSS(WNWSWENESE|)EESSESWSWNNNWSSWWSW(NWES|)SESWSSSESWSSENEEESWWSESEEENEESWSSSEENN(WSNE|)ENNNW(SS|NNNENNNWWSWSE(ENSW|)SSWNWNWNNE(N(WWWNWSSEESSSWNW(SSEEE(N|SE(S(ENES|WSW)|N))|N(WSNE|)E)|E(ENNNEN(EESSW(N|SS(WNNSSE|)EESSEENNEENNNNWWSSWS(EENNSSWW|)(SS|W(W|NNENWNN(WSWWEENE|)ESEENNESSENNESSEENESENENWNWWS(E|W(S|NNNNNNENENNNEENNNWSSWWWSESWWWNWWSSE(N|SSSWWNWNE(ESNW|)NNWNWWNWWNENENWNWWWNEENNESENENESESWWSESSW(NWNWESES|)SS(ES(W|E(ENWN(W|NESESSENE(ENWWNWNNW(SWNSEN|)NEEEENENESSESSS(ENNNNWNEESSESEEESEENNESESSSWSWSWWWNENE(N(E(ENSW|)S|WWSWWNEN(WW(N|SSSSEE(NWES|)SWWSWSW(SESSSSESS(WNWNWSWNNEN(NESSNNWS|)W|SSSWSEESSWSSEEN(W|ESSWSESSENESEENENWW(S|WNNNW(SSS|NNNNNESEEESESWSSSWNW(NENNWWS(E|S)|SSEEESEEENNENESSWSSSWWN(WWSESSESSEESSSE(SWWWSSSWNWSWSWWSWWNNE(S|EENNE(S|ENNNEN(WWNWNWWSSWNWSWSESENESSWSS(EEN(W|NENWNE(NWN|ESS))|WNNWSWWSESSEE(NWNSES|)SWSWWSEESSWWWN(EE|WWSWNNWWNNNNEESENEE(ESS(WSWS(E|WNN(ENEWSW|)WW(SEWN|)N)|E)|NNWNEENE(S|NNNNWSSSWNWWSS(SSS(WNNNNWSSSSWWWWNNWSWWNENWNW(NENNENWNENWN(EESEESWSSSEEES(EENEENE(NWWWNWNWSSES(S|WWWNENNNEENWNW(SWNWSSE(WNNESEWNWSSE|)|NNEENEEEN(E(E|SSWWSSESEN(NWES|)ESSWSES(WWNW(N(E|NW(SS|NWN(ENSW|)W))|S)|ES(ES(ENN(WNNW(S|NN)|EEES(WWSNEE|)EESE(ESWENW|)NNW(N|W))|S)|W)))|NWSWWWN(WSSEWNNE|)EE))|EE)|S)|SSSSWWNENWWWNN(ESEENW|W(NENNNSSSWS|)S))|W(SSWSESS(NNWNENSWSESS|)|NN))|SSSW(SEESENESSSWSEESEE(SEESSWSEEESSSSWWNENNWWS(WWSWNWWWWNNEEEES(WWW|ENE(S|NN(E|WWS(WNN(NWSSSWNNWWSESWWNNNNNNESSSEENNW(N(EE|NWWNNWWSWSSESWSEE(SSSWWWWSESSESSWNWWWNEENWNNWWSS(ENSW|)WNWSSSSEE(NWNEWSES|)SWSSWSESSESSENNNWNNNEENE(NWWSNEES|)SSWS(WNSE|)SENENNEN(ESENENWNENWW(NE(NWWSNEES|)EESSSSENESESESEESENESSWSWWN(NWWWN(WSWSSENESSSSSESEESSWWWWSSENEESSESENNWNENESSSSESSSWS(EEENNNW(SS|NEESESWSES(W|EEENENWWNW(SSEWNN|)NEENWWW(S|NEEEEESSS(ENEEENWWNNW(WWWWNNESEENWNENEENNESENEESENENWNNWWSS(ENSW|)WWWWNWSSS(ENSW|)WSWNNNWNENWWWWNEENNW(NNENNW(NEN(W(WW|N)|EESSENEEEEESSWSSWSEENEESSES(EEEE(NNWWNWNNEEE(SW(SEWN|)W|NNNNWSWSESWWWNNWW(SESSW(N|S(EE(SSESEE|N)|W))|NENESE(SS|ENNEE(SWEN|)NNNNNNWSSW(SWWSEES(ENNSSW|)WS(WWWSWNWWN(WSW(SESS(EEN(ES|NWS)|W(N|W))|N)|EENEE(N|S(E|W)))|S)|NN))))|SWSSW(NNWSNESS|)SESSE(SSSWNWN(WSSSSEESE(NNWWNSEESS|)SSSSWS(E|WNNENNWSWWNN(NNNWNENN(EENWESWW|)WSWSSWSS(WNNNN(NE(ENSW|)SS|WWSESW)|EE(NWES|)SSW(N|SSWWSES(EEEENWN(W(SWEN|)N|E)|WWWNN(WSSWENNE|)E(NEEWWS|)S)))|E(E|S)))|E)|NNNN))|WWN(WWWSS(ENESSWW(EENNWSNESSWW|)|WNNNWSSSW(SSS|NNWW(SEWN|)NENW(NEEN(WWNNSSEE|)ENESS(ENNEWSSW|)WS(WSNE|)E|W)))|N)))|S)|WWS(W(SESSEESSSESS(SWNWSWSEES(ENSW|)WWSS(ENSW|)WWNNNNNNWSSWNNNENWN(EESES(ENE(NWWN(W|N)|SS(E|WSW(SSSS|N)))|W)|WWSESSWNWNNNNES(NWSSSSNNNNES|))|E(NNNWNN|E))|NWWN(NESNWS|)WW(WNW|SE))|EE))|SS)|W(NN|W)))))|WNNN(ESNW|)WWWN(E|WN(ENSW|)WWSSSEN(N|ESESS(EENNWS|WWWN(WSWNNENWNNNNWNWSWWSWWNENNWNEESE(S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EESSSS(NNNNWWEESSSS|)|SWWSS(EENWESWW|)W(SEWN|)WW)|SEEESENNEESWSEENEENEENNWNNWWWNEEENESSSENESEN(EESSE(N|SSENNESENNNNNWN(ENNNNENNNW(WNEENESEESESSESSSWWSWNNNW(SWSESWSSEEN(W|ESSWSWSW(NNEWSS|)SSSSENESENNESSSSSSWSEEEENNWSWNNNEEES(WW|SESSSEEENEEESWS(EEEEEENEEENWWWNNWNNNESENNESSSESES(ESWSEES(EEENENNNWN(EEENEESSW(WSEESSWWN(W(SS(EEE|W)|NN)|E)|N)|WWNNNWNWSSESSS(SSENE(NWES|)S(EN|SW)|WNWN(E|NNNNN(EEEESS(WNWWEESE|)S(E|SS)|WSWWNWSS(SWWWNWWSWSSSSWNWWNNWSS(SSE(SWEN|)E(NWES|)EEENNENESSE(SWSW(SEENE(S|N)|NN)|NNNWW(WSNE|)N)|WNNWWWWNEENNNWSW(SEWN|)WWW(SWNSEN|)NENEE(SWEN|)NENNN(WWSESWS(NENWNEWSESWS|)|ESENNESSSENNESESESESSWSE(ENEES(W|ENNWWWNEEEEE(NWWN(WSWWN(NNWNWSW(NNENWNNWSSSWNWNNNE(NEENWWWNNEEES(WW|EESWSS(EE(SSW(NWSNES|)SS|N(NNEE(SWSNEN|)NWWWNNWS(WNWNENW(WSWSES(E|WWSSSS(E|WWNNNNE(NNNE(NWWWSESWS(WWWN(ENE(NWES|)S|W(SSEESSSS(WNNW(NEWS|)S|ESE(NNWNENWNE(WSESWSNENWNE|)|EEESSWSSW(NNWNEE|SSENEE(NWN|EESW))))|WW))|E)|E|SS)|SSS)))|NENE(ESESS(WWN(N|E)|ESWSEEEES(ENENWWWNNNENNWSWW(NEWS|)(SES(SS|W)|W)|W))|NWW(S|N(E|W))))|S)|W))|WW))|SS)|SEES(W|S))|E)|EENWN(NNN(EEE|N)|E))|S(WSSSWENNNE|)ENES(ENSW|)S))|SWSSW(SEWN|)NNNNWWNN(E(N|ES(W|E))|WSSW(SSENEESSW(N|WW)|NNNWSSW(ENNESSNNWSSW|))))))|EEESSS)))))|WWWWW)|WWWN(NWES|)E)|W(N|WWWWWWWWN(EEENNSSWWW|)WWWNNNWWNN(WSWSWSWNWNWNEEN(ES(SW|ENNES)|WNNWWWW(NEEENSWWWS|)SSSSENNNES(ENSW|)SSSESESSEEN(EESWS(WWWWNNWSSWNNN(E|WSWNWWSWNWWNEEEENE(SEEWWN|)NNWSWSW(WWWSSWWSESS(EEEEN(WNWSWN|ESEN(ESENSWNW|)N)|WWWWNNWNEENWNN(ESE(S(EENWESWW|)SSS(WNSE|)E|N)|WSWNN(E|WWSSWSSWWSSEEES(WWWWNNNWNWNENEE(NNWWWNWWSESS(ENEEWWSW|)SSWNNNW(SSSSESENESESSWNWSWNW(N|S)|NNNNEENENWNWSSWNNN(EEESESEE(SWWSWS(ESNW|)WW|NWN(EESE|WNW))|N))|SE(SWWN|NE))|EEN(ESNW|)WNW(WW|NEE(N(E|W(W|NN))|S))))))|N))|EENNN(W(N|W)|ESSSEEE(WWWNNNSSSEEE|)))|W))|ESEE(NWES|)S)))))|NEN(WNEWSE|)ESSSEN)|SS)|W))|NNWSWNN(EENNEWSSWW|)WWWWWS(EE|WNWSSESWSSES(W|ESENNE(SEWN|)NWW(S|W))))))|NN)|NNENEESSW(SEENENNENWW(SS|WWWNW(NNESEEEENNENWNWSWSESWWNNNNE(S|NNWWW(SSSE(SWSE|NNE)|NENWNEESENESS(ESSENNEENENEENWWWSWSWNW(NWWNNENEENNWNENNWWNWNNNWNENNENNWSWSSWW(NENNNW(SS|NNNENENENESSSW(SSW(N(WSNE|)N|S(S|EENNEENWNNEES(W|ENENESSESSSWWNENW(WWSSSE(NN|SWWW(NNESNWSS|)SSESSSWSEEENESSWWS(WNW(S|WNNNENW(ESWSSSNNNENW|))|ESENESSWSSESWWW(NENWN(N|E)|SEESS(WWN(E|WS(SEWN|)W(N|W))|EEEESESSSENEE(NWWNNENWNENENWWNWWWNW(NEESENNWNNWWNNNESSENENWNNESENENWWWNW(NNENNNW(SS|WNNWNWNNNWWWWSSESESE(NNNW(W|S)|SWWNW(NWWS(E|WWW(SS(ENEWSW|)S|NEENENNE(SS|NEENWWWSWWNNNW(SSSSSE(ENW|SW)|NNNENNEENESEEEESSWWSEESSSESES(SSES(SEENEENNENNEENEESSSEESWSSSWNNNWWSWW(SWSSW(SSEESEENWNEEESESSWW(SSWW(WWWN(EN(NWSNES|)ESENES|W)|SEEENEESSSSESEESENENWNEENNNNNENNWNENEENWWNWSSWWNWNNWNEENNWWW(S(EE|SSWSESE(SESSWNWSSSW(S(WW|EENEN(ENE(NWES|)S(E|SSW(N|SSS(ENNSSW|)WSW(SEWN|)NW(NNEE(SWEN|)N|S)))|W))|NNNWN(E(N|E)|WWNWW(NEENSWWS|)S(E|W(SWEN|)N)))|N))|NNNWNNEENESEENENNEENENNENENENEENWNWNNEENNESSSS(WNWESE|)ENNNNNWNWNWSS(E|SWNWNNE(S|NWNN(WWWSWSSESSEE(NNNW(NEWS|)(W|SS)|SWSEE(SWWWSWSESWWWNNE(S|NNNWNWWWNEENNWNEEE(SSW(SEES(SS(ENSW|)S|W)|N)|N(WWWWWSSWSWSWWSSSWWSSENESEESWSSSESENNN(WSNE|)ESENEE(NNWNWSWNNN(WWSW(NNEENE(NE(NN|E)|S)|SEE(SSEEEWWWNN|)N)|ESENESESW(ENWNWSNESESW|))|SSSSWNN(WSW(SSSWNWWN(WWWWNWNWNNWSSWWWWSWNWWNEEENEENWNNEENWWWWWWSSENEESWS(WWS(EE|WWSSWWSWNNNENNENENNWSWSWW(NNNES(S|ENENENWNWNEEN(ESEEEN(WW|EEESENESSWWSSSWWNENWN(NESNWS|)WWWW(SEEESWWWS(S(SSSWS(WSSWENNE|)E|ENESE(EEEEEEENWNENNNN(ESSEES(EENENWW(S|N(EEES|WSWN))|WWSSEE(NWES|)SWWSWSESWWW(NENWESWS|)S(W(SSWW|NW)|EESENESSS(WNWESE|)EE(S(WW|E)|NWNENW)))|WSSSWSW(SEWN|)N)|N))|W)|W))|WWWSSW(SES(ENSW|)W|NN)))|SESWSSSSSSS(ENNEES(WSNE|)ENN(W|E(NN|SESWSEEENN(W(NWES|)S|ESSSSEENNESSSWWWSSSEEESW(W|SEESSW(WNEWSE|)S(S|EENNNNWNNWN(WSWNSENE|)ENESEENNW(S|NEESSENNESSESSS(WNNWWSS(ENSW|)SWW(NN(ES|WS)|SS)|E(NNNNWNE(NWWWWN(EE|WWWW(SE(SWSEWNEN|)EE|WNEN(ESEWNW|)WWSW(S(E|SS)|N)))|EEEENWN(EESE(SWS(E|S|WWWSWN)|NNESSENENWNEENENW(WWS(WW(SE|NE)|E)|NNNESSE(S|NN|E)))|N))|SSSENN))))))))|SS)))|E)|EE)|N)|N))|E)))|N|EE))|ESEES(W|ESEES(SEENNW(S|NENN(WWWW(SESENE|WW)|ESENESENEEEEESWSSESESSWSWSSSWNWWSWSESWSSSESSSWSWSSSSSSSSSWWWNENNE(SS|NWNENWNENWNWWWNENNESENNNNWSSWNWWNW(NNEEENEENWNWNEESESE(NE(NWNW(S|W(NNESEEEESSE(SWWNNW|NNN(WWNWW(SEWN|)WWNEEEENESSENN(SSWNNWESSENN|)|ES(S|E)))|WWWSSS(E|S)))|S)|SWSWWS(EEE(SWSSSE(NN|S(ENSW|)WS(WW|S|E))|N)|WW(SEWN|)W))|SSWSESWWWSEESSEE(NWNENENNWS(NESSWSNENNWS|)|SSWWSESEEEE(SSWNWSWSWWNEN(WNWSWSESSSWSEENEESEEEN(ESESWWWSEEES(EEES(SWNSEN|)ENNWWWNNEEEEESW(SEESEEEESWSWNWWW(NWSNES|)SESSEEESEESWWSEE(EEESE(NEES(W|E(S|NEEEENNNNNWSSSSWWWWNENWWSSWNWSWNNW(SS|WNN(ESEESENNNWNEENESEEEES(EEEE(SWSESS(ENNNESSSENNES(E|SSW(SEESESESS(ENNN(ENNE(SSSSSWNN(SSENNNSSSWNN|)|NWNEE(E|S))|W)|W(N|S(W|S)))|W))|WNW(SSESSW(WSWNWW|N)|NN))|NNN(ESNW|)WSWW(SEEWWN|)NENWWNEENWNENNESSE(SWEN|)NEENE(EENNNNNNEENWNNNENNWSWSSWNNNWSSWNNWWWNWWWNNNNWNWWSSSSWSEESE(NNWNN(ESNW|)N|SWWSSENEESENNE(NWWSNEES|)SESENE(NWWEES|)SESSSWNWWN(EE|W(SSSWSWNWWNNWWWNE(NWNNN(E(SS|E)|WSSWWWNWSSESWSSENEENWNEESSSWWSSENESSEENWNEE(NWWEES|)SSSSESESWSWNWN(NNWWSWWSWNNN(EESWENWW|)NWSSSWSESWSSWWSEESSEENNW(NEESESENNWNWW(NEENEE(N|SWSESSSS(EESEEN(ESNW|)NNN(EN(NENNENENW(NENE(NWES|)SESEESE(NNNW(W(SEWN|)W|NENN(ESNW|)W(S|N))|SWWNWSSWN(NN|W))|WSWS(S|WNN(NWSSNNES|)E))|W)|WSS(WWNN(ESNW|)N|S))|WSWW(SS(SEWN|)WWNENWWWNNWWNNNENE(S|NWNENNNE(SS|N(WNNWNNWWWNEEENWNEESSSE(S(SS|W)|NNNNWWWNW(SWWW(SWSEE(NESENSWNWS|)SSSSENESE(N|SSE(N|SSSWNWWNNN(ESSEWNNW|)WW(NNNN|SESSWWSW(SEENEESWSWWSW(N|SEENESSWWWS(EEEENE(SSSEESW(ENWWNNSSEESW|)|NNN(WSSNNE|)E(NWNSES|)S)|WW))|NNNE(SEWN|)N))))|N(EE|N))|NENWNENENESSEESWWSS(WNNNSSSE|)EESES(W|ESENNNW(S|WN(NNEEENWWNWWS(E|WNNENNWSWW(SEWN|)NENEENESSESEENWNNN(W(WWWSWNWSSW(W|NN|S)|SS)|ESSENNESESESWW(SW(N|SES(W(WNW(WWNSEE|)S|SSSS(ENNNSSSW|)W(SSEN|NWWSE))|ENEEN(WW|ENNNN(EESSESENENWN(WSNE|)EEEEESEEESEESSWNWSSEESEEEENWNWNW(SSEWNN|)NNESEES(SEESWSSSESWWNWN(E|WWSSWNWWNE(NWWNWSSWNWSWNNEENENE(NWWWNWWSSE(N|E(E|SWWSWSESSEEESEE(SESS(SESWSESEENWNENESSSEENENENNNEN(WWSSWW(WWNEEN(ESNW|)W(N(N|E)|WWSW(SES|NNW))|SS(ENEWSW|)S)|NEEEESESENNWNNNWSSWNWNENWWSW(NNEEENWWNWNWSW(SEEWWN|)NN(EEESESEEENESSESENENWWNN(WWWSWNW(ESENEEWWSWNW|)|EES(ESENN(EESWSESSSSWNNWW(NEEWWS|)WSSWNWSSEESENNNESSEESSSWSWWNWWW(SESWSSSWNWSSSWSEEESESSWWSESEEEESESWWSEESSWNWWSW(SSESSSW(WSWSESSWNWNWSWNWSWWSSSESSSW(SSESWSEE(NEEENNNWWW(S(W|ES(ENSW|)W)|NEEEENESEESWSESSWWW(S(W|EEES(SESEEE(NWWNNNNW(NEEE(NWWNNNEE(SWSEWNEN|)NNWSWWSWNW(NEEENENE(S|NNWNENNN(WSSWNNW(SSSESWSWWSSENE(ENEWSW|)S|W|N)|NNNNNNWNENWNWNWW(SSS(EN(ESNW|)N|W)|NENWNNNENW(N(N|EESSEE(NN(WSNE|)N|SWSW(NWSNES|)SES(W|E(NN|S(W|S)))))|WSSSS(WWNEWSEE|)S))))|WWS(WNWWW(WNEEEE|SEES(WW|E))|EESEESS(NNWWNWESEESS|)))|SSSW(SEWN|)NN)|SSS)|SWWWS(WW(SEESW|NEN)|E))|W))|NNNESSE(WNNWSSNNESSE|)))|SSW(SSEN|NW))|NNW(S|NNN))|NN)|NNWWS(ESNW|)WWS(WNWSWNWNEEEENWNNWNNNWSWSWWNWSWNWNENENN(WSWNWSWWW(N(WNEWSE|)EE|SEEE(E|SWSSWWNWW(NEEESNWWWS|)SSE(EESSES(ENNN(WSNE|)E(NWNSES|)ESWSEENNESEES(EN(ESNW|)N(N|WW)|WW)|SWWWNNW(S|NEESSE))|N)))|EEN(W|EN(NENENNW(SWSNEN|)NEESESES(ENSW|)WSW(WSSSE(NNESNWSS|)SWS(WNN(WSWWSS(E(ENWESW|)S|W)|NN)|EEES(E(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S|NNE(SEWN|)NNW(NENWESWS|)WWSS(WNNSSE|)E(SW|NE))|SS(E|SSSW(SWEN|)NN))))))|EE(ENSW|)SS)))|E))|NNN)))|ENNNE(S|NNN)))|WWN(ENWESW|)WWW)|E)|NWW(W|NNEE(NWW|SW))))))))|W)))))))|N(E|N))|WN(WS|EN))|NENEEN(N|WW))|W)|WWWN(NWNENWWNWSSWW(S(EEENSWWW|)S|NENNW(SWSNEN|)NEESENEE(WWSWNWESENEE|))|E))))))|S)|E))|WWWSSEEE(NWWEES|)SWWSS(SSSESEN(SWNWNNSSESEN|)|WNWN(W(N(E|W)|SS(E|S))|E)))|S(W|SEESWWSS(WNSE|)EEE(N(WW|N(N|E))|S)))|ESWSSS(WWNN(E(N|S)|WSSWSEEESWSESSWWWNNE(SEWN|)NWWSWSESWWSESSENNESSSWSWNWNWSSESWWNWW(NENNNW(NEEE(SS(W(SS|N)|E)|NENNWSWSW(W|NNNWN(WWNNSSEE|)EENESENNW(WWSNEE|)NENESSSSS(WWWSNEEE|)(S|ENNNE(NNW(S|N(E|N))|S))))|WWWW)|SWSES(WWNSEE|)(SS|EN(N|ESENEESENESESWWWSESEEN(ESEENESSSES(WWNWSSWNWWNW(SSE(E|S)|N(EEE(SWEN|)EE|WNW(S|NNN)))|ENESEENESE(NENNWNNN(EESS(WNSE|)S(SS|EENWN(N|EE))|WN(WWNENWNWWSESWWNWSWNWSSEEESWS(ESENNNESSEE(NWES|)SWWSS(WWNEWSEE|)E(NEE(NN|S(W|E))|S)|WW(S|N(E|W(NWNN(WSWWEENE|)NE(NWNNEEESSS(WNNWESSE|)EENWNNENENWN(WW(SESWENWN|)NN|EESEES(ENESEN|WSESWSWWN(W|EN(N|W))))|SS)|S))))|E))|SWWWWWW))|W)))))|ENEN(N|W)))))))|N))))|N))|SESSW(SSENE(N|SSWSW(SEEEE(SS(WSWNN(E|WWSESSESSWNW(NN|S))|E)|N(W(W|N)|E))|N))|N))|S)|WW)))|SS))|W|N)))|NNESEES(NWWNWSNESEES|)))))))|W))|NWWNNN)|E))))))))))|S)|E)|ESSSWSSW(NNNEWSSS|)SW(N|WSSSES(WSWNNWSSWNW(NNNENESS(WS|ENN)|SWSSSS(WNWNENWWSSW(ENNEESNWWSSW|)|ENNNESSENN(SSWNNWESSENN|)))|EENNENE(SSWSEEENW(ESWWWNSEEENW|)|NNN(NNE(NNWSNESS|)S|WSSWSWWSES(NWNEENSWWSES|))))))|S))))|NE(EE|S))|SSENESSSWNWWN(N|WSSESS(EE(N(WNSE|)EES(EE|W)|SW(W|SS(ENSW|)SS))|WNW(S|NNN))))|EE)))))|E)|E)|SS)|W)|NNN(W|N)))|S)|EE)|E))))|E)|NWNENWW(NEEWWS|)S)|NN))|E)|E(E|N))|E))))|ESS(ENN|WSS))))|NNNNWWNEN(E(NNN|S)|WW))|E))))))|N))|E))|S)|WNNW(SS(SESWENWN|)WNNWWSES(NWNEESNWWSES|)|N))|SS))|S))|W)))))))|WW(SSSWENNN|)W)|S))|S))|ESE(EE|S))|NEN(WNEWSE|)E)|W)|W(W|S)))|NN))|WWSESWSESWWWWNNENE(SSWENN|)NWWWNN(E(NNE|SE)|WW(SESSSWWSW(NNEENWWW(EEESWWEENWWW|)|SSESE(SWWW(W|N(N|E))|ENE(EESSENN(SSWNNWESSENN|)|NWN(ENNEWSSW|)WS(S|W))))|N)))|E))))|S)|S)|W)$ diff --git a/2018/src/day20.rs b/2018/src/day20.rs new file mode 100644 index 0000000..2f90983 --- /dev/null +++ b/2018/src/day20.rs @@ -0,0 +1,118 @@ +use std::io; +use std::io::BufRead; +use std::collections::BinaryHeap; +use std::collections::HashMap; +use std::collections::HashSet; + +type Pos = (i32, i32); + +fn add(a: Pos, b: Pos) -> Pos { + (a.0 + b.0, a.1 + b.1) +} + +struct Room { + conn: Vec<Pos>, +} + +struct Chart { + rooms: HashMap<Pos, Room>, + stk: Vec<Pos>, +} + +impl Chart { + fn new() -> Self { + let mut hm = HashMap::new(); + hm.insert((0, 0), Room { conn: vec![] }); + Chart { + rooms: hm, + stk: vec![(0, 0)], + } + } + + fn save(&mut self) { + self.stk.push(*self.stk.last().unwrap()); + } + + fn restore(&mut self) { + self.stk.pop(); + } + + fn walk(&mut self, dir: Pos) { + assert!(dir.0 == 0 || dir.1 == 0); + assert!(dir.0.abs() + dir.1.abs() == 1); + + let pos = *self.stk.last().unwrap(); + let newpos = add(pos, dir); + match self.rooms.get_mut(&newpos) { + Some(newroom) => { + if !newroom.conn.contains(&pos) { + newroom.conn.push(pos); + self.rooms.get_mut(&pos).unwrap().conn.push(newpos); + } + } + None => { + self.rooms.insert(newpos, Room { conn: vec![pos] }); + self.rooms.get_mut(&pos).unwrap().conn.push(newpos); + } + } + + *self.stk.last_mut().unwrap() = newpos; + } +} + +fn floodfill(chart: &Chart, mincount: i32) -> (i32, i32) { + let mut pqu = BinaryHeap::new(); + pqu.push((0, (0, 0))); + + let mut seen = HashSet::new(); + + let mut highest = 0; + let mut count = 0; + + while pqu.len() > 0 { + let (md, pos) = pqu.pop().unwrap(); + let d = -md; + if seen.contains(&pos) { + continue; + } + + seen.insert(pos); + + highest = std::cmp::max(highest, d); + if d >= mincount { + count += 1; + } + + for p2 in &chart.rooms.get(&pos).unwrap().conn { + if !seen.contains(p2) { + pqu.push((-(d+1), *p2)); + } + } + } + + (highest, count) +} + +pub fn main<T: BufRead>(reader: T) -> io::Result<(String, String)> { + let regex = reader.lines().next().unwrap().unwrap(); + + let mut chart = Chart::new(); + for c in regex.chars() { + match c { + '^' => {}, + '$' => {}, + 'N' => chart.walk((0, -1)), + 'E' => chart.walk((1, 0)), + 'S' => chart.walk((0, 1)), + 'W' => chart.walk((-1, 0)), + '(' => chart.save(), + ')' => chart.restore(), + '|' => { chart.restore(); chart.save(); }, + _ => panic!("Unexpected character in input"), + } + } + + let (part1, part2) = floodfill(&chart, 1000); + + Ok((part1.to_string(), part2.to_string())) +} diff --git a/2018/src/main.rs b/2018/src/main.rs index 1c38fad..dece97e 100644 --- a/2018/src/main.rs +++ b/2018/src/main.rs @@ -24,8 +24,9 @@ mod day16; mod day17; mod day18; mod day19; +mod day20; -static NUM_DAYS: i32 = 19; +static NUM_DAYS: i32 = 20; fn day_switch<T: BufRead>(day: i32, reader: T) -> io::Result<(String, String)> { match day { @@ -48,6 +49,7 @@ fn day_switch<T: BufRead>(day: i32, reader: T) -> io::Result<(String, String)> { 17 => day17::main(reader), 18 => day18::main(reader), 19 => day19::main(reader), + 20 => day20::main(reader), _ => Err(Error::new(ErrorKind::Other, "Invalid day")) } } |