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 :: FilePath
input = "src/advent_of_code/2024/1.input" input = "src/advent_of_code/2024/1.input"
entries :: ([Int], [Int]) -- entries :: ([Int], [Int])
entries = unzip $ map parse' $ unsafePerformIO $ lines <$> readFile input -- entries = unzip $ map parse' $ unsafePerformIO $ lines <$> readFile input
entries = unsafePerformIO $ lines <$> readFile input
main :: IO () main :: IO ()
main = do main = do
@ -20,12 +21,10 @@ main = do
parse' :: String -> (Int, Int) parse' :: String -> (Int, Int)
parse' str = (read l, read r) parse' str = (read l, read r)
where where
l = take' str [l, r] = words str
r = reverse $ take' $ reverse str
take' = takeWhile (/= ' ')
solveP1 :: ([Int], [Int]) -> Int 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 where
as' = sort as as' = sort as
bs' = sort bs bs' = sort bs