-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdventOfCode2018Day20.java
88 lines (77 loc) · 15.9 KB
/
AdventOfCode2018Day20.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.*;
/*
* Parse the input, take a character.
* If the character '(', push the current location on the stack.
* If the character ')', pop from the stack.
* If the character '|', peek from the stack.
* Keep rooms in an array and use path variable to know
* how many doors this room is from the original location.
*/
class Room {
int x;
int y;
int path;
Room() { x = y = 0; path = 0; }
Room(int x, int y, int path) {
this.x = x;
this.y = y;
this.path = path;
}
@Override
public boolean equals(Object r) {
return (x == ((Room)r).x && y == ((Room)r).y);
}
}
public class AdventOfCode2018Day20 {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
String regex = s.nextLine();
s.close();
int index = 1;
Stack<Room> stack = new Stack<>();
ArrayList<Room> rooms = new ArrayList<>();
Room curr = new Room();
while (true) {
Character c = regex.charAt(index);
if (c == 'N') curr.y++;
else if (c == 'E') curr.x++;
else if (c == 'S') curr.y--;
else if (c == 'W') curr.x--;
else if (c == '(') {
stack.push(new Room(curr.x, curr.y, curr.path));
index++;
continue;
}
else if (c == '|') {
curr = new Room(stack.peek().x, stack.peek().y, stack.peek().path);
index++;
continue;
}
else if (c == ')') {
curr = stack.pop();
index++;
continue;
}
else if (c == '$') break;
Room r = new Room(curr.x, curr.y, ++curr.path);
if (!rooms.contains(r)) rooms.add(r);
index++;
}
// find a room with the longest shortest path
Room answer1 = null;
int max = Integer.MIN_VALUE;
int answer2 = 0;
for (Room r : rooms) {
if (r.path > max) {
max = r.path;
answer1 = r;
}
if (r.path >= 1000) answer2++;
}
System.out.println("Answer to the first part: " + answer1.path);
System.out.println("Answer to the second part: " + answer2);
}
}
/*
^SESWSSSSESWWNNNNNWNENNWSWWNNWSWNWSWSESWSESENNNESEESWWSESSSSSESWWNWSWWNWSWWSESWSEENEN(W|EEEEESEESEEENNWSWNWWNEN(WNNW(S|NENWNE)|ESEEN(ENESSSW(N|SSESWSSSEESENENWWWNEENWNN(W|ENENWW(S|NEEENWNWNENNWNEENWNENNESSENNNENESENESSESESWWSSEEN(W|EEESENENENNNWNNWNWNENNNWSSWWSESSESSWSESS(WNW(NNW(WNEE(NWWNWSWWNWSWNNWNEESEE(S|NWNENEENWWWSWNWNNNNENESESWSS(WNNSSE|)EEN(NNENWWNENWNENENWNEEEENNEEEEESWWSWSESSWSEESSESSWNWNWN(E|WWNWSSSW(SEEEE(NWNWSNESES|)ESESWWNWSWS(SSWW(WSES(WWNN|SE)|NENNN(E|WS(WNNSSE|)S))|EEEESESSWW(SEESSS(WNNWESSE|)SESSENNNWNENNW(S|NNEEENNNNNWNNWNNENEESSSS(SENEESEESWSESENEESSEENEENWWW(NWNEENNNNESSEESWSEESSSEEENNWNENESSSEESWSSWWWN(EENSWW|)WSSSSENNESESSSSESWSSENENEESSSWN(N|WSWSWSSSSWWSSWWSWNWNNWNWWWNWWNWWNWSWNWWSSE(SSWWN(WNWSWNNWSSSSWWSWSSWWSSEESWSWWN(E|NNWNWSWSSSENE(NWES|)SSSESENN(W|EEEN(W|NNENEESWSSW(N|SSSWWSSENEEENNN(WSSNNE|)NNESENNNNNNN(ESSSESSSSENESENENNNNWSSSWNNNNN(EES(W|ENEESWSSSW(SESWSESSENNNENEEESWWSSSSW(NNN|WWWWNN(ESNW|)(N|WSWWSSWWNENWN(NNNN|EEE|WSW(SESSW(SSENESEEEENESESWSESWWWWNN(ESENSWNW|)WSSWSSWNWNNE(ENWWWSSSSSE(ESSWNWWWWSESEE(NWES|)ESENESSESSWNWSWNN(E|WWWWWWNWNNWSSSSWWSSWNNWNEEENWWNNNENWNNWSWSESWSSS(ENNSSW|)WNNNNWWWWNENENNESSS(W|ENNE(NNW(S|WNNWWSESWWWNENNN(EN(W|EESES(WW(N|W)|EENNNN(EESWSSSESWSSW(SSENENNEENESESWSESSSENNENWNEESE(NNWN(NEES(S|W)|WSWNWNN(NNEEWWSS|)WWS(E|W(NNWSNESS|)S))|SSW(N|SW(N|S(EENSWW|)WSW(NWWS(E|W(SSWNSENN|)NNNN(WSSNNE|)E(ESWSE|NWNE))|SES(W|ES(W|EEE))))))|NNWWSE)|WWS(WNWW(SEWN|)NWNENEEENWNEEE(SSSW(WS(WWNEWSEE|)EE|NN)|ENWNWNEESENENWWNWSWWWSW(NWNENWNENEEN(WW|NNNESSE(SSSEEEESEN(NWES|)ESSWW(SSSES(ENNN(WSNE|)E(NENE(SSWENN|)NN(WSWSNENE|)EEEENWN(WW(S(W|E)|NN)|ENNENWNNENWNN(W|EENNENWNNESEN(N|ESSESWSESSENEEN(WN(WS|EN)|ESSESEESENNWNN(WS(WNSE|)S|EEN(WW|NNNWW(W|NN)|ESSW(W|SESWSEEESE(NN|SSSSS(SWSSWNNNWWWNEENENE(NWNWWSESWWWS(WSESWSWWNWNWWNNNNWWWSWSESWW(SES(WW(SS(S|WW)|NN)|EEN(W|NE(NNWSNESS|)SSEES(W|ESEEEEEESE(NNWWWEEESS|)SSE(NEENNSSWWS|)SWWNNWNWWW(EEESESNWNWWW|))))|NNN(ENWNEN(NNE(NN|SESWSES(ENEEE(NWES|)ESWSSEEN(W|NESES(ENSW|)WSWSW(SESNWN|)NWSWNNNNW(ESSSSEWNNNNW|))|W))|WW)|W))|EE)|SS(W|S))|E)))))))))|S)|W(W(N|W)|S))|WNW(S|WWWSWWNNE(ENNSSW|)S))|N(N|E)))|SEE(S(E|WWWSS(WSW|EN))|N)))|ES(W|S)))))|WWSS(ENSW|)SSSSSE(ENWNEES(NWWSESNWNEES|)|SWWNWNWNWSWWWSEESESESSSSENNNN(NWNWESES|)ESSSSENNEESWSSEEN(W|ESSSSESSENENE(SESSWSWSESWSEENENEESSW(N|SW(SEENEEENNNENEENWNNENWWSWNWNN(EES(W|ENEES(W|SESENEESSENESENNESSSWWSSSESEESWSSWNWN(WWSSE(N|SSWSWSS(WWWWNEEENNEN(WWNENNE(SS|NNWSWSSWSWSWNWWN(EEENWNEE(S|NWN(WSWSSNNENE|)EE(S|NNN(ESSSEEE(SWSEEWWNEN|)NWWN(NN|EE)|W(SS|W|N))))|WWSWWSWSSSWS(EENNESSEEEEENWWWWNNN(WSWENE|)E(SSENE(NWES|)SEEN(E(SENSWN|)N|W)|N)|WWWNWSWWWWWWNNNWSSSWWNWSWNWWWWS(WNWSWWNNWWSESWWNWWWWWNNWSSS(EEEEE|WNWSWWNENENNWNEEENENENWNNENNWWNNNWWNWWWSSWSSEEN(W|NNESSEE(NWES|)SSWSSSWNNN(NEWS|)WSWWWN(NWNWSSESSWWN(WNNNNE(NWWSWNWWWWSWWNWNNEENWWWWNWSWWSESSWSSESENESSESWWNWSWNWN(WSWNWSWW(NENWNENESEES(WW|ENNWNE(E|NNWNWWWSW(NNEENESEEENWNW(WWWNW(SSEWNN|)NNNNNEEESESWWSESW(WNNNEWSSSE|)SEEEENWWNEEEEESWSSSES(EENWNWNEENEENEEESEESESSSWNNWWSESSSEEEN(WW|EESWSS(WNWWWS(EE|WWNENWNN(ESNW|)NNN(EE|W(NEWS|)WSW(W|SESE(NN|S(SSSW(W|S)|WW(WW|N)))|N)))|EEN(EE(EENWWWWNNENESES(EENWNWNWWWWWW(SES(ENEWSW|)W|NENWWNWNNESESENNNW(S|NEENEESWSESESESWSS(ENEENESSEESEEENWNEESSEENWNNNNNWWSWWNWWWSWNWNWS(WNNNNNESEESENNEESEENNENWNENWNEENESE(NNWNNWNNENNWSWWNENEEENWWWWWS(WWNNE(S|EENENESENNESSES(WWWW|SESSEE(NWNNNNNENEEEENNNNNWWNWNWWWSWWSESEEN(E(NWES|)ESSENESSSWWWWSWSS(SS|WNNWNNN(NWSWNWNNWSSSESEESSWSWWWS(E|SWWWSSSSWNWNNE(S|NWWNNNENWWNENWNEEENWNWNENNNWWWWSESWSEE(NNESNWSS|)SWWSWNWNENWNWSWWNNNES(EENWNNESEEENWWNWWWWWWNWSWSWNWSSWNNNWWNWWWNENNNNNNESSSSSES(W|ENNNEEEEESSENESSEENNNENWNENWWWWWSEESE(N|S(SS|WWNWWWWWWW(SS|NNNNWWNNESENNWNNESESSEESWSW(N|SSES(W|EEENNNW(NEENNEESSW(N|SS(WNSE|)ENESENESENNESESENEENWNWNNNNWNEEESENENNWWWWNWSS(WSSSWNWWWSESW(SESE(SWWNSEEN|)NN(N|ESSENE(SSEWNN|)N(W|N))|WWWNENE(S|NWNENENWWSWSWNNWSWNWNENWNWNNESESEENESESS(EENNEEEEENNNNEESSW(N|SSENENEENESEESWSWWW(NEEWWS|)WSEESS(WNWW(SEWN|)NWWWS(EE|SWWW(NEENWW|SSS(WNSE|)EENWNEE(WWSESWENWNEE|)))|ESEESWSSW(SESENEEENENWNEESSESEESSWWN(E|WSWN(NEWS|)WWSESWSWSEENESSSEEESWWSSWWNN(ESNW|)NNWWWNWWWW(SSESSENEEEN(ESSWWSW(SSSWSSWWNWNEE(S|NWNWSWNWNNEES(E(EES(W|S)|NNWNNWSWWW(N|SSE(NEEWWS|)SWSW(SW(N|SESENEE(ESWSEESEEEEENN(WSNE|)NNEN(W|NESESENEENNEENENWNWNNEN(WWW(W|SESSWN)|ENNEESWSEENEESENNENESENEENNWSWWWWNWSS(E|SWNNNNWSSWS(ESNW|)WNW(NENWNEE(NESENNNNWNWSSS(ENSW|)WSWWNNWWNEEES(S|ENNNWWS(E|WWNWSSWNNWSSWW(SW(N|SW(WNEWSE|)SEEES(ENNESEN(ESE(N|SESWS(WNNWW|ESW))|NWWWSW)|WSSE(SWWNSEEN|)N))|NENNNNNNN(WWWWWSWNWWSSWNNWSWNWWWWWSSSSEENNEN(WWSSNNEE|)ESES(WWSSENESSWS(E|WNWWS(E|W(SS|NW(N(WSWNNNWNWSWSEESS(WNWWNWWWSWSWSSWSWWNNWNNNEEEE(SWWS(ESWS|WN)|ENEEENE(S|ENN(WWWWWSWWSWS(WWNW(NNESE(NE(EE|S)|S)|SSSSSSESSSSW(SESSEENWNENENWW(S|NEEESENN(ESESSW(SWW(NEWS|)WSEESSE(SSWWWNN(NESSEWNNWS|)WSSWNNWW(SESWSESWSSEEEESSENE(SSWSESSWNWWWWSEESSWNWSSSW(NNNNNNNNNESENESSWS(WN|EEN)|SESWSSSSESESSSSWNW(NN(ESNW|)N|SSEEEEENEESSW(SWSEENESSESESSEENWNNNESES(ENNNNWNENNNWSWNNNNWSSSWSSWW(NENNWNNWNWNNNESENESSES(ENEN(EEN(W|ENEES(EENWESWW|)SSSWNN(WSWSESEESWWS(SENEENEESSESSWWN(WW(NEENSWWS|)SSSSWSW(SEENEENEEEESWWWSWSEENESESSSWWNWSSESSENEN(ESENE(NWNN(ESNW|)NNNW(S(W|SSSS)|N(E|NNNN(NEEWWS|)WSW(SS(ENSW|)WWWW(N(N|EEE)|S)|N)))|ESESSWNW(N|SSSENESESWSEESENNNNW(SS|NW(NEEE(NWW(NEEWWS|)W|EESWW(SESWSS(SSSWNWWWSWSES(ENE(NWES|)EES(S|WW)|W(SEWN|)WWWWNWWWWWWSEEEEESEESWWWWSWS(SSWWWNWSSEES(WWWNNWWNWNWWWWNWWSESESWSEEES(WWWWNNWN(WNENNNWNNNNWNWW(NENWNENWNNNNESSENNNNENNESENESEN(NWWWWNNN(E(E|SS)|WWSSE(SWW(NNN|SES(EN|SSWNN))|N))|ESSSSWNNWWSESWWW(NENSWS|)SEEESSSSSEESSWSWSWSW(SEENESEEEEEEEENWNENWWWNEEENWNNESEENESEESSWNWSSEEENNESESEEE(SSWNW(WW(WWWWWNW(NENWESWS|)SSSSWSWWN(E|WWWWWWWWSEEEES(W|ENESE(SESENEEN(EN(W|E(SSSWNSENNN|)N(E(EE|S)|W))|WWW)|N)))|N)|S)|NE(EE|S|NNWWNWWNWSW(SEESE(SENEWSWN|)N|NN(EENESE(SWEN|)N|WSW(SEWN|)NNENWNWSSSWS(W(S|WNNE(NWNNNWW(SSSSSE(NNNN|SWSWNWNWSSSW(SSSSES(EN(ESENSWNW|)NWNNE(S|EENWWN)|WWN(W|N))|NWWNNNESE(SWEN|)NN(WW|NN(NN|ESEE(NWES|)SS(WWNEWSEE|)S))))|NEENESESS(ENE(S|N(EEESNWWW|)WN(N|W))|S(WNNSSE|)SS))|S))|E)))))|NNENN(NWWS(ESWENW|)WNNNN(EEE(NWWEES|)SWS(WNSE|)E|W)|E(E|S))))|SESESWW(SEESSWSE(ENSW|)SWS(E|WNNNNE)|N))|E)|ENN(NWSWNSENES|)ESSE(SWWS|ENW))|S)|EENEEE))|ENE(ENWNSESW|)S)|W))|S))))|W)|NNNNE(NWES|)SS)|E)|WNNW(N(W|N)|SS))|N))|WWNNWN(E|WNWWSES(WWSSWWW(NENWNNEENN(ESSSW(W|SS)|N)|SS(WNNSSE|)EEN(ESSESSWNWW(SSE(N|S(WSEWNE|)EEEN(WW|E|NN))|N(E|W))|W))|E)))|W(WNWESE|)SES(S|W))|SSEEN(ESS(WWSESNWNEE|)E(ESNW|)NNN(WNSE|)E|W))|W)|N)))|N(NNWWN(WSS(EESNWW|)W(W|NN)|EE)|EE))|NN)|NEN(W|EENE(NWW(SWEN|)NNE(NWWNENWN(ENW|WSWSE)|S)|ESE(EESWWSWW(SES(W|ENE(SSWENN|)N)|N(N|E|W(S|W)))|N))))|N)|W))|NNN))|EENEENE(EE|S))|EEES(SEE(NWNE|SWSE)|WW))))|S)|EEE)|S))))|E(N|EEEN(N|ESS(WSEWNE|)ENNESSEES(W|E(NNNNWSSWNNW(ESSENNSSWNNW|)|S)))))|ESSSEEENESSEEEES(WWWW(S|WNWWS(WNSE|)E)|ES(EEEESSSEEENNNNEENWWWNEENENN(ESSS(SENNNNESSSEEENNESESENEESESEEEENNNWSWS(WNWNN(ESENEEESENEESSW(WSESSWNW(NN|SSWSSSEENESENNENNENWN(NNEEN(ESSWWSEESSW(N|SSENEESWSWWW(NN|SESS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SW|)WW|N)|WS(S|W)))|NEEE(SWEN|)EN(ESENSWNW|)W))|N))))|W))|WW(SEEWWN|)WNW(S|NNNE(NNW(S|W)|SES(W|SENNES)))))|NN)|E))|N)|N)))|E(NN|E)))|ESESWS(ESWENW|)WW(NEWS|)W))|ENESENEENENNNEN(WWSSSWNWNWNNESE(NEN(ESNW|)WWWWWWSW(N|SEEE(NWES|)S(W|SSSEN(ESEWNW|)N))|S)|ESSESSWW(N(E|N)|SEESEESE(NNNWSWN(SENESSNNWSWN|)|SSSS(EN(ESSSSES(WWWNNNESS(NNWSSSNNNESS|)|SENENWN(NW(NENWESWS|)S|EESSS(SSWNNSSENN|)EENWNEN(N|W)))|N)|WNWWS(E|WWNENNW(SWSW(SSE(SE(NEWS|)S(W|SSESSSWN(N|WSSESEEN(NN|W)))|N)|N)|NE(EESS(WN|EN)|NWW(N|WW)))))))))))|ESENN(W|E(SSSWWEENNN|)E))|E))))|N)))|NNNWWW(SSENES|WW|NEENW(NN(N(N|W)|EES(W|SS))|W)))|W)|W)|N(N|E))|N)|NN)))|WWWWSSWWNENWWSSSESESWSEEENNN(NNESSSE(E|SWSESWSEE(NESNWS|)SWSESWWWSEEESWWSS(EENWESWW|)WNWSSS(ENESNWSW|)WNNNWWWWNENEENWNNNWNE(EEESSWNWSSEE(EN(ESNW|)NN|SSW(S(EE|WW)|N))|NWWW(NENNNE(SSSENSWNNN|)NNWWS(E|SWW(NENWESWS|)SSSENENW(ESWSWNSENENW|))|SSE(SWW(N|WSEEEE(SWSWSWSESEESS(ENE(NWES|)S|WSWWNWNE(E(E|S)|NWNWNENEN(WW(NN|S)|E)))|N))|N))))|W(SS|W))))|WW)))|WW)|WSSSWSW(WSNE|)N))|N)|WWWW(SEEEWWWN|)WWWWSESW(ENWNEEWWSESW|))|E)|W)|WWWWWWWWWWWSWNWS(SSENEES(ENN(EESESEE(NEEN(WWW(S|W)|E)|SWWWNW(S(W|SEEEEESSSWNN(SSENNNSSSWNN|))|N))|W)|W)|WWN(E|WWSESW)))|W))))))|SS)|S))))|NW(N|W)))|NNNN)))|W))|N)|WWWN(W|E))|NNWNWNN(N|EES(E(NN|S(SSENEE(SWEN|)EN(WWWNSEEE|)N|W))|W))))|NN)))|W(S|WN(WSNE|)E))))|EEEE))|WS(ESWENW|)W)))))))|S)))|EES(WSEWNE|)ENE(SEEWWN|)N))|W)|ESEE(NWES|)SSWW(N(WWN(WWSW(NNENSWSS|)S(ES(WSNE|)EN(N|EE)|W)|E)|E)|S))))|E)|SEESSSWNWWN(EE|NWSSSSSESSS(ENNESSSWSSESEESSSEESSWWN(E|WNNW(N(WNSE|)E|SSSESWWWSWWNNWSWNWWW(NN(W(NWSNES|)S|ESEEEEEEESWWS(NEENWWEESWWS|))|SSS(WNSE|)ESEEEN(NWSWNWNE(WSESENSWNWNE|)|EESSENNENEESSW(WSSWSWSW(NWWNEE(N(N|WW)|E)|SSS(W|SEEEENWNENNEESWSESWSESENESSENEENESENNENNWWWWNWWW(SESE(EES(ENEWSW|)WSWNWWN(SEESENSWNWWN|)|N)|NEENWNNWSW(WSE(SWW(NN|WSSW(WSESWENWNE|)N)|E)|NNNNEEEEESESSSWSW(NWNNWN(WSNE|)EESSEN|SESEEEEENWNNWNW(NENENE(NWWNNWWWWNW(SSSEEN(W|ESE(S(E|W|S)|N))|WNENNNENNNNWSWSESWSWS(ESWSSNNENW|)WNNNE(NWNNESENNNESSEENESSSSENNNENEEE(NNWNWWN(EEESNWWW|)WNWSWWNWN(EESNWW|)WSWSEESES(ENEESS(S|EE(NWES|)E|W(WWSNEE|)N)|WWWSW(S(WS(SSSSS(W|S)|WNW(WNEWSE|)S)|E)|NN(EE|N)))|ESWSESWWNW(NEWS|)SW(N|SSE(NEEEE(SS(WNWWEESE|)S|NNNN)|SWWWN(E|W(NNN|SSSS(WNNSSE|)SEN(EES(ESSENSWNNW|)W|NN))))))|S))|SSENESEE(NWES|)SEEN(ESSWSSWSWSESSEEEESSWSSEEN(W|EEN(WWNNNWWWWNN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