Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Ghosts Age by bartosz_lyzwa
import math
def if_perfect_square(num):
return float(int(math.sqrt(num))) == math.sqrt(num)
def if_fibonacci(num):
return if_perfect_square(5*num*num+4) or if_perfect_square(5*num*num-4)
def all_years():
years={}
opacity=10000
for i in range(5000):
if i!=0:
if if_fibonacci(i):
opacity-=i
else:
opacity+=1
years[str(opacity)]=i
return years
def checkio(opacity):
years=all_years()
return years[str(opacity)]
#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. 31, 2017