fork download
  1. <?php
  2.  
  3. function weak_compositions($nboxes, $nballs, $parent="", $nested=0) {
  4. $one = $nested ? "1" : "";
  5. if ($nboxes > 1) {
  6. for ($i = 0; $i <= $nballs; $i++) {
  7. weak_compositions($nboxes - 1, $i, $parent . $one . str_repeat("0", $nballs - $i), 1);
  8. }
  9. } else {
  10. echo $parent . $one . str_repeat("0", $nballs) . "\n";
  11. }
  12. }
  13.  
  14. $f=5;
  15. $c=2;
  16. weak_compositions($c+1, $f-$c);
  17.  
  18. ?>
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
00011
00101
00110
01001
01010
01100
10001
10010
10100
11000