diff options
| -rw-r--r-- | challenge-090/adam-russell/blog.txt | 0 | ||||
| -rw-r--r-- | challenge-090/adam-russell/perl/ch-1.pl | 27 | ||||
| -rw-r--r-- | challenge-090/adam-russell/perl/ch-2.pl | 23 |
3 files changed, 50 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..e69de29bb2 --- /dev/null +++ b/challenge-090/adam-russell/blog.txt 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); +} |
