diff options
| author | Aaron Smith <asmith@sumologic.com> | 2020-12-07 14:26:21 -0600 |
|---|---|---|
| committer | Aaron Smith <asmith@sumologic.com> | 2020-12-07 14:26:21 -0600 |
| commit | d6eeb2228b999315263e96d4b00bdf6f8d7c090e (patch) | |
| tree | 14c299d54b5e2c1383e2c5e0de1e58df32fb111a | |
| parent | d181a79cc3b10b862de348d6a6ca503df28e5203 (diff) | |
| download | perlweeklychallenge-club-d6eeb2228b999315263e96d4b00bdf6f8d7c090e.tar.gz perlweeklychallenge-club-d6eeb2228b999315263e96d4b00bdf6f8d7c090e.tar.bz2 perlweeklychallenge-club-d6eeb2228b999315263e96d4b00bdf6f8d7c090e.zip | |
Challenge 90 Raku solutions
| -rw-r--r-- | challenge-090/aaronreidsmith/raku/ch-1.raku | 14 | ||||
| -rw-r--r-- | challenge-090/aaronreidsmith/raku/ch-2.raku | 21 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-090/aaronreidsmith/raku/ch-1.raku b/challenge-090/aaronreidsmith/raku/ch-1.raku new file mode 100644 index 0000000000..96adad1541 --- /dev/null +++ b/challenge-090/aaronreidsmith/raku/ch-1.raku @@ -0,0 +1,14 @@ +#!/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) { + my $translated = $dna.trans('ATGC' => 'TACG'); + if $reverse-complement { + say "5'-{$translated.reverse}-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..cc85350dc6 --- /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}"; +} |
