aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-207/2colours/raku/ch-1-blead.raku46
-rwxr-xr-xchallenge-207/2colours/raku/ch-1.raku13
-rwxr-xr-xchallenge-207/2colours/raku/ch-2.raku21
3 files changed, 80 insertions, 0 deletions
diff --git a/challenge-207/2colours/raku/ch-1-blead.raku b/challenge-207/2colours/raku/ch-1-blead.raku
new file mode 100755
index 0000000000..4e7ea3e6d8
--- /dev/null
+++ b/challenge-207/2colours/raku/ch-1-blead.raku
@@ -0,0 +1,46 @@
+#!/usr/bin/env raku
+# WARNING: this solution only works with recent "nightly" builds of Rakudo! Not released yet, not even as 6.e preview!
+use v6.*;
+
+sub either-char-class(@classes) {
+ my @word-choices = @classes.map: {
+ RakuAST::Regex::Group.new(
+ RakuAST::Regex::QuantifiedAtom.new(
+ atom => .&to-char-class,
+ quantifier => RakuAST::Regex::Quantifier::ZeroOrMore.new(
+ backtrack => RakuAST::Regex::Backtrack
+ ),
+ trailing-separator => False
+ )
+ )
+ };
+ RakuAST::QuotedRegex.new(
+ match-immediately => False,
+ body =>
+ RakuAST::Regex::Sequence.new(
+ RakuAST::Regex::InternalModifier::IgnoreCase.new,
+ RakuAST::Regex::Anchor::BeginningOfString.new,
+ RakuAST::Regex::Alternation.new(|@word-choices),
+ RakuAST::Regex::Anchor::EndOfString.new
+ )
+ ).EVAL
+}
+
+sub to-char-class(Str:D $input) {
+ my @elements = $input.comb.map: {
+ RakuAST::Regex::CharClassEnumerationElement::Character.new($_)
+ }
+ RakuAST::Regex::Assertion::CharClass.new(
+ RakuAST::Regex::CharClassElement::Enumeration.new(:@elements)
+ )
+
+}
+
+constant @rows = <qwertyuiop asdfghjkl zxcvbnm>;
+subset StrList of Str where /^ '(' ['"' $<str-content>=[.*?] '"']* % ',' ')' $/;
+
+sub MAIN(Str $input) {
+ die 'Please provide a valid list of double-quoted (constant) strings.' unless $input.subst(/\s/, '', :g) ~~ StrList;
+ my Str() @words = $<str-content>;
+ @words.grep(either-char-class(@rows)).say;
+} \ No newline at end of file
diff --git a/challenge-207/2colours/raku/ch-1.raku b/challenge-207/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..64f119bc1d
--- /dev/null
+++ b/challenge-207/2colours/raku/ch-1.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+
+
+constant @rows = <qwertyuiop asdfghjkl zxcvbnm>;
+subset StrList of Str where /^ '(' ['"' $<str-content>=[.*?] '"']* % ',' ')' $/;
+
+sub MAIN(Str $input) {
+ die 'Please provide a valid list of double-quoted (constant) strings.' unless $input.subst(/\s/, '', :g) ~~ StrList;
+ my Str() @words = $<str-content>;
+ @words
+ .grep: *.lc.comb.Set (<=) @rows.any.comb.Set andthen
+ .say
+} \ No newline at end of file
diff --git a/challenge-207/2colours/raku/ch-2.raku b/challenge-207/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..e3b16bbbbd
--- /dev/null
+++ b/challenge-207/2colours/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+
+
+my token unsigned-integer { 0 | <[1..9]><[0..9]>* };
+my token integer { '-'? <unsigned-integer> };
+# negative citation counts don't really make sense but that's what the task said /s
+subset IntList of Str where /^ '(' <integer>* % ',' ')' $/;
+
+sub MAIN(Str $array) {
+ die 'Please supply a valid list of integers.' unless $array.subst(/\s/, '', :g) ~~ IntList;
+ my Int() @array = $<integer>;
+ @array
+ .sort
+ .reverse
+ .map: {
+ last unless $_ >= ++$;
+ 1
+ } andthen
+ .sum
+ .say;
+}