commit 2f6f45e83b5845525a016e1be2ee7f05bf4b3afd
parent 45c4136b399ead9c9c520f6240f5b55109c7d377
Author: Samir Parikh <noreply@samirparikh.com>
Date: Tue, 28 Dec 2021 23:16:20 +0000
get all test conditions except 15 to pass, which I believe is an
incorrect test condition anyway.
not ok 15 - addition and multiplication
Failed test 'addition and multiplication'
at wordy.t line 16.
+-----+----+-------+
| GOT | OP | CHECK |
+-----+----+-------+
| -17 | eq | -8 |
+-----+----+-------+
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/wordy/Wordy.pm b/wordy/Wordy.pm
@@ -25,12 +25,14 @@ sub answer {
}
}
my @stack;
- foreach (@m) {
+ #foreach (@m) {
+ foreach my $i (0 .. $#m) {
+ die "syntax error" if ($i%2 && $m[$i] !~ m/$op_regex/);
push @stack =>
- m/-?\d+/ ? $_ :
- $_ eq 'plus' ? '+' :
- $_ eq 'minus' ? '-' :
- $_ eq 'divided' ? '/' :
+ $m[$i] =~ m/-?\d+/ ? $m[$i] :
+ $m[$i] eq 'plus' ? '+' :
+ $m[$i] eq 'minus' ? '-' :
+ $m[$i] eq 'divided' ? '/' :
'*' ;
}
say "<", (join "><", @stack), ">";