Re: PyEuler

2008-02-25 Thread bearophileHUGS
Arnaud Delobelle: > I disagree; the generator function has no right to keep a and b to > itself. a and b cry out to be function parameters. I see. Then that's a generator for a generalized Fibonacci sequence :-) Your version too is useful. Bye, bearophile -- http://mail.python.org/mailman/listi

Re: PyEuler

2008-02-25 Thread Arnaud Delobelle
On Feb 25, 10:52 pm, [EMAIL PROTECTED] wrote: > Arnaud Delobelle: > > > In this case why not: > > > def xfib(a=1, b=1): > >     while True: > >         yield a > >         a += b > >         yield b > >         b += a > > That's a bit less easy to understand than my version, for me. > In my version

Re: PyEuler

2008-02-25 Thread bearophileHUGS
Arnaud Delobelle: > In this case why not: > > def xfib(a=1, b=1): > while True: > yield a > a += b > yield b > b += a That's a bit less easy to understand than my version, for me. In my version is easy to see the values of the variables. And using a longer funct

Re: PyEuler

2008-02-25 Thread Arnaud Delobelle
On Feb 25, 10:25 pm, [EMAIL PROTECTED] wrote: > Paul Rubin: > > >     def ggenfib(): > >       a,b = 1,2 > >       while True: > >          yield a > >          a,b = b, a=b > > Your version is the nice basic generator version (the last line > contains a +, I presume), but I like this other version

Re: PyEuler

2008-02-25 Thread bearophileHUGS
Paul Rubin: > def ggenfib(): > a,b = 1,2 > while True: > yield a > a,b = b, a=b Your version is the nice basic generator version (the last line contains a +, I presume), but I like this other version too: def xfibonacci(): a = b = 1 yield a yield b

Re: PyEuler

2008-02-25 Thread Mark Dickinson
On Feb 25, 4:24 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > def genfib(a=0, b=1): >     for a, b in iter(lambda:(b, a+b), None): >         yield a > > ;-) > > Ahem.  I admit that somehow, I am proud of this. You're one sick puppy dog. :-) (P.S. Your mother was a hamster, and your father s

Re: PyEuler

2008-02-25 Thread Arnaud Delobelle
On Feb 25, 7:25 pm, Paul Rubin wrote: > Are you kidding? >     def ggenfib(): >       a,b = 1,2 >       while True: >          yield a >          a,b = b, a=b Or: def genfib(a=0, b=1): for a, b in iter(lambda:(b, a+b), None): yield a ;-) Ahem. I admit tha

Re: PyEuler

2008-02-25 Thread Paul Rubin
[EMAIL PROTECTED] writes: > def takenth(n, iterable): > "Returns the nth item" > return list(islice(iterable, n, n+1))[0] > return islice(iterable, n).next() > isanymultiple = lambda x: any((x % y == 0) for y in nums) > return sum(filter(isanymultiple, xrange(end))) This isn't

Re: PyEuler

2008-02-25 Thread Mark Dickinson
On Feb 25, 11:25 am, [EMAIL PROTECTED] wrote: > This is the first time I write something that looks like a little > rant :-) Surely I'll be wrong in many points, but I presume this isn't > going to damage people, so... Agreed on all points. :-) This looks a lot like someone trying to write Haskel