~rootmos/AoC

e49569b390b34c97448cb452f7ac407180ea9485 — Gustav Behm a month ago d3c916a
Add solution to AoC 2023 #11b
1 files changed, 14 insertions(+), 13 deletions(-)

M 2023/11.hs
M 2023/11.hs => 2023/11.hs +14 -13
@@ 40,21 40,22 @@ parser = post . b <$> lines
        xs ls = f $ List.transpose ls
        gs ls = fmap fst . filter snd $ withXY ls

partA :: Parse -> Int
partA (ex, ey, gs) = sum [ taxi g0 g1 | g0<-egs, g1<-egs, g0 < g1 ]
  where taxi (x0,y0) (x1,y1) = abs (x1-x0) + abs (y1-y0)
        egs = fmap expand gs
        expand (x,y) =
          ( x + (count $ fmap ((>) x) ex)
          , y + (count $ fmap ((>) y) ey)
expand :: Int -> Parse -> [(Int, Int)]
expand e (ex, ey, gs) = fmap f gs
  where f (x,y) =
          ( x + (e-1)*(count $ fmap ((>) x) ex)
          , y + (e-1)*(count $ fmap ((>) y) ey)
          )

--partB :: Parse -> Parse
--partB = id
taxi (x0,y0) (x1,y1) = abs (x1-x0) + abs (y1-y0)

part :: Int -> Parse -> Int
part e p = sum [ taxi g0 g1 | g0<-gs, g1<-gs, g0 < g1 ]
  where gs = expand e p

main :: IO ()
main = with parser $ do
  run "11.example" "a example" partA -- 374
  run "11.input" "a input" partA -- 9418609
  --run "11.example" "b example" partB
  --run "11.input" "b input" partB
  run "11.example" "a example" (part 2) -- 374
  run "11.input" "a input" (part 2) -- 9418609
  run "11.example" "b example" (part 10) -- 1030
  run "11.input" "b input" (part 1000000) -- 593821230983