aoc2021

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

commit 8e4bbcf6b7e31c7932b59fbb55ca67b4283c5961
parent f97b0e27d2a63bb7bd1089bc2b0d04edb13dab6a
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Mon,  6 Dec 2021 14:54:37 +0000

add initial logic to check for winners in column

Diffstat:
Mday04-1.pl | 40++++++++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/day04-1.pl b/day04-1.pl @@ -99,10 +99,34 @@ sub check_for_winner { return 1; } } + foreach (0 .. 4) { + foreach my $row (@$boards) { + say @{${$row}[$_]}; + } + } } return 0; # no winner found } +sub check_for_horiz_winner { + my ($boards, $state) = @_; + foreach my $board (@$boards) { # $board is ref to board array + foreach (0 .. 4) { + foreach my $row (@$board) { + say "$board\t$_\t$row->[$_]\t$state->{$board}{$row}{$row->[$_]}"; + } + } + #foreach my $row (@$board) { # $row is ref to board row array +# foreach my $column (@$row) { +# say "$board\t$row\t$column"; +# } +# foreach (0 .. 4) { +# say "$board\t$row\t$row->[$_]"; +# } + #} + } +} + # Advent of Code 2021 Day 04 Part 1 # initialize game variables my $filehandle = get_filehandle(); @@ -113,14 +137,14 @@ my %state = initialize_state(\@boards); my $turn = 0; my $winner_found = 0; -until ($winner_found) { - $turn++; - say "turn: $turn"; - play_turn(\@numbers, \@boards, \%state); - $winner_found = check_for_winner(\@boards, \%state); -} - -print_board_state(\@boards, \%state); +#until ($winner_found) { +# $turn++; +# say "turn: $turn"; +# play_turn(\@numbers, \@boards, \%state); +# $winner_found = check_for_winner(\@boards, \%state); +#} +check_for_horiz_winner(\@boards, \%state); +#print_board_state(\@boards, \%state); #p(@boards); #p(%state);