Removed the unnecessary extra zero row

This commit is contained in:
Natty 2023-12-09 16:19:21 +01:00
parent 4b23d58e5e
commit 6682bd9757
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
2 changed files with 2 additions and 6 deletions

View File

@ -2,9 +2,7 @@
module Main (main) where
import Data.Bifunctor (Bifunctor (second))
main :: IO ()
main = do
values <- (fmap (read @Integer) . words <$>) . lines <$> getContents
print $ sum $ foldr ((+) . last) 0 . uncurry (++) . second (pure . head) . span (any (/= 0)) . iterate (zipWith (flip (-)) <*> tail) <$> values
print $ sum $ foldr ((+) . last) 0 . takeWhile (any (/= 0)) . iterate (zipWith (flip (-)) <*> tail) <$> values

View File

@ -2,9 +2,7 @@
module Main (main) where
import Data.Bifunctor (Bifunctor (second))
main :: IO ()
main = do
values <- (fmap (read @Integer) . words <$>) . lines <$> getContents
print $ sum $ foldr (flip subtract . head) 0 . uncurry (++) . second (pure . head) . span (any (/= 0)) . iterate (zipWith (flip (-)) <*> tail) <$> values
print $ sum $ foldr (flip subtract . head) 0 . takeWhile (any (/= 0)) . iterate (zipWith (flip (-)) <*> tail) <$> values