Boolean tasks

I added ackerman.py and series.py.
Hi Josh,

I used my previous code and writed it like below.
Then the last test "assert sum_series(i, 2, 1) == lucas(i)" causes
AssertionError.

Could you tell me what's wrong with is?

Thanks,
Saki

def fibonacci(n):
    """Return fibonacci function.First two number of series are (0,1),
which is n.
    After 2, return the sum of (n-2)th number and (n-1)th number."""

    if n < 2:
        return n
    else:
        return fibonacci(n - 2) + fibonacci(n - 1)


def lucas(n):
    """Return lucas function. First two number of series has to be (2,1).
    After that, return the sum of (n-2)th number and (n-1)th number."""

    if n == 0:
        return 2
    if n == 1:
        return 1
    else:
        return lucas(n - 2) + lucas(n - 1)


def sum_series(n, m=0, r=1):
    """Generalize fibonacci and lucas so that the 0th and 1th number can
     take arbituary value."""
    if n == 0:
        return m
    if n == 1:
        return r
    else:
        return sum_series(n - 2) + sum_series(n - 1)


if __name__ == "__main__":
    """Test if fibonacci, lucas and sum_series work properly.
    Tests if sum_series returns fibonucci
    when it has no optional parameter
    and if it returns lucas when the first two numbers are (2,1)
    and if it returns other series
    when the first numbers are other than that"""
    # assert function(input) == expected
    assert fibonacci(0) == 0
    assert fibonacci(1) == 1
    assert fibonacci(2) == 1
    assert fibonacci(3) == 2
    assert fibonacci(4) == 3
    assert fibonacci(5) == 5
    assert fibonacci(6) == 8
    assert fibonacci(7) == 13
    assert lucas(0) == 2
    assert lucas(1) == 1
    assert lucas(2) == 3
    assert lucas(3) == 4
    assert lucas(4) == 7
    assert lucas(5) == 11
    assert lucas(6) == 18
    assert lucas(7) == 29

    for i in range(7):
        assert sum_series(i) == fibonacci(i)
        assert sum_series(i, 2, 1) == lucas(i)
    print ("All Tests Pass")


On Tue, Dec 9, 2014 at 3:33 PM, Saki Fu <saki.fu86@gmail.com> wrote:

> Hi Josh,
>
> Thank you for the feedback!
> I was trying to say that
> "if it doesn't have (m,r) ,return fibonacci(n),
> if (m,r) = (2,1), which is sum_series(0) and sum_series(1) respectively,
> return rucas(n),
> else, return sum_series(n-2) + sum_series(n-1) with arbituary
> sum_series(0)and sum_series(1).
>
> Thanks,
> Saki
>
> On Mon, Dec 8, 2014 at 7:56 PM, Joshua Frailey <notifications@github.com>
> wrote:
>
>> In Students/SakiFu/series.py:
>>
>> > +def lucas(n):
>> > +    """Return lucas function. First two number of series has to be (2,1).
>> > +    After that, return the sum of (n-2)th number and (n-1)th number."""
>> > +
>> > +    if n == 0:
>> > +        return 2
>> > +    if n == 1:
>> > +        return 1
>> > +    else:
>> > +        return lucas(n - 2) + lucas(n - 1)
>> > +
>> > +
>> > +def sum_series(n, m=0, r=1):
>> > +    sum_series(n) == fibonacci(n)
>> > +    sum_series(n, 2, 1) == lucas(n)
>> > +    return sum_series(n - 2) + sum_series(n - 1)
>>
>> This definition for sum_series() is causing a RuntimeError because it's
>> reaching the "maximum recursion depth." Can you explain what you are trying
>> to accomplish with this function? We might be able to re-write this
>> function so that it does what you intend without hitting the recursion
>> limit. Alternatively, you could replace it with your previous version as I
>> believe it worked correctly.
>>
>> —
>> Reply to this email directly or view it on GitHub
>> <https://github.com/codefellows/sea-c28-students/pull/62/files#r21505930>
>> .
>>
>
>