Skip to content

Instantly share code, notes, and snippets.

@lgastako
Created April 28, 2019 16:08
Show Gist options
  • Save lgastako/dfb543030354590ffda19a646960d70f to your computer and use it in GitHub Desktop.
Save lgastako/dfb543030354590ffda19a646960d70f to your computer and use it in GitHub Desktop.
main = interact $ show . f . map read . words
f (n:a:b:c:_)
| b - a == c - b = arith !! n
| otherwise = geo !! n
where
arith = [a, b ..]
geo = if diffsigns || increasing
then a:map (*d) geo
else a:map (`div` e) geo
where
diffsigns = signum a /= signum b
d = c `div` b
e = a `div` b
increasing = b > a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment