Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ghosts Age by freeman_lex
from math import sqrt
def checkio(Op, age=0, Op1=10**4):
while not Op1 == Op:
age+=1
Op1 -= (-1, age)[not sqrt(5*age**2+4)%1 or not sqrt(5*age**2-4)%1]
return (4999, age)[age < 5000]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(10000) == 0, "Newborn"
assert checkio(9999) == 1, "1 year"
assert checkio(9997) == 2, "2 years"
assert checkio(9994) == 3, "3 years"
assert checkio(9995) == 4, "4 years"
assert checkio(9990) == 5, "5 years"
July 26, 2014
Comments: