aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-111/aaronreidsmith/blog.txt1
-rw-r--r--challenge-111/aaronreidsmith/raku/ch-1.raku47
-rw-r--r--challenge-111/aaronreidsmith/raku/ch-2.raku40
3 files changed, 88 insertions, 0 deletions
diff --git a/challenge-111/aaronreidsmith/blog.txt b/challenge-111/aaronreidsmith/blog.txt
new file mode 100644
index 0000000000..ac97767574
--- /dev/null
+++ b/challenge-111/aaronreidsmith/blog.txt
@@ -0,0 +1 @@
+https://aaronreidsmith.github.io/blog/perl-weekly-challenge-111/
diff --git a/challenge-111/aaronreidsmith/raku/ch-1.raku b/challenge-111/aaronreidsmith/raku/ch-1.raku
new file mode 100644
index 0000000000..d6344858c7
--- /dev/null
+++ b/challenge-111/aaronreidsmith/raku/ch-1.raku
@@ -0,0 +1,47 @@
+#!/usr/bin/env raku
+
+sub challenge(@list-of-lists, Int $N) returns Int {
+ my $output = 0;
+ for (0..^@list-of-lists.end) Z (0^..@list-of-lists.end) -> ($i, $j) {
+ if @list-of-lists[$i].head == $N || @list-of-lists[$j].head == $N {
+ $output = 1;
+ last;
+ } elsif @list-of-lists[$i].head < $N < @list-of-lists[$j].head {
+ $output = (any(@list-of-lists[$i][1..*]) ~~ $N).Int;
+ last;
+ } elsif $j == @list-of-lists.end && $N > @list-of-lists[$j].head {
+ $output = (any(@list-of-lists[$j][1..*]) ~~ $N).Int;
+ last;
+ }
+ }
+ $output;
+}
+
+multi sub MAIN(Int $N) {
+ my @list-of-lists = (
+ ( 1, 2, 3, 5, 7),
+ ( 9, 11, 15, 19, 20),
+ (23, 24, 25, 29, 31),
+ (32, 33, 39, 40, 42),
+ (45, 47, 48, 49, 50)
+ );
+ say challenge(@list-of-lists, $N);
+}
+
+multi sub MAIN(Bool :$test) {
+ use Test;
+
+ my @list-of-lists = (
+ ( 1, 2, 3, 5, 7),
+ ( 9, 11, 15, 19, 20),
+ (23, 24, 25, 29, 31),
+ (32, 33, 39, 40, 42),
+ (45, 47, 48, 49, 50)
+ );
+
+ is(challenge(@list-of-lists, 35), 0);
+ is(challenge(@list-of-lists, 39), 1);
+ is(challenge(@list-of-lists, 47), 1);
+
+ done-testing;
+}
diff --git a/challenge-111/aaronreidsmith/raku/ch-2.raku b/challenge-111/aaronreidsmith/raku/ch-2.raku
new file mode 100644
index 0000000000..7b07b9ea31
--- /dev/null
+++ b/challenge-111/aaronreidsmith/raku/ch-2.raku
@@ -0,0 +1,40 @@
+#!/usr/bin/env raku
+
+use LibCurl::HTTP :subs; # Imports jget
+
+sub get-english-words {
+ my %words = jget('https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json');
+ %words.keys;
+}
+
+sub challenge(Int $threshold) {
+ my @words = get-english-words;
+ my @matching-words = gather for @words.race -> $word {
+ my @chars = $word.comb;
+ if @chars.elems >= $threshold && @chars.sort.join eq $word {
+ take $word;
+ }
+ }
+ @matching-words.sort;
+}
+
+multi sub MAIN(Int $threshold = 7) {
+ for challenge($threshold) -> $word {
+ say $word;
+ }
+}
+
+multi sub MAIN(Bool :$test) {
+ use Test;
+
+ my @tests = (
+ (7, ('adelops', 'aegilops', 'alloquy', 'beefily', 'begorry', 'belloot', 'billowy', 'deglory', 'egilops')),
+ (8, ('aegilops',))
+ );
+
+ for @tests -> ($threshold, @expected) {
+ is(challenge($threshold), @expected);
+ }
+
+ done-testing;
+}