---
# System prepended metadata

title: WDI 5.6

---

---
title: WDI 5.6
---
DO POPRAWY
```python=
def fib(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return fib(n-1) + fib(n-2)

def fibonacci(k, r):
    wynik = 0
    if k == 0:
        wynik = 1
    if k == 1 or k == 2:
        wynik = 1
    if k > 2:
        wynik = (fib(k-1) + fib(k-2)) % r
    return wynik

print(fibonacci(9, 3))

'''
v2. dalej nie działa, jak powinno
'''

from wdi import *
def fibonacci(k, r):
    tab = Array(4)
    tab[0] = 0
    tab[1] = 1
    tab[2] = 1
    for i in range(2, k + 1):
        tab[2] = tab[0] % r + tab[1] % r
        tab[1] = tab[2]
        tab[0] = tab[1]
    return tab[2]

print(fibonacci(6, 4))