From ab2b9d0c3425e5d14fd6cbed4f8be1e71741ada7 Mon Sep 17 00:00:00 2001 From: James Allenspach Date: Fri, 7 Jan 2022 21:51:00 -0600 Subject: [PATCH 1/3] Initial commit --- 51_Hurkle/perl/hurkle.pl | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 51_Hurkle/perl/hurkle.pl diff --git a/51_Hurkle/perl/hurkle.pl b/51_Hurkle/perl/hurkle.pl new file mode 100755 index 00000000..abb42d5a --- /dev/null +++ b/51_Hurkle/perl/hurkle.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# global variables + +my($GRID) = 10; +my($TRIES) = 5; + + +# main program starts here + +# print instructions +print <); + # Use a regex to attempt to parse out + # two integers separated by a comma. + if ($in =~ m{(\d+)\s*,\s*(\d+)}) { + $G1 = $1; $G2 = $2; + last CHECK; + } + # Input not accepted, please try again + print "Please enter two numbers separated by a comma ? "; + } + + if (abs($H1 - $G1) + abs($H2 - $G2) != 0) { + + # print directional info + printf("Go %s%s\n\n", + ($G2 == $H2 ? '' : $G2 < $H2 ? 'north' : 'south'), + ($G1 == $H1 ? '' : $G1 < $H1 ? 'east' : 'west' ), + ); + } else { + # win! + printf("\nYou found him in %d tries!\n", $i); + # move to the continue block + next PLAY; + } + } # tries loop + + # No more guesses + printf("Sorry, that's %d gueses.\n", $TRIES); + printf("The Hurkle is at %d, %d\n", $H1, $H2); +} + +# Execution comes here either from the "next PLAY" +# statement, or by the PLAY block naturally ending +# after the player has lost. +continue { + print "\nLet's play again. Hurkle is hiding.\n\n"; +} \ No newline at end of file From 4d66d18e714e08384395a03775d6f1756ef43bc8 Mon Sep 17 00:00:00 2001 From: James Allenspach Date: Fri, 7 Jan 2022 21:51:56 -0600 Subject: [PATCH 2/3] typo --- 51_Hurkle/perl/hurkle.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/51_Hurkle/perl/hurkle.pl b/51_Hurkle/perl/hurkle.pl index abb42d5a..52d7e853 100755 --- a/51_Hurkle/perl/hurkle.pl +++ b/51_Hurkle/perl/hurkle.pl @@ -72,7 +72,7 @@ PLAY: while (1) { } # tries loop # No more guesses - printf("Sorry, that's %d gueses.\n", $TRIES); + printf("Sorry, that's %d guesses.\n", $TRIES); printf("The Hurkle is at %d, %d\n", $H1, $H2); } From 83a9d95fc43f65233719434f2af5f4039aec50ab Mon Sep 17 00:00:00 2001 From: James Allenspach Date: Fri, 7 Jan 2022 21:52:30 -0600 Subject: [PATCH 3/3] add line break at eof --- 51_Hurkle/perl/hurkle.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/51_Hurkle/perl/hurkle.pl b/51_Hurkle/perl/hurkle.pl index 52d7e853..1497e50c 100755 --- a/51_Hurkle/perl/hurkle.pl +++ b/51_Hurkle/perl/hurkle.pl @@ -81,4 +81,4 @@ PLAY: while (1) { # after the player has lost. continue { print "\nLet's play again. Hurkle is hiding.\n\n"; -} \ No newline at end of file +}