aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjuliodcs <julio.dcs@gmail.com>2020-12-12 01:12:48 +0100
committerjuliodcs <julio.dcs@gmail.com>2020-12-12 01:12:48 +0100
commit707e308ed8be245e461f9f5132187cae8b4cd16e (patch)
tree1d5454bbd5048f222c5a53c47ac8e989588f2698
parent931e28a9fe63ad0942cf9f3099191a0e21a978c2 (diff)
downloadperlweeklychallenge-club-707e308ed8be245e461f9f5132187cae8b4cd16e.tar.gz
perlweeklychallenge-club-707e308ed8be245e461f9f5132187cae8b4cd16e.tar.bz2
perlweeklychallenge-club-707e308ed8be245e461f9f5132187cae8b4cd16e.zip
juliodcs-week90
-rw-r--r--challenge-090/juliodcs/perl/ch-1.pl9
-rw-r--r--challenge-090/juliodcs/perl/ch-2.pl34
-rw-r--r--challenge-090/juliodcs/raku/ch-1.raku7
-rw-r--r--challenge-090/juliodcs/raku/ch-2.raku23
4 files changed, 73 insertions, 0 deletions
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;