in reply to (Golf) Let's go bowling
Anyway.. I'm sure this can be improved..
I'm not sure on the counting rules, but if it's everything inside the sub, not counting whitespace, it's 150
update: original was missing the pound symbol on the first line.. nothing to do with the sub.. just mised it in the copy-n-paste. Also, put the exact array from the example in case someone thought it was giving the wrong answer#!/usr/bin/perl $|=1; my @b = ('5', '/', '6', '3', 'X', 'X', '7', '0', '4', '3', 'X', '4', ' +/', '8', '1', '3', '/', '6'); $r = a(@b); print "score is $r\n"; sub a { map {s/(\/|X)/10/} @_ ; while ($_ = shift) { if (/^.$/) { $t += ($_[0] == 10 ? $_[1] + shift : $_ + shift) }else{ $t+= ($_[0] < 10 && $_[1] == 10 ? 20 : 10 + $_[0] + $_[1]) } last if ++$f ==10 } $t }
update II
The sub inluding nesisairy whitespace is now 150..
update III removed a space I didn't think I could and removed the closing } from the count... 148
update III same principle, just trimming it down..removed while loop and if statements.. 131sub a { map{s#(/|X)#10#}@_;while($_=shift){if(/10/){$t+=($_[0]<10&&$_[1]==10?2 +0:10+$_[0]+$_[1])}else{$t+=($_[0]==10?$_[1]+shift:$_+shift)}last if++ +$f==10}$t }
yet anotherupdate IV: Got it down to 123. But as Tilly pointed out, it doesn't look like this runs on 5.005_03.. so I don't know what it's worth then. I have since tested this and it works on AIX with perl 5.005_03sub a { map{s#(/|X)#10#}@_;for(1..10){$_=shift;/10/?{$t+=($_[0]<10&&$_[1]==10? +20:10+$_[0]+$_[1])}:{$t+=($_[0]==10?$_[1]+shift:$_+shift)}}$t }
-Richsub a { map{s#[/X]#10#}@_;for(0..9){$_=shift;/10/?$t+=$_[0]<10&&$_[1]==10?20:1 +0+$_[0]+$_[1]:($t+=$_[0]==10?$_[1]+shift:$_+shift)}$t }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: (Golf) Let's go bowling
by dragonchild (Archbishop) on Aug 09, 2001 at 17:56 UTC | |
by abstracts (Hermit) on Aug 09, 2001 at 18:08 UTC | |
by dragonchild (Archbishop) on Aug 09, 2001 at 18:17 UTC | |
Re: Re: (Golf) Let's go bowling
by dragonchild (Archbishop) on Aug 09, 2001 at 01:51 UTC | |
by rchiav (Deacon) on Aug 09, 2001 at 02:13 UTC | |
by tilly (Archbishop) on Aug 09, 2001 at 05:51 UTC |