diff options
| -rw-r--r-- | challenge-076/jason-messer/raku/ch-2.p6 | 81 |
1 files changed, 6 insertions, 75 deletions
diff --git a/challenge-076/jason-messer/raku/ch-2.p6 b/challenge-076/jason-messer/raku/ch-2.p6 index 2bb26bdfd3..39985d4576 100644 --- a/challenge-076/jason-messer/raku/ch-2.p6 +++ b/challenge-076/jason-messer/raku/ch-2.p6 @@ -16,87 +16,18 @@ sub MAIN($dict) { } 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 } + for ( ((0,-1,1) X (0,-1,1))[1..*] ) -> $dir_offset { + with cast_ray($dir_offset,$x, $y).grep( {.chars >= 4} ) { .say if .elems > 0 } + } } } } -# (-1, -1) #nw -sub cast_nw($x is copy, Int $y is copy) { +sub cast_ray($dir, $x is copy, Int $y is copy) { my @potential; - my @found = gather loop (; $x > 0 and $y > 0; $x--, $y--) { + my @found = gather + loop (; (0 <= $x < @grid.elems) and (0 <= $y < @grid.first.elems); $x += $dir.first, $y += $dir.tail) { @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{$_} } - } -} - |
