diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-10-15 01:50:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-15 01:50:33 +0100 |
| commit | e4b2707aec67e29442f450d242f0772a717fe12f (patch) | |
| tree | dee348671ec0278506dde7cac876f70ef82c4db9 | |
| parent | 19a6485b426eda8c9e83fd79d07c8ea733f55cdc (diff) | |
| parent | f8529d853f9671b5cb34bcf4f0a61f4c688b97a1 (diff) | |
| download | perlweeklychallenge-club-e4b2707aec67e29442f450d242f0772a717fe12f.tar.gz perlweeklychallenge-club-e4b2707aec67e29442f450d242f0772a717fe12f.tar.bz2 perlweeklychallenge-club-e4b2707aec67e29442f450d242f0772a717fe12f.zip | |
Merge pull request #2527 from jacoby/master
Challenge 82 - does it do CRLF right?
| -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; +} + |
