aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-090/adam-russell/blog.txt1
-rw-r--r--challenge-090/adam-russell/perl/ch-1.pl27
-rw-r--r--challenge-090/adam-russell/perl/ch-2.pl27
3 files changed, 55 insertions, 0 deletions
diff --git a/challenge-090/adam-russell/blog.txt b/challenge-090/adam-russell/blog.txt
new file mode 100644
index 0000000000..f29baaf0b9
--- /dev/null
+++ 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-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..2654c6476f
--- /dev/null
+++ b/challenge-090/adam-russell/perl/ch-2.pl
@@ -0,0 +1,27 @@
+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 $product = 0;
+ my ($x, $y) = ($a, $b);
+ do{
+ $x = int($x / 2);
+ $y = $y * 2;
+ push @steps, [$x, $y] if $x % 2 != 0;
+ }until $steps[-1]->[0] == 1;
+ for my $step (@steps){
+ $product += $step->[1];
+ }
+ return $product;
+}
+
+MAIN:{
+ my($A, $B) = (14, 12);
+ print "$A x $B = " . ethiopian_multiplication($A, $B) . "\n";
+}