forked from Shivi91/Rosalind-1
-
Notifications
You must be signed in to change notification settings - Fork 14
/
004_FIB.py
31 lines (27 loc) · 802 Bytes
/
004_FIB.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
#!/usr/bin/env python
'''
A solution to a ROSALIND bioinformatics problem.
Problem Title: Rabbits and Recurrence Relations
Rosalind ID: FIB
Rosalind #: 004
URL: http://rosalind.info/problems/fib/
'''
def Fib(n,k):
'''The total number of rabbit pairs that will be present
after n months if we begin with 1 pair and in each generation,
every pair of reproduction-age rabbits produces a litter of k rabbit pairs
'''
if n < 1:
return 0
elif n == 1:
return 1
elif n == 2:
return 1
else:
return Fib(n-1,k) + k*Fib(n-2, k)
with open('data/rosalind_fib.txt') as input_data:
n,k = map(int, input_data.read().split())
rabbits = str(Fib(n,k))
print rabbits
with open('output/004_FIB.txt', 'w') as output_data:
output_data.write(rabbits)