commit 93f994f99449fd4fb0b57fa7b0071e6514b342b8
parent fd54938189040d4541471a2c5da1be366810fe3c
Author: Samir Parikh <noreply@samirparikh.com>
Date: Sun, 5 Dec 2021 16:59:36 +0000
got initial version of play_turn subroutine working
Diffstat:
M | day04-1.pl | | | 38 | +++++++++++++++++++++++++------------- |
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/day04-1.pl b/day04-1.pl
@@ -39,30 +39,39 @@ sub initialize_boards {
return (@boards);
}
-sub initialize_state2 {
- my $state = shift;
+sub initialize_state {
+ my %state;
my $boards = shift;
foreach my $board (@$boards) {
foreach my $row (@$board) {
foreach my $column (@$row) {
- ${$state}{$board}{$row}{$column} = 0;
+ $state{$board}{$row}{$column} = 0;
}
}
}
+ return %state;
}
-sub initialize_state {
- #my $state = shift;
- my %state;
- my $boards = shift;
- foreach my $board (@$boards) {
- foreach my $row (@$board) {
- foreach my $column (@$row) {
- $state{$board}{$row}{$column} = 0;
+sub play_turn {
+ my ($numbers, $boards, $state) = @_;
+ my $number = shift(@$numbers);
+ say "playing number $number";
+ #say $boards->[1][2][2];
+ #p($boards);
+ #print Dumper($boards);
+ foreach my $board (@$boards) { # $board is ref to board array
+ foreach my $row (@$board) { # $row is ref to board row array
+ foreach my $column (@$row) { # $column is element of row array
+ print "$boards\t$board\t$row\t";
+ if ($column == $number) {
+ $state->{$board}{$row}{$column} = 1;
+ say "-> $column <-";
+ } else {
+ say "$column";
+ }
}
}
}
- return %state;
}
# Advent of Code 2021 Day 04 Part 1
@@ -71,5 +80,8 @@ my @numbers = get_numbers($filehandle);
my @boards = initialize_boards($filehandle);
my %state = initialize_state(\@boards);
+say "numbers are @numbers";
+play_turn(\@numbers, \@boards, \%state);
+#say "numbers are now @numbers";
#p(@boards);
-#p(%state);
+p(%state);