Created
December 9, 2023 06:36
-
-
Save Alwinfy/a061387f662811de1ca2adb176849957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Arrow ((&&&)) | |
trapolate :: ([Integer] -> Integer -> Integer) -> [Integer] -> Integer | |
trapolate f ls | all (== 0) ls = 0 | |
| otherwise = f ls $ trapolate f (zipWith (-) (tail ls) ls) | |
main :: IO () | |
main = ((sum . map (trapolate ((+) . last)) &&& sum . map (trapolate ((-) . head))) . map (map read . words) . lines <$> getContents) >>= print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment