summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/mastermind.pl19
-rw-r--r--bin/solve-ghost.pl8
-rw-r--r--bin/solve-superghost.pl8
-rw-r--r--bin/solve-xghost.pl9
4 files changed, 44 insertions, 0 deletions
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";
diff --git a/bin/solve-ghost.pl b/bin/solve-ghost.pl
new file mode 100644
index 0000000..ec59165
--- /dev/null
+++ b/bin/solve-ghost.pl
@@ -0,0 +1,8 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Games::Word::Wordlist;
+
+my $start = $ARGV[0] or die "Usage: $0 <word_prefix>\n";
+my $wl = Games::Word::Wordlist->new('/usr/share/dict/words');
+print "$_\n" for $wl->words_like(qr/^\Q$ARGV[0]/i);
diff --git a/bin/solve-superghost.pl b/bin/solve-superghost.pl
new file mode 100644
index 0000000..b020057
--- /dev/null
+++ b/bin/solve-superghost.pl
@@ -0,0 +1,8 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Games::Word::Wordlist;
+
+my $start = $ARGV[0] or die "Usage: $0 <word_prefix>\n";
+my $wl = Games::Word::Wordlist->new('/usr/share/dict/words');
+print "$_\n" for $wl->words_like(qr/\Q$ARGV[0]/i);
diff --git a/bin/solve-xghost.pl b/bin/solve-xghost.pl
new file mode 100644
index 0000000..ebfa864
--- /dev/null
+++ b/bin/solve-xghost.pl
@@ -0,0 +1,9 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Games::Word::Wordlist;
+
+my $start = $ARGV[0] or die "Usage: $0 <subword>\n";
+my $wl = Games::Word::Wordlist->new('/usr/share/dict/words');
+my $re = join '.*', split(//, $ARGV[0]);
+print "$_\n" for $wl->words_like(qr/$re/i);