BINP
  • Home
  • Bioinformatics
    • Rosalind
    • Galaxy
    • Bioinformatics Concepts
  • Biology Concepts
    • Evolution
    • Systematics
    • Molecular Biology
  • Computer Science
    • R
    • Python
    • Computer Basics
  • Research
  • Resources
  • About
  1. Stronghold
  2. Pra-4 Rabbit And Recurrence Relations
  • Rosalind
  • Python Village
    • Pra0 Install Python
    • Pra1 Variables And Some Arithmetic
    • Pra4 working with files
  • Stronghold
    • Pra-1 Count Nucleotides
    • Pra-2 Transcribing DNA Into RNA
    • Pra-3 The Secondary and Tertiary Structures of DNAclick to expand
    • Pra-4 Rabbit And Recurrence Relations
    • Pra-5 Computing GC Content
  1. Stronghold
  2. Pra-4 Rabbit And Recurrence Relations

Pra-4 Rabbit And Recurrence Relations

n = 5 
k = 3


def rabbit_number(n, k):
    mature = 0
    immature = 1
    for i in range(1, n):
        new_mature = mature + immature
        new_immature = mature * k
        mature = new_mature
        immature = new_immature
    return mature + immature

print(rabbit_number(5, 3))
print(rabbit_number(28, 5))
19
662854323131
mature = 0
immature = 1

mature = (mature * k) + immature

print(mature)
1
#another method
def rabbit_number(n, k):
    if n == 1 or n == 2:
        return 1
    
    prev2 = 1  # F(1)
    prev1 = 1  # F(2)
    
    for i in range(3, n + 1):
        current = prev1 + k * prev2
        prev2 = prev1
        prev1 = current
    
    return prev1

© 2026 BINP

  • Content: CC BY 4.0

  • Code: MIT