diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-12-09 04:55:53 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-12-09 04:55:53 +0000 |
| commit | 48118ab04e8fb1f5164e9712d28a2b1877aa2a9f (patch) | |
| tree | c32afb258f8240af78ae29b38bdbae15f909d188 /challenge-090 | |
| parent | 7a81a293415612144e83f99a11c04190727814d6 (diff) | |
| download | perlweeklychallenge-club-48118ab04e8fb1f5164e9712d28a2b1877aa2a9f.tar.gz perlweeklychallenge-club-48118ab04e8fb1f5164e9712d28a2b1877aa2a9f.tar.bz2 perlweeklychallenge-club-48118ab04e8fb1f5164e9712d28a2b1877aa2a9f.zip | |
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-090')
| -rw-r--r-- | challenge-090/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-090/laurent-rosenfeld/perl/ch-1.pl | 12 | ||||
| -rw-r--r-- | challenge-090/laurent-rosenfeld/perl/ch-2.pl | 12 | ||||
| -rw-r--r-- | challenge-090/laurent-rosenfeld/raku/ch-1.raku | 13 | ||||
| -rw-r--r-- | challenge-090/laurent-rosenfeld/raku/ch-2.raku | 10 |
5 files changed, 48 insertions, 0 deletions
diff --git a/challenge-090/laurent-rosenfeld/blog.txt b/challenge-090/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..fbb7836743 --- /dev/null +++ b/challenge-090/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2020/12/perl-weekly-challenge-90-dna-sequence-and-ethiopian-multiplication.html diff --git a/challenge-090/laurent-rosenfeld/perl/ch-1.pl b/challenge-090/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..bb0ca420cb --- /dev/null +++ b/challenge-090/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,12 @@ +use strict; +use warnings; +use feature "say"; + +my $dna = 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG'; +# count +my %histogram; +$histogram{$_}++ for split '', $dna; +say "$_: $histogram{$_}" for keys %histogram; + +# Complementary sequence +say for "Complement:", $dna =~ tr/TAGC/ATCG/r; diff --git a/challenge-090/laurent-rosenfeld/perl/ch-2.pl b/challenge-090/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..0b8ef08383 --- /dev/null +++ b/challenge-090/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,12 @@ +use strict; +use warnings; +use feature "say"; + +my ($c, $d) = @ARGV; +my $result = $c % 2 ? $d : 0; +while ($c > 1) { + $c = $c >> 1; # right shift 1 bit = div by 2 + $d *= 2; + $result += $d if $c % 2; +} +say $result; diff --git a/challenge-090/laurent-rosenfeld/raku/ch-1.raku b/challenge-090/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..16c141c593 --- /dev/null +++ b/challenge-090/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,13 @@ +use v6; + +my $dna = 'GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG'; + +# count +my %histo; +%histo{$_}++ for $dna.comb; +say "Histogram:"; +.say for %histo.pairs; + +# Complementary sequence +my %complement = T => 'A', A => 'T', G => 'C', C => 'G'; +.say for "Complement:", $dna.comb.map({%complement{$_}}).join: ''; diff --git a/challenge-090/laurent-rosenfeld/raku/ch-2.raku b/challenge-090/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..8c1d413537 --- /dev/null +++ b/challenge-090/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,10 @@ +use v6; + +my ($a, $b) = map {$_.Int}, @*ARGS; +my $result = $a % 2 ?? $b !! 0; +while $a > 1 { + $a div= 2; + $b *= 2; + $result += $b if $a % 2; +} +say $result; |
