From 1c166e353d82643b70d87044e300a1a6237cf9a8 Mon Sep 17 00:00:00 2001 From: Laura Orvokki Kursula Date: Sat, 7 Dec 2024 00:47:26 +0100 Subject: Bugfix; now works Fix a bug that was caused by advancing after turning without checking for obstacles. Now produces correct results, but atrociously slowly. Trying to make it more efficient with mutable arrays on another branch, but STArray is j a n k y. --- 6-2.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/6-2.hs b/6-2.hs index 5153fb8..835bb23 100644 --- a/6-2.hs +++ b/6-2.hs @@ -50,9 +50,10 @@ checkAhead :: Map -> Vel -> Coords -> Bool checkAhead m = (((== Free) . sub m) .) . move turn :: Vel -> Coords -> (Coords, Vel) -turn v p = let rot (Coords x y) = Coords (-y) x - v' = rot v - in (move v' p, v') +turn v p = + let rot (Coords x y) = Coords (-y) x + v' = rot v + in (p, v') step :: Map -> Vel -> Coords -> (Coords, Vel) step m v p = if checkAhead m v p @@ -103,6 +104,4 @@ main = do let path = map fst $ execState (run m v p) [] let ms = possibilities m $ nub path let res = ms `pseq` (map (\ n -> evalState (run n v p) []) ms `using` parList rdeepseq) --- putStr . unlines . intersperse "--" . map (showMap . fst) . filter snd . zip ms $ res print . length . filter id $ res --- print . length $ ms -- cgit v1.2.3