aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-12-08 10:08:37 +0000
committerGitHub <noreply@github.com>2020-12-08 10:08:37 +0000
commitac7cd97e82a7f526e6f9a300844462db6d1b7fca (patch)
tree208e89b9717dbdc49bc4bae0c71167c107ca4bbc
parentd516a0c34ab55ccc6a4eb285757a5988ac6fb1a4 (diff)
parent38277932edb4d62b034b9bc189fafc6fb432f1c4 (diff)
downloadperlweeklychallenge-club-ac7cd97e82a7f526e6f9a300844462db6d1b7fca.tar.gz
perlweeklychallenge-club-ac7cd97e82a7f526e6f9a300844462db6d1b7fca.tar.bz2
perlweeklychallenge-club-ac7cd97e82a7f526e6f9a300844462db6d1b7fca.zip
Merge pull request #2945 from aaronreidsmith/week-090
Week 90 Raku solutions
-rw-r--r--challenge-090/aaronreidsmith/blog.txt1
-rw-r--r--challenge-090/aaronreidsmith/raku/ch-1.raku17
-rw-r--r--challenge-090/aaronreidsmith/raku/ch-2.raku21
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-090/aaronreidsmith/blog.txt b/challenge-090/aaronreidsmith/blog.txt
new file mode 100644
index 0000000000..c0bf9276a7
--- /dev/null
+++ b/challenge-090/aaronreidsmith/blog.txt
@@ -0,0 +1 @@
+https://aaronreidsmith.github.io/blog/perl-weekly-challenge-090/ \ No newline at end of file
diff --git a/challenge-090/aaronreidsmith/raku/ch-1.raku b/challenge-090/aaronreidsmith/raku/ch-1.raku
new file mode 100644
index 0000000000..3c12a719c9
--- /dev/null
+++ b/challenge-090/aaronreidsmith/raku/ch-1.raku
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl6
+
+subset ValidDna of Str where { $_ ~~ /^^[A|T|G|C]+$$/ }
+
+# Since DNA is generally read from 5' to 3', I included the option to find the
+# reverse compliment in addition to the complement
+sub MAIN($dna where $dna ~~ ValidDna, Bool :rc(:$reverse-complement) = False) {
+ say "Input stats:\n{$dna.comb.Bag.Hash}\n";
+
+ say "Complement:";
+ my $translated = $dna.trans('ATGC' => 'TACG');
+ if $reverse-complement {
+ say "5'-{$translated.flip}-3'";
+ } else {
+ say "3'-$translated-5'"
+ }
+}
diff --git a/challenge-090/aaronreidsmith/raku/ch-2.raku b/challenge-090/aaronreidsmith/raku/ch-2.raku
new file mode 100644
index 0000000000..fa5fe375c6
--- /dev/null
+++ b/challenge-090/aaronreidsmith/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl6
+
+subset PositiveInt of Int where { $_ ~~ Int && $_ > 0 }
+
+sub generate-pairs($a, $b) {
+ sprintf("%02d, %02d", $a, $b).put;
+ if $a == 1 {
+ (($a, $b),);
+ } else {
+ (($a, $b), |generate-pairs($a div 2, $b * 2));
+ }
+}
+
+sub MAIN(PositiveInt $A, PositiveInt $B) {
+ say "Input: A=$A, B=$B";
+ say "Divide A by 2 (ignoring remainders) until it is 1. Multiply B by 2 as we go:";
+ my @pairs = generate-pairs($A, $B);
+ say "Then, wherever A is odd, we add the Bs together:";
+ my @odd-bs = @pairs.grep(-> @pair { !(@pair[0] %% 2) }).map(-> @pair { @pair[1] });
+ say "{@odd-bs.join(' + ')} = {@odd-bs.sum}";
+}