aboutsummaryrefslogtreecommitdiff
path: root/challenge-111
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-111')
-rwxr-xr-xchallenge-111/stuart-little/raku/ch-1.p630
-rwxr-xr-xchallenge-111/stuart-little/raku/ch-2.p631
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-111/stuart-little/raku/ch-1.p6 b/challenge-111/stuart-little/raku/ch-1.p6
new file mode 100755
index 0000000000..3aef0338f6
--- /dev/null
+++ b/challenge-111/stuart-little/raku/ch-1.p6
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl6
+use v6;
+
+# run <script>
+
+use MONKEY-SEE-NO-EVAL;
+
+my @ar = [
+ [ 1, 12, 3, 5, 7 ],
+ [ 9, 11, 15, 19, 20 ],
+ [ 23, 24, 25, 29, 31 ],
+ [ 32, 33, 39, 40, 42 ],
+ [ 45, 47, 48, 49, 50 ],
+ ];
+say "Array:";
+for (@ar) -> @row {
+ say @row;
+}
+say "";
+
+my $arrStr = @ar.map(|*).join(',');
+my &fun = EVAL 'use List::AllUtils qw(bsearchidx); sub f {bsearchidx {$_ - $_[0]} \qq[$arrStr]}; \&f', :lang<Perl5>;
+
+my @toSearch=(1,35,39,100);
+
+for (@toSearch) {
+ say "Found $_?";
+ say (fun($_) >= 0) ?? (1) !! (0);
+}
+
diff --git a/challenge-111/stuart-little/raku/ch-2.p6 b/challenge-111/stuart-little/raku/ch-2.p6
new file mode 100755
index 0000000000..3930ac7236
--- /dev/null
+++ b/challenge-111/stuart-little/raku/ch-2.p6
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl6
+use v6;
+
+# run <script> <path-to-dict-file, one word per line>
+
+sub isSorted($word) {
+ my @word = $word.lc.split("", :skip-empty);
+ my @diffs = zip @word[0..^$word.chars-1], @word[1..$word.chars-1], :with({ord($^b) - ord($^a)});
+ return ($word.lc ~~ /^<[a..z]>+$/).Bool && @diffs.map({$_ >= 0}).all.Bool;
+}
+
+sub longestWith(@list,&pred) {
+ my $length=0;
+ my @res=();
+ for (@list) {
+ my $l=$_.chars;
+ next if (! &pred($_));
+ $l > $length && do {
+ $length = $l;
+ @res=($_,);
+ next;
+ };
+ $l == $length && push @res, $_;
+ }
+ return @res;
+}
+
+my @words = @*ARGS[0].IO.lines;
+for (longestWith(@words,&isSorted)) {
+ .say;
+}