Skip to content

Commit

Permalink
faster
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 18, 2024
1 parent abf8f18 commit 6d375ef
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions solutions/src/2024/18.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,30 @@ Maintainer : emertens@gmail.com
<https://adventofcode.com/2024/day/18>
Initial brute force solution
Uses a binary search to reduce the number of reachable searchs
that need to be done.
-}
module Main where

import Advent (arrIx, format)
import Advent (arrIx, format, binSearchLargest)
import Advent.Coord (Coord(..), cardinal)
import Advent.Search (AStep(AStep), astar)
import Data.Array.Unboxed (UArray, accumArray)
import Data.List (find, inits)
import Data.Maybe (isNothing, listToMaybe)

-- | >>> :main
-- 278
-- 43,12
main :: IO ()
main =
do input <- [format|2024 18 (%u,%u%n)*|]
let Just cost = search (take 1024 input)
print cost
let (x,y) : _ = [last points' | points' <- inits input, isNothing (search points')]
let input' = reverse input
isBlocking i = isNothing (search (drop i input'))
(x,y) = input' !! binSearchLargest isBlocking 0 1024
putStrLn (show x ++ "," ++ show y)

-- | Find the minimum cost to go from one side of the maze to the other, if there is one.
Expand Down

0 comments on commit 6d375ef

Please sign in to comment.