aboutsummaryrefslogtreecommitdiff
path: root/challenge-200/colin-crain
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-01-23 01:51:15 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-01-23 01:51:15 +0000
commit3a0d3971fee4f0e88baa2cf83e7a4a33b24ca8ec (patch)
tree8c67d01edbb6591029af2b3f44fba80427971172 /challenge-200/colin-crain
parent297f41de92d136922e9c85c2f8075966d6ef80ed (diff)
downloadperlweeklychallenge-club-3a0d3971fee4f0e88baa2cf83e7a4a33b24ca8ec.tar.gz
perlweeklychallenge-club-3a0d3971fee4f0e88baa2cf83e7a4a33b24ca8ec.tar.bz2
perlweeklychallenge-club-3a0d3971fee4f0e88baa2cf83e7a4a33b24ca8ec.zip
- Added solutions by Roger Bell_West.
- Added solutions by Dave Jacoby. - Added solutions by David Ferrone. - Added solutions by Luca Ferrari. - Added solutions by Mark Anderson. - Added solutions by W. Luis Mochan. - Added solutions by Peter Campbell Smith. - Added solutions by Mariano Spadaccini. - Added solutions by Thomas Kohler. - Added solutions by Bob Lied. - Added solutions by Jorg Sommrey. - Added solutions by Flavio Poletti. - Added solutions by Pip Stuart. - Added solutions by E. Choroba. - Added solutions by Stephen G. Lynn. - Added solutions by Matthew Neleigh. - Added solutions by Robert Ransbottom. - Added solutions by Athanasius. - Added solutions by Simon Green. - Added solutions by Cheok-Yin Fung. - Added solutions by Tyler Wardhaugh. - Added solutions by Jan Krnavek. - Added solutions by Bruce Gray. - Added solutions by James Smith. - Added solutions by Robbie Hatley. - Added solutions by Solathian. - Added solutions by Arne Sommer. - Added solutions by Carlos Oliveira. - Added solutions by Marton Polgar. - Added solutions by Adam Russell. - Added solutions by Duncan C. White. - Added solutions by Lars Balker. - Added solutions by Colin Crain. - Added solutions by Laurent Rosenfeld. - Added solutions by Robert DiCicco. - Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-200/colin-crain')
-rw-r--r--challenge-200/colin-crain/blog.txt1
-rwxr-xr-xchallenge-200/colin-crain/perl/ch-1.pl78
-rwxr-xr-xchallenge-200/colin-crain/perl/ch-2.pl89
3 files changed, 168 insertions, 0 deletions
diff --git a/challenge-200/colin-crain/blog.txt b/challenge-200/colin-crain/blog.txt
new file mode 100644
index 0000000000..de69cd7720
--- /dev/null
+++ b/challenge-200/colin-crain/blog.txt
@@ -0,0 +1 @@
+https://colincrain.com/2023/01/22/seven-segments-to-midnight
diff --git a/challenge-200/colin-crain/perl/ch-1.pl b/challenge-200/colin-crain/perl/ch-1.pl
new file mode 100755
index 0000000000..3afdc4e84e
--- /dev/null
+++ b/challenge-200/colin-crain/perl/ch-1.pl
@@ -0,0 +1,78 @@
+#!/Users/colincrain/perl5/perlbrew/perls/perl-5.32.0/bin/perl
+#
+# arithmetic-sequences.pl
+#
+# 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.
+#
+#
+# method:
+#
+# we work from left to right. Starting at element [0], we look
+# ahead to element [1]. We set the $last difference as the
+# difference between elements [1] and [0]. We then look to
+# element 2. If the difference between it and [1] is the same
+# we have a sequence: store the slice between our starting and
+# ending positions as a nested array in @out.
+#
+# We then move through the rest of the array as long as the
+# difference between adjacent elements remains the same as the
+# last difference. If it is, again store the slice from the start to
+# current lookahead in @out as well.
+#
+# On failure move the start position up one and begin to search again.
+#
+# Stop two places from the end position, as that is the minimal space to
+# find a new sequence.
+#
+# © 2022 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+
+use warnings;
+use strict;
+use utf8;
+use feature ":5.26";
+use feature qw(signatures);
+no warnings 'experimental::signatures';
+
+
+my @arr = @ARGV;
+@arr == 0 and @arr = (1,2,3,5,7,9,6,3,0,-3);
+
+my @out;
+my $last;
+my $curr;
+
+for (0..$#arr-2) {
+ $curr = $_+1;
+ $last = $arr[$_+1] - $arr[$_];
+ while ($arr[$curr+1] - $arr[$curr] == $last) {
+ push @out, [ @arr[$_..$curr+1] ];
+ last if ++$curr == $#arr;
+ }
+}
+
+say "$_->@*" for @out;
+
+
+
+
diff --git a/challenge-200/colin-crain/perl/ch-2.pl b/challenge-200/colin-crain/perl/ch-2.pl
new file mode 100755
index 0000000000..b328ae1429
--- /dev/null
+++ b/challenge-200/colin-crain/perl/ch-2.pl
@@ -0,0 +1,89 @@
+#!/Users/colincrain/perl5/perlbrew/perls/perl-5.32.0/bin/perl
+#
+# seven-seconds.pl
+#
+# 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>; For example, $truth[1] = ‘bc’. The digit 1 would
+# have segments ‘b’ and ‘c’ enabled.
+#
+# Write a program that accepts any decimal number and draws that
+# number as a horizontal sequence of ASCII seven segment displays,
+# similar to the following:
+#
+#
+# ------- ------- -------
+# | | | | |
+# | | | | |
+# -------
+# | | | | |
+# | | | | |
+# ------- ------- -------
+#
+# To qualify as a seven segment display, each segment must be drawn
+# (or not drawn) according to your @truth table.
+#
+# The number "200" was of course chosen to celebrate our 200th
+# week!
+#
+#
+#
+# © 2022 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+
+use warnings;
+use strict;
+use utf8;
+use feature ":5.26";
+use feature qw(signatures);
+no warnings 'experimental::signatures';
+use open ':std', ':encoding(UTF-8)';
+
+## given encoding method
+my @truth = qw( abcdef bc abdeg abcdg bcfg acdfg acdefg abc abcdefg abcfg );
+
+## input
+my $num = shift @ARGV // 31415926;
+my @out;
+
+for my $d (split //, $num) {
+ $out[0] .= $truth[$d] =~ s/(a?)[bcdefg]*/ $1 ? ' ╺╸ ' : ' '/er;
+ $out[1] .= reverse $truth[$d] =~ s/a?(b?)[cde]*(f?)g?/
+ ($1 ? '┃' : ' ')
+ . ' '
+ . ($2 ? '┃' : ' ')/er;
+ $out[2] .= $truth[$d] =~ s/[abcdef]*(g?)/ $1 ? ' ━━ ' : ' '/er;
+ $out[3] .= reverse $truth[$d] =~ s/a?b?(c?)d?(e?)f?g?/
+ ($1 ? '┃' : ' ')
+ . ' '
+ . ($2 ? '┃' : ' ')/er;
+ $out[4] .= $truth[$d] =~ s/[abc]*(d?)[efg]*/$1 ? ' ╺╸ ' : ' '/er;
+
+ $out[$_] .= ' ' for (0..4);
+}
+
+## output
+for my $i (0..4) {
+ say $out[$i];
+}
+
+
+
+