http://qs321.pair.com?node_id=11121918


in reply to Re: Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's
in thread Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's

This one ends up somewhere in the middle:

sub tux_for { my ($length, $ones) = @_; [ map { substr unpack ("b*", $_), 0, $length } grep { $ones == unpack "%32b*" => $_ } map { pack "L<", $_ } 0 .. oct "0b".join""=> (1) x $ones, (0) x ($length - $ones) ]; }

Enjoy, Have FUN! H.Merijn
  • Comment on Re^2: Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's
  • Download Code