Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Ghosts Age by Degusto
def checkio(opacity):
start = 10000
i = 0
while start != opacity:
i += 1
start -= i if is_fibo(i) else -1
return i
def is_fibo(n):
i = 1
while fibo(i) < n:
i += 1
return fibo(i) == n
def fibo(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibo(n - 1) + fibo(n - 2)
# 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"
Nov. 18, 2015