projects
/
advent-of-code-16.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Realised I was doing hillclimbing search, not A*
[advent-of-code-16.git]
/
advent11.hs
diff --git
a/advent11.hs
b/advent11.hs
index 58215fd6da22ec671ee05f3b22d21d66ea734ca3..5fd4e40b784658a12580906efbbb2cb5774d336f 100644
(file)
--- a/
advent11.hs
+++ b/
advent11.hs
@@
-48,22
+48,22
@@
main = do
part1 :: IO ()
part1 :: IO ()
--- part1 = print $ length $ init $ extractJust $
aStar
[[buildingTest]] []
-part1 = print $ length $ init $ extractJust $
aStar
[[building1]] []
+-- part1 = print $ length $ init $ extractJust $
hillClimb
[[buildingTest]] []
+part1 = print $ length $ init $ extractJust $
hillClimb
[[building1]] []
part2 :: IO ()
part2 :: IO ()
-part2 = print $ length $ init $ extractJust $
aStar
[[building2]] []
+part2 = print $ length $ init $ extractJust $
hillClimb
[[building2]] []
extractJust :: Maybe [a] -> [a]
extractJust Nothing = []
extractJust (Just x) = x
extractJust :: Maybe [a] -> [a]
extractJust Nothing = []
extractJust (Just x) = x
-
aStar
:: [[Building]] -> [Building] -> Maybe [Building]
-
aStar
[] _ = Nothing
-
aStar
(currentTrail:trails) closed =
+
hillClimb
:: [[Building]] -> [Building] -> Maybe [Building]
+
hillClimb
[] _ = Nothing
+
hillClimb
(currentTrail:trails) closed =
if isGoal (head currentTrail) then Just currentTrail
if isGoal (head currentTrail) then Just currentTrail
- else
aStar
newAgenda ((head currentTrail): closed)
+ else
hillClimb
newAgenda ((head currentTrail): closed)
where newAgenda =
sortBy (\t1 t2 -> (head t1) `compare` (head t2)) $
trails ++ (candidates currentTrail closed)
where newAgenda =
sortBy (\t1 t2 -> (head t1) `compare` (head t2)) $
trails ++ (candidates currentTrail closed)