With the power of Perlmonks::Combinatorics I combined Lanx's solution and mine:
sub Eily_LanX {
my ($length, $ones) = @_;
my $iter = combinations([0..$length-1], $ones);
my (@r, $str);
while (my $positions = $iter->next) {
$str = '0' x $length;
substr $str, $_, 1, '1' for @$positions;
push @r, $str;
}
return \@r
}
Rate salva tybalt89_re choroba tybalt89 Eily GrandFather
+ Eily_LanX
salva 795/s -- -10% -57% -59% -62% -84%
+ -85%
tybalt89_re 879/s 11% -- -52% -54% -59% -82%
+ -83%
choroba 1842/s 132% 110% -- -4% -13% -63%
+ -64%
tybalt89 1916/s 141% 118% 4% -- -10% -61%
+ -63%
Eily 2120/s 167% 141% 15% 11% -- -57%
+ -59%
GrandFather 4960/s 524% 464% 169% 159% 134% --
+ -4%
Eily_LanX 5154/s 548% 486% 180% 169% 143% 4%
+ --
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|