Updated readme
authorNeil Smith <neil.git@njae.me.uk>
Mon, 12 Dec 2016 16:34:52 +0000 (16:34 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Mon, 12 Dec 2016 16:34:52 +0000 (16:34 +0000)
README.html
README.md
advent11.hs

index 754e9be307265ae2d03a10941cbb19667d976dea..7bffdaa8d1e090570dc1fd0cebb1d75d9d42f768 100644 (file)
@@ -17,8 +17,9 @@
 <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>
index 5c7f379a22baa53e2a9673e7b95e1cf955897635..9fa57694a2f05e1ef846ed9f8f365a003b09484c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -13,9 +13,10 @@ $ sudo aptitude install haskell-platform
 ```
 ).
 
-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
 ```
 )
 
index 5fd4e40b784658a12580906efbbb2cb5774d336f..fd96636830de0ea89fe69ff06fc187d0edbb83a1 100644 (file)
@@ -44,12 +44,13 @@ buildingTest = Building 0 [
 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]] []
@@ -68,6 +69,17 @@ hillClimb (currentTrail:trails) closed =
             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