Skip to content

Commit 379bdb3

Browse files
committed
Day 23: 1m14 -> 1m1
1 parent 5c21ee0 commit 379bdb3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

2021/23/Main.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import qualified Data.PQueue.Prio.Min as P
12
import qualified Data.Array as A
23
import qualified Data.IntMap as M
34
import qualified Data.Set as S
4-
import qualified Data.Heap as H
55
import Data.Maybe (isJust, isNothing)
66
import Data.Maybe (catMaybes, fromJust)
77

@@ -109,23 +109,23 @@ unsolvable (Burrow _ rm) = f A 0 || f B 1 || f C 2 || f D 3
109109
g e (L a ) = a /= e
110110
g e _ = False
111111

112-
type PH = H.MinPrioHeap Cost Burrow
112+
type PH = P.MinPQueue Cost Burrow
113113
type SB = S.Set Burrow
114114

115115
solve :: Burrow -> Cost
116-
solve b = loop S.empty $ H.singleton (0, b)
116+
solve b = loop S.empty $ P.singleton 0 b
117117
where
118118
loop :: SB -> PH -> Cost
119119
loop s m | solved b = c
120120
| otherwise = loop s' m''
121-
where ((c, b), m') = fromJust $ H.view m
121+
where ((c, b), m') = fromJust $ P.minViewWithKey m
122122
lh = [moveToHallway r h b | r <- [0..3], h <- hallwayPositions]
123123
lr = [moveToRoom h r b | r <- [0..3], h <- hallwayPositions]
124124
l = h lr ++ h lh
125125
h = filter (\(b,c) -> S.notMember b s)
126126
. filter (not . unsolvable . fst)
127127
. catMaybes
128-
m'' = foldr H.insert m' $ map (\(b,c') -> (c + c', b)) l
128+
m'' = foldr (uncurry P.insert) m' $ map (\(b,c') -> (c + c', b)) l
129129
s' = S.insert b s
130130

131131
main = print $ solve input

0 commit comments

Comments
 (0)