diff options
| author | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-07 00:47:26 +0100 | 
|---|---|---|
| committer | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-07 00:50:32 +0100 | 
| commit | 1c166e353d82643b70d87044e300a1a6237cf9a8 (patch) | |
| tree | d2ac2a22269aed814135508e48c56f1016938697 | |
| parent | dbc00d64a4a2a5feb249773a1154ec136ce831c9 (diff) | |
| download | aoc2024-1c166e353d82643b70d87044e300a1a6237cf9a8.tar.gz aoc2024-1c166e353d82643b70d87044e300a1a6237cf9a8.zip | |
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.
| -rw-r--r-- | 6-2.hs | 9 | 
1 files changed, 4 insertions, 5 deletions
| @@ -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 |