Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simulation with generators solution in Clear category for Ghosts Age by nickie
# Complete simulation, isn't it scary? :-)
def fib():
a, b = 0, 1
yield a
yield b
while True:
a, b = b, a+b
yield b
def opgen():
op = 10000
age = 0
yield (op, age)
fibs = fib()
f = next(fibs)
while True:
age += 1
while f < age:
f = next(fibs)
while age < f:
op += 1
yield (op, age)
age += 1
op -= age
yield (op, age)
def checkio(opacity):
for op, age in opgen():
if op == opacity:
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"
Nov. 4, 2013
Comments: