Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: YAGG (Yet Another Golf Game)

by jmcnamara (Monsignor)
on Feb 12, 2002 at 09:58 UTC ( [id://144817]=note: print w/replies, xml ) Need Help??


in reply to YAGG (Yet Another Golf Game)


Thanks for the practice Necos but there are too many requirements here for a Golf game. ;-)

Anyone thinking of posting a Golf game should have a look at chipmunk's Tips on Writing a Golf Challenge.

Anyway, 90 chars:

#!/usr/bin/perl $s.=rand()<.5?H:$"for+a..gr; $_=$s; $c=y/H/H/; s/(H+| +)/"|".length$1/ge; print"$s\n$_|\n$c\n"

--
John.

Replies are listed 'Best First'.
Re: Re: YAGG (Yet Another Golf Game)
by trs80 (Priest) on Feb 13, 2002 at 02:25 UTC
    Nice round. I did notice an error however. The output for the H's in a row doesn't match the H count. I changed the regex and all is fine now. I also removed the y/H/H/;
    #!/usr/bin/perl $s.=rand()<.5?H:$"for+a..gr; $_=$s; s/(H+) +/"|".length$1/ge; print"$s\n$_|\n$c\n"

      You're right. :-) I thought that the runs of tails had to be included as well.

      This is closer to what is required, but fudges the pipes a little, 88 chars:

      $s.=rand()<.5?H:$"for+a..gr; $_=$s; $c=200-tr/ /|/s; s/(H+)/length$1/ge; print"$s\n$_\n$c\n"

      --
      John.

      This introduces a different error: if the last coin flip is a head, it doesn't get substituted, because it's not followed by a space. So, change the + to a *:
      #!/usr/bin/perl $s.=rand()<.5?H:$"for+a..gr; $_=$s; s/(H+) */"|".length$1/ge; print"$s\n$_|\n$c\n"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found