Well, if it's a one-off script, perhaps this is the time to learn Prolog, a language which does this sort of thing naturally:
#!/usr/local/bin/perl use strict; use warnings; use AI::Prolog 0.65; my $by_two = AI::Prolog->make_list(map { $_ * 2 } 1 .. 50); my $by_five = AI::Prolog->make_list(map { $_ * 5 } 1 .. 20); my $prolog = AI::Prolog->new(<<"END_PROLOG"); member(X,[X|Tail]). member(X,[Head|Tail]) :- member(X, Tail). one_hundred(A,B,C,D,E) :- or(member(A, [$by_five]), member(A, [$by_two])), or(member(B, [$by_five]), member(B, [$by_two])), or(member(C, [$by_five]), member(C, [$by_two])), or(member(D, [$by_five]), member(D, [$by_two])), or(member(E, [$by_five]), member(E, [$by_two])), is(100, plus(A, plus(B, plus(C, plus(D, E))))). END_PROLOG $prolog->query('one_hundred(A,B,C,D,E).'); while (my $results = $prolog->results) { print join(',' =>@{$results}[1 .. 5]), $/; }
Cheers,
Ovid
New address of my CGI Course.
In reply to Re: How to determine & record all possible variations (AI::Prolog)
by Ovid
in thread How to determine & record all possible variations for 5 items?
by Stenyj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |