diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-03-09 19:33:35 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-03-09 19:33:35 +0000 |
| commit | 2bdf51703359ef35c7ec3829ee25be3e89c45490 (patch) | |
| tree | 1f13e0339062b99bd978537a12e97436c8f34b24 | |
| parent | 6ba83654820bad00ba3c679bbe18764269dabe0f (diff) | |
| download | perlweeklychallenge-club-2bdf51703359ef35c7ec3829ee25be3e89c45490.tar.gz perlweeklychallenge-club-2bdf51703359ef35c7ec3829ee25be3e89c45490.tar.bz2 perlweeklychallenge-club-2bdf51703359ef35c7ec3829ee25be3e89c45490.zip | |
Add Lua and Python solutions to challenge 090
| -rw-r--r-- | challenge-090/paulo-custodio/forth/ch-2.fs | 7 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/lua/ch-1.lua | 32 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/lua/ch-2.lua | 28 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/python/ch-1.py | 27 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/python/ch-2.py | 24 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/t/test-1.yaml | 14 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/t/test-2.yaml | 275 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/test.pl | 28 |
8 files changed, 405 insertions, 30 deletions
diff --git a/challenge-090/paulo-custodio/forth/ch-2.fs b/challenge-090/paulo-custodio/forth/ch-2.fs index 134fd22e16..3e72d78a3f 100644 --- a/challenge-090/paulo-custodio/forth/ch-2.fs +++ b/challenge-090/paulo-custodio/forth/ch-2.fs @@ -5,9 +5,6 @@ \ \ Write a script to demonstrate Ethiopian Multiplication using the given numbers. -\ Start the script with A and B in the stack, e.g. -\ gforth -e '14 12' ch-1.fs - \ The solution is just as described in the algorithm, using locals to \ simplify the stack juggling. @@ -23,5 +20,7 @@ AGAIN ; -\ input in stack +\ input to stack +NEXT-ARG S>NUMBER? 0= THROW DROP +NEXT-ARG S>NUMBER? 0= THROW DROP mult . CR BYE diff --git a/challenge-090/paulo-custodio/lua/ch-1.lua b/challenge-090/paulo-custodio/lua/ch-1.lua new file mode 100644 index 0000000000..021f4c3a90 --- /dev/null +++ b/challenge-090/paulo-custodio/lua/ch-1.lua @@ -0,0 +1,32 @@ +#!/usr/bin/env lua + +--[[ +Challenge 090 + +TASK #1 > DNA Sequence +Submitted by: Mohammad S Anwar +DNA is a long, chainlike molecule which has two strands twisted into a +double helix. The two strands are made up of simpler molecules called +nucleotides. Each nucleotide is composed of one of the four nitrogen-containing +nucleobases cytosine (C), guanine (G), adenine (A) and thymine (T). + +You are given DNA sequence, +GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG. + +Write a script to print nucleiobase count in the given DNA sequence. +Also print the complementary sequence where Thymine (T) on one strand +is always facing an adenine (A) and vice versa; guanine (G) is always +facing a cytosine (C) and vice versa. +--]] + +function complement(seq) + local trans = {T = "A", A = "T", G = "C", C = "G"} + local compl = string.gsub(seq, "[TAGC]", trans) + return compl +end + +seq = arg[1] +compl = complement(seq) + +io.write(#seq, "\n") +io.write(compl) diff --git a/challenge-090/paulo-custodio/lua/ch-2.lua b/challenge-090/paulo-custodio/lua/ch-2.lua new file mode 100644 index 0000000000..c93074b04f --- /dev/null +++ b/challenge-090/paulo-custodio/lua/ch-2.lua @@ -0,0 +1,28 @@ +#!/usr/bin/env lua + +--[[ +Challenge 090 + +TASK #2 > Ethiopian Multiplication +Submitted by: Mohammad S Anwar +You are given two positive numbers $a and $b. + +Write a script to demonstrate Ethiopian Multiplication using the given numbers. +--]] + +function mul(a, b) + local m = 0 + while (true) do + if ((a & 1) ~= 0) then + m = m + b + end + if (a <= 1) then + break + end + a = a >> 1 + b = b << 1 + end + return m +end + +io.write(mul(tonumber(arg[1]), tonumber(arg[2])), "\n") diff --git a/challenge-090/paulo-custodio/python/ch-1.py b/challenge-090/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..0af71bfe29 --- /dev/null +++ b/challenge-090/paulo-custodio/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +# Challenge 090 +# +# TASK #1 > DNA Sequence +# Submitted by: Mohammad S Anwar +# DNA is a long, chainlike molecule which has two strands twisted into a +# double helix. The two strands are made up of simpler molecules called +# nucleotides. Each nucleotide is composed of one of the four nitrogen-containing +# nucleobases cytosine (C), guanine (G), adenine (A) and thymine (T). +# +# You are given DNA sequence, +# GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG. +# +# Write a script to print nucleiobase count in the given DNA sequence. +# Also print the complementary sequence where Thymine (T) on one strand +# is always facing an adenine (A) and vice versa; guanine (G) is always +# facing a cytosine (C) and vice versa. + +import sys +import string + +seq = sys.argv[1] +compl = seq.translate(str.maketrans("TAGC", "ATCG")) + +print(len(seq)) +print(compl) diff --git a/challenge-090/paulo-custodio/python/ch-2.py b/challenge-090/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..29efd0d507 --- /dev/null +++ b/challenge-090/paulo-custodio/python/ch-2.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +# Challenge 090 +# +# TASK #2 > Ethiopian Multiplication +# Submitted by: Mohammad S Anwar +# You are given two positive numbers $a and $b. +# +# Write a script to demonstrate Ethiopian Multiplication using the given numbers. + +import sys + +def mul(a,b): + mul = 0 + while True: + if (a & 1) != 0: + mul += b + if a <= 1: + break + a >>= 1 + b <<= 1 + return mul + +print(mul(int(sys.argv[1]), int(sys.argv[2]))) diff --git a/challenge-090/paulo-custodio/t/test-1.yaml b/challenge-090/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..7ffbeae833 --- /dev/null +++ b/challenge-090/paulo-custodio/t/test-1.yaml @@ -0,0 +1,14 @@ +- setup: + cleanup: + args: GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG + input: + output: | + 67 + CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC +- setup: + cleanup: + args: CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC + input: + output: | + 67 + GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG diff --git a/challenge-090/paulo-custodio/t/test-2.yaml b/challenge-090/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..c66b5f2e9a --- /dev/null +++ b/challenge-090/paulo-custodio/t/test-2.yaml @@ -0,0 +1,275 @@ +- setup: + cleanup: + args: 0 0 + intput: + output: 0 +- setup: + cleanup: + args: 0 1 + intput: + output: 0 +- setup: + cleanup: + args: 0 2 + intput: + output: 0 +- setup: + cleanup: + args: 0 3 + intput: + output: 0 +- setup: + cleanup: + args: 0 5 + intput: + output: 0 +- setup: + cleanup: + args: 0 7 + intput: + output: 0 +- setup: + cleanup: + args: 0 11 + intput: + output: 0 +- setup: + cleanup: + args: 0 23 + intput: + output: 0 +- setup: + cleanup: + args: 0 37 + intput: + output: 0 +- setup: + cleanup: + args: 0 47 + intput: + output: 0 +- setup: + cleanup: + args: 1 1 + intput: + output: 1 +- setup: + cleanup: + args: 1 2 + intput: + output: 2 +- setup: + cleanup: + args: 1 3 + intput: + output: 3 +- setup: + cleanup: + args: 1 5 + intput: + output: 5 +- setup: + cleanup: + args: 1 7 + intput: + output: 7 +- setup: + cleanup: + args: 1 11 + intput: + output: 11 +- setup: + cleanup: + args: 1 23 + intput: + output: 23 +- setup: + cleanup: + args: 1 37 + intput: + output: 37 +- setup: + cleanup: + args: 1 47 + intput: + output: 47 +- setup: + cleanup: + args: 2 2 + intput: + output: 4 +- setup: + cleanup: + args: 2 3 + intput: + output: 6 +- setup: + cleanup: + args: 2 5 + intput: + output: 10 +- setup: + cleanup: + args: 2 7 + intput: + output: 14 +- setup: + cleanup: + args: 2 11 + intput: + output: 22 +- setup: + cleanup: + args: 2 23 + intput: + output: 46 +- setup: + cleanup: + args: 2 37 + intput: + output: 74 +- setup: + cleanup: + args: 2 47 + intput: + output: 94 +- setup: + cleanup: + args: 3 3 + intput: + output: 9 +- setup: + cleanup: + args: 3 5 + intput: + output: 15 +- setup: + cleanup: + args: 3 7 + intput: + output: 21 +- setup: + cleanup: + args: 3 11 + intput: + output: 33 +- setup: + cleanup: + args: 3 23 + intput: + output: 69 +- setup: + cleanup: + args: 3 37 + intput: + output: 111 +- setup: + cleanup: + args: 3 47 + intput: + output: 141 +- setup: + cleanup: + args: 5 5 + intput: + output: 25 +- setup: + cleanup: + args: 5 7 + intput: + output: 35 +- setup: + cleanup: + args: 5 11 + intput: + output: 55 +- setup: + cleanup: + args: 5 23 + intput: + output: 115 +- setup: + cleanup: + args: 5 37 + intput: + output: 185 +- setup: + cleanup: + args: 5 47 + intput: + output: 235 +- setup: + cleanup: + args: 7 7 + intput: + output: 49 +- setup: + cleanup: + args: 7 11 + intput: + output: 77 +- setup: + cleanup: + args: 7 23 + intput: + output: 161 +- setup: + cleanup: + args: 7 37 + intput: + output: 259 +- setup: + cleanup: + args: 7 47 + intput: + output: 329 +- setup: + cleanup: + args: 11 11 + intput: + output: 121 +- setup: + cleanup: + args: 11 23 + intput: + output: 253 +- setup: + cleanup: + args: 11 37 + intput: + output: 407 +- setup: + cleanup: + args: 11 47 + intput: + output: 517 +- setup: + cleanup: + args: 23 23 + intput: + output: 529 +- setup: + cleanup: + args: 23 37 + intput: + output: 851 +- setup: + cleanup: + args: 23 47 + intput: + output: 1081 +- setup: + cleanup: + args: 37 37 + intput: + output: 1369 +- setup: + cleanup: + args: 37 47 + intput: + output: 1739 +- setup: + cleanup: + args: 47 47 + intput: + output: 2209 diff --git a/challenge-090/paulo-custodio/test.pl b/challenge-090/paulo-custodio/test.pl index 8e24f40f17..01ed2b83cd 100644 --- a/challenge-090/paulo-custodio/test.pl +++ b/challenge-090/paulo-custodio/test.pl @@ -2,30 +2,6 @@ use strict; use warnings; -use Test::More; +use 5.030; -# task 1 - -my $adn = "GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG"; -my $cpl = "CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC"; -my $len = length($adn); - -is `gforth forth/ch-1.fs $adn`, "$len \n$cpl\n"; -is `gforth forth/ch-1.fs $cpl`, "$len \n$adn\n"; - -is `perl perl/ch-1.pl $adn`, "$len\n$cpl\n"; -is `perl perl/ch-1.pl $cpl`, "$len\n$adn\n"; - - -# task 2 - -for my $a (0,1,2,3,4,5,14) { - for my $b (0,1,2,3,4,5,12) { - my $r = $a*$b; - is `gforth -e ' $a $b' forth/ch-2.fs`, "$r \n"; - - is `perl perl/ch-2.pl $a $b`, "$r\n"; - } -} - -done_testing; +require '../../challenge-001/paulo-custodio/test.pl'; |
