-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibd.py
59 lines (48 loc) · 1000 Bytes
/
fibd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from rosa_util import *
#fibonacci mortal rabbits, #pairs after n months, each dead after m month
class fibd(n,m):
def __init__(self):
self.time = 0
self.maturity = 1
self.start = n
self.lifespan = m
self.total = 1
self.born = [1]
self.mature = 0
self.dead = 0
if self.start == 1:
return self.total
def __iter__(self):
return self
def __next__(self):
if self.start 1:
raise StopIteration
else:
self.time += 1
self.death()
self.birth()
return self
def birth(self):
self.born.append(self.p + self.mature*2)
return
def mature(self):
newlymatured = self.born[max(0,self.time-self.maturity)]
self.matured.append(self.born
return
def death(self):
return
for i in range(1,n):
temp = p
dead.append() = p
dead.insert(0,p)
p = p + repro - dead.pop()
repro = temp
return p
flushResult()
data = readData()
line = data[0]
n = int(line.split()[0])
m = int(line.split()[1])
p = fibd(n,m)
print p
writeResult(str(p))