Day eight: Use Flow for more sane piping

This commit is contained in:
2024-12-08 14:01:32 +01:00
parent ff74e85ba6
commit 3fe54232b2
5 changed files with 10 additions and 5 deletions

View File

@@ -4,10 +4,11 @@ import Common (Position, readWorld, multiMapFromList, pairPermutations)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Control.Monad (join)
import Flow
task2 :: String -> Int
task2 input = case readWorld input of
((width, height), antennas) -> length $ Set.fromList $ join $ map antinodesOfFrequency $ Map.elems $ multiMapFromList antennas
((width, height), antennas) -> multiMapFromList antennas |> Map.elems |> map antinodesOfFrequency |> join |> Set.fromList |> length
where
antinodesOfFrequency :: [Position] -> [Position]
antinodesOfFrequency nodes = pairPermutations nodes >>= antinodesOfPair
@@ -19,7 +20,7 @@ task2 input = case readWorld input of
in castInWorld a (-diffX, -diffY) ++ castInWorld b (diffX, diffY)
castInWorld (sx, sy) (ox, oy) =
takeWhile isInWorld $ map (\f -> (sx + ox * f, sy + oy * f)) [0..]
map (\f -> (sx + ox * f, sy + oy * f)) [0..] |> takeWhile isInWorld
isInWorld :: Position -> Bool
isInWorld (x, y)