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"