Be smarter!
parent
b818aa089e
commit
d54b9f9812
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue