aboutsummaryrefslogtreecommitdiff
path: root/challenge-090/dave-jacoby
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2020-12-07 22:45:47 -0500
committerDave Jacoby <jacoby.david@gmail.com>2020-12-07 22:45:47 -0500
commit4e09c2a1bcfc3828ec9855f7f9a3fa15529118ba (patch)
tree0fb5fe9bdcb7eb669ed30c07c6a083dedcea9a1e /challenge-090/dave-jacoby
parentd516a0c34ab55ccc6a4eb285757a5988ac6fb1a4 (diff)
downloadperlweeklychallenge-club-4e09c2a1bcfc3828ec9855f7f9a3fa15529118ba.tar.gz
perlweeklychallenge-club-4e09c2a1bcfc3828ec9855f7f9a3fa15529118ba.tar.bz2
perlweeklychallenge-club-4e09c2a1bcfc3828ec9855f7f9a3fa15529118ba.zip
Challenge 90 in Perl
Diffstat (limited to 'challenge-090/dave-jacoby')
-rw-r--r--challenge-090/dave-jacoby/perl/ch-1.pl22
-rw-r--r--challenge-090/dave-jacoby/perl/ch-2.pl38
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-090/dave-jacoby/perl/ch-1.pl b/challenge-090/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..ed5f5e8cc6
--- /dev/null
+++ b/challenge-090/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say signatures state };
+no warnings qw{ experimental };
+
+my $sequence = 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG' ;
+my $complement = $sequence;
+$complement =~ tr/TACG/ATGC/;
+
+say <<"END";
+ Sequence: $sequence
+ Complement: $complement
+END
+
+for my $i ( qw( A T C G ) ) {
+ my $n = scalar grep {/$i/} split // , $sequence;
+ say qq( $i: $n );
+}
+
+
diff --git a/challenge-090/dave-jacoby/perl/ch-2.pl b/challenge-090/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..2973f52f1d
--- /dev/null
+++ b/challenge-090/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw{ say signatures state };
+no warnings qw{ experimental };
+
+use Scalar::Util qw{looks_like_number};
+
+my ( $m, $n ) = map { abs $_ } grep { looks_like_number $_ } @ARGV;
+
+$m //= 17;
+$n //= 38;
+
+say <<"END";
+
+ m $m
+ n $n
+END
+
+say egyptian( $m, $n );
+say $m * $n;
+
+exit;
+
+sub egyptian ( $m, $n ) {
+ my $o = 0;
+ my $i = 1;
+ do {
+ my $e = $m % 2 != 0 ? 1 : 0;
+ say join "\t", $o, $e, $i, $m, $n;
+ $o += $n if $e;
+ $i *= 2;
+ $m = int $m / 2;
+ $n = $n * 2;
+ } while ( $m > 0 );
+ return $o;
+}