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]), $/;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.