Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Hamming Sequences and Lazy Lists

by tall_man (Parson)
on Mar 17, 2005 at 18:25 UTC ( #440473=note: print w/ replies, xml ) Need Help??


in reply to Re: Hamming Sequences and Lazy Lists
in thread Hamming Sequences and Lazy Lists

The number 1 = 2**0 * 3**0 * 5**0, so it is a legitimate part of the series, not just a seed to be stripped off. It is part of the answer produced by the Haskell genHam above. Otherwise, your generator looks great and the output checks with the Haskell one.


Comment on Re^2: Hamming Sequences and Lazy Lists
Re^3: Hamming Sequences and Lazy Lists
by Roy Johnson (Monsignor) on Mar 17, 2005 at 18:40 UTC
    Ok, well here it is, corrected for that, and without using coderefs for streams. I realized there really wasn't much point to that. All I really need to know is what my multiplier is, and which element of the output stream I'm looking at.
    use strict; use warnings; sub lazy_ham { my ($how_many) = @_; my @output_stream = (1); my @streams = map [$_,0], (2, 3, 5); for (@output_stream+1..$how_many) { # Find the lowest next item in the available streams my @peeks = map {$output_stream[$_->[1]] * $_->[0]} @streams; my ($lowest) = sort {$a <=> $b} @peeks; $peeks[$_] == $lowest and $streams[$_][1]++ for 0..$#streams; push(@output_stream, $lowest); } @output_stream; } print join(', ', lazy_ham(80)), "\n";

    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://440473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2014-09-17 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls