From 149b344eb3f530de016ba0b877f903d333608f71 Mon Sep 17 00:00:00 2001 From: threadless-screw Date: Sat, 21 Sep 2019 16:09:44 +0200 Subject: Solutions wk26 --- challenge-026/ozzy/perl6/ch-1.p6 | 21 +++++++++++++++++++++ challenge-026/ozzy/perl6/ch-2.p6 | 15 +++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 challenge-026/ozzy/perl6/ch-1.p6 create mode 100755 challenge-026/ozzy/perl6/ch-2.p6 diff --git a/challenge-026/ozzy/perl6/ch-1.p6 b/challenge-026/ozzy/perl6/ch-1.p6 new file mode 100755 index 0000000000..1bfeb089f6 --- /dev/null +++ b/challenge-026/ozzy/perl6/ch-1.p6 @@ -0,0 +1,21 @@ +#!/usr/bin/env perl6 + +# 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 ($string1 where { m/^<[a..z]>+$/ } , $string2 where { m/^<[a..z]>+$/ } ) { + + say my @string1 = $string1.comb; + say my @string2 = $string2.comb; + my $count = 0; + + for @string1 -> $i { + $count++ if @string2.grep: { $_ eq $i }; + } + + say $count; +} \ No newline at end of file diff --git a/challenge-026/ozzy/perl6/ch-2.p6 b/challenge-026/ozzy/perl6/ch-2.p6 new file mode 100755 index 0000000000..a6ec27e6a0 --- /dev/null +++ b/challenge-026/ozzy/perl6/ch-2.p6 @@ -0,0 +1,15 @@ +#!/usr/bin/env perl6 + +# Script that prints the mean angle of a given list of +# angles in degrees. + +sub MAIN (*@ang_deg where .elems > 0) { + + my constant \deg2rad = (pi/180); + my constant \rad2deg = (180/pi); + + my $y = [+] map { ($_ * deg2rad).sin }, @ang_deg; + my $x = [+] map { ($_ * deg2rad).cos }, @ang_deg; + + printf "Mean angle = %.2f degrees\n", (atan2($y,$x) * rad2deg); +} \ No newline at end of file -- cgit