aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-06 15:28:29 +0100
committerGitHub <noreply@github.com>2020-09-06 15:28:29 +0100
commit602f4b2d28333ba44afda77af3e750a33d096b83 (patch)
treee4545c6b15e92d65aeb23d9ef680a1863cc4bc10
parent5ea3691b7602fc2d06796d77497e207be4b333b8 (diff)
parent4fa314c929e47f5cd77f760b02ae156a4ba6dabb (diff)
downloadperlweeklychallenge-club-602f4b2d28333ba44afda77af3e750a33d096b83.tar.gz
perlweeklychallenge-club-602f4b2d28333ba44afda77af3e750a33d096b83.tar.bz2
perlweeklychallenge-club-602f4b2d28333ba44afda77af3e750a33d096b83.zip
Merge pull request #2218 from holli-holzer/master
improved and explained
-rw-r--r--challenge-076/markus-holzer/raku/ch-2.board.small3
-rw-r--r--challenge-076/markus-holzer/raku/ch-2.explained.raku49
-rw-r--r--challenge-076/markus-holzer/raku/ch-2.raku18
-rw-r--r--challenge-076/markus-holzer/raku/ch-2.words10
-rw-r--r--challenge-076/markus-holzer/raku/ch-2.words.small10
5 files changed, 77 insertions, 13 deletions
diff --git a/challenge-076/markus-holzer/raku/ch-2.board.small b/challenge-076/markus-holzer/raku/ch-2.board.small
new file mode 100644
index 0000000000..77e71d5ad1
--- /dev/null
+++ b/challenge-076/markus-holzer/raku/ch-2.board.small
@@ -0,0 +1,3 @@
+B U G
+O E A
+T I W
diff --git a/challenge-076/markus-holzer/raku/ch-2.explained.raku b/challenge-076/markus-holzer/raku/ch-2.explained.raku
new file mode 100644
index 0000000000..061e2a7986
--- /dev/null
+++ b/challenge-076/markus-holzer/raku/ch-2.explained.raku
@@ -0,0 +1,49 @@
+unit sub MAIN($words-file, $board-file);
+
+my @words = $words-file.IO.lines;
+say "Looking for words:";
+dd @words;
+
+my @chars = $board-file.IO.slurp.comb( /\H/ );
+say "Grid:\n", @chars.join;
+say "Searching these characters:";
+dd @chars;
+
+my $width = @chars.first( "\n", :k ) + 1;
+say "Grid has a width of {$width}";
+
+my $rotated-chars = rotated-chars;
+say "Data after rotation";
+dd $rotated-chars;
+
+my $search-text = $rotated-chars.flat.join;
+say "Final text to search:";
+dd $search-text;
+
+say "Results:";
+.Str.say for words-in $search-text;
+
+sub words-in( $text ) {
+ $text ~ "\n" ~ $text.flip ~~ m:ex:i/@words/ }
+
+sub rotated-chars {
+ eager # just so the output is in the right order
+ @chars.batch( $width ), # horizontal lines
+ | (
+ (0,0), # vertical lines
+ (0,1), # left to right diagonal
+ (1,0) # right to left diagonal
+ ).map: &rotate-chars }
+
+sub rotate-chars( @offsets ) {
+ say "Rotate the grid with offsets";
+ dd @offsets;
+
+ eager
+ (^$width).map: -> $start {
+ my $first = $start + @offsets[0];
+ my $next = $start + $width + @offsets[1];
+ say "Line {$start}, Indices: {$first}, {$next} ... *";
+ | @chars[ $first, $next ... * ], "\n";
+ }
+} \ No newline at end of file
diff --git a/challenge-076/markus-holzer/raku/ch-2.raku b/challenge-076/markus-holzer/raku/ch-2.raku
index 28e90a4d17..f5211d34be 100644
--- a/challenge-076/markus-holzer/raku/ch-2.raku
+++ b/challenge-076/markus-holzer/raku/ch-2.raku
@@ -1,16 +1,18 @@
unit sub MAIN($words-file, $board-file);
my @words = $words-file.IO.lines;
-my $width = $board-file.IO.lines.head.chars div 2 + 1;
-my @chars = $board-file.IO.slurp.comb( /\w/ );
+my @chars = $board-file.IO.slurp.comb( /\H/ );
+my $width = @chars.first( "\n", :k ) + 1;
-.Str.say for words-in rotated-data.flat.join;
+.Str.say for words-in rotated-chars.flat.join;
sub words-in( $text ) {
- $text ~'~'~ $text.flip ~~ m:ex:i/@words/ }
+ $text ~ "\n" ~ $text.flip ~~ m:ex:i/@words/ }
-sub rotated-data {
- @chars.batch( $width ), |( (0,0), (0,1), (1,0) ).map: &rotate-data }
+sub rotated-chars {
+ @chars.batch( $width ),
+ |( (0,0), (0,1), (1,0) ).map: &rotate-chars }
-sub rotate-data( @offsets ) {
- (^$width).map: { @chars[ ($_ + @offsets[0]), ($_ + $width + @offsets[1]) ... * ] } }
+sub rotate-chars( @offsets ) {
+ (^$width).map: -> $start {
+ | @chars[ ($start + @offsets[0]), ($start + $width + @offsets[1]) ... * ], "\n" } } \ No newline at end of file
diff --git a/challenge-076/markus-holzer/raku/ch-2.words b/challenge-076/markus-holzer/raku/ch-2.words
index f566351133..73e550eaa3 100644
--- a/challenge-076/markus-holzer/raku/ch-2.words
+++ b/challenge-076/markus-holzer/raku/ch-2.words
@@ -1,11 +1,7 @@
-argos
-margo
-patna
-traci
-tracie
aimed
align
antes
+argos
arose
ashed
blunt
@@ -30,10 +26,12 @@ liens
malign
malignant
malls
+margo
midst
ought
ovary
parted
+patna
pudgiest
quash
quashed
@@ -49,6 +47,8 @@ succor
succors
theorem
theorems
+traci
+tracie
virus
viruses
wigged \ No newline at end of file
diff --git a/challenge-076/markus-holzer/raku/ch-2.words.small b/challenge-076/markus-holzer/raku/ch-2.words.small
new file mode 100644
index 0000000000..d345d6a2d0
--- /dev/null
+++ b/challenge-076/markus-holzer/raku/ch-2.words.small
@@ -0,0 +1,10 @@
+bug
+bot
+wit
+wag
+web
+get
+to
+it
+we
+at \ No newline at end of file