Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Select from Table solution in Speedy category for Ghosts Age by U.V
# Fibonacci numbers
last, next, fa=0, 1, []
for i in range(30):
last, next = next, last + next
fa.append(next)
# Ghost's age table
op, op1 = {10000: 0,}, 10000
for n in range(1, 10000):
op1,op2 = op1 - n if n in fa else op1 + 1 , op1
op[op1] = n
def checkio(n):
return op[n]
#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"
March 11, 2023
Comments: