From 84b481cb5a64383678b8a31f8cf43ec4e614db60 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Thu, 19 Dec 2024 23:08:14 -0800 Subject: [PATCH] faster --- solutions/src/2024/20.hs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/solutions/src/2024/20.hs b/solutions/src/2024/20.hs index b038612..910d9ba 100644 --- a/solutions/src/2024/20.hs +++ b/solutions/src/2024/20.hs @@ -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, (!)) @@ -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