aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2020-12-07 08:44:10 +0000
committerdrbaggy <js5@sanger.ac.uk>2020-12-07 08:44:10 +0000
commitfd8e32585a0b9d3abcc7c22c3f30e19354a039ef (patch)
tree75af3ec492b259c654fe8daf16eee3520f261885
parentd181a79cc3b10b862de348d6a6ca503df28e5203 (diff)
downloadperlweeklychallenge-club-fd8e32585a0b9d3abcc7c22c3f30e19354a039ef.tar.gz
perlweeklychallenge-club-fd8e32585a0b9d3abcc7c22c3f30e19354a039ef.tar.bz2
perlweeklychallenge-club-fd8e32585a0b9d3abcc7c22c3f30e19354a039ef.zip
new ch1/2
-rw-r--r--challenge-090/james-smith/perl/ch-1.pl28
-rw-r--r--challenge-090/james-smith/perl/ch-2.pl30
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-090/james-smith/perl/ch-1.pl b/challenge-090/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..0970dfd554
--- /dev/null
+++ b/challenge-090/james-smith/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+
+## Ah! The day job....
+## Both these we've always used `tr` for as the fastest way to compute the
+## DNA count and to get reverse complement of sequence
+
+my $seq = 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG';
+
+is( revcomp($seq), 'CGGCGACCAGCAACACATCTCTGAGAATGGATAAGGAGTCGATCTGTCTAAATGAAAAGGGGTTTAC' );
+is_deeply( counts($seq), { 'T' => 22, 'A' => 14, 'C' => 18, 'G' => 13 } );
+
+done_testing();
+
+sub counts {
+ return { 'T' => $_[0] =~ tr/T/T/, 'A' => $_[0] =~ tr/A/A/,
+ 'C' => $_[0] =~ tr/C/C/, 'G' => $_[0] =~ tr/G/G/, };
+}
+
+sub revcomp {
+ return reverse $_[0] =~ tr/ATCG/TAGC/r;
+}
+
diff --git a/challenge-090/james-smith/perl/ch-2.pl b/challenge-090/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..618a88f999
--- /dev/null
+++ b/challenge-090/james-smith/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+
+## This is ripe for bit operators - as it is about multiplying/diving by 2...
+## and checking for the value of the "1s" bit....
+
+foreach(1..10) {
+ my $x = int rand(40);
+ my $y = int rand(40);
+ is( eth_mult( $x , $y ), $x*$y );
+}
+
+done_testing();
+
+sub eth_mult {
+ my( $n, $m ) = @_;
+ my $res = 0;
+ while($n) {
+ $res += $m if $n&1;
+ $m<<=1;
+ $n>>=1;
+ }
+ return $res;
+}
+