aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPolgár Márton <polgar@astron.hu>2022-04-24 23:11:04 +0200
committerPolgár Márton <polgar@astron.hu>2022-04-24 23:11:04 +0200
commita25b8c96b7febbbfbc039d72e62c587e918e01fb (patch)
tree003d4d8003525b21e38e28aebc05205ed269edc5
parent9abc0cc42a70f7e3a13c066d97b092cb972db38a (diff)
downloadperlweeklychallenge-club-a25b8c96b7febbbfbc039d72e62c587e918e01fb.tar.gz
perlweeklychallenge-club-a25b8c96b7febbbfbc039d72e62c587e918e01fb.tar.bz2
perlweeklychallenge-club-a25b8c96b7febbbfbc039d72e62c587e918e01fb.zip
Solutions for week #161
-rwxr-xr-xchallenge-161/2colours/raku/ch-1.raku23
-rwxr-xr-xchallenge-161/2colours/raku/ch-2.raku35
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-161/2colours/raku/ch-1.raku b/challenge-161/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..18ee621797
--- /dev/null
+++ b/challenge-161/2colours/raku/ch-1.raku
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+constant $file-url = 'https://raw.githubusercontent.com/manwar/perlweeklychallenge-club/master/data/dictionary.txt';
+
+sub MAIN(
+ Str :$load where { ! .defined || .IO.f }, #= local path of the dictionary file to load
+ Str :$save #= local path for saving the dictionary
+) {
+ my @lines;
+ with $load {
+ @lines = .IO.lines;
+ }
+ else {
+ use HTTP::Tiny;
+ @lines = HTTP::Tiny.new.get($file-url)<content>.decode.lines;
+ }
+ with $save {
+ my $f = .IO.open: :w;
+ $f.put: @lines.join("\n");
+ $f.close;
+ }
+ @lines.grep({ .comb.cache andthen $_ Zlt .skip andthen .all.so}).sort(*.chars).reverse.join(', ').say;
+} \ No newline at end of file
diff --git a/challenge-161/2colours/raku/ch-2.raku b/challenge-161/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..a2c8b1a641
--- /dev/null
+++ b/challenge-161/2colours/raku/ch-2.raku
@@ -0,0 +1,35 @@
+#!/usr/bin/env raku
+
+constant $file-url = 'https://raw.githubusercontent.com/manwar/perlweeklychallenge-club/master/data/dictionary.txt';
+
+sub MAIN(
+ Str :$load where { ! .defined || .IO.f }, #= local path of the dictionary file to load
+ Str :$save #= local path for saving the dictionary
+) {
+ my @lines;
+ with $load {
+ @lines = .IO.lines;
+ }
+ else {
+ use HTTP::Tiny;
+ @lines = HTTP::Tiny.new.get($file-url)<content>.decode.lines;
+ }
+ with $save {
+ my $f = .IO.open: :w;
+ $f.put: @lines.join("\n");
+ $f.close;
+ }
+ # going for the shortest "one letter added only"
+ @lines .= sort: *.chars;
+ my @solution;
+ my $covered-letters = Set.new;
+ for @lines -> $current-word {
+ if $current-word.comb (-) $covered-letters == 1 {
+ @solution.push: $current-word;
+ $covered-letters (|)= $current-word.comb;
+ last if 'a' .. 'z' ~~ $covered-letters;
+ }
+ }
+ die 'No solution available.' unless 'a' .. 'z' ~~ $covered-letters;
+ @solution.join(' ').say;
+} \ No newline at end of file