Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: PGA Golf, Round 1

by Anonymous Monk
on May 24, 2001 at 22:01 UTC ( #83032=note: print w/ replies, xml ) Need Help??


in reply to PGA Golf, Round 1

# 1 -- 16 chars sub g1 { (pop=~/\w+/g)[4] } # 2 -- 19 chars (23 with newlines) perl -e'goto\ \ \ \ TPC' # 3 -- 23 chars # note: using $ instead of \z is *wrong* # note: using . without /s is *wrong* sub g3 { pop=~/^(.*?)\1+\z/s&&$1 } # 4 -- 12 chars sub g4 { pack"H*",pop } # 5 -- 29 chars sub g5 { $x=pop;$x<$_&&($x=$_)for@_;$x } # 6 -- 49 chars sub g6 { sort{($a=~/[aeiou]/g)[0]cmp($b=~/[aeiou]/g)[0]}@_ }


japhy -- Perl and Regex Hacker


Comment on Re: PGA Golf, Round 1
Download Code
Re: Re: PGA Golf, Round 1
by japhy (Canon) on May 24, 2001 at 22:02 UTC
    Um, that is my code. My cookie expired or something. Anyway, direct any ++'s here, please.

    japhy -- Perl and Regex Hacker
Re: Re: PGA Golf, Round 1
by japhy (Canon) on May 24, 2001 at 22:44 UTC
    Fixes/optimizations:
    # 4 -- 19 chars sub g4 { split//,pack"H*",@_ } # 6 -- 47 chars sub g6 { sort{($a=~($_='([aeiou])'))[0]cmp($b=~$_)[0]}@_ }


    japhy -- Perl and Regex Hacker
Re (tilly) 2: PGA Golf, Round 1
by tilly (Archbishop) on May 24, 2001 at 22:55 UTC
    I had similar solutions. But I improved on hole 3 to 20:
    sub hole{map/^(.*?)\1+\z/s,@_}
    and my solution for hole 5 was also 29 but somewhat different.
    sub hole{$,=pop;$,=$,<$_?$_:$,for@_;$,}
    However we can improve hole 5 to 28 taking your solution and applying my trick to it.:
    sub hole{$,=pop;$_<$,or$,=$_ for@_;$,}

    UPDATE
    Oops. My test code put hole 3 in the wrong context. My bad.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://83032]
help
Chatterbox?
and the web crawler heard nothing...

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

    My favorite cookbook is:










    Results (25 votes), past polls