Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ghosts Age by Molot
def checkio(opacity):
fib = lambda n: fib(n - 1) + fib(n - 2) if n > 2 else 1
fib_set = set(map(lambda x: fib(x), range(21))) # fibonacci of 21 = 6765 > 5000
year, opacity_ = 0, 10000
while opacity_ != opacity:
year += 1
x = -year if (year in fib_set) else 1
opacity_ += x
return year
#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"
June 19, 2018