fork(1) download
  1. <?php
  2. $len = 5;
  3. $output = array();
  4. for( $i = 1; $i < pow( 2, $len ); $i++ ) {
  5. $line = array();
  6. for( $j = 0; $j < $len; $j++ ) {
  7. if( ( 1 << $j ) & $i ) $line[] = $j + 1;
  8. }
  9. $output[count($line)][] = $line;
  10. }
  11.  
  12. foreach( $output as $group ) {
  13. foreach( $group as $line ) {
  14. foreach( $line as $item ) echo "$item ";
  15. echo "\n";
  16. }
  17. }
  18. ?>
Success #stdin #stdout 0.02s 20568KB
stdin
Standard input is empty
stdout
1 
2 
3 
4 
5 
1 2 
1 3 
2 3 
1 4 
2 4 
3 4 
1 5 
2 5 
3 5 
4 5 
1 2 3 
1 2 4 
1 3 4 
2 3 4 
1 2 5 
1 3 5 
2 3 5 
1 4 5 
2 4 5 
3 4 5 
1 2 3 4 
1 2 3 5 
1 2 4 5 
1 3 4 5 
2 3 4 5 
1 2 3 4 5