aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoneWolfiNTj <Hatley.Software@gmail.com>2023-01-22 11:28:08 -0800
committerLoneWolfiNTj <Hatley.Software@gmail.com>2023-01-22 11:28:08 -0800
commitf1249991c0a493ec1340df80d1e5b4b1dc4db05a (patch)
tree20be958e8eb3a238d61723bcb5acaf5f7b0f1989
parent952f98a3d4e479992cd18e544ebb441a952f7159 (diff)
downloadperlweeklychallenge-club-f1249991c0a493ec1340df80d1e5b4b1dc4db05a.tar.gz
perlweeklychallenge-club-f1249991c0a493ec1340df80d1e5b4b1dc4db05a.tar.bz2
perlweeklychallenge-club-f1249991c0a493ec1340df80d1e5b4b1dc4db05a.zip
Robbie Hatley's Perl solutions to Weekly Challenge #200.
-rwxr-xr-x[-rw-r--r--]challenge-200/robbie-hatley/README0
-rwxr-xr-xchallenge-200/robbie-hatley/blog.txt1
-rwxr-xr-xchallenge-200/robbie-hatley/perl/ch-1.pl29
-rwxr-xr-xchallenge-200/robbie-hatley/perl/ch-2.pl161
4 files changed, 191 insertions, 0 deletions
diff --git a/challenge-200/robbie-hatley/README b/challenge-200/robbie-hatley/README
index 1b1dc91203..1b1dc91203 100644..100755
--- a/challenge-200/robbie-hatley/README
+++ b/challenge-200/robbie-hatley/README
diff --git a/challenge-200/robbie-hatley/blog.txt b/challenge-200/robbie-hatley/blog.txt
new file mode 100755
index 0000000000..8889821122
--- /dev/null
+++ b/challenge-200/robbie-hatley/blog.txt
@@ -0,0 +1 @@
+https://hatley-software.blogspot.com/2023/01/robbie-hatleys-perl-solutions-to-weekly_22.html \ No newline at end of file
diff --git a/challenge-200/robbie-hatley/perl/ch-1.pl b/challenge-200/robbie-hatley/perl/ch-1.pl
new file mode 100755
index 0000000000..2d69624d72
--- /dev/null
+++ b/challenge-200/robbie-hatley/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#! /usr/bin/perl
+# Robbie Hatley's Perl solution to The Weekly Challenge #200-1
+
+=pod
+
+Task 1: Arithmetic Slices
+Submitted by: Mohammad S Anwar
+You are given an array of integers. Write a script to find out all Arithmetic
+Slices for the given array of integers. An integer array is called "arithmetic"
+if it has at least 3 elements and the differences between any three
+consecutive elements are the same.
+
+Example 1: Input: @array = (1,2,3,4) Output: (1,2,3), (2,3,4), (1,2,3,4)
+Example 2: Input: @array = (2) Output: () as no slice found.
+
+=cut
+
+# NOTE: Input is by either built-in array of arrays, or by @ARGV. If using
+# @ARGV, input should be a space-separated list of integers, which will
+# be interpreted as a single array.
+
+# NOTE: Output is to stdout and will be a list of all arithmetic slice for
+# each input array.
+
+# PRELIMINARIES:
+use v5.36;
+
+say "Sorry, this is just a stub; ran out of time.";
+say "\"Task 2\", however, is fully functional.";
diff --git a/challenge-200/robbie-hatley/perl/ch-2.pl b/challenge-200/robbie-hatley/perl/ch-2.pl
new file mode 100755
index 0000000000..e06aab39d2
--- /dev/null
+++ b/challenge-200/robbie-hatley/perl/ch-2.pl
@@ -0,0 +1,161 @@
+#! /usr/bin/perl
+# Robbie Hatley's Perl solution to The Weekly Challenge #200-2
+
+=pod
+
+Task 2: Seven Segment 200
+Submitted by: Ryan J Thompson
+A seven segment display is an electronic component, usually used to display
+digits. The segments are labeled 'a' through 'g' as shown:
+
+ a
+ f b
+ g
+ e c
+ d
+
+The encoding of each digit can thus be represented compactly as a truth table:
+my @truth = qw<abcdef bc abdeg abcdg bcfg acdfg acdefg abc abcdefg abcfg>;
+$truth[1] would thus be "bc", indicating that the digit 1 would have segments
+"b" and "c" enabled. Write a program that accepts any [non-negative integer
+of 1-9 digits] and draws that number as a horizontal sequence of seven-segment
+digit displays, similar to the following:
+ ------- ------- -------
+ | | | | |
+ | | | | |
+ -------
+ | | | | |
+ | | | | |
+ ------- ------- -------
+Note that each row consists of 7 lines of 9*n characters, where n is the number
+of digits to be displayed.
+
+=cut
+
+# NOTE: Input is by @ARGV and should be a single integer in the range
+# 0 to 999999999.
+
+# NOTE: Output is to stdout and will be a row of 7-segment digit displays for
+# the digits of the input number.
+
+# PRELIMINARIES:
+use v5.36;
+
+# SUBROUTINES:
+sub display_row($x)
+{
+ my $l = length($x);
+ my @digits = split //,$x;
+ my @lines =
+ (' 'x(9*$l),' 'x(9*$l),' 'x(9*$l),' 'x(9*$l),' 'x(9*$l),' 'x(9*$l),' 'x(9*$l));
+ for ( my $idx = 0; $idx < $l ; ++$idx )
+ {
+ if ( '0' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, '| |';
+ substr $lines[2], 9*$idx+2, 7, '| |';
+ substr $lines[3], 9*$idx+2, 7, ' ';
+ substr $lines[4], 9*$idx+2, 7, '| |';
+ substr $lines[5], 9*$idx+2, 7, '| |';
+ substr $lines[6], 9*$idx+2, 7, '-------';
+ }
+ elsif ( '1' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, ' ';
+ substr $lines[1], 9*$idx+2, 7, ' |';
+ substr $lines[2], 9*$idx+2, 7, ' |';
+ substr $lines[3], 9*$idx+2, 7, ' ';
+ substr $lines[4], 9*$idx+2, 7, ' |';
+ substr $lines[5], 9*$idx+2, 7, ' |';
+ substr $lines[6], 9*$idx+2, 7, ' ';
+ }
+ elsif ( '2' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, ' |';
+ substr $lines[2], 9*$idx+2, 7, ' |';
+ substr $lines[3], 9*$idx+2, 7, '-------';
+ substr $lines[4], 9*$idx+2, 7, '| ';
+ substr $lines[5], 9*$idx+2, 7, '| ';
+ substr $lines[6], 9*$idx+2, 7, '-------';
+ }
+ elsif ( '3' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, ' |';
+ substr $lines[2], 9*$idx+2, 7, ' |';
+ substr $lines[3], 9*$idx+2, 7, '-------';
+ substr $lines[4], 9*$idx+2, 7, ' |';
+ substr $lines[5], 9*$idx+2, 7, ' |';
+ substr $lines[6], 9*$idx+2, 7, '-------';
+ }
+ elsif ( '4' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, ' ';
+ substr $lines[1], 9*$idx+2, 7, '| |';
+ substr $lines[2], 9*$idx+2, 7, '| |';
+ substr $lines[3], 9*$idx+2, 7, '-------';
+ substr $lines[4], 9*$idx+2, 7, ' |';
+ substr $lines[5], 9*$idx+2, 7, ' |';
+ substr $lines[6], 9*$idx+2, 7, ' ';
+ }
+ elsif ( '5' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, '| ';
+ substr $lines[2], 9*$idx+2, 7, '| ';
+ substr $lines[3], 9*$idx+2, 7, '-------';
+ substr $lines[4], 9*$idx+2, 7, ' |';
+ substr $lines[5], 9*$idx+2, 7, ' |';
+ substr $lines[6], 9*$idx+2, 7, '-------';
+ }
+ elsif ( '6' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, '| ';
+ substr $lines[2], 9*$idx+2, 7, '| ';
+ substr $lines[3], 9*$idx+2, 7, '-------';
+ substr $lines[4], 9*$idx+2, 7, '| |';
+ substr $lines[5], 9*$idx+2, 7, '| |';
+ substr $lines[6], 9*$idx+2, 7, '-------';
+ }
+ elsif ( '7' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, ' |';
+ substr $lines[2], 9*$idx+2, 7, ' |';
+ substr $lines[3], 9*$idx+2, 7, ' ';
+ substr $lines[4], 9*$idx+2, 7, ' |';
+ substr $lines[5], 9*$idx+2, 7, ' |';
+ substr $lines[6], 9*$idx+2, 7, ' ';
+ }
+ elsif ( '8' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, '| |';
+ substr $lines[2], 9*$idx+2, 7, '| |';
+ substr $lines[3], 9*$idx+2, 7, '-------';
+ substr $lines[4], 9*$idx+2, 7, '| |';
+ substr $lines[5], 9*$idx+2, 7, '| |';
+ substr $lines[6], 9*$idx+2, 7, '-------';
+ }
+ elsif ( '9' eq $digits[$idx] )
+ {
+ substr $lines[0], 9*$idx+2, 7, '-------';
+ substr $lines[1], 9*$idx+2, 7, '| |';
+ substr $lines[2], 9*$idx+2, 7, '| |';
+ substr $lines[3], 9*$idx+2, 7, '-------';
+ substr $lines[4], 9*$idx+2, 7, ' |';
+ substr $lines[5], 9*$idx+2, 7, ' |';
+ substr $lines[6], 9*$idx+2, 7, ' ';
+ }
+ }
+ say for @lines;
+}
+
+# SCRIPT BODY:
+my $x = 200;
+if (@ARGV) {$x=$ARGV[0]}
+die if $x !~ m/^\d{1,9}$/;
+display_row($x);