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

Re: Re: YAGG (Yet Another Golf Game)

by trs80 (Priest)
on Feb 13, 2002 at 02:25 UTC ( [id://145044]=note: print w/replies, xml ) Need Help??


in reply to Re: YAGG (Yet Another Golf Game)
in thread YAGG (Yet Another Golf Game)

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"

Replies are listed 'Best First'.
Re: Re: Re: YAGG (Yet Another Golf Game)
by jmcnamara (Monsignor) on Feb 13, 2002 at 09:20 UTC

    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.

Re: Re: Re: YAGG (Yet Another Golf Game)
by chipmunk (Parson) on Feb 13, 2002 at 06:27 UTC
    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://145044]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-19 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found