From 6fd63feb846f57024642ed6c7a98f4a6e0c03816 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 7 Dec 2020 09:05:11 +0000 Subject: Challenge 90 --- challenge-090/simon-proctor/raku/ch-1.raku | 27 +++++++++++++++++++++++++++ challenge-090/simon-proctor/raku/ch-2.raku | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 challenge-090/simon-proctor/raku/ch-1.raku create mode 100644 challenge-090/simon-proctor/raku/ch-2.raku diff --git a/challenge-090/simon-proctor/raku/ch-1.raku b/challenge-090/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..b20646d40b --- /dev/null +++ b/challenge-090/simon-proctor/raku/ch-1.raku @@ -0,0 +1,27 @@ +#!/usr/bin/env raku + +use v6; + +my $sequence = "GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG"; + +say nucleotide-count( $sequence ); +say complement( $sequence ); + +sub nucleotide-count( $sequence ) { + my @cytosines = $sequence.comb; + my @nucleotide; + my $count = 0; + + for @cytosines -> $cytosine { + @nucleotide.push($cytosine); + if ( all( "G", "T", "A", "C" ) (elem) @nucleotide ) { + $count++; + @nucleotide = (); + } + } + return $count; +} + +sub complement( $sequence ) { + with $sequence { return TR/TAGC/ATCG/; } +} diff --git a/challenge-090/simon-proctor/raku/ch-2.raku b/challenge-090/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..a15b088f50 --- /dev/null +++ b/challenge-090/simon-proctor/raku/ch-2.raku @@ -0,0 +1,17 @@ +#!/usr/bin/env raku + +use v6; + +#| Given two Integers demonstrate Ethiopian Multiplication with them +sub MAIN ( UInt $A is copy, UInt $B is copy ) { + my @parts; + say "Given $A and $B {$A %% 2 ?? '' !! '*'}"; + @parts.push($B) unless $A %% 2; + while ( $A > 1 ) { + $A div= 2; + $B *= 2; + say "Got $A and $B {$A %% 2 ?? '' !! '*'}"; + @parts.push($B) unless $A %% 2; + } + say "Adding {@parts.join(",")} to get {[+] @parts}"; +} -- cgit From b60693356e3c00112901af37b26f19babfc6fa4d Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 7 Dec 2020 09:11:17 +0000 Subject: Doh --- challenge-090/simon-proctor/raku/ch-1.raku | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/challenge-090/simon-proctor/raku/ch-1.raku b/challenge-090/simon-proctor/raku/ch-1.raku index b20646d40b..62d13ce95c 100644 --- a/challenge-090/simon-proctor/raku/ch-1.raku +++ b/challenge-090/simon-proctor/raku/ch-1.raku @@ -8,18 +8,7 @@ say nucleotide-count( $sequence ); say complement( $sequence ); sub nucleotide-count( $sequence ) { - my @cytosines = $sequence.comb; - my @nucleotide; - my $count = 0; - - for @cytosines -> $cytosine { - @nucleotide.push($cytosine); - if ( all( "G", "T", "A", "C" ) (elem) @nucleotide ) { - $count++; - @nucleotide = (); - } - } - return $count; + return $sequence.comb.Bag.pairs.sort( *.value ).reverse.map( -> $p { "{$p.key} : {$p.value}" } ).join("\n"); } sub complement( $sequence ) { -- cgit