diff options
| author | 冯昶 <seaker@qq.com> | 2021-03-15 18:13:51 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-03-15 18:13:51 +0800 |
| commit | 8b6be37fe4dac8b4c6489a95e55514b76b298d15 (patch) | |
| tree | ae36c8ec2c71f606c0e36adaa19dba366a68a0b4 /challenge-090 | |
| parent | 865acfd056fb6f409ec6b1a81d60b931cbcb69fe (diff) | |
| parent | c9aec2da6bcb04b488183f09ca94bee488557aff (diff) | |
| download | perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.gz perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.bz2 perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.zip | |
Merge branch 'master' of github.com:seaker/perlweeklychallenge-club
Diffstat (limited to 'challenge-090')
| -rw-r--r-- | challenge-090/andinus/README | 2 | ||||
| -rw-r--r-- | challenge-090/andinus/README.org | 2 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/forth/ch-1.fs | 54 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/forth/ch-2.fs | 22 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/perl/ch-2.pl | 10 | ||||
| -rw-r--r-- | challenge-090/paulo-custodio/test.pl | 12 | ||||
| -rwxr-xr-x | challenge-090/wlmb/perl/ch-1.pl | 2 | ||||
| -rwxr-xr-x | challenge-090/wlmb/perl/ch-2.pl | 2 |
9 files changed, 62 insertions, 62 deletions
diff --git a/challenge-090/andinus/README b/challenge-090/andinus/README index b662f1cb50..3b627c71f9 100644 --- a/challenge-090/andinus/README +++ b/challenge-090/andinus/README @@ -33,7 +33,7 @@ Table of Contents 1.1 Raku ──────── - • Program: <file:perl/ch-2.raku> + • Program: <file:raku/ch-2.raku> Start by taking `$A' & `$B' which are defined to be `Int' & positive. ┌──── diff --git a/challenge-090/andinus/README.org b/challenge-090/andinus/README.org index c4f5da3378..8ebbde0e84 100644 --- a/challenge-090/andinus/README.org +++ b/challenge-090/andinus/README.org @@ -11,7 +11,7 @@ You are given two positive numbers $A and $B. Write a script to demonstrate [[https://threesixty360.wordpress.com/2009/06/09/ethiopian-multiplication/][Ethiopian Multiplication]] using the given numbers. ** Raku -- Program: [[file:perl/ch-2.raku]] +- Program: [[file:raku/ch-2.raku]] Start by taking =$A= & =$B= which are defined to be =Int= & positive. #+BEGIN_SRC raku diff --git a/challenge-090/paulo-custodio/forth/ch-1.fs b/challenge-090/paulo-custodio/forth/ch-1.fs index 01bdb3dcaa..9314ab943d 100644 --- a/challenge-090/paulo-custodio/forth/ch-1.fs +++ b/challenge-090/paulo-custodio/forth/ch-1.fs @@ -1,45 +1,45 @@ \ 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 +\ 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, +\ +\ 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 +\ +\ 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. \ Start the script with the DNA sequence is the command line, e.g. -\ gforth ch-1.fs GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG +\ gforth ch-1.fs GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG \ The solution copies the input string to the PAD and then replaces \ each character representing a nucleiobase by its complement. -: compl-one ( c -- c ) - DUP 'T' = IF DROP 'A' - ELSE DUP 'A' = IF DROP 'T' - ELSE DUP 'G' = IF DROP 'C' - ELSE DUP 'C' = IF DROP 'G' - ELSE DROP BL - THEN THEN THEN THEN +: compl-one ( c -- c ) + DUP 'T' = IF DROP 'A' + ELSE DUP 'A' = IF DROP 'T' + ELSE DUP 'G' = IF DROP 'C' + ELSE DUP 'C' = IF DROP 'G' + ELSE DROP BL + THEN THEN THEN THEN ; -: compl-seq ( c-addr n -- c-addr n ) - PAD C! - PAD 1+ PAD C@ CMOVE \ copy as counted string to PAD - PAD 1+ - PAD C@ 0 DO - DUP C@ compl-one OVER C! 1+ - LOOP - PAD COUNT +: compl-seq ( c-addr n -- c-addr n ) + PAD C! + PAD 1+ PAD C@ CMOVE \ copy as counted string to PAD + PAD 1+ + PAD C@ 0 DO + DUP C@ compl-one OVER C! 1+ + LOOP + PAD COUNT ; -next-arg \ collect string -DUP . CR \ print length -compl-seq TYPE CR \ print complemented sequence +next-arg \ collect string +DUP . CR \ print length +compl-seq TYPE CR \ print complemented sequence BYE diff --git a/challenge-090/paulo-custodio/forth/ch-2.fs b/challenge-090/paulo-custodio/forth/ch-2.fs index a5386ae532..134fd22e16 100644 --- a/challenge-090/paulo-custodio/forth/ch-2.fs +++ b/challenge-090/paulo-custodio/forth/ch-2.fs @@ -2,7 +2,7 @@ \ 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. \ Start the script with A and B in the stack, e.g. @@ -11,16 +11,16 @@ \ The solution is just as described in the algorithm, using locals to \ simplify the stack juggling. -: mult { a b -- a*b } \ a, b: locals - 0 ( sum ) - BEGIN - a 1 AND IF \ a is even - b + \ sum += b - THEN - a 1 <= IF EXIT THEN \ exit when a=1 or a=0 - a 2/ TO a - b 2* TO b - AGAIN +: mult { a b -- a*b } \ a, b: locals + 0 ( sum ) + BEGIN + a 1 AND IF \ a is even + b + \ sum += b + THEN + a 1 <= IF EXIT THEN \ exit when a=1 or a=0 + a 2/ TO a + b 2* TO b + AGAIN ; \ input in stack diff --git a/challenge-090/paulo-custodio/perl/ch-1.pl b/challenge-090/paulo-custodio/perl/ch-1.pl index f65a287354..df194190d1 100644 --- a/challenge-090/paulo-custodio/perl/ch-1.pl +++ b/challenge-090/paulo-custodio/perl/ch-1.pl @@ -1,19 +1,19 @@ -#!/usr/bin/env perl +#!/usr/bin/perl # 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 +# 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, +# +# 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 +# +# 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. # Start the script with the ADN sequence in the command line. diff --git a/challenge-090/paulo-custodio/perl/ch-2.pl b/challenge-090/paulo-custodio/perl/ch-2.pl index 16dba08035..5a5dfb78d3 100644 --- a/challenge-090/paulo-custodio/perl/ch-2.pl +++ b/challenge-090/paulo-custodio/perl/ch-2.pl @@ -1,10 +1,10 @@ -#!/usr/bin/env perl +#!/usr/bin/perl # 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. # The solution is just as described in the algorithm. @@ -16,9 +16,9 @@ my($a, $b) = @ARGV; my $mul = 0; while (1) { - $mul += $b if ($a & 1) != 0; - last if $a <= 1; - $a >>= 1; $b <<= 1; + $mul += $b if ($a & 1) != 0; + last if $a <= 1; + $a >>= 1; $b <<= 1; } print $mul, "\n"; diff --git a/challenge-090/paulo-custodio/test.pl b/challenge-090/paulo-custodio/test.pl index 4a46cdba03..8e24f40f17 100644 --- a/challenge-090/paulo-custodio/test.pl +++ b/challenge-090/paulo-custodio/test.pl @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/perl use strict; use warnings; @@ -20,12 +20,12 @@ 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"; + 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"; - } + is `perl perl/ch-2.pl $a $b`, "$r\n"; + } } done_testing; diff --git a/challenge-090/wlmb/perl/ch-1.pl b/challenge-090/wlmb/perl/ch-1.pl index 9e5f5c07c4..b1614b8cf9 100755 --- a/challenge-090/wlmb/perl/ch-1.pl +++ b/challenge-090/wlmb/perl/ch-1.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # For sequences of DNA get nucleotide counts and its complement -# See https:/wlmb.github.io/2020/12/07/PWC90/#task-1-dna-sequence +# See https://wlmb.github.io/2020/12/07/PWC90/#task-1-dna-sequence use strict; use warnings; use v5.10; diff --git a/challenge-090/wlmb/perl/ch-2.pl b/challenge-090/wlmb/perl/ch-2.pl index 44f9f1ab56..47cad06d73 100755 --- a/challenge-090/wlmb/perl/ch-2.pl +++ b/challenge-090/wlmb/perl/ch-2.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # Multiply two numbers using the Ethiopian Multiplication -# See https:/wlmb.github.io/2020/12/07/PWC90/#task-2-ethiopian-multiplication +# See https://wlmb.github.io/2020/12/07/PWC90/#task-2-ethiopian-multiplication use strict; use warnings; use v5.10; |
