#!/usr/bin/perl use strict; use warnings 'all'; use re 'eval'; use vars '%seen'; my $regex = <<'--'; (?{ local $x = 0 }) (?{ local @x = (-1) x @ARGV }) -- my $i = 0; foreach my $number (@ARGV) { $regex .= "(?:(?{ local \$x = \$x + $number; local \$x [$i] = $i } +)|)\n"; $i ++ } $regex .= <<'--'; (?(?{ $x }) fail | ) (?(?{ grep {$_ >= 0} @x }) | fail) (?{ local $str = join " + " => @ARGV [grep {$_ >= 0} @x] }) (?(?{ $seen {$str} ++ }) fail | ) (?(?{ print "$str = 0\n" }) fail | ) -- "" =~ /$regex/x;
Abigail
In reply to Re: permuation algorithm
by Abigail-II
in thread permutation algorithm
by Basilides
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |