diff options
| -rw-r--r-- | challenge-082/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-082/dave-jacoby/perl/ch-1.pl | 23 | ||||
| -rw-r--r-- | challenge-082/dave-jacoby/perl/ch-2.pl | 32 |
3 files changed, 56 insertions, 0 deletions
diff --git a/challenge-082/dave-jacoby/blog.txt b/challenge-082/dave-jacoby/blog.txt new file mode 100644 index 0000000000..e434f71c11 --- /dev/null +++ b/challenge-082/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby.github.io/2020/10/14/perl-challenge-82.html
\ No newline at end of file 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; +} + |
