Skip to content

Instantly share code, notes, and snippets.

@Alwinfy
Created December 9, 2023 06:36
Show Gist options
  • Save Alwinfy/a061387f662811de1ca2adb176849957 to your computer and use it in GitHub Desktop.
Save Alwinfy/a061387f662811de1ca2adb176849957 to your computer and use it in GitHub Desktop.
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