Skip to content

Commit

Permalink
faster
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 20, 2024
1 parent 0f71573 commit 84b481c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions solutions/src/2024/20.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Maintainer : emertens@gmail.com
-}
module Main (main) where

import Advent (getInputArray, arrIx)
import Advent (getInputArray, arrIx, count)
import Advent.Coord (cardinal, Coord, manhattan)
import Advent.Search (astar, AStep(AStep))
import Data.Array.Unboxed (UArray, amap, assocs, accumArray, bounds, (!))
Expand All @@ -27,15 +27,14 @@ main =
start : _ = [p | (p,'S') <- assocs input]
end : _ = [p | (p,'E') <- assocs input]
optimals = search open end
cheat n = length [()
| (p1,c1) : more <- tails optimals
, (p2,c2) <- more
, let d = manhattan p1 p2
, d >= 2, d <= n
, abs (c1 - c2) >= 100 + d
]
print (cheat 2)
print (cheat 20)
cheats = [ d
| (p1,c1) : more <- tails optimals
, (p2,c2) <- more
, let d = manhattan p1 p2, d <= 20
, abs (c1 - c2) >= 100 + d
]
print (count 2 cheats)
print (length cheats)

search :: UArray Coord Bool -> Coord -> [(Coord, Int)]
search open = astar step
Expand Down

0 comments on commit 84b481c

Please sign in to comment.