From 90bbb36d90d4f98ba52785b931c75de0304f6839 Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Wed, 18 Aug 2021 17:50:04 -0400 Subject: One Twenty Six, which would be skipped --- challenge-126/dave-jacoby/perl/ch-1.pl | 22 +++++++++++++ challenge-126/dave-jacoby/perl/ch-2.pl | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 challenge-126/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-126/dave-jacoby/perl/ch-2.pl 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 = <@* ; + +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 '' ; + } + -- cgit