-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoratlFibbonacciRabbits.py
56 lines (50 loc) · 2.15 KB
/
MoratlFibbonacciRabbits.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
def Mortal_Fib_Rabbit(months, alive_months):
a, b, F = 0, 1, [1,1]
for i in range(2, months):
if i < alive_months:
F.append(F[a]+ F[b])
a +=1
b +=1
elif i == alive_months or i == alive_months+1:
F.append(F[a]+F[b]-1)
a+=1
b+=1
else:
F.append(F[a]+F[b]-F[-(alive_months + 1)])
a +=1
b +=1
print("\nThe number of rabit pairs after %s months is %s.\n" %(months, F[months-1]))
return F
MONTHS = int(input("Enter the number of countdown months:"))
ALIVE_MONTHS = int(input("\nEnther the number of months the rabbit lives for:"))
print(Mortal_Fib_Rabbit(MONTHS, ALIVE_MONTHS))
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# def Rabbit_Fib_number(months, offsprings):
# parent, child, = 1,1
# for i in range(0, months-1):
# child, parent = parent, parent + (child*offsprings)
# return child
# print(Rabbit_Fib_number(34,3))
# def Rabbit(n,k):
# import numpy as np
# P = np.zeros(n)
# P[0] = 1
# P[1] = 1
# for i in range(3, n):
# P[i] = P[i-1] + P[i-2]*k
# print(P)
# n = 5
# k = 3
# Rabbit(n,k)
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# import numpy as np
# def Mortal_Fib_Rabbit(months, offsprings, alive_months):
# F = np.zeros(months)
# F[0], F[1], F[2], F[3], F[4] = 1, 1, 2, 2, 3
# for n in range(5,months):
# F[n] = F[n-1] + F[n-2]*offsprings - F[-(alive_months + 1)]
# print(F[n])
# return F
# print(Mortal_Fib_Rabbit(10, 2, 3))
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------