Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
itertools.count and for loop solution in Clear category for Ghosts Age by Splitter
from itertools import count
def checkio(opacity):
if opacity == 10000:
return 0
fib1 = 1
fib2 = 2
estimated_opacity = 10000
for age in count(1):
if age == fib1:
estimated_opacity -= age
fib1, fib2 = fib2, fib1 + fib2
else:
estimated_opacity += 1
if estimated_opacity == opacity or age == 4999:
return age
#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"
Aug. 28, 2019