• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Buried in cloud files? We can help with Spring cleaning!

    Whether you use Dropbox, Drive, G-Suite, OneDrive, Gmail, Slack, Notion, or all of the above, Dokkio will organize your files for you. Try Dokkio (from the makers of PBworks) for free today.

  • Dokkio (from the makers of PBworks) was #2 on Product Hunt! Check out what people are saying by clicking here.



Page history last edited by David B 13 years, 2 months ago

A fully-functional game of Mastermind written in Perl.


Consult the Mastermind Instructions if you are unfamiliar with how the original game is played. This demonstration shows how my script is used to play the game:


perl mind.pl


1 1234


Program prompts with '1', which indicates the first guess. Player guesses '1234'.




Program responds with 1 white peg and no red pegs.


2 5678



8 8822

0W4R 8822


4 red pegs followed by the answer shows the player guessed the code correctly before his ten tries were exceeded.



sub q{$;=1;$q='';$q.=int(rand(9))for(5..8)}sub _{print@_}&q;for(;;){$:=$~=0;_
"$/$; ";chop($_=<>);if(/^d{4}$/){$_.=q,_._,.$q;$:++while+s/(.)(.{6})1/;$2,/
;$~++while+s/(.)(...+)1/;$2$1/;_"$~W$:R ";++$;;$:==4|$;>10&&_($q)&&&q}}

Comments (0)

You don't have permission to comment on this page.