This horribly inefficient brute-force conversion seems like it's getting close, but needs work.
#! perl -slw
use strict;
sub merge {
return unless @_ == 2;
return @{ $_[1] } unless @{ $_[0] };
return @{ $_[0] } unless @{ $_[1] };
my( $x, $y ) = ( $_[0][0], $_[1][0] );
return shift @{ $_[0] }, merge( @_ ) if $x < $y;
return shift @{ $_[1] }, merge( @_ ) if $x > $y;
shift @{ $_[0] };
return shift @{ $_[1] }, merge( @_ );
}
my @out;
sub genHam {
return unless @_;
my( $x, @xs ) = @_;
return @out = merge [ 1, map{ $_*$x } @out ], [ genHam( @xs ) ];
}
print join'|',genHam 2, 3, 5 for 1..5;
__END__
[ 8:26:05.53] P:\test>440284
1
1|2|3|5
1|2|3|4|5|6|9|10|15|25
1|2|3|4|5|6|8|9|10|12|15|18|20|25|27|30|45|50|75|125
1|2|3|4|5|6|8|9|10|12|15|16|18|20|24|25|27|30|36|40|45|50|54|60|75|81|
+90|100|125|135|150|225|250|375|625
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.