Day14, move stuff to libraries, aoc2024 -> samples, fix FC on an error
This commit is contained in:
@@ -16,21 +16,6 @@ gridPoints text = go 0 0 (unpack text) Nil
|
||||
go row col ('\n' :: cs) points = go (row + 1) 0 cs points
|
||||
go row col (c :: cs) points = go row (col + 1) cs ((c,row,col) :: points)
|
||||
|
||||
Point : U
|
||||
Point = Int × Int
|
||||
|
||||
instance Add Point where
|
||||
(a,b) + (c,d) = (a + c, b + d)
|
||||
|
||||
instance Sub Point where
|
||||
(a,b) - (c,d) = (a - c, b - d)
|
||||
|
||||
instance Ord Point where
|
||||
(a,b) < (c,d) = a < c || a == c && b < d
|
||||
|
||||
instance Eq Point where
|
||||
(a,b) == (c,d) = a == c && b == d
|
||||
|
||||
-- TODO add parameter a and pass Char -> a into getGrid
|
||||
Grid : U
|
||||
Grid = SortedMap Point Int
|
||||
@@ -59,12 +44,6 @@ paths grid pts ht =
|
||||
getCands : Point → List (Point × Int)
|
||||
getCands pt = mapMaybe (\ p => lookupMap p grid) (peers pt)
|
||||
|
||||
foldMap : ∀ a b. {{Ord a}} {{Eq a}} → (b → b → b) → SortedMap a b → List (a × b) → SortedMap a b
|
||||
foldMap f m Nil = m
|
||||
foldMap f m ((a,b) :: xs) = case lookupMap a m of
|
||||
Nothing => foldMap f (updateMap a b m) xs
|
||||
Just (_, b') => foldMap f (updateMap a (f b' b) m) xs
|
||||
|
||||
paths2 : Grid → List (Point × Int) → Int → Int
|
||||
paths2 grid pts ht =
|
||||
if ht == 9 then foldl _+_ 0 $ map snd $ pts else
|
||||
|
||||
Reference in New Issue
Block a user