From ac7fd1b400c0a4d11047f80fd151c5df84c9d1a9 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Fri, 1 Feb 2008 23:16:17 -0500 Subject: add a few example utilities --- bin/mastermind.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bin/mastermind.pl (limited to 'bin/mastermind.pl') diff --git a/bin/mastermind.pl b/bin/mastermind.pl new file mode 100644 index 0000000..b48cf4c --- /dev/null +++ b/bin/mastermind.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Games::Word qw/random_string_from shared_letters + shared_letters_by_position/; + +my $word = random_string_from "abcdefg", 5; +while (1) { + print "Guess? "; + my $guess = <>; + chomp $guess; + last if $guess eq $word; + my $gears = shared_letters_by_position $guess, $word; + my $tumblers = shared_letters($guess, $word) - $gears; + printf "You hear $tumblers tumbler%s and $gears gear%s.\n", + $tumblers == 1 ? '' : 's', + $gears == 1 ? '' : 's'; +} +print "You see the drawbridge open.\n"; -- cgit v1.2.3-54-g00ecf