diff options
| -rw-r--r-- | challenge-026/markus-holzer/perl6/ch-1.p6 | 7 | ||||
| -rw-r--r-- | challenge-026/markus-holzer/perl6/ch-2.p6 | 6 |
2 files changed, 9 insertions, 4 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 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" ); |
