Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ghosts Age by tarik.dsm
fibonaci_numbers = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,
987, 1597, 2584, 4181, 6765]
#On every birthday, a ghost's opacity is reduced by a number of units
#equal to its age when its age is a Fibonacci number (Read about this here)
#or increased by 1 if it is not.
def checkio(opacity):
op = 10000
age = 0
while op != opacity:
age += 1
if age in fibonaci_numbers:
op -= age
else:
op += 1
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"
Oct. 3, 2016
Comments: