aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-12-13 15:25:59 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-12-13 15:25:59 +0000
commitab946757870f0ca4dee4c39ba7c6ac75e3f88810 (patch)
tree6850cbc2a4bb6876a1502d0dccab65151423e21e
parent0e35881209a1d02a2e3c9659001c1f78e043de8f (diff)
parent20fbf4317c9c009554168d8b48de3bc66282559d (diff)
downloadperlweeklychallenge-club-ab946757870f0ca4dee4c39ba7c6ac75e3f88810.tar.gz
perlweeklychallenge-club-ab946757870f0ca4dee4c39ba7c6ac75e3f88810.tar.bz2
perlweeklychallenge-club-ab946757870f0ca4dee4c39ba7c6ac75e3f88810.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
-rw-r--r--challenge-090/wanderdoc/perl/ch-1.pl29
-rw-r--r--challenge-090/wanderdoc/perl/ch-2.pl55
2 files changed, 84 insertions, 0 deletions
diff --git a/challenge-090/wanderdoc/perl/ch-1.pl b/challenge-090/wanderdoc/perl/ch-1.pl
new file mode 100644
index 0000000000..ca0ae57c9e
--- /dev/null
+++ b/challenge-090/wanderdoc/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given DNA sequence, GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG.
+Write a script to print nucleiobase count in the given DNA sequence. Also print the complementary sequence.
+=cut
+
+
+
+
+
+
+
+
+
+
+my $strand_1 = 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG';
+my %compl = (T => 'A', A => 'T', G => 'C', C => 'G');
+
+my %count;
+my $strand_2 = join('', map { $count{$_}++; $compl{$_}} split(//, $strand_1));
+
+print "$_ => $count{$_}$/" for sort { $a cmp $b } keys %count;
+
+print $strand_1, $/;
+print '|' x length($strand_1), $/;
+print $strand_2, $/; \ No newline at end of file
diff --git a/challenge-090/wanderdoc/perl/ch-2.pl b/challenge-090/wanderdoc/perl/ch-2.pl
new file mode 100644
index 0000000000..1aca7425b9
--- /dev/null
+++ b/challenge-090/wanderdoc/perl/ch-2.pl
@@ -0,0 +1,55 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given two positive numbers $A and $B.
+Write a script to demonstrate Ethiopian Multiplication using the given numbers.
+https://threesixty360.wordpress.com/2009/06/09/ethiopian-multiplication/
+=cut
+
+
+
+
+
+
+
+
+
+use Test::More;
+use Scalar::Util qw(looks_like_number);
+
+sub em
+{
+
+ my ($num_1, $num_2) = @_;
+
+ die "Two positive integers required!$/"
+ unless (looks_like_number($num_1) and looks_like_number($num_2) and
+ $num_1 > 0 and $num_2 > 0 and
+ $num_1 = int($num_1) and $num_2 = int($num_2));
+ return 0 if ($num_1 == 0 or $num_2 == 0);
+ my $sum;
+ while ( $num_1 > 0 )
+ {
+ if ( $num_1 % 2 )
+ {
+ $sum += $num_2;
+ }
+
+
+ $num_1 = int($num_1/2);
+ $num_2 *= 2;
+ }
+
+ return $sum;
+}
+
+
+
+is(em(14, 12), 14 * 12, 'Example 1');
+is(em(25, 5), 25 * 5, 'Example 2');
+is(em(15, 30), 15 * 30, 'Example 3');
+
+
+done_testing; \ No newline at end of file