Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ghosts Age by hypehr96
def fibo():
fiboList = [0, 1]
for i in range(2,300):
index1 = (i - 1)
index2 = (i - 2)
newNum = fiboList[index1] + fiboList[index2]
fiboList.append(newNum)
return fiboList
def checkio(number):
# Set my basic variables.
opacity = 10000
fiboList = fibo()
opacityList = [10000]
ageList = [0]
# This makes a list of all ages that my ghost could be.
for i in range(1,5000):
ageList.append(i)
# This makes a list of all opacities that my ghost could be.
age = 1
while opacity > 0:
if age in fiboList:
opacity -= age
else:
opacity += 1
opacityList.append(opacity)
age += 1
# Since the indices of my age and opacity lists should correspond
# I can find my age by find the opacity index and checking the age index.
myIndex = opacityList.index(number)
myAge = ageList[myIndex]
return myAge
#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"
Jan. 9, 2017
Comments: