in reply to Re^2: One Zero variants_without_repetition
in thread One Zero variants_without_repetition
Recursion:
use strict; use warnings; doShift (2, 5); print "\n"; doShift (3, 6); print "\n"; sub doShift { my ($ones, $bits, $pattern, $limit) = @_; --$ones; $limit ||= $bits; $pattern ||= 0; for my $right ($ones .. $limit - 1) { if ($ones) { doShift ($ones, $bits, $pattern | (1 << $right), $right); } else { printf "%0*b\n", $bits, $pattern | (1 << $right); } } }
Prints:
00011 00101 00110 01001 01010 01100 10001 10010 10100 11000 000111 001011 001101 001110 010011 010101 010110 011001 011010 011100 100011 100101 100110 101001 101010 101100 110001 110010 110100 111000
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: One Zero variants_without_repetition
by papidave (Pilgrim) on Aug 07, 2007 at 15:08 UTC | |
by tye (Sage) on Aug 07, 2007 at 16:29 UTC | |
|
Re^4: One Zero variants_without_repetition
by thenetfreaker (Friar) on Aug 07, 2007 at 11:58 UTC | |
by ohcamacj (Beadle) on Aug 08, 2007 at 02:59 UTC | |
by tye (Sage) on Aug 08, 2007 at 05:58 UTC | |
by GrandFather (Saint) on Aug 07, 2007 at 21:03 UTC |