aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-04 07:00:06 +0100
committerGitHub <noreply@github.com>2021-05-04 07:00:06 +0100
commit728b1f16d4f9ec289cfa0f7ab0fb327f4601d152 (patch)
tree9f27c7de99428df682f6e94ec8e65512e671e24a
parentc678224f677b433c0d0bbd1b3ab68e5da32fc255 (diff)
parente7f7ab322b7c9580efe6b6a37cfe4c3e4852c097 (diff)
downloadperlweeklychallenge-club-728b1f16d4f9ec289cfa0f7ab0fb327f4601d152.tar.gz
perlweeklychallenge-club-728b1f16d4f9ec289cfa0f7ab0fb327f4601d152.tar.bz2
perlweeklychallenge-club-728b1f16d4f9ec289cfa0f7ab0fb327f4601d152.zip
Merge pull request #4009 from stuart-little/stuart-little_111_raku
1st commit on 111_raku
-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;
+}