aoc2021

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

commit 016d954754a4b9d734650ddd755b98f5e6d105c7
parent e2c3777dbefac1f1f09dccca62e2a9f267c81f37
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Fri,  3 Dec 2021 15:59:12 +0000

cleanup code

Diffstat:
Mday03.pl | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/day03.pl b/day03.pl @@ -16,9 +16,9 @@ chomp( my @input = ( <$filehandle> ) ); # Part 1 my $len = length($input[0]) - 1; # number of bits - 1 -my %count_0 = (); -my %count_1 = (); -my $gamma_rate = ""; +my %count_0 = (); +my %count_1 = (); +my $gamma_rate = ""; my $epsilon_rate = ""; foreach (@input) { @@ -34,10 +34,10 @@ foreach (@input) { for (0 .. $len) { # find which bit occurs the most at each position if ($count_0{$_} > $count_1{$_}) { - $gamma_rate .= "0"; + $gamma_rate .= "0"; $epsilon_rate .= "1"; } else { - $gamma_rate .= "1"; + $gamma_rate .= "1"; $epsilon_rate .= "0"; } }