I don't know if my logic is wrong but I get a score of 162. I havn't bothered to obfuscate it and print out a score sheet to show the frame by frame results.
my @b = ('5', '/', '6', '3', 'X', 'X', '7', '0', '4', '3',
'X', '4', '/', '8', '1', '3', '/', '6');
print "Frame tog ball score total\n";
print score(@b),"\n\n";
print "Frame tog ball score total\n";
print score(('X')x12);
sub score {
$i=0;$f=1;$t=1;$score=0;
for (@_) {
last if $f>10;
if(/X/) {
$s=10+n($_[$i+1])+n($_[$i+2]);
$t=1
}
elsif(/\//) {
$s=10+n($_[$i+1]);
$t=1
}
else {
$s=$_;
$t^=1 # flip the toggle with XOR
}
$score+=$s;
printf "%2d %d %s %2d %3d\n",$f, $t, $_, $s, $scor
+e;
$t&&$f++; # count the frames
$i++;
}
sub n{$v=pop;$v=~/[X\/]/?10:$v}
return $score
}
__END__
Frame tog ball score total
1 0 5 5 5
1 1 / 16 21
2 0 6 6 27
2 1 3 3 30
3 1 X 27 57
4 1 X 17 74
5 0 7 7 81
5 1 0 0 81
6 0 4 4 85
6 1 3 3 88
7 1 X 24 112
8 0 4 4 116
8 1 / 18 134
9 0 8 8 142
9 1 1 1 143
10 0 3 3 146
10 1 / 16 162
162
Frame tog ball score total
1 1 X 30 30
2 1 X 30 60
3 1 X 30 90
4 1 X 30 120
5 1 X 30 150
6 1 X 30 180
7 1 X 30 210
8 1 X 30 240
9 1 X 30 270
10 1 X 30 300
300
Did I miss something?
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print