aboutsummaryrefslogtreecommitdiff
path: root/challenge-089
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-089')
-rw-r--r--challenge-089/jcrosswh/perl/ch-1.pl6
-rw-r--r--challenge-089/jcrosswh/perl/ch-2.pl72
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-089/jcrosswh/perl/ch-1.pl b/challenge-089/jcrosswh/perl/ch-1.pl
index ff0f0979a0..c23100948e 100644
--- a/challenge-089/jcrosswh/perl/ch-1.pl
+++ b/challenge-089/jcrosswh/perl/ch-1.pl
@@ -21,6 +21,12 @@ Given a positive integer, this script will sum the
L<GCD|https://en.wikipedia.org/wiki/Greatest_common_divisor> of all possible
unique pairs between 1 and the inputed positive integer.
+=head1 SOLUTION
+
+This solution uses the
+L<Binary GCD algorithm|https://en.wikipedia.org/wiki/Binary_GCD_algorithm> to
+determine the different GCD values.
+
=head1 AUTHORS
Joel Crosswhite E<lt>joel.crosswhite@ix.netcom.comE<gt>
diff --git a/challenge-089/jcrosswh/perl/ch-2.pl b/challenge-089/jcrosswh/perl/ch-2.pl
new file mode 100644
index 0000000000..349f43d523
--- /dev/null
+++ b/challenge-089/jcrosswh/perl/ch-2.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+PWC 089 Challenge 2
+
+=head1 SYNOPSIS
+
+ $ ch-2.pl
+ [ a b c ]
+ [ d e f ]
+ [ g h i ]
+
+=head1 DESCRIPTION
+
+A script to display matrix as below with numbers 1 - 9.
+
+ [ a b c ]
+ [ d e f ]
+ [ g h i ]
+
+The matrix will satisfy the following rules:
+
+ a + b + c = 15
+ d + e + f = 15
+ g + h + i = 15
+ a + d + g = 15
+ b + e + h = 15
+ c + f + i = 15
+ a + e + i = 15
+ c + e + g = 15
+
+The numbers will only be used once.
+
+=head1 SOLUTION
+
+This solution uses the
+L<Siamese method|https://en.wikipedia.org/wiki/Siamese_method> to populate and
+print the array.
+
+=head1 AUTHORS
+
+Joel Crosswhite E<lt>joel.crosswhite@ix.netcom.comE<gt>
+
+=cut
+
+my @matrix;
+my $LENGTH = 3;
+my @location = (0, int($LENGTH / 2));
+my $value = 1;
+my $max_value = $LENGTH * $LENGTH + 1;
+
+while ($value < $max_value) {
+
+ if (!defined($matrix[$location[0]][$location[1]])) {
+ $matrix[$location[0]][$location[1]] = $value++;
+ $location[0] = ($location[0] - 1) % $LENGTH;
+ $location[1] = ($location[1] + 1) % $LENGTH;
+ } else {
+ $location[0] = ((($location[0] + 1) % $LENGTH) + 1) % $LENGTH;
+ $location[1] = ($location[1] - 1) % $LENGTH;
+ }
+}
+
+foreach my $line (@matrix) {
+ printf("[ %d %d %d ]\n", $line->[0], $line->[1], $line->[2]);
+}
+
+exit 0;