aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-09-18 12:33:18 +0100
committerGitHub <noreply@github.com>2019-09-18 12:33:18 +0100
commitea8a19b61c4b7b969d880a2042b2415c6aae55c0 (patch)
tree50c8f0886653aae1e6b751346781a40fb7670727
parentbe71b7a3db240ec47e9673f7fe3193346237ef6d (diff)
parent6c77e048169c579bcf26bea7d917366db388c2e8 (diff)
downloadperlweeklychallenge-club-ea8a19b61c4b7b969d880a2042b2415c6aae55c0.tar.gz
perlweeklychallenge-club-ea8a19b61c4b7b969d880a2042b2415c6aae55c0.tar.bz2
perlweeklychallenge-club-ea8a19b61c4b7b969d880a2042b2415c6aae55c0.zip
Merge pull request #643 from holli-holzer/master
Better wording, now enforcing the alphabet
-rw-r--r--challenge-026/markus-holzer/perl6/ch-1.p67
-rw-r--r--challenge-026/markus-holzer/perl6/ch-2.p66
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" );