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

Re: New golf game (for the extremely bored)

by chipmunk (Parson)
on Feb 08, 2002 at 17:49 UTC ( #144164=note: print w/ replies, xml ) Need Help??


in reply to New golf game (for the extremely bored)

Two solutions of 38 characters:

# 1 2 3 #2345678901234567890123456789012345678 perl -le'print+(H,T)[rand 2]for a..gr' perl -le'print 1<rand 2?H:T for a..gr'


Comment on Re: New golf game (for the extremely bored)
Download Code
Re: Re: New golf game (for the extremely bored)
by redsquirrel (Hermit) on Feb 08, 2002 at 18:06 UTC
    Using your second example, you can take the score down to 37 like this:

    perl -le'print+rand>.5?H:T for a..gr'

    --Dave

Re: Re: New golf game (for the extremely bored)
by Cody Pendant (Prior) on Feb 09, 2002 at 11:02 UTC
    Can someone explain that "a..gr" thing to me please?

    I'm baffled.
    --

    ($_='
      jjjjjjuuuuuuuuusssssssssttttttttt annnnnnoootttttthhhhheeeeeerrrrrr
      pppeeeerrrrrrrrrrrrllllllllllllll haaaaccccccckkkkkkkeeeeeeeerrrrrr')
                   =~y/[a-z]//s;print;
      >Can someone explain that "a..gr" thing to me please?

      Same as 1..200, really ;)

      Basically you just use letters instead of numbers.

      a..z yields the 26 characters of the alphabet,
      a..az yields those and another 26 prefixed with a
      a..bz yields those and another 26 prefixed with b
      and so on. Same system, more "numbers" ...

      Incidentally a..gr yields 7*26 + 18 "numbers".

      update : as crazyinsomniac pointed out, the range-operator is discussed in more detail in perlman:perlop.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2015-07-02 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (36 votes), past polls