From 76d2fecd7ff88a846d1a3fedc2b6efb4d6345a72 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 13 Dec 2020 01:37:16 -0500 Subject: initial commit --- challenge-090/adam-russell/blog.txt | 0 challenge-090/adam-russell/perl/ch-1.pl | 27 +++++++++++++++++++++++++++ challenge-090/adam-russell/perl/ch-2.pl | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 challenge-090/adam-russell/blog.txt create mode 100644 challenge-090/adam-russell/perl/ch-1.pl create mode 100644 challenge-090/adam-russell/perl/ch-2.pl diff --git a/challenge-090/adam-russell/blog.txt b/challenge-090/adam-russell/blog.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/challenge-090/adam-russell/perl/ch-1.pl b/challenge-090/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..382f19295f --- /dev/null +++ b/challenge-090/adam-russell/perl/ch-1.pl @@ -0,0 +1,27 @@ +use strict; +use warnings; +## +# Write a script to print the nucleiobase count in +# the given DNA sequence. Also print the complementary +# sequence where Thymine (T) on one strand is always +# facing an adenine (A) and vice versa; guanine (G) is +# always facing a cytosine (C) and vice versa. +## +use constant SEQUENCE => "GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG"; +my %nucleotide_map = ( + "T" => "A", + "A" => "T", + "G" => "C", + "C" => "G" +); + +sub complementary_sequence{ + my($sequence) = @_; + my @complement = map { $nucleotide_map{$_} } split(//, $sequence); + return @complement; +} + +MAIN:{ + print "length of sequence: " . length(SEQUENCE) . "\n"; + print "complementary sequence: " . join("", complementary_sequence(SEQUENCE)) . "\n"; +} diff --git a/challenge-090/adam-russell/perl/ch-2.pl b/challenge-090/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..6d5d0a4852 --- /dev/null +++ b/challenge-090/adam-russell/perl/ch-2.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +## +# You are given two positive numbers $A and $B. +# Write a script to demonstrate Ethiopian Multiplication +# using the given numbers. +## +sub ethiopian_multiplication{ + my($a, $b) = @_; + my @steps; + my ($x, $y) = ($a, $b); + do{ + $x = int($x / 2); + $y = $y * 2; +print "$x $y\n"; + push @steps, [$x, $y]; + }until $steps[-1]->[0] == 1 || $steps[-1]->[1] == 1; +} + +MAIN:{ + my($A, $B) = (14, 12); + ethiopian_multiplication($A, $B); +} -- cgit From 25729a15432147223ae0920ff217ec5422544cff Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 13 Dec 2020 16:57:15 -0500 Subject: solutions for challenge 090 --- challenge-090/adam-russell/blog.txt | 1 + challenge-090/adam-russell/perl/ch-2.pl | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/challenge-090/adam-russell/blog.txt b/challenge-090/adam-russell/blog.txt index e69de29bb2..f29baaf0b9 100644 --- a/challenge-090/adam-russell/blog.txt +++ b/challenge-090/adam-russell/blog.txt @@ -0,0 +1 @@ +www.rabbitfarm.com/cgi-bin/blosxom/perl/2020/12/13 diff --git a/challenge-090/adam-russell/perl/ch-2.pl b/challenge-090/adam-russell/perl/ch-2.pl index 6d5d0a4852..fb6e4c7919 100644 --- a/challenge-090/adam-russell/perl/ch-2.pl +++ b/challenge-090/adam-russell/perl/ch-2.pl @@ -8,16 +8,20 @@ use warnings; sub ethiopian_multiplication{ my($a, $b) = @_; my @steps; + my $product = 0; my ($x, $y) = ($a, $b); do{ $x = int($x / 2); $y = $y * 2; -print "$x $y\n"; - push @steps, [$x, $y]; + push @steps, [$x, $y] if $x % 2 != 0; }until $steps[-1]->[0] == 1 || $steps[-1]->[1] == 1; + for my $step (@steps){ + $product += $step->[1]; + } + return $product; } MAIN:{ my($A, $B) = (14, 12); - ethiopian_multiplication($A, $B); + print "$A x $B = " . ethiopian_multiplication($A, $B) . "\n"; } -- cgit From 9574d750f4be19fd25966be9ad881e14b8d8174c Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 13 Dec 2020 18:37:10 -0500 Subject: updated part 2 --- challenge-090/adam-russell/perl/ch-2.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-090/adam-russell/perl/ch-2.pl b/challenge-090/adam-russell/perl/ch-2.pl index fb6e4c7919..2654c6476f 100644 --- a/challenge-090/adam-russell/perl/ch-2.pl +++ b/challenge-090/adam-russell/perl/ch-2.pl @@ -14,7 +14,7 @@ sub ethiopian_multiplication{ $x = int($x / 2); $y = $y * 2; push @steps, [$x, $y] if $x % 2 != 0; - }until $steps[-1]->[0] == 1 || $steps[-1]->[1] == 1; + }until $steps[-1]->[0] == 1; for my $step (@steps){ $product += $step->[1]; } -- cgit