diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2021-08-18 17:50:04 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2021-08-18 17:50:04 -0400 |
| commit | 90bbb36d90d4f98ba52785b931c75de0304f6839 (patch) | |
| tree | 62f0c63d3909d2b375694059b41a7cd8d05035ff | |
| parent | 710837b2a38b5fbd4404f8d9be06ef368af0d366 (diff) | |
| download | perlweeklychallenge-club-90bbb36d90d4f98ba52785b931c75de0304f6839.tar.gz perlweeklychallenge-club-90bbb36d90d4f98ba52785b931c75de0304f6839.tar.bz2 perlweeklychallenge-club-90bbb36d90d4f98ba52785b931c75de0304f6839.zip | |
One Twenty Six, which would be skipped
| -rw-r--r-- | challenge-126/dave-jacoby/perl/ch-1.pl | 22 | ||||
| -rw-r--r-- | challenge-126/dave-jacoby/perl/ch-2.pl | 59 |
2 files changed, 81 insertions, 0 deletions
diff --git a/challenge-126/dave-jacoby/perl/ch-1.pl b/challenge-126/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..d71d1e9f8a --- /dev/null +++ b/challenge-126/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl + +use strict ; +use warnings ; +use feature qw{ say postderef signatures state } ; +no warnings qw{ experimental } ; + +use Carp; +use Getopt::Long; + +my $n = 15; +GetOptions( + 'n=i' => \$n +); + +croak 'Out of Range!' if $n < 1; + +say join ', ' , dont_contain( $n ); + +sub dont_contain ($n ) { + return grep { ! /1/ } 1 .. $n +} diff --git a/challenge-126/dave-jacoby/perl/ch-2.pl b/challenge-126/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..bcdd6d9741 --- /dev/null +++ b/challenge-126/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl + +use strict ; +use warnings ; +use feature qw{ say postderef signatures state } ; +no warnings qw{ experimental } ; + +use JSON ; +my $json = JSON->new->space_after->utf8 ; + +my $field = <<END; +x * * * x * x x x x +* * * * * * * * * x +* * * * x * x * x * +* * * x x * * * * * +x * * * x * * * * x +END + +my @field = map { [ split /\s/, $_ ] } + split /\n/, $field ; + +my $h = -1 + scalar @field ; +my $w = -1 + scalar $field[ 0 ]->@* ; + +my @map ; + +for my $i ( 0 .. $h ) { + for my $j ( 0 .. $w ) { + $map[ $i ][ $j ] = $field[ $i ][ $j ] eq 'x' ? 'x' : 0 ; + } + } + +for my $i ( 0 .. $h ) { + for my $j ( 0 .. $w ) { + next unless $map[ $i ][ $j ] eq 'x' ; + for my $x ( -1 .. 1 ) { + for my $y ( -1 .. 1 ) { + my $xx = $i + $x ; + my $yy = $j + $y ; + next if $xx == 0 && $yy == 0 ; + next if $xx < 0 ; + next if $yy < 0 ; + next if $xx > $h ; + next if $yy > $w ; + next if $map[ $xx ][ $yy ] eq 'x' ; + $map[ $xx ][ $yy ]++ ; + } + } + } + } +show_map( \@map ) ; + +sub show_map ( $ref ) { + say '-' x 20 ; + say join "\n", map { join ' ', $_->@* } $ref->@* ; + say '-' x 20 ; + say '' ; + } + |
