From a904c5cd889548f999fd21132100d654837cfb19 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Thu, 8 Dec 2022 06:23:10 +0100 Subject: [PATCH] Day 8: dummy solution with off-by-one errors --- 2022/15.pl | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2022/16.pl | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100755 2022/15.pl create mode 100755 2022/16.pl diff --git a/2022/15.pl b/2022/15.pl new file mode 100755 index 0000000..f8c3ff1 --- /dev/null +++ b/2022/15.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl -w + +use v5.36; +use strict; +use experimental 'multidimensional'; + +my @m = map { chomp; [ split // ] } <>; +my $xmax = @{ $m[0] }; +my $ymax = @m; + +my $count; +for my $x (1 .. $xmax-2) { +for my $y (1 .. $ymax-2) { + my $h = $m[$y][$x]; + say $h; + my $visible = 1; + for my $dx (0 .. $x-1) { + $visible = 0 if $m[$y][$dx] >= $h; + } + if ($visible) { + $count++; next; + } + $visible = 1; + say " $visible"; + for my $dx ($x+1 .. $xmax-1) { + $visible = 0 if $m[$y][$dx] >= $h; + } + if ($visible) { + $count++; next; + } + $visible = 1; + say " $visible"; + for my $dy (0 .. $y-1) { + $visible = 0 if $m[$dy][$x] >= $h; + } + if ($visible) { + $count++; next; + } + $visible = 1; + say " $visible"; + for my $dy ($y+1 .. $ymax-1) { + $visible = 0 if $m[$dy][$x] >= $h; + } + if ($visible) { + $count++; next; + } + $count++ if $visible; +} } + +say $count + 2* $xmax + 2*$ymax-4; diff --git a/2022/16.pl b/2022/16.pl new file mode 100755 index 0000000..c83a77f --- /dev/null +++ b/2022/16.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl -w + +use v5.36; +use strict; +use experimental 'multidimensional'; + +my @m = map { chomp; [ split // ] } <>; +my $xmax = @{ $m[0] }; +my $ymax = @m; + +my $max = 0; +for my $y (1 .. $ymax-2) { +for my $x (1 .. $xmax-2) { + my $h = $m[$y][$x]; + my $mul = 1; + my $count = 0; + for my $dx (reverse (0 .. $x-1)) { + $count++; + last if $m[$y][$dx] >= $h; + } + $mul *= $count; + + $count = 0; + for my $dx ($x+1 .. $xmax-1) { + $count++; + last if $m[$y][$dx] >= $h; + } + $mul *= $count; + + $count = 0; + for my $dy (reverse 0 .. $y-1) { + $count++; + last if $m[$dy][$x] >= $h; + } + $mul *= $count; + + $count = 0; + for my $dy ($y+1 .. $ymax-1) { + $count++; + last if $m[$dy][$x] >= $h; + } + $mul *= $count; + # say "$x $y $h $mul"; + + $max = $mul if $max < $mul; + +} } + +say $max; -- 2.43.5