diff options
| author | holli-holzer <holli.holzer@gmail.com> | 2019-09-17 22:00:41 +0200 |
|---|---|---|
| committer | holli-holzer <holli.holzer@gmail.com> | 2019-09-17 22:00:41 +0200 |
| commit | 62a8eaa47b92e0808f24cbdd89c29a164a168c62 (patch) | |
| tree | 48feebec7ed480c235b61233333426f933d68eff | |
| parent | f8f36e82595be65d74b99feef6a2779d36cdc0d3 (diff) | |
| download | perlweeklychallenge-club-62a8eaa47b92e0808f24cbdd89c29a164a168c62.tar.gz perlweeklychallenge-club-62a8eaa47b92e0808f24cbdd89c29a164a168c62.tar.bz2 perlweeklychallenge-club-62a8eaa47b92e0808f24cbdd89c29a164a168c62.zip | |
Enforce alphabet
| -rw-r--r-- | challenge-026/markus-holzer/perl6/ch-1.p6 | 7 | ||||
| -rw-r--r-- | 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`) |
