in reply to Hamming Sequences and Lazy Lists
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hamming Sequences and Lazy Lists
by Roy Johnson (Monsignor) on Apr 21, 2005 at 23:13 UTC |