aoc2021

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

commit 09dcac8c2592d88d35dbacda0800573f912de707
parent 2247d9305702f1804f846070d00a05aa3e2a1fa1
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Mon,  6 Dec 2021 20:27:50 +0000

got to one final board remaining
need to determine how to play it out to get the last number played
from which we can calculate the final score

Diffstat:
Mday04-2.pl | 11++---------
1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/day04-2.pl b/day04-2.pl @@ -138,22 +138,15 @@ my $number; my @boards = initialize_boards($filehandle); my %state = initialize_state(\@boards); my $turn = 0; - -# $winner_found plays double duty. When equal to 0, it means that -# we haven't yet found a winning board. When we do, the subroutine -# check_for_winner returns a reference to the array of the winning -# board which we can then submit to calculate_score. -#my $winner_found = 0; my @winner_found; -#until ($winner_found) { while ( scalar ( @boards ) > 1 ) { @winner_found = (); $turn++; printf "turn: %2d, playing number %2d\n", $turn, $number; $number = shift( @numbers ); play_turn($number, \@boards, \%state); - $winner_found = check_for_winner(\@boards, \%state); + @winner_found = check_for_winner(\@boards, \%state); if ( @winner_found ) { say "found a winning board"; say "we had ", scalar(@boards), " boards"; @@ -168,5 +161,5 @@ while ( scalar ( @boards ) > 1 ) { exit; } } -my $score = calculate_score($number, $boards[0], %state); +my $score = calculate_score($number, $boards[0], \%state); say "winning score is $score";