Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Well this is my first golf, and I was pretty proud of it until I saw tilly's post. But then again, when doesn't he have the lowest score? :)

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

#!/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: 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

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

sub 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 }
update III same principle, just trimming it down..removed while loop and if statements.. 131
sub 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 }
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_03
sub 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 }
-Rich

In reply to Re: (Golf) Let's go bowling by rchiav
in thread (Golf) Let's go bowling by virtualsue

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (4)
    As of 2014-09-02 01:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (18 votes), past polls