aoc2021

Advent of Code 2021 solutions in Perl.
git clone git://git.samirparikh.com/aoc2021
Log | Files | Refs | README

commit a29521cf38e95af24e41e89eb5cb3ec0e4c1112a
parent 93f994f99449fd4fb0b57fa7b0071e6514b342b8
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Sun,  5 Dec 2021 17:12:30 +0000

got initial game play working

Diffstat:
Mday04-1.pl | 34+++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/day04-1.pl b/day04-1.pl @@ -62,9 +62,25 @@ sub play_turn { 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"; + #print "$boards\t$board\t$row\t"; if ($column == $number) { $state->{$board}{$row}{$column} = 1; + #say "-> $column <-"; + #} else { + #say "$column"; + } + } + } + } +} + +sub print_board_state { + my ($boards, $state) = @_; + 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 ($state->{$board}{$row}{$column} == 1) { say "-> $column <-"; } else { say "$column"; @@ -75,13 +91,21 @@ sub play_turn { } # Advent of Code 2021 Day 04 Part 1 +# initialize game variables my $filehandle = get_filehandle(); 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"; +my $turn = 1; + +while ($turn < 12) { + say "turn: $turn"; + play_turn(\@numbers, \@boards, \%state); + $turn++; +} + +print_board_state(\@boards, \%state); + #p(@boards); -p(%state); +#p(%state);