aboutsummaryrefslogtreecommitdiff
path: root/challenge-026/markus-holzer
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-09-17 13:21:44 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-09-17 13:21:44 +0100
commitecc3de5bb7bd780c1300ae1d3fba5379a5f82a7b (patch)
treea7c42a4971e77fdc33b3963e0ae75ce73829b884 /challenge-026/markus-holzer
parentab98ce23a507882351339483b3215e75d46c50f4 (diff)
downloadperlweeklychallenge-club-ecc3de5bb7bd780c1300ae1d3fba5379a5f82a7b.tar.gz
perlweeklychallenge-club-ecc3de5bb7bd780c1300ae1d3fba5379a5f82a7b.tar.bz2
perlweeklychallenge-club-ecc3de5bb7bd780c1300ae1d3fba5379a5f82a7b.zip
- Added solutions by Markus Holzer.
Diffstat (limited to 'challenge-026/markus-holzer')
-rw-r--r--challenge-026/markus-holzer/README1
-rw-r--r--challenge-026/markus-holzer/perl6/ch-1.p621
-rw-r--r--challenge-026/markus-holzer/perl6/ch-2.p626
3 files changed, 48 insertions, 0 deletions
diff --git a/challenge-026/markus-holzer/README b/challenge-026/markus-holzer/README
new file mode 100644
index 0000000000..64aaa503e7
--- /dev/null
+++ b/challenge-026/markus-holzer/README
@@ -0,0 +1 @@
+Solutions by Markus Holzer.
diff --git a/challenge-026/markus-holzer/perl6/ch-1.p6 b/challenge-026/markus-holzer/perl6/ch-1.p6
new file mode 100644
index 0000000000..cd39fe4cb7
--- /dev/null
+++ b/challenge-026/markus-holzer/perl6/ch-1.p6
@@ -0,0 +1,21 @@
+use v6;
+use Test;
+
+multi sub infix:<+∩>( $stones, $jewels )
+{
+ $stones.Str +∩ $jewels.Str
+}
+
+multi sub infix:<+∩>( Str $stones, Str $jewels )
+{
+ $stones.split( '', :skip-empty ) +∩ $jewels.split( '', :skip-empty ).Set
+}
+
+multi sub infix:<+∩>( Iterable $stones, Set $jewels )
+{
+ $stones.grep({ $_ ∈ $jewels })
+}
+
+ok( ( "chancellor" +∩ "chocolates" ).elems == 8 );
+ok( ( "chocolatiers" +∩ "chancellor" ).elems == 9 );
+ok( ( "bottle" +∩ "beer" ).elems == 2 );
diff --git a/challenge-026/markus-holzer/perl6/ch-2.p6 b/challenge-026/markus-holzer/perl6/ch-2.p6
new file mode 100644
index 0000000000..0fc41be74d
--- /dev/null
+++ b/challenge-026/markus-holzer/perl6/ch-2.p6
@@ -0,0 +1,26 @@
+use v6;
+use Test;
+
+sub radians( $degrees )
+{
+ $degrees * π / 180
+}
+
+sub degrees( $radians )
+{
+ $radians * 180 / π
+}
+
+sub mean-angle( *@angles )
+{
+ my $inv = 1 / @angles.elems;
+
+ degrees( atan2(
+ $inv * [+] @angles.map({ radians( $_ ).sin }),
+ $inv * [+] @angles.map({ radians( $_ ).cos })
+ ));
+}
+
+ok( mean-angle( 10, 10, 10 ) =~= 10 );
+ok( mean-angle( 10, 20, 30 ) =~= 20 );
+ok( mean-angle( 355, 5, 15 ) =~= 5 );