aoc2021

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

commit c2d924194149964c6d3a855d43f7bf3863f92ce4
parent 6ab15f4b31aa97d85cee5e75aa8a52a311f7c1c2
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Fri, 17 Dec 2021 18:30:15 +0000

initial commit for day06-1.pl

Diffstat:
Aday06-1.pl | 39+++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+), 0 deletions(-)

diff --git a/day06-1.pl b/day06-1.pl @@ -0,0 +1,39 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use v5.22; +use Data::Dumper; + +sub get_filehandle { + if (@ARGV !=1) { + die "Usage: $0 [input-filename]"; + } + my $input_filename = $ARGV[0]; + open my $filehandle, '<', $input_filename or + die "Could not open input file $input_filename: $!"; + return $filehandle; +} + +sub get_numbers { + my $fh = shift; + chomp( my $numbers = ( <$fh> ) ); + return (split( ",", $numbers)); +} + +# Advent of Code 2021 Day 04 Part 1 +# initialize variables +my $filehandle = get_filehandle(); +my @numbers = get_numbers($filehandle); +say "@numbers"; +# initialize fish timer +my %fish_timer = map { $_, 0 } (0 .. 8); +$fish_timer{$_}++ foreach (@numbers); +print Dumper (\%fish_timer); +for (my $i = 0; $i < 2; $i++) { + say "day ", $i+1; + my %tmp_timer = %fish_timer; + foreach my $age (reverse 0 .. 8) { + say "age is $age"; + } +}