-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay23.hs
238 lines (193 loc) · 3.59 KB
/
Day23.hs
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ViewPatterns #-}
module Day23 where
import Control.Arrow ((&&&))
import Control.Monad
import Data.Array (Array)
import Data.Bifunctor
import Data.Char
import Data.Either
import Data.Function (on)
import Data.Functor
import Data.Map (Map)
import Data.Maybe
import Data.Set (Set)
import Text.ParserCombinators.ReadP
import Harness
import ParseHelper
import qualified Data.Array as A
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Set as S
import Debug.Trace
main :: IO ()
main = getInputAndSolve (parseInputRaw parseLayout) id (const "Implement Part 2")
{-
22 days of programming, I think I earned a logic puzzle insted of
a programming puzzle, so I just did these by hand:
Pt1:
#############
#...........#
###A#D#A#B###
#B#C#D#C#
#########
#############
#A..........#
###.#D#A#B###
#B#C#D#C#
#########
#############
#AA.........#
###.#D#.#B###
#B#C#D#C#
#########
#############
#AA.......B.#
###.#D#.#.###
#B#C#D#C#
#########
#############
#AA...C...B.#
###.#D#.#.###
#B#C#D#.#
#########
#############
#AA...C...B.#
###.#D#.#.###
#B#C#.#D#
#########
#############
#AA.......B.#
###.#D#.#.###
#B#C#C#D#
#########
#############
#AA.......B.#
###.#.#.#D###
#B#C#C#D#
#########
#############
#AA.......B.#
###.#.#C#D###
#B#.#C#D#
#########
#############
#AA.......B.#
###.#.#C#D###
#.#B#C#D#
#########
#############
#AA.........#
###.#B#C#D###
#.#B#C#D#
#########
#############
#A..........#
###.#B#C#D###
#A#B#C#D#
#########
#############
#...........#
###A#B#C#D###
#A#B#C#D#
#########
Pt2:
#############
#...........#
###A#D#A#B###
#D#C#B#A#
#D#B#A#C#
#B#C#D#C#
#########
#############
#AB.B.D...AA#
###A#D#.#.###
#D#C#.#.#
#D#B#.#C#
#B#C#.#C#
#########
#############
#AB.B.....AA#
###A#.#.#.###
#D#C#.#.#
#D#B#C#D#
#B#C#C#D#
#########
#############
#AB.B...B.AA#
###A#.#C#.###
#D#.#C#.#
#D#.#C#D#
#B#.#C#D#
#########
#############
#AA.......AA#
###.#.#C#.###
#D#B#C#.#
#D#B#C#D#
#B#B#C#D#
#########
#############
#AA.......AA#
###.#B#C#D###
#.#B#C#D#
#.#B#C#D#
#.#B#C#D#
#########
#############
#...........#
###A#B#C#D###
#A#B#C#D#
#A#B#C#D#
#A#B#C#D#
#########
-}
-- SOLVE
-- positions like this:
--
-- 12 3 4 5 67
-- 8 9 0 1
-- 2 3 4 5
--
-- ?
--
-- Make a graph of all possible states, weight is amount of energy needed
-- to reach that state. destination is final layout.
--
-- if A*, heuristic is distance of all aphipods to their desired lanes
--
-- Given a state, find all possible moves for all amphipod, add the states
-- to explore.
--
-- Track amphipod type & position.
--
-- Where track position? in Array would be nice for checking valid moves.
--
-- Need Set for visited states, Map for distances
-- HELPERS
-- PARSE
newtype Layout =
Layout
{ lLanes :: [[Char]]
} deriving (Show, Read, Eq, Ord)
parseLayout :: ReadP Layout
parseLayout = do
parseWall <* newline
parseWall <* newline
parseWall
firstLine <- sepBy1 (satisfy isAlpha) parseWall <* parseWall <* newline
parseWall
secondLine <- sepBy1 (satisfy isAlpha) parseWall <* parseWall <* newline
let lLanes = L.transpose [firstLine, secondLine]
parseWall
void newline
return Layout{..}
where
parseWall :: ReadP ()
parseWall = void . many1 $ choice [char '#', char ' ', char '.']