Re: Classical FP problem in python : Hamming problem
On 25 Jan 2005 08:30:03 GMT, Nick Craig-Wood <nick@craig-wood.com> wrote:
[color=blue]
>Francis Girard <francis.girard @free.fr> wrote:[color=green]
>> def hamming():
>> def _hamming():
>> yield 1
>> hamming2 = hammingGenerato rs[0]
>> hamming3 = hammingGenerato rs[1]
>> hamming5 = hammingGenerato rs[2]
>> for n in imerge(imap(lam bda h: 2*h, iter(hamming2)) ,
>> imerge(imap(lam bda h: 3*h, iter(hamming3)) ,
>> imap(lambda h: 5*h, iter(hamming5)) )):
>> yield n
>> hammingGenerato rs = tee(_hamming(), 4)
>> return hammingGenerato rs[3][/color]
>
>If you are after readability, you might prefer this...
>
>def hamming():
> def _hamming():
> yield 1
> for n in imerge(imap(lam bda h: 2*h, iter(hamming2)) ,
> imerge(imap(lam bda h: 3*h, iter(hamming3)) ,
> imap(lambda h: 5*h, iter(hamming5)) )):
> yield n
> hamming2, hamming3, hamming5, result = tee(_hamming(), 4)
> return result
>
>PS interesting thread - never heard of Hamming sequences before![/color]
Are the long words really that helpful?
def hamming():
def _hamming():
yield 1
for n in imerge(imap(lam bda h: 2*h, iter(hg2)),
imerge(imap(lam bda h: 3*h, iter(hg3)),
imap(lambda h: 5*h, iter(hg5)))):
yield n
hg2, hg3, hg5, result = tee(_hamming(), 4) # four hamming generators
return result
Regards,
Bengt Richter
On 25 Jan 2005 08:30:03 GMT, Nick Craig-Wood <nick@craig-wood.com> wrote:
[color=blue]
>Francis Girard <francis.girard @free.fr> wrote:[color=green]
>> def hamming():
>> def _hamming():
>> yield 1
>> hamming2 = hammingGenerato rs[0]
>> hamming3 = hammingGenerato rs[1]
>> hamming5 = hammingGenerato rs[2]
>> for n in imerge(imap(lam bda h: 2*h, iter(hamming2)) ,
>> imerge(imap(lam bda h: 3*h, iter(hamming3)) ,
>> imap(lambda h: 5*h, iter(hamming5)) )):
>> yield n
>> hammingGenerato rs = tee(_hamming(), 4)
>> return hammingGenerato rs[3][/color]
>
>If you are after readability, you might prefer this...
>
>def hamming():
> def _hamming():
> yield 1
> for n in imerge(imap(lam bda h: 2*h, iter(hamming2)) ,
> imerge(imap(lam bda h: 3*h, iter(hamming3)) ,
> imap(lambda h: 5*h, iter(hamming5)) )):
> yield n
> hamming2, hamming3, hamming5, result = tee(_hamming(), 4)
> return result
>
>PS interesting thread - never heard of Hamming sequences before![/color]
Are the long words really that helpful?
def hamming():
def _hamming():
yield 1
for n in imerge(imap(lam bda h: 2*h, iter(hg2)),
imerge(imap(lam bda h: 3*h, iter(hg3)),
imap(lambda h: 5*h, iter(hg5)))):
yield n
hg2, hg3, hg5, result = tee(_hamming(), 4) # four hamming generators
return result
Regards,
Bengt Richter
Comment