aoc2021

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

commit fd54938189040d4541471a2c5da1be366810fe3c
parent 94cc980d75d836c67af1cdb95b36d315d42f4376
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Sun,  5 Dec 2021 16:07:15 +0000

add subroutine to initialize hash storing board state

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

diff --git a/day04-1.pl b/day04-1.pl @@ -39,20 +39,37 @@ sub initialize_boards { return (@boards); } -# Advent of Code 2021 Day 04 Part 1 -my $filehandle = get_filehandle(); -my @numbers = get_numbers($filehandle); -my @boards = initialize_boards($filehandle); - -p(@boards); +sub initialize_state2 { + my $state = shift; + my $boards = shift; + foreach my $board (@$boards) { + foreach my $row (@$board) { + foreach my $column (@$row) { + ${$state}{$board}{$row}{$column} = 0; + } + } + } +} -my %state; -foreach my $board (@boards) { - foreach my $row (@$board) { - foreach my $column (@$row) { - $state{$board}{$row}{$column} = 0; +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; + } } } + return %state; } -p(%state); +# Advent of Code 2021 Day 04 Part 1 +my $filehandle = get_filehandle(); +my @numbers = get_numbers($filehandle); +my @boards = initialize_boards($filehandle); +my %state = initialize_state(\@boards); + +#p(@boards); +#p(%state);