diff options
| author | Ysmael Ebreo <Ysmael.Ebreo@latticesemi.com> | 2019-09-19 18:03:46 +0800 |
|---|---|---|
| committer | Ysmael Ebreo <Ysmael.Ebreo@latticesemi.com> | 2019-09-19 18:03:46 +0800 |
| commit | f6cc983e566f206f59f459f3dc6e241771882f8b (patch) | |
| tree | 8779439fe620081c29da535a3ae988080fa13f69 /challenge-026 | |
| parent | be71b7a3db240ec47e9673f7fe3193346237ef6d (diff) | |
| download | perlweeklychallenge-club-f6cc983e566f206f59f459f3dc6e241771882f8b.tar.gz perlweeklychallenge-club-f6cc983e566f206f59f459f3dc6e241771882f8b.tar.bz2 perlweeklychallenge-club-f6cc983e566f206f59f459f3dc6e241771882f8b.zip | |
Added perl6 solutions
Diffstat (limited to 'challenge-026')
| -rw-r--r-- | challenge-026/yet-ebreo/perl5/ch-2.pl | 2 | ||||
| -rw-r--r-- | challenge-026/yet-ebreo/perl6/ch-1.p6 | 15 | ||||
| -rw-r--r-- | challenge-026/yet-ebreo/perl6/ch-2.p6 | 14 |
3 files changed, 30 insertions, 1 deletions
diff --git a/challenge-026/yet-ebreo/perl5/ch-2.pl b/challenge-026/yet-ebreo/perl5/ch-2.pl index 6522d08534..8203324e9f 100644 --- a/challenge-026/yet-ebreo/perl5/ch-2.pl +++ b/challenge-026/yet-ebreo/perl5/ch-2.pl @@ -9,7 +9,7 @@ use v5.10; use Math::Trig; die "Usage:\n\tch-2.pl <angle1> .. <anglen>\n\n" if !@ARGV; -die "Only numbers are allowed as input\n" if "@ARGV"=~/[^0-9 ]/; +die "Only numbers are allowed as input\n" if grep !/^[-+]?\d+$/, @ARGV; my ($y_comp,$x_comp) = 0; $y_comp+=sin deg2rad($_),$x_comp+=cos deg2rad($_) for @ARGV; diff --git a/challenge-026/yet-ebreo/perl6/ch-1.p6 b/challenge-026/yet-ebreo/perl6/ch-1.p6 new file mode 100644 index 0000000000..b88ed72660 --- /dev/null +++ b/challenge-026/yet-ebreo/perl6/ch-1.p6 @@ -0,0 +1,15 @@ +# Create a script that accepts two strings, let us call it, “stones” and “jewels”. +# It should print the count of “alphabet” from the string “stones” found in the string “jewels”. +# For example, if your stones is “chancellor” and “jewels” is “chocolate”, then the script should print “8”. +# To keep it simple, only A-Z,a-z characters are acceptable. Also make the comparison case sensitive. + +sub MAIN ( + Str $string1, #= String to represent "stones" + Str $string2 #= String to represent "jewels" +){ + if ($string1~$string2 ~~ /<-[A .. Za .. z]>/) { + say "Only A-Z and a-z characters are allowed\n"; + } else { + say ($string2.chars-$string2.trans( $string1 => "").chars); + } +}
\ No newline at end of file diff --git a/challenge-026/yet-ebreo/perl6/ch-2.p6 b/challenge-026/yet-ebreo/perl6/ch-2.p6 new file mode 100644 index 0000000000..d63ede9e6a --- /dev/null +++ b/challenge-026/yet-ebreo/perl6/ch-2.p6 @@ -0,0 +1,14 @@ +# Create a script that prints mean angles of the given list of angles in degrees. +# Please read wiki(https://en.wikipedia.org/wiki/Mean_of_circular_quantities) page +# that explains the formula in details with an example. + +sub MAIN ( + *@angles #= Angle(s) in degrees +){ + my ($x,$y) = (0,0); + for @angles -> $r { + $y += sin($r*π/180); + $x += cos($r*π/180) + } + say atan2($y,$x)*180/π +}
\ No newline at end of file |
