1
0
Fork 0

Be smarter!

main
Bill Ewanick 2024-12-21 13:06:55 -05:00
parent b818aa089e
commit d54b9f9812
1 changed files with 5 additions and 6 deletions

View File

@ -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