I have two questions about this example code (taken from http://svn.openfoundry.org/pugs/examples/sendmoremoney.p6)
(btw, a really nice example of how to use junctions - just try to write this in perl5 :)
#!perl6 use v6;
my $s; my $e; my $n; my $d; my $m; my $o; my $r;
my $y;
$s = any(0..10) & none(0); $e = any(0..10); $n = any(0..10); $d = any(0..10); $m = any(0..10) & none(0); $o = any(0..10); $r = any(0..10); $n = any(0..10); $y = any(0..10);
I think these should be any(0..9).
my $send := construct($s,$e,$n,$d); my $more := construct($m,$o,$r,$e); my $money := construct($m,$o,$n,$e,$y);
if ($send + $more == $money) { say " send = $send"; say "+more = $more"; say "-------------" say "money = $money"; }
sub foldl(Code &op, Any $initial, [EMAIL PROTECTED]) returns Any { if ([EMAIL PROTECTED] == 0) { return $initial; } else { return &op(shift @values, &?SUB(&op, $initial, @values)); } }
sub add(Int $x, Int $y) returns Int { return $x + $y; }
sub construct([EMAIL PROTECTED]) returns Junction { return foldl( sub ($x, $y) { $x * 10 + $y}, 0, @values); }
How would the if (...) {...} work if there were more than one possible match to this equation?
How would I rewrite this example to be more general, so that given 3 strings (in this case 'send', 'more', 'money'), the program would give all possible results for the equation <first string> + <second string> = <third string>.
-- Markus Laire <Jam. 1:5-6>