http://www.perlmonks.org?node_id=103229


in reply to Re (tilly) 3: (Golf) Let's go bowling
in thread (Golf) Let's go bowling

Short though this is it fails the test suite

print score(qw(5 / 6 3 X X 7 0 4 3 X 4 / 8 1 3 / 6)),"--> 146\n"; print score(qw(X X X X X X X X X X X X)), "--> 300\n"; print score(qw(0 / X 0 / X 0 / X 0 / X 0 / X 0 /)),"--> 200\n"; print score(qw(X 0 / X 0 / X 0 / X 0 / X 0 / X 0)),"--> 200\n"; sub score { $i=$s=0;$s-=$_[-1]if"@_[-2,-1]"=~m!/|X!;map{$s+=$_[$i-1],$_=/X/?($s+=$ +_[$i-2],10):10-$_[$i+1]if/\D/;$s+=$_;$i++}@_=(0,0,reverse@_);$s } __END__ 146--> 146 330--> 300 210--> 200 210--> 200

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re (tilly) 5: (Golf) Let's go bowling
by tilly (Archbishop) on Aug 09, 2001 at 02:53 UTC
    Grrr. All of the way up to 175:
    sub score { $i=$s=0;map{$b=!(++$i<5&&$_[4]eq X||4>$i&&$_[3]eq'/');$s+=$b*$_[$i-2], +$_=/X/?($s+=$b*$_[$i-3],10):10-$_[$i]if/\D/;$s+=$_ if$b}@_=(0,0,rever +se@_);$s }
    Note that this does not pass the final test in your suite, but the score given in the final test cannot come from a real bowling game. Remove the trailing 0 that I am sensitive to and I pass.

    Ah well. Yet another cute idea killed by horrible boundary conditions.