<p>I'm using the basic Haskell Platform installation (install with</p>
<pre><code>$ sudo aptitude install haskell-platform</code></pre>
<p>).</p>
-<p>I'm also using the <code>MissingH</code> library (install with</p>
-<pre><code>$ cabal install MissingH</code></pre>
+<p>I'm also using the <code>MissingH</code> and <code>Parsec-number</code> libraries (install with</p>
+<pre><code>$ cabal install MissingH
+$ cabal install parsec-number</code></pre>
<p>)</p>
<p>Compile the code with</p>
<pre><code>ghc --make advent01.hs</code></pre>
```
).
-I'm also using the `MissingH` library (install with
+I'm also using the `MissingH` and `Parsec-number` libraries (install with
```
$ cabal install MissingH
+$ cabal install parsec-number
```
)
main :: IO ()
main = do
part1
- part2
+ -- part2
part1 :: IO ()
-- part1 = print $ length $ init $ extractJust $ hillClimb [[buildingTest]] []
-part1 = print $ length $ init $ extractJust $ hillClimb [[building1]] []
+-- part1 = print $ length $ init $ extractJust $ hillClimb [[building1]] []
+part1 = print $ length $ init $ extractJust $ aStar [[building1]] []
part2 :: IO ()
part2 = print $ length $ init $ extractJust $ hillClimb [[building2]] []
sortBy (\t1 t2 -> (head t1) `compare` (head t2)) $
trails ++ (candidates currentTrail closed)
+aStar :: [[Building]] -> [Building] -> Maybe [Building]
+aStar [] _ = Nothing
+aStar (currentTrail:trails) closed =
+ if isGoal (head currentTrail) then Just currentTrail
+ else aStar newAgenda ((head currentTrail): closed)
+ where newAgenda =
+ sortBy (\t1 t2 -> (trailCost t1) `compare` (trailCost t2)) $
+ trails ++ (candidates currentTrail closed)
+ trailCost t = estimateCost (head t) + length t - 1
+
+
candidates :: [Building] -> [Building] -> [[Building]]
candidates currentTrail closed = newCandidates
where