commit 605e6a6de8270c97055e13724de8ef48fa621178
parent a59553c92fd8f85cd09274d8756a2cf61f540b74
Author: Samir Parikh <noreply@samirparikh.com>
Date: Tue, 21 Dec 2021 15:52:43 +0000
update day09-2.pl to figure out logic on how to deference array
to find location height
Diffstat:
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/day09-2.pl b/day09-2.pl
@@ -7,6 +7,17 @@ use Data::Dumper;
sub find_basin {
my ($row, $column, $heightmap_ref) = @_;
+ my $size = 1; # lowpoint is already part of basin
+ my @queue = ( [$row, $column] );
+ while ( @queue ) { # there are still locations in queue to check
+ my $location = shift @queue;
+ my $r = $location->[0];
+ my $c = $location->[1];
+ my $location_height = $heightmap_ref->[$r][$c]
+ }
+ #say "row is $location->[0] and column is $location->[1]";
+ #my $location_height = $heightmap_ref->[$location->[0]][$location->[1]];
+ #say "recvd lowpoint of height $location_height at $row, $column";
}
my @heightmap = map{ [m/\d/g, 9] } <>; # add extra column of 9s
@@ -27,7 +38,11 @@ foreach my $row (0 .. $rows - 2) { # don't care about last row that we added
}
}
# found low point
- $risk_level += $height + 1 if $lowpoint;
+ if ($lowpoint) {
+ say "found lowpoint of height $height at $row, $column";
+ $risk_level += $height + 1;
+ find_basin( $row, $column, \@heightmap );
+ }
}
}