Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: How to determine & record all possible variations (AI::Prolog)

by jdporter (Paladin)
on May 19, 2005 at 12:17 UTC ( [id://458600]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to determine & record all possible variations (AI::Prolog)
in thread How to determine & record all possible variations for 5 items?

could just put all of the numbers in one list. That makes the code simpler and faster
and
the first and fourth numbers are always 4 and 45, respectively
Well that raises some interesting possibilities for even greater generality. To wit: allowing to specify the exact range of each column, individually. Here's my code, modified to do it. (I agree with you that it's rather obtuse. But it is concise. :-)
my @all_nums = 0 .. 100; my @nums = grep { !($_ % 2) or !($_ % 5) } @all_nums; # and throw some special nums in column 3: gen( [ \@nums, \@nums, [4,5], \@nums, \@all_nums, ], 100, 0, sub { print "@_\n" } ); sub gen { my( $col_ranges, $max, $used, $found, @vec ) = @_; if ( @$col_ranges == 0 ) { $found->( @vec ) if $max == $used; return; } my @col_ranges = @$col_ranges; my $col_range = shift @col_ranges; gen( \@col_ranges, $max, $used+$_, $found, @vec, $_ ) for @$col_range; }
  • Comment on Re^4: How to determine & record all possible variations (AI::Prolog)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://458600]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2024-04-25 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found