Ghost的寿命在斐波那契数列中则能力递减,反之能力+1
这个随机答案直接把斐波那契数列导入了可还行hhhhhhh
# ghost-age_20180405.original.temp.NEWEST.py
# vim: ts=4 sw=4 expandtab
# Copyright (C) 2018 CheckiO, Inc. All rights reserved.
##!/usr/bin/env python
#
#"""
#fib.py - Print out fibonacci integer sequence up to N.
#
#Usage: ./fib.py N
#"""
#__license__ = "GPL"
#__version__ = "0.0.1"
#__status__ = "Prototype"
#__copyright__ = "(C) 2003 Sakata Industry"
import scipy#,sys
from math import *
import pprint
import time
#import string
FIBOS = []
def isfib(n):
if n in FIBOS:
return True
if not len(FIBOS):
for n in range(3000):
#FIBOS.append(fibonati_original(n)
#FIBOS.append(fibonati(n))
FIBOS.append(FibonacciMASTER(n))
def isfib2(target):
# Fixed by Kate (2018/3/3)
if isfib(target) is None: return False
return True
'''aВычисляет число фибоначчи при заданном
индексе'''
def fibonati_original(num):
if num <= 1 or num == 5: return num
if 1 < num and 4 >= num: return num - 1
if num == 6: return 8
if num == 7: return 13
if num == 8: return 21
if num == 9: return 34
if num == 10: return 55
if num == 11: return 89
if num == 12: return 144
if num == 13: return 233
if num == 14: return 377
if num == 15: return 610
if num == 16: return 987
if num == 17: return 1597
if num == 18: return 2584
if num == 19: return 4181
if num == 20: return float('inf')
def fibonati(int):
# https://docs.python.org/3/tutorial/modules.html
if int<2:
return int
else:
return fibonati(int-1)+fibonati(int-2)
def fibonacci_revised(len):
'''
フィボナッチ数列を計算する
:param len: 数列の長さ (取得したい)
:retval: 数字
'''
リスト = [0, 1]
len += 1
while リスト.__len__() < len:
リスト.append(リスト[-2]+リスト[-1])
return リスト[-1]
# CALL THIS MASTER FUNCTION TO GET CORRECT RESULT FAST
def FibonacciMASTER(number):
if number < 20:
return fibonati(number)
elif number < 1000:
return jessie_ver_fib(number)
else:
fibonacci_revised(number)
jessie_ver_fib = lambda n: round((((1+sqrt(5))/2)**n-((1-sqrt(5))/2)**n)/sqrt(5))
#if __name__ == "__main__":
# goto = int(sys.argv[1])
#
# for val in range(goto + 1):
# if isfib(val):
# print(val, end=' ')
### MAIN FUNCTION !!!!! ###
# 2018.1.1 / Ticket #101 fixed (A HAPPY NEW YEAR!)
# 2017/10/9, Improved performance by Peter
# 2017.03.03 / Takeshi / Fixed bug.
# 2017.01.12 (second), Kate, minor update
# 2017.01.12, john, first version
def checkio(opacity_sensor_value):
age = 0
opacity = 10000
# XXX: i don't know why but it seems required?
isfib(42)
while opacity != opacity_sensor_value:
if isfib2(age):
opacity -= age
else:
opacity += 1
age += 1
return max(0, age - 1)
#print(checkio(10000))
#print(checkio(9999))
#print(checkio(9997))
#print(checkio(9994))
#print(checkio(9995))
#print(checkio(9990))
#print(checkio(9000)) # NOT WORK ?
print(checkio(1000))