Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87874

Re: fibonacci series what Iam is missing ?

From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: fibonacci series what Iam is missing ?
Date 2015-03-24 20:54 +1300
Message-ID <cncji4F35ulU1@mid.individual.net> (permalink)
References (3 earlier) <meq5i2$53s$1@ger.gmane.org> <55109DEF.9070001@davea.name> <CAPTjJmrARj2870KzAPvs8F_Y=n3hic+JW=iAxQKT+Euh-6UA-A@mail.gmail.com> <5510AB29.8060105@davea.name> <mailman.87.1427156876.10327.python-list@python.org>

Show all headers | View raw


Chris Angelico wrote:
> Commenting is like dieting. You can always start tomorrow.

I've been meaning to become a procrastinator, but
I think I'll start tomorrow.

In the meantime, since we seem to be having a
fibbing competition, here's my contribution, that
uses neither recursion nor (explicit) iteration:

from numpy import array, dot

a = array([[0,1],[1,1]])
b = array([0,1])

def fib(n):
    return reduce(dot,[a]*n+[b])[1]

for i in range(10):
    print(fib(i))

-- 
Greg

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: fibonacci series what Iam is missing ? Chris Angelico <rosuav@gmail.com> - 2015-03-24 11:27 +1100
  Re: fibonacci series what Iam is missing ? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-03-24 20:54 +1300

csiph-web