From f8f36e82595be65d74b99feef6a2779d36cdc0d3 Mon Sep 17 00:00:00 2001 From: holli-holzer Date: Tue, 17 Sep 2019 21:14:23 +0200 Subject: Better wording, added missing "use Test;" --- challenge-026/markus-holzer/perl6/ch-2.p6 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/challenge-026/markus-holzer/perl6/ch-2.p6 b/challenge-026/markus-holzer/perl6/ch-2.p6 index 2273b4f199..8c53908732 100644 --- a/challenge-026/markus-holzer/perl6/ch-2.p6 +++ b/challenge-026/markus-holzer/perl6/ch-2.p6 @@ -1,3 +1,5 @@ +use Test; + # Rakus trigonometry functions operate on radians. So we must convert degrees to radians. # That's simple enough using a new postfix operator and high school math. multi sub postfix:<°>( Numeric $degrees ) returns Real { $degrees * π / 180 } @@ -15,11 +17,11 @@ sub mean-angle( *@α ) returns Real ); ρ > 0 - ?? ρ # We always want positive values + ?? ρ # We always want a positive value !! ρ + 2 * π # When it isn't, we add 360° } -ok( mean-angle( 10°, 10°, 10° ) =~= 10°, "The mean of 3 times alpha is alpha" ); +ok( mean-angle( 10°, 10°, 10° ) =~= 10°, "The mean of equal angles is the angle" ); ok( mean-angle( 10°, 20°, 30° ) =~= 20°, "All angles in one quadrant" ); ok( mean-angle( 355°, 5°, 15° ) =~= 5°, "Angles in multiple quadrants" ); ok( mean-angle( 90°, 180°, 270°, 360° ) =~= 270°, "Angle is not negative" ); -- cgit From 62a8eaa47b92e0808f24cbdd89c29a164a168c62 Mon Sep 17 00:00:00 2001 From: holli-holzer Date: Tue, 17 Sep 2019 22:00:41 +0200 Subject: Enforce alphabet --- challenge-026/markus-holzer/perl6/ch-1.p6 | 7 +++++-- challenge-026/markus-holzer/perl6/ch-2.p6 | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/challenge-026/markus-holzer/perl6/ch-1.p6 b/challenge-026/markus-holzer/perl6/ch-1.p6 index 85f29cab2c..70e6ceeaeb 100644 --- a/challenge-026/markus-holzer/perl6/ch-1.p6 +++ b/challenge-026/markus-holzer/perl6/ch-1.p6 @@ -3,11 +3,14 @@ use Test; # In Raku, all operators are just multi - functions. # So we can easily define ourselves an infix left-associative element-of operator. # It will take an `Iterable` (`Seq`, `Array`, `List`) on its left side and a `Set` on the right side. -# It returns a `Seq` of all elements of the left side that are present on the right side. +# It returns a `Seq` of all elements of the left side that are present on the right side and that +# are part of our alphabet multi sub infix:<\<∈>( Iterable $stones, Set $jewels ) returns Seq { - $stones.grep: * ∈ $jewels + # constant runs at BEGIN time, so this work gets only done once + constant \alphabet = ( 'a' .. 'z', 'A' .. 'Z' ).Set; + $stones.grep({ $_ ∈ alphabet && $_ ∈ $jewels }); } # Now we could call that good, but in true Raku spirit we provide additional diff --git a/challenge-026/markus-holzer/perl6/ch-2.p6 b/challenge-026/markus-holzer/perl6/ch-2.p6 index 8c53908732..68e4321c19 100644 --- a/challenge-026/markus-holzer/perl6/ch-2.p6 +++ b/challenge-026/markus-holzer/perl6/ch-2.p6 @@ -2,7 +2,7 @@ use Test; # Rakus trigonometry functions operate on radians. So we must convert degrees to radians. # That's simple enough using a new postfix operator and high school math. -multi sub postfix:<°>( Numeric $degrees ) returns Real { $degrees * π / 180 } +multi sub postfix:<°>( Numeric $degrees ) is looser(&prefix:<->) returns Real { $degrees * π / 180 } # This implements the "simple" version of the algorithm as described on Wikipedia. # There already is an implementation of the complex math version (that uses `i`) -- cgit From e326199ba2d83e1c78579d3f5a2945126a91a5c6 Mon Sep 17 00:00:00 2001 From: holli-holzer Date: Tue, 17 Sep 2019 22:05:11 +0200 Subject: Update ch-2.p6 --- challenge-026/markus-holzer/perl6/ch-2.p6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-026/markus-holzer/perl6/ch-2.p6 b/challenge-026/markus-holzer/perl6/ch-2.p6 index 68e4321c19..8c53908732 100644 --- a/challenge-026/markus-holzer/perl6/ch-2.p6 +++ b/challenge-026/markus-holzer/perl6/ch-2.p6 @@ -2,7 +2,7 @@ use Test; # Rakus trigonometry functions operate on radians. So we must convert degrees to radians. # That's simple enough using a new postfix operator and high school math. -multi sub postfix:<°>( Numeric $degrees ) is looser(&prefix:<->) returns Real { $degrees * π / 180 } +multi sub postfix:<°>( Numeric $degrees ) returns Real { $degrees * π / 180 } # This implements the "simple" version of the algorithm as described on Wikipedia. # There already is an implementation of the complex math version (that uses `i`) -- cgit From a5f2fcebc521f4200e04947ccd454ab35e317be6 Mon Sep 17 00:00:00 2001 From: holli-holzer Date: Tue, 17 Sep 2019 22:06:54 +0200 Subject: ... --- challenge-026/markus-holzer/perl6/ch-2.p6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenge-026/markus-holzer/perl6/ch-2.p6 b/challenge-026/markus-holzer/perl6/ch-2.p6 index 68e4321c19..d4a6529a4f 100644 --- a/challenge-026/markus-holzer/perl6/ch-2.p6 +++ b/challenge-026/markus-holzer/perl6/ch-2.p6 @@ -2,8 +2,8 @@ use Test; # Rakus trigonometry functions operate on radians. So we must convert degrees to radians. # That's simple enough using a new postfix operator and high school math. -multi sub postfix:<°>( Numeric $degrees ) is looser(&prefix:<->) returns Real { $degrees * π / 180 } - +multi sub postfix:<°>( Numeric $degrees ) returns Real { $degrees * π / 180 } + # This implements the "simple" version of the algorithm as described on Wikipedia. # There already is an implementation of the complex math version (that uses `i`) # on Rosetta-Code https://rosettacode.org/wiki/Averages/Mean_angle#Perl_6 -- cgit