aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2020-10-14 19:59:52 -0400
committerDave Jacoby <jacoby.david@gmail.com>2020-10-14 19:59:52 -0400
commit6cf3d3e248635ce84ace0906f57c40f1316245cc (patch)
treee9c182afc359066fe3b8b518ed8f918d007e878b
parente52495e8c6f82618c98fef8cbee389ceb7db6769 (diff)
downloadperlweeklychallenge-club-6cf3d3e248635ce84ace0906f57c40f1316245cc.tar.gz
perlweeklychallenge-club-6cf3d3e248635ce84ace0906f57c40f1316245cc.tar.bz2
perlweeklychallenge-club-6cf3d3e248635ce84ace0906f57c40f1316245cc.zip
Challenge 82 - does it do CRLF right?
-rw-r--r--challenge-082/dave-jacoby/perl/ch-1.pl23
-rw-r--r--challenge-082/dave-jacoby/perl/ch-2.pl32
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-082/dave-jacoby/perl/ch-1.pl b/challenge-082/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..5d00a2b121
--- /dev/null
+++ b/challenge-082/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say signatures state };
+no warnings qw{ experimental };
+
+use List::Util qw{ min max };
+
+push @ARGV, 12, 18 unless scalar @ARGV;
+
+common_factors( min(@ARGV), max(@ARGV) );
+
+sub common_factors ( $min, $max ) {
+ my @factors;
+ say qq{MIN: $min};
+ say qq{MAX: $max};
+
+ for my $i ( 1 .. $min ) {
+ push @factors, $i if $min % $i == 0 && $max % $i == 0;
+ }
+ say join ',', @factors;
+}
diff --git a/challenge-082/dave-jacoby/perl/ch-2.pl b/challenge-082/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..5f7273fd68
--- /dev/null
+++ b/challenge-082/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say signatures state };
+no warnings qw{ experimental };
+
+my ( $aa, $bb, $cc ) = @ARGV;
+
+$aa //= "XY";
+$bb //= "X";
+$cc //= "XXY";
+
+say check_interleave( $aa, $bb, $cc );
+
+sub check_interleave ( $aa, $bb, $cc ) {
+ my $afirst;
+ my $bfirst;
+
+ while ( $aa ne "" || $bb ne "" ) {
+ my $la = substr $aa, 0, 1;
+ my $lb = substr $bb, 0, 1;
+ $afirst .= $la . $lb;
+ $bfirst .= $lb . $la;
+ substr( $aa, 0, 1 ) = '';
+ substr( $bb, 0, 1 ) = '';
+ }
+ return 1 if $cc eq $afirst;
+ return 1 if $cc eq $bfirst;
+ return 0;
+}
+