Created
April 28, 2019 16:08
-
-
Save lgastako/dfb543030354590ffda19a646960d70f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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