09_oasis.py 309 B

12345678910
  1. #!/usr/bin/env python3
  2. import sys
  3. from itertools import pairwise
  4. def predict(n):
  5. return n[-1] + predict([r - l for l, r in pairwise(n)]) if any(n) else 0
  6. histories = [list(map(int, line.split())) for line in sys.stdin]
  7. print(sum(map(predict, histories)))
  8. print(sum(predict(h[::-1]) for h in histories))