aboutsummaryrefslogtreecommitdiff
path: root/challenge-076
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-07 00:47:56 +0100
committerGitHub <noreply@github.com>2020-09-07 00:47:56 +0100
commit5b2b0312e43d3ca78f05f4c28815f795b31c90de (patch)
tree2974a3f0846445e4683c67f4fe5b355f32e0eef6 /challenge-076
parent2a33c23bddcf3ae8a1e6ce89a0d029e1ef7b0e38 (diff)
parent9f97779c31c1fe1bac9620a35b9d7780da2e1bdc (diff)
downloadperlweeklychallenge-club-5b2b0312e43d3ca78f05f4c28815f795b31c90de.tar.gz
perlweeklychallenge-club-5b2b0312e43d3ca78f05f4c28815f795b31c90de.tar.bz2
perlweeklychallenge-club-5b2b0312e43d3ca78f05f4c28815f795b31c90de.zip
Merge pull request #2224 from therealjcm/branch-for-challenge-076
raku solution by Jason Messer for challenge #76
Diffstat (limited to 'challenge-076')
-rw-r--r--challenge-076/jason-messer/raku/ch-1.p65
-rw-r--r--challenge-076/jason-messer/raku/ch-2.p6102
-rw-r--r--challenge-076/jason-messer/raku/grid.txt19
3 files changed, 126 insertions, 0 deletions
diff --git a/challenge-076/jason-messer/raku/ch-1.p6 b/challenge-076/jason-messer/raku/ch-1.p6
new file mode 100644
index 0000000000..46117c39dc
--- /dev/null
+++ b/challenge-076/jason-messer/raku/ch-1.p6
@@ -0,0 +1,5 @@
+#! /usr/bin/env rakudo
+
+my $N = 9;
+my @p = gather for (2..^$N) { .take if .is-prime }
+say @p.combinations.grep( {.sum == $N} ).sort( {$^a.elems > $^b.elems } ).first.elems
diff --git a/challenge-076/jason-messer/raku/ch-2.p6 b/challenge-076/jason-messer/raku/ch-2.p6
new file mode 100644
index 0000000000..2bb26bdfd3
--- /dev/null
+++ b/challenge-076/jason-messer/raku/ch-2.p6
@@ -0,0 +1,102 @@
+#! /usr/bin/env rakudo
+
+my @grid;
+my %dict;
+
+sub MAIN($dict) {
+ my $grid_fh = open :r, 'grid.txt' or die($grid_fh);
+ my @lines = $grid_fh.lines();
+ loop (my $i = 0; $i < @lines.elems; $i++) {
+ @grid[$i] = @lines[$i].comb.map( {.lc} );
+ }
+
+ my $dict_fh = open :r, $dict or die($dict_fh);
+ for $dict_fh.lines() -> $line {
+ %dict{$line} = True;
+ }
+ for ^@grid.elems -> $x {
+ for ^@grid[$x].elems -> $y {
+ with cast_nw($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ with cast_n($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ with cast_ne($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ with cast_e($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ with cast_se($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ with cast_s($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ with cast_sw($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ with cast_w($x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 }
+ }
+ }
+}
+
+# (-1, -1) #nw
+sub cast_nw($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $x > 0 and $y > 0; $x--, $y--) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
+# (-1, 0), #n
+sub cast_n($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $x > 0; $x--) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
+# (-1, 1), #ne
+sub cast_ne($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $x > 0 and $y < @grid.first.elems; $x--, $y++) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
+# (0, 1), #e
+sub cast_e($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $y < @grid.first.elems; $y++) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
+# (1, 1), #se
+sub cast_se($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $x < @grid.elems and $y > @grid.first.elems; $x++, $y++) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
+# (1, 0), #s
+sub cast_s($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $x < @grid.elems; $x++) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
+# (1, -1), #sw
+sub cast_sw($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $x < @grid.elems and $y > 0; $x++, $y--) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
+# (0, -1), #w
+sub cast_w($x is copy, Int $y is copy) {
+ my @potential;
+ my @found = gather loop (; $y > 0; $y--) {
+ @potential.append: lc(@grid[$x][$y]);
+ with @potential.join { .take if %dict{$_} }
+ }
+}
+
diff --git a/challenge-076/jason-messer/raku/grid.txt b/challenge-076/jason-messer/raku/grid.txt
new file mode 100644
index 0000000000..b010521de2
--- /dev/null
+++ b/challenge-076/jason-messer/raku/grid.txt
@@ -0,0 +1,19 @@
+BIDEMIATSUCCORST
+LDEGGIWQHODEEHDP
+USEIRUBUTEASLAGU
+NGNIZILAICOSCNUD
+TGMIDSTSARAREIFG
+SRENMDCHASIVEELI
+SCSHAEUEBROADMTE
+HWOVLPEDDLAIULSS
+RYONLASFCSTAOGOT
+IGUSSRRUGOVARYOC
+NRGPATNANGILAMOO
+EIHACEIVIRUSESED
+SETSUDTTGARLICNH
+HVRMXLWIUMSNSOTB
+AEAOFILCHTODCAEU
+ZSCDFECAAIIRLNRF
+ARIIANYUTOOOUTPF
+RSECISNABOSCNERA
+DRSMPCUUNELTESIL