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"