From 6cf3d3e248635ce84ace0906f57c40f1316245cc Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Wed, 14 Oct 2020 19:59:52 -0400 Subject: Challenge 82 - does it do CRLF right? --- challenge-082/dave-jacoby/perl/ch-1.pl | 23 +++++++++++++++++++++++ challenge-082/dave-jacoby/perl/ch-2.pl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 challenge-082/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-082/dave-jacoby/perl/ch-2.pl 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; +} + -- cgit From f8529d853f9671b5cb34bcf4f0a61f4c688b97a1 Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Wed, 14 Oct 2020 20:07:43 -0400 Subject: I Wrote A Thing! --- challenge-082/dave-jacoby/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-082/dave-jacoby/blog.txt 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 -- cgit