diff --git a/src/advent_of_code/2024/1.hs b/src/advent_of_code/2024/1.hs index 3a32bc0..b9bd34f 100644 --- a/src/advent_of_code/2024/1.hs +++ b/src/advent_of_code/2024/1.hs @@ -6,8 +6,9 @@ import GHC.IO (unsafePerformIO) input :: FilePath input = "src/advent_of_code/2024/1.input" -entries :: ([Int], [Int]) -entries = unzip $ map parse' $ unsafePerformIO $ lines <$> readFile input +-- entries :: ([Int], [Int]) +-- entries = unzip $ map parse' $ unsafePerformIO $ lines <$> readFile input +entries = unsafePerformIO $ lines <$> readFile input main :: IO () main = do @@ -20,12 +21,10 @@ main = do parse' :: String -> (Int, Int) parse' str = (read l, read r) where - l = take' str - r = reverse $ take' $ reverse str - take' = takeWhile (/= ' ') + [l, r] = words str solveP1 :: ([Int], [Int]) -> Int -solveP1 (as, bs) = sum $ zipWith (\i j -> abs (i - j)) as' bs' +solveP1 (as, bs) = sum $ map abs $ zipWith subtract as' bs' where as' = sort as bs' = sort bs