Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Hamming Sequences and Lazy Lists

by Limbic~Region (Chancellor)
on Apr 21, 2005 at 15:02 UTC ( #450038=note: print w/ replies, xml ) Need Help??


in reply to Hamming Sequences and Lazy Lists

tall_man,
This idea poppped into my head today and I didn't really get a chance to play with it before a marathon meeting.

use List::Util 'min'; my $iter = hamming(2, 3, 5); print $iter->(), "\n" while 1; sub hamming { my @factor = @_; my %pool = (1 => 1); return sub { my $next = delete $pool{ min keys %pool }; @pool{ map { $next * $_ } @factor } = map { $next * $_ } @fact +or; return $next; }; }

Cheers - L~R

Update: Removed faulty optimization


Comment on Re: Hamming Sequences and Lazy Lists
Download Code
Re^2: Hamming Sequences and Lazy Lists
by Roy Johnson (Monsignor) on Apr 21, 2005 at 23:13 UTC
    No need to populate values, though.
    return sub { my $next = min keys %pool; @pool{ map { $next * $_ } @factor } = (); delete $pool{$next}; return $next; };

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://450038]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-12-25 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls