aoc2021

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

commit f45642928b8e57f47586249d48ce0315ac574da0
parent c8d8d6be6d144c53aa784e67cbb6a03486b6ba33
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Sat,  4 Dec 2021 01:48:29 +0000

got Part 2 of Day 3 to work now

Diffstat:
Mday03-2.pl | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/day03-2.pl b/day03-2.pl @@ -50,10 +50,10 @@ foreach my $index (0 .. $len) { # iterate through each bit } } @ogr = @temp_ogr; # replace real array with temporary array + last if (scalar( @ogr ) == 1); } #} -say @{$ogr[0]}; # ++++++++++++++++++++++++++++++++++++++++++++++++ @@ -61,7 +61,7 @@ say @{$ogr[0]}; my @co2sr= @numbers; #while ( scalar ( @co2sr ) > 1 ) { # while we still have more than one co2sr -say "size of co2sr is ", scalar(@co2sr); +#say "size of co2sr is ", scalar(@co2sr); foreach my $index (0 .. $len) { # iterate through each bit # bit counters my %count_0 = (); @@ -75,7 +75,7 @@ foreach my $index (0 .. $len) { # iterate through each bit } my $most_freq_bit = ($count_1{$index} >= $count_0{$index}) ? 1 : 0; - say "most frequent bit at index $index is $most_freq_bit"; + #say "most frequent bit at index $index is $most_freq_bit"; my @temp_co2sr; # temp array to hold elements whose bits match the # most frequently occuring one # go through each remaining element and only keep those where the bit at @@ -83,13 +83,14 @@ foreach my $index (0 .. $len) { # iterate through each bit # array foreach my $num (@co2sr) { unless ($num->[$index] == $most_freq_bit) { - say "keeping @$num"; + #say "keeping @$num"; push( @temp_co2sr, $num); } } @co2sr = @temp_co2sr; # replace real array with temporary array - say "size of co2sr down here is now ", scalar(@co2sr); + #say "size of co2sr down here is now ", scalar(@co2sr); + last if (scalar( @co2sr ) == 1); } #} -say @{$co2sr[0]}; +say oct("0b" . join("", @{$ogr[0]})) * oct("0b" . join("", @{$co2sr[0]}));