diff options
| author | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-09-06 14:43:08 +0200 |
|---|---|---|
| committer | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-09-06 14:43:08 +0200 |
| commit | 8aeed8d3fe1636af18d90b87e78497aa310ee228 (patch) | |
| tree | 2ff7c938fdbc26b2c4660ca4ec908b0d636d0aeb /challenge-076/markus-holzer | |
| parent | e8f14facf014ee3483edfb70e97bb65ca20aabc6 (diff) | |
| download | perlweeklychallenge-club-8aeed8d3fe1636af18d90b87e78497aa310ee228.tar.gz perlweeklychallenge-club-8aeed8d3fe1636af18d90b87e78497aa310ee228.tar.bz2 perlweeklychallenge-club-8aeed8d3fe1636af18d90b87e78497aa310ee228.zip | |
improved and explained
Diffstat (limited to 'challenge-076/markus-holzer')
| -rw-r--r-- | challenge-076/markus-holzer/raku/ch-2.board.small | 3 | ||||
| -rw-r--r-- | challenge-076/markus-holzer/raku/ch-2.explained.raku | 48 | ||||
| -rw-r--r-- | challenge-076/markus-holzer/raku/ch-2.raku | 19 | ||||
| -rw-r--r-- | challenge-076/markus-holzer/raku/ch-2.words | 10 | ||||
| -rw-r--r-- | challenge-076/markus-holzer/raku/ch-2.words.small | 10 |
5 files changed, 76 insertions, 14 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..66a7804cdf --- /dev/null +++ b/challenge-076/markus-holzer/raku/ch-2.explained.raku @@ -0,0 +1,48 @@ +unit sub MAIN($words-file, $word-file); + +my @words = $words-file.IO.lines; +say "Looking for words:"; +dd @words; + +my @chars = $word-file.IO.slurp.comb( /\H/ ); +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..ec95986c7b 100644 --- a/challenge-076/markus-holzer/raku/ch-2.raku +++ b/challenge-076/markus-holzer/raku/ch-2.raku @@ -1,16 +1,17 @@ -unit sub MAIN($words-file, $board-file); +unit sub MAIN($words-file, $word-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 = $word-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 |
