diff options
| -rw-r--r-- | challenge-026/ruben-westerberg/README | 16 | ||||
| -rwxr-xr-x | challenge-026/ruben-westerberg/perl5/ch-1.pl | 11 | ||||
| -rwxr-xr-x | challenge-026/ruben-westerberg/perl5/ch-2.pl | 14 | ||||
| -rwxr-xr-x | challenge-026/ruben-westerberg/perl6/ch-1.p6 | 6 | ||||
| -rwxr-xr-x | challenge-026/ruben-westerberg/perl6/ch-2.p6 | 9 |
5 files changed, 48 insertions, 8 deletions
diff --git a/challenge-026/ruben-westerberg/README b/challenge-026/ruben-westerberg/README index e7a3e41132..b22be03bd3 100644 --- a/challenge-026/ruben-westerberg/README +++ b/challenge-026/ruben-westerberg/README @@ -2,15 +2,15 @@ Solution by Ruben Westerberg ch-1.pl and ch-1.p6 === -Longest Pokemon name sequence. -Simply run the program to see the sequence update. Last one printed in the longest one - +Stone and Jewels +Run the program with two arguments, the first one being the stone, and the second one the jewel. +The total number of letters in the jewel present in the stone is printed. +If no arguments are given a test set is used. ch-2.pl and ch-2.p6 === -Implements the chaochiper -usage example (encode and decode pipeline reading from standard input) - ch-2.pl | ch-2.pl decode - - ch-2.p6 | ch-2.p6 --decode +Angular average +Run the program with at least one argument. Each argument is an angle in degrees. +The output is the average of the list of angles supplied. +If no arguments are given, a test list is used. diff --git a/challenge-026/ruben-westerberg/perl5/ch-1.pl b/challenge-026/ruben-westerberg/perl5/ch-1.pl new file mode 100755 index 0000000000..314f86073a --- /dev/null +++ b/challenge-026/ruben-westerberg/perl5/ch-1.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::Util qw(uniqstr); + +my ($stones, $jewels)= @ARGV?@ARGV: qw(chancellor chocolate); +print "Alphabet (stone) word: $stones\nTest (jewel) word: $jewels\n"; +$_=$jewels; +my @stones= uniqstr(split "", $stones); +s/[@stones]//g; +print "Number of letters of Alphabet found in Test: ", length($jewels) - length, "\n"; diff --git a/challenge-026/ruben-westerberg/perl5/ch-2.pl b/challenge-026/ruben-westerberg/perl5/ch-2.pl new file mode 100755 index 0000000000..147fc7a2d8 --- /dev/null +++ b/challenge-026/ruben-westerberg/perl5/ch-2.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::Util qw<reduce>; +use Math::Trig; + +my @angles= @ARGV?@ARGV:(181,179); +print "Average of angles [ @angles ] is: "; +my $avgCos= (reduce {$a+$b} map {cos $_ * pi/180} @angles)/@angles; +my $avgSin= (reduce {$a+$b} map {sin $_ * pi/180} @angles)/@angles; +my $avg=atan2($avgSin, $avgCos)*180/pi; +$avg+=360 if $avg <0; +print "$avg\n"; + diff --git a/challenge-026/ruben-westerberg/perl6/ch-1.p6 b/challenge-026/ruben-westerberg/perl6/ch-1.p6 new file mode 100755 index 0000000000..6106d49293 --- /dev/null +++ b/challenge-026/ruben-westerberg/perl6/ch-1.p6 @@ -0,0 +1,6 @@ +#!/usr/bin/env perl6 + +my ($stones,$jewels)=@*ARGS??@*ARGS!! <chancellor chocolate>; +print "Alphabet (stone) word: $stones\nTest (jewel) word: $jewels\n"; +my @stones= $stones.comb.unique; +put "Number of letters of Alphabet found in Test: ", $jewels.chars-(S:g/[@stones]// given $jewels).chars; diff --git a/challenge-026/ruben-westerberg/perl6/ch-2.p6 b/challenge-026/ruben-westerberg/perl6/ch-2.p6 new file mode 100755 index 0000000000..9973484074 --- /dev/null +++ b/challenge-026/ruben-westerberg/perl6/ch-2.p6 @@ -0,0 +1,9 @@ +#!/usr/bin/env perl6 + +my @angles=@*ARGS??@*ARGS!![181,179]; +print "Average of [ @angles[] ] is: "; +my $avgCos= ( [+] @angles.map({($_*pi/180).cos}))/@angles; +my $avgSin= ( [+] @angles.map({($_*pi/180).sin}))/@angles; +my $avg=atan2($avgSin,$avgCos)*180/pi; +$avg+=360 if $avg < 0; +put $avg; |
