Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Ghosts Age by Kurush
import math
def checkio(opacity):
if opacity == 10000: return 0
InOpacity = 10000
for Age in range(1, 10001):
IsFibonacci = False
i = 1
while round((2 / (5 - math.sqrt(5)) * ((1 + math.sqrt(5)) / 2) ** i + (3 - math.sqrt(5)) / (5 - math.sqrt(5)) * ((1 - math.sqrt(5)) / 2) ** i)) <= Age:
if round((2 / (5 - math.sqrt(5)) * ((1 + math.sqrt(5)) / 2) ** i + (3 - math.sqrt(5)) / (5 - math.sqrt(5)) * ((1 - math.sqrt(5)) / 2) ** i)) == Age:
IsFibonacci = True
break
i += 1
if IsFibonacci:
InOpacity -= Age
else:
InOpacity += 1
if InOpacity == opacity:
return Age
return -100
#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