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


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

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11121888 use warnings; print "$_\n" for strings( 4, 10 ); sub strings { my ($ones, $length) = @_; $length <= $ones ? 1 x $length : $ones < 1 ? 0 x $length : ( map("1$_", strings( $ones - 1, $length - 1 ) ), map "0$_", strings( $ones, $length - 1 ) ) }
  • Comment on Re: Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's
  • Download Code