in reply to How to determine & record all possible variations for 5 items?
Update: I passed 50 for the 'max' value here because it gives the result you want when going to 100 by 2's. Just multiply every number in every cell of the result by 2. Similarly, if you want to go to 100 by 5's, pass 20, and multiply all the numbers in the result by 5.gen( 5, 50, 0, sub { print "@_\n" } ); sub gen { my( $cols, $max, $used, $found, @vec ) = @_; return $found->( @vec, $max-$used ) if $cols == 1; gen( $cols-1, $max, $used+$_, $found, @vec, $_ ) for 0 .. $max-$used; }
|
|---|