diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-05-03 10:10:20 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-05-03 10:10:20 -0400 |
| commit | e7f7ab322b7c9580efe6b6a37cfe4c3e4852c097 (patch) | |
| tree | e306a3505f6fc8a3fa9227cea1010df0fb8c7bcc | |
| parent | 0381a39b17ccd040302474f25d3c1cbbef703327 (diff) | |
| download | perlweeklychallenge-club-e7f7ab322b7c9580efe6b6a37cfe4c3e4852c097.tar.gz perlweeklychallenge-club-e7f7ab322b7c9580efe6b6a37cfe4c3e4852c097.tar.bz2 perlweeklychallenge-club-e7f7ab322b7c9580efe6b6a37cfe4c3e4852c097.zip | |
1st commit on 111_raku
| -rwxr-xr-x | challenge-111/stuart-little/raku/ch-1.p6 | 30 | ||||
| -rwxr-xr-x | challenge-111/stuart-little/raku/ch-2.p6 | 31 |
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; +} |
