From 707e308ed8be245e461f9f5132187cae8b4cd16e Mon Sep 17 00:00:00 2001 From: juliodcs Date: Sat, 12 Dec 2020 01:12:48 +0100 Subject: juliodcs-week90 --- challenge-090/juliodcs/perl/ch-1.pl | 9 +++++++++ challenge-090/juliodcs/perl/ch-2.pl | 34 ++++++++++++++++++++++++++++++++++ challenge-090/juliodcs/raku/ch-1.raku | 7 +++++++ challenge-090/juliodcs/raku/ch-2.raku | 23 +++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 challenge-090/juliodcs/perl/ch-1.pl create mode 100644 challenge-090/juliodcs/perl/ch-2.pl create mode 100644 challenge-090/juliodcs/raku/ch-1.raku create mode 100644 challenge-090/juliodcs/raku/ch-2.raku diff --git a/challenge-090/juliodcs/perl/ch-1.pl b/challenge-090/juliodcs/perl/ch-1.pl new file mode 100644 index 0000000000..e988d6bf0f --- /dev/null +++ b/challenge-090/juliodcs/perl/ch-1.pl @@ -0,0 +1,9 @@ +use strict; +use warnings; +use feature 'say'; + +my $input = shift // 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG'; + +say "Input : $input"; +say 'Length : ' . $input =~ tr/TAGC/ATCG/; +say "Complementary : $input"; diff --git a/challenge-090/juliodcs/perl/ch-2.pl b/challenge-090/juliodcs/perl/ch-2.pl new file mode 100644 index 0000000000..a5c42b4d08 --- /dev/null +++ b/challenge-090/juliodcs/perl/ch-2.pl @@ -0,0 +1,34 @@ +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; +use List::Util 'sum0'; + +my ($first, $second) = @ARGV; + +die 'Please input 2 numbers' if not @ARGV == 2; + +say "Ethiopian multiplication of $first and $second\n"; + +sub operate(@items) { + my $last = @items[@items - 1]; + + $last->[0] == 1 + ? @items + : operate (@items, [int($last->[0] / 2), $last->[1] * 2]) +} + +my @steps = operate([$first, $second]); +say 'Steps:'; +say join ', ', $_->@* for @steps; + +say "\nKepp odd numbers:"; +my @odd = grep { $_->[0] % 2 } @steps; +say join ', ', $_->@* for @odd; + +say "\nKeep right values:"; +my @right = map { $_->[1] } @odd; +say $_ for @right; + +say "\nAdd the numbers:"; +say sum0 @right; diff --git a/challenge-090/juliodcs/raku/ch-1.raku b/challenge-090/juliodcs/raku/ch-1.raku new file mode 100644 index 0000000000..820630e301 --- /dev/null +++ b/challenge-090/juliodcs/raku/ch-1.raku @@ -0,0 +1,7 @@ +#!/usr/bin/env raku + +my $input = @*ARGS.head // 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG'; + +say 'Input : ' ~ $input; +say 'Length : ' ~ $input.chars; +say 'Complementary : ' ~ $input.trans: 'TAGC' => 'ATCG'; diff --git a/challenge-090/juliodcs/raku/ch-2.raku b/challenge-090/juliodcs/raku/ch-2.raku new file mode 100644 index 0000000000..43d9c11477 --- /dev/null +++ b/challenge-090/juliodcs/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/usr/bin/env raku + +unit sub MAIN(UInt $first, UInt $second); + +say "Ethiopian multiplication of $first and $second\n"; + +multi operate(@items where *.tail.head == 1) { @items } +multi operate(@items) { operate (|@items, (@items.tail.head div 2, @items.tail.tail * 2)) } + +my @steps = operate (($first.Int, $second.Int),); +say 'Steps:'; +.say for @steps; + +say "\nKepp odd numbers:"; +my @odd = @steps.grep: *.head % 2; +.say for @odd; + +say "\nKeep right values:"; +my @right = @odd.map: *.tail; +.say for @right; + +say "\nAdd the numbers:"; +say @right.sum; -- cgit