-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday22.clj
160 lines (149 loc) · 33.4 KB
/
day22.clj
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
(ns aoc.day22
[:require [clojure.string :as str]
[clojure.math :as math]
[clojure.set :as set]])
(def input " ................................#............#.....#..........#.........................#........#.#\n .........................#.........##..#..#.#........#.#........#...........#....#...........#.#....\n .......#......##........##.....#.........................#.............#..................#.........\n .....................#..#.#.....##.......#.#...........#..#.....#......#..............#..#...#......\n ..........#...................#.....#.....................#...........................#.............\n .............................#.....................#........#...#.................#.......#.........\n ..............#...#..#.......................##..................##.#.......#........#..............\n .#.........#...........#.#...............#....##...#...##.............#...#...........#....#........\n ...#.................................................#...........#.............................#..#.\n ....................#......#......#..................#....................#..................##.....\n .....#...#.##..................#.............#.........#.##.............................#.#...##....\n ...#......#..........#.....................#....#........#...#...........##.#.....#......##.........\n .........#.....#.....#.....................#..................#.......#................#............\n .##.......#........#................................#.....#.#.......#...............................\n .........#.........#.......#...#...#......#.......#.#......#.......#......#.........................\n .#.#....#..#...............##..........##.#..#...............#..............#..#....................\n ......................##.............#......#......#...#..............#.............##...##.........\n #..........................................#.......................................................#\n ...........#........#...................#...........................................#...............\n ...#....#.......#..............#..........#............................#.......##..............#.##.\n .......#..................#..#......................#....................#...#...##..........#.##...\n ................................#.........................................##.#..........#........#..\n .......#..............#..#..........#..#....#....#.....................#...#..........#.......##....\n .#..#.......................#.#........................................#...........#...##.#.....#.##\n #.#............##...............##.............#........##...............#.....#...#................\n .........................#..#.......#......................................#.............#..........\n ..........#.#..##..#.........#.#.............#..#.....#......#..#......#.......................#....\n ......#...........#.#.......#........#.#...............#..........#...#..............#...........#..\n ........##.............#.#....#...........#..#............#...#....................#..........##...#\n ........#...#.......#...#..............#...................#...........##.....#...#...........#.....\n .....#....#...#................#..............#........#.....##......#..#.........#..#............#.\n .....#.#....#.....#.......#.#.......#.............#.##........................#..#........#.##.#...#\n .............#...........##........#..................#........#...............#....................\n .#.........#......#.........#...###.#.#......................#......#...#.............#...#.........\n ..................#..............#...#....................#....................#....................\n ...............#....................#...#..............#............#..#.#......#..#..#.............\n ....#.....#.........##..#..........##................##....#..............#.........#.#...#.....#.#.\n ...............#....#........#.#.......................#...#..........#...................#.........\n ..........#.........##..........#............#..................#.....................#....#..#...##\n ........#.............#.....................#..#............#......#.#..............#........#..#...\n ............#............#.........#...............##..##....#...#...........##....##...............\n .....#..#..........................#..#.....#.............#....#......#.....................#.#.....\n .................................#....##.......................#.......#...........#.#....#.........\n ...#...#...........#..#...............................#............#.....#....................#...#.\n .......##...#...#...#........#.#......#.....................................#.......#..##...........\n ..............#.#....###................#...........................#.................#.............\n ...#.......#..#....#.......#.......##.....#.......#.............#...............#..#................\n ...................#......#.......#..#.#..#....................#...............##...........#.......\n .#.#.................#.#..#.#........................#.........................#.............#.#....\n #...#.........................#........#..............................#...#......................##.\n ..................................#..#.##.........\n .#.......................##..#...#...#.......#....\n ........................##................#......#\n ......#.......................................#...\n ...#..........##.....#....#.#..#.........#.......#\n ........##...#....#..........#...#........#....#..\n ....#..#....#.#....................#..............\n .#.....#....#......................##......#......\n ...##.....#........#.....#.#............#.........\n ..................#....#........................#.\n ..........#.....#......##.......#..#.#.....#......\n ......................##...#......#......#....#...\n ##..............#........#......#..............#..\n ...............#...#.....................#..#..#..\n .................#.........#...##.....#..#.....#..\n #.#....#..#...#...#...##.....#....................\n ...#..#...#.................................#...#.\n .#...#............................#.....#.........\n ...................#....#..#...............#..#...\n .....#.............#................#.#..#...#....\n .............#..#..#.....#..#.#.#.................\n ..........#...#..........#..........#........##...\n ......#...................................#..#....\n #.............#.....#........#.#.....#..#...#.....\n ............##................#..........#........\n ..................##............................##\n .#.......#.#..........#.............#.............\n ..........#.............#....#..#.........#....#..\n .................#......#...#..........#.##.......\n .................#....................#......#.#..\n #.....#...........#.#..............#......#.......\n .......#....................#..##..........#..##..\n ..#....#.....#.........#..........................\n .#.#........#....##....#..........##..#...........\n ##...............#.............#..................\n .#.....#..#........#........#..#.......##.........\n ....................#....#............#...........\n #.##......#....#...#...#..#.#.......#.............\n ........#.....#.##...#...#....#.............#.#.#.\n ..........................###...............#.....\n .....#...........##.............#.#.##.....#.....#\n ....#.#................##..........#.....#..#.....\n ..............................................##..\n ......#.....#...............#........#............\n ....#...##.........#..#.....#........#...#........\n #....................#.#...#.................#....\n ..#...................................#.........#.\n ........#..........#...............#....#........#\n .......#.........#....#....#...#..................\n .#...................#......#..........#..........\n............#.#.......#...........#...##...............#...#.#...#.....#........#..#....#...........\n....................##...........#...........#..........#..........#....#....#............#.#.......\n#..................#........#.......#................#.....#.#......##..#.............#.........#...\n.##.................................................#........#...#.......................#........#.\n.#...................#........#..#..#...#............#.........................................#.#..\n....#.......#...#....................#......#....#.#.#........#.##.#.#..#.......#........#........#.\n......................#................##...#.#.......#..#..#.##..#......#...#...#..................\n...#...............#..#.......#.......#..#........................#..#........#..#...#..............\n...........#.....................##...................#..#.....#..............#...............#.....\n..........#......#........#....#......#.................#...........................#.............#.\n#..###............#.......#....#.#.#.............................#...#...#.##..............#....#...\n.............#.#.....#...............................#...................#........#.................\n..................#.................................#..#...................#...#....................\n.....#..#.........#......##...........#.......#......................#..............##..#...#.......\n.....#....#.........#..........#....#......##...#.#............................#...............#....\n.....#...#.#...#..#.#..............#.......##..........#...........##............#.......#..#.....#.\n#.....#............##............................#........................##.#.....................#\n.............#...#..#........##...............................#...........................##........\n.#.......#....#.........#.............#...#.#...................................#.....#...#......#..\n................#...........#..#......#...............#......#..#............#....#...............#.\n..#........................#...............................#..........................#.#....#......\n.........#.............#......#........#...#...#.....#.......#....#..##..#..#..................#....\n...........#....#...#.......#............................#.....##......#....#.......#.............#.\n.........#......................#.....#..........#..............#.......................#......#....\n..............#...........##...........#...........................................#................\n...............................#....#...#......................##...........#..............#...#..#.\n......#........#........#.................#.#...#........#........#..#....................#.........\n...........##..............................#...........##.............##.............#..............\n...#..###......................##...........#......#.......#..#..#........................#.#...#...\n................#.....#........#.....#....#.#...#.#......#.........................#................\n....#........##.....#..........................................#..........#...............#.......#.\n#.#.......#.#.......#...........#...........##..#..........................#.....#...........###.#..\n#.........#.........................#...................##......#........#..........................\n....#.......#...............................#.#..................................................#..\n...................#............#...#.....#.....#......#..........#..##.#........#..................\n.......#........#....#.....#.........................#.#.................#..#.........#..........#..\n.#..........#...#.......#.....#.......................#.......#....#..........#......#..............\n..#..#.#...........#.........#......................................#...#.......................#...\n..........................................................#.....#.....................#.............\n...............#......#.........#...........#.#.....................................................\n.#.#.......##...........#..........#..#......#.............#...............................#....#...\n.......#...#....#......#.......#...#....................#.....#..............##.....................\n.................#....#............#..................#.............#...............................\n#.......##...#.#....#..#...........#....................#.#...#..........##.#................#....##\n.....#.......#.........#............##..#...............#..........#......#................#...#...#\n.....#..........#.#.#....#............#...........#...........#......##....................#........\n..............#.......#...#................#.........#.#.#...........#.#...#........................\n........#.........#........##...#................#......#.....#.....#...........#...................\n.........................#...........................#.............#.......#....................#...\n.....#................................#.....#......#.........#........#.............#...#...........\n.........................................#.....#.#\n......#........................#.........##....#..\n.........#.............................#..........\n.....#..........#........................#........\n.............#................#...................\n...#...#..........#......#............#...........\n.###................................#.............\n..........#........................#..............\n..#...#.........##...........##....#..............\n............#.......#.............#.........#.....\n..#......#....#..#....#..#....#.....#......#......\n#.................................................\n.......#.#............#..............#...#........\n..................................................\n........................##.......#...........##...\n.#.............#.#...............#..#.............\n............................................#..#..\n.................##....#.....#..........#.........\n.............#.....##.....................#.......\n...#...........#............#..#.........#.#...#..\n.............#.......#.......#...#................\n...............##.................................\n............#.............................#.......\n.........#....#..#.....#..........#..........#....\n#.........#..............#.......#.#.........##...\n...#....................#.#..............#........\n...##........................##.#...#...#......#.#\n...........................#.......#..............\n..........#....#.................#.....#.......#..\n.........#.......##.......#.#....#.......##..###..\n#....................#......................#.....\n.............#...#.##................#.#..........\n.........#...#......#....#........................\n#....#..........#.....#............#...#..........\n..........#...#...#...............................\n.................#...............#..#.............\n#.................................#......#........\n.......#.#....#..................#................\n.##...........#...........#........#.#.....#....#.\n........#..#.................#..#.#.....#.......#.\n.......#..............#...#.........#.............\n.......#..#.............#...........#.#....#......\n......#..#...........................#..........#.\n.......#...#........#..#.....#....#.......##.#.#..\n......#.......#........#.........#..........#.....\n.....#..##....#...#.#..........##.........#..#...#\n#......##.....#...........#..#....#.#..........#..\n...#.........................#..#...........#.#...\n#....#...............................#............\n........#.........................#........#....#.\n\n23L34R4L9R5L23R42L32L17L25R37R35R40R44R3L37R13R12L28R39R23L34R28L39L45L23R35R22R22R16R4R12L11L16R50L36R32R20R15R9L42L42R33R44R14R5R11R4R13L29L11L3R33L8R16L48R8L32L33L7L25L36R7L40R5R28R22L18L12R12L28L11R14L6R37L7L46R26L35R29L10L32L18R9R47R4L27L42R19R38R43L29L33R43R27R18L28L11R3L39R23L47R41L40R47R43R39R25R9L27R34L24R18R39L42L37R29R29L39R19R23L49L9R50L19R33L36L32R27R50L47R40R20R10L18L40R8L5R43R22R6L48R49R19R3L39L11R28R19L19R43L47L40L29L12L38R36R15L13L44R10L26L34R29R23L11L31L13R33L36R46R18R46R41R30R24R25L1L1R4R48L30R4R44L26L19R20L47R46L5R28L12R40L41R45R12L36R28R19R48R46R45L47R7R33L12L29R17L41L4L19L3R47R41L27L7R10R16R37R48L17L31R39L29L46L48L46L33R14R19R10L14L1R39R2R50L13L39L48R33L18R25L37L22L30R17L36R12R32L12L30R30R31R2L46L25L39R47R31R23L1L40L8L8L29R22R6L30R44L47L3L24L10L37L2L31L32L41L16L24R3L1R3R12R1R38L14L29L3R42L38R16R26L33R41R30L48L5L23R22R15L38L4L26L50R30L45R37R17L49R16L19L20R44L46R17R3R16L6R43L33L11L16R27R15L18L25L3L42L33R43R17R41R50L40R44R2R30R17R20L41R37L21R15L48R1L38L8R25R23R26L33L2L38R9L40R13L8L32L19L43L16L39R23R6R12R35L42L25R40R20R31R32L25L28R27R10R19R17L34L18R25R31L27R24L10R7L10L17R24R32L39R31L27R48L12L33R24R6L2L50L43R20R47R33R33L40R21R48L40R12L47L19L1R47R29R46L21L4R28L28R34L37L14L48L17R2R44R8R40R47L44R22L13L6L43R5L25L19R37R36L14L36R22L33R31L3R44R35R45R17L50L7L47R13L10R23L34L32L43R17L18L11R5L49L46R20L25R41R8R3R26R13R35L41L42L27R5L31L16L45L18L23R32R2R23L4R47L3R10R30L41L46R37R17R36L20R40L48R27L48L50R40R44L25L23L40L3L38L45R15R28R33R31L6R36L27L44L21R10L9R10L26L34L48L16R12L7L33L6R25L17R40L6L26R17R33R38L35R18R41L26R19L17R45R40R16L42L18L48L33L6R45R39R18R48L17R2L48R27R31L25L46L19L36R9L9R8L26L41L14L47R30L32R18L47L10L34R40L27L34R27R36L50R20L22R33R23R24L22L19L23L6L28R49R47R31R23R10L3R6R25L5R28R18R50L40R47L1L20L39R4R39L34R21R2R39L33R31R47L21L46R15R41R17R32L2R1R26R9L1L12L31L7R45L32L39R46R29R13R5L13R41R21R29L6L12L20L50R43L32L22R5R7R37L43L13R42R11R21R14R49L46L23L15L32L10L17L17R45L10L22L7R49R4L32R36L45R16L32R4L39R8L24L38R43R22R36R26L18R29L13L41L43L9R31L5L41R14R10L3L22R27R3L35R4L35R15L33L21R31R5L35R35L26R35R44L42L29R46L20L44R38L32L16L5L16R15R3R48L10L36R16L8R34L29L21R22R29R22R10L23R22R45L38L18R17L38L1R8R48L18R10L25L42R22L44L33L41R44L13L34R10L22R1R11L8R15L18R15L9L21R11L38R4R45R29R41L45L18R12L36L9R16L38R33R15L31R15L33L42R28R49R1R17R5R46L44L13L33L40L19R42L18R25L28R44R4R46L32L2R34L25L46L6R49R10L20R20R29R12L13L21L48R46L37R21R9R21L23L36L36R1L12L8L30L3R35R20R4R32L22L50L46L25R32L45R50R3R50R36R39R21R32R39R36L48L49R49L29L13L15R36R47L30L49L33R24L28L29L44R1R16R27L39R8R33R31L37L20L26R32L1R38L16L21L44L23L46R49R42R31R43R14L45L8R37R7L39L24L49R41L2L31R15L49L29L24L21L40R16L32L50R22L10R10L47L4R17L1R35R17R29R12L27L19L42L44L50R39R1L19L30L38R44L21L44L33L32R18L34L6R16L6L46L40R36L20L46L42L24L44L34L8L24R25L13R26L37R38L10L49R22L45R12L26L6R25R45L42L6R7L34L26R7R37L39L43R6R46L41L35L34R42L12L39L35R17L25L37L13L20R29R22R13L21L31L3L23L6L15L43R21L2L47R11R1L39R23R16L41L25L38L39L48L49R36L27R27R24L20L26L37R15L14R15R42R4R9L38R22R48R15R5L34L7R26L7L13L2R35R21R9L11L9L40L43R42L23L45R8R36R5L19R30R9L45R23R46L50L47R48L19R18R25R8L27R39R29L32L38R13L50L11R45L47L50R49L25L47R10R37R19L18L22R43R47R22L28R43L49R46R38L47R28R43L21L19R4L10L6L31L41R35R31L10R22R45R43L49L48L18L34R50L46L50L43R24R24R48R47L6R49R44L37L7L37R5R9R24L8L15R1L33R9R5R40R45R48L37L40R17R41L38L24L23L31L21R23L11L39R3L42R27L13R18L49L28R40L42L31L30R43R43R14R26L12L35R25L4L14L28R48L47R3L30R8L44R10L45R26L5L27L40R35L5R37L22R26R19R41L15L19L21R12R37L26L47L35L37R48L45L16R20R39R41R8R25R29L14R4R32R1R4L17L23R34L2L19R26L27R2L11R35R24L36L17R32L41R31R12L50R49L25R25L44L15L13L17L50L29R29L26L25L28R5R24R16R35R17L44R48R38R12R13R7L49R2L22R44R34R19L29L38L1R37R36R6L34L4L16R25R39L22R47L50L30R28L10L35R48R36L27L8L13L27L38L30R3R31L29L23L13R38L41R45R43L12L15L45L4L9L1R23R34R14L33R26L35R41L3R5R28L39R27L44R17R46L2L18R11R34R14L26R49R37R45L12R21R31R18L5R37L19L36L39R4R33R33R39R13R9R29R43R20L18R17L39R37L37R9R23L34L40R26R40L10R34R21L13L34L7L18R15L15R20R20L31R33L44L38R30R20R45L9L41L22R11L17L8R5L49R24R28R13R34R4R33L16R30L31L47R7L14R45R41R17R14L18R11R41R41R1L43L4R31L16L18R1R47L43R2L37R29R9L4L13R6L47L2R47R34R38L44L10L49R41L37R16R41R50R9L41L49L16R33L25L1R45L32L33L1R17L22R22R9R18R20L37L10R4L44L26L50R30L35R6R36R24L19L25L24L48L43R6L44L12R45R36L28R46R7L40R19L37L47L42R1L15R28L48R37R25L36R50L25L6L34R47R10L17L49R21L17L24R7R2R28L11R50L30L37L20L22L9L45R10R22L36R10L41R49L11R1R20R27L45R15L32L30L43L50R40L32L19R27L45L13L26R27R46R39L46L20L28L5L6R20R4L10L44L47R5R27L34L37L39R44L30R5R5L49L38R35L9L19R15L35L33R6R17L38R40L40R38R14R8L5R10R38R2L8R47R23R27L50L39R12L5R6R39R48R26R17R48L3R6L34R42R38L14L34R20L4L4L37R6R1L9R11R13L14R30R22R30R39R3R22L29L48R16R11L14R17R43R46L16R31L5L1R33L6L35R31R18L35L41L11R43L10R41R41R28L20L34L9L6L46R30L9L28R7R9L23L1L14R50L24R27R22L13R45R1L42R48R18L27L6R13R36L43L35R24R46R4R28L31L28L50R19L37L39R30R41L32L27L18L44R3L27R34R5R25L50L32R12R47R13L48L10L28R40L15L17L17R17L19L18L22R1R47R40R35L21R12R49L35L2R27L8R44R35L48L4L37L24R37L36R28L48L37R23R25R32R21R37L45R18R19L48R5L46L3L42R33L22L4R3L14L44L25R46L45R12R40L6L24L40L21L40R3L8R34L34L40R34L19R22L48R15L30L34R19L12L14R20L3L9R30R33R33R14L44L50L2R5R7R7L33L25L9L21R29R29L10R37R17L35L17L16L37L33L27L50R33R35L7R6R24R50R7R25R41R43L12R45L8R46L1R9L36L25R39L24L3R7R16L39L44R45L46L4R14L20R21R32L10L48R33L45R24R34L4L32R11R44L34R19R21R26L14R36L43L17L16R34L15L16R9R19R45R29R43L13L7R14R1L47L29L9R29L50R47L47L18R45R44L49L24L23R11L20L35L10L33L3L27R30R16R50L24R14L37R34L40L15R13R40L46L30L17L45L41L4R20R12R11L32R27R48L13L40L6R38L13L37L43R45R24L45L46R16L24L9R47L43R28L43L7R7R44R23R47R47L9R38L45L47R10R32R12L45R4R2L7R27R34L11R24L32R8L50L29L44R1R40L46L35L21R26R12L20L27L38L48R42L14L9L45L26L16R21R49R23R7R32L18R45R12R27R50L44L43L39R26R11L48L13R40L9R41L29R32L5L16L23L26L12L39R1R22L11L31R29R40L31L18R39R30L35R40\n")
(defn parse-input [input portals]
(let [[board-str instructions-str] (str/split (str/trim-newline input) #"\n\n")
board (str/split-lines board-str)]
{:board board
:coord [(first (keep-indexed #(if (not= %2 \ )
%1
nil) (first board)))
0]
:direction :right
:instructions (map (fn [s]
(if-let [n (parse-long s)]
{:move n}
{:turn (keyword s)}))
(re-seq #"\d+|[LR]" instructions-str))
:portals portals}))
(defn tile-size [state]
(let [board (:board state)
y (count board)
x (reduce max (map count board))]
(long (math/sqrt (/ (* x y) 12)))))
(defn teleport-coords [state]
(let [tile-size (tile-size state)]
(->> (into (:portals state) (set/map-invert (:portals state)))
(map (fn [[[from-x from-y from-edge] [to-x to-y to-edge]]]
(into (case from-edge
:top {:direction :up
:xa (* from-x tile-size)
:xb (dec (* (inc from-x) tile-size))
:ya (dec (* from-y tile-size))
:yb (dec (* from-y tile-size))}
:right {:direction :right
:ya (* from-y tile-size)
:yb (dec (* (inc from-y) tile-size))
:xa (* (inc from-x) tile-size)
:xb (* (inc from-x) tile-size)}
:bottom {:direction :down
:xa (* from-x tile-size)
:xb (dec (* (inc from-x) tile-size))
:ya (* (inc from-y) tile-size)
:yb (* (inc from-y) tile-size)}
:left {:direction :left
:ya (* from-y tile-size)
:yb (dec (* (inc from-y) tile-size))
:xa (dec (* from-x tile-size))
:xb (dec (* from-x tile-size))})
(case to-edge
:top {:transform (fn [[x y]]
[(+ (* to-x tile-size)
(case from-edge
:bottom (mod x tile-size)
:left (mod y tile-size)))
(* to-y tile-size)])
:new-direction :down}
:right {:transform (fn [[x y]]
[(dec (* (inc to-x) tile-size))
(+ (* to-y tile-size)
(case from-edge
:right (- (dec tile-size) (mod y tile-size))
:bottom (mod x tile-size)
:left (mod y tile-size)))])
:new-direction :left}
:bottom {:transform (fn [[x y]]
[(+ (* to-x tile-size)
(case from-edge
:top (mod x tile-size)
:right (mod y tile-size)))
(dec (* (inc to-y) tile-size))])
:new-direction :up}
:left {:transform (fn [[x y]]
[(* to-x tile-size)
(+ (* to-y tile-size)
(case from-edge
:top (mod x tile-size)
:right (mod y tile-size)
:left (- (dec tile-size) (mod y tile-size))))])
:new-direction :right})))))))
(defn teleport [state]
(let [{[x y] :coord, direction :direction} state]
(if-let [{transform :transform, new-direction :new-direction}
(->> (teleport-coords state)
(filter (fn [{xa :xa, xb :xb, ya :ya, yb :yb, dir :direction}]
(and (= direction dir)
(<= xa x xb)
(<= ya y yb))))
(first))]
(-> state
(assoc :coord (transform [x y]))
(assoc :direction new-direction))
state)))
(defn move [state]
(let [{[x y] :coord, direction :direction} state
state' (teleport (assoc state :coord (case direction
:up [x (dec y)]
:right [(inc x) y]
:down [x (inc y)]
:left [(dec x) y])))
blocked? (let [{board :board, [x y] :coord} state']
(= (get-in board [y x]) \#))]
(if blocked? state state')))
(defn exec-instruction [state]
(let [[instruction & instructions] (:instructions state)]
(-> (cond
(contains? instruction :move) (nth (iterate move state) (:move instruction))
(contains? instruction :turn) (update state :direction #(case [% (:turn instruction)]
[:up :R] :right
[:up :L] :left
[:right :R] :down
[:right :L] :up
[:down :R] :left
[:down :L] :right
[:left :R] :up
[:left :L] :down)))
(assoc :instructions instructions))))
(defn exec-instructions [state]
(if (seq (:instructions state))
(recur (exec-instruction state))
state))
(defn password [state]
(let [{[x y] :coord, direction :direction} state]
(+ (* (inc y) 1000)
(* (inc x) 4)
(case direction
:up 3
:right 0
:down 1
:left 2))))
(defn part1 []
(let [state (parse-input input {[1 0 :top] [1 2 :bottom]
[1 0 :left] [2 0 :right]
[2 0 :top] [2 0 :bottom]
[1 1 :right] [1 1 :left]
[0 2 :top] [0 3 :bottom]
[0 2 :left] [1 2 :right]
[0 3 :right] [0 3 :left]})]
(password (exec-instructions state))))
(defn part2 []
(let [state (parse-input input {[1 0 :top] [0 3 :left]
[1 0 :left] [0 2 :left]
[2 0 :top] [0 3 :bottom]
[2 0 :right] [1 2 :right]
[2 0 :bottom] [1 1 :right]
[1 1 :left] [0 2 :top]
[1 2 :bottom] [0 3 :right]})]
(password (exec-instructions state))))