aoc2021

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

day01.pl (470B) - raw


      1 #!/usr/bin/env perl
      2 
      3 use strict;
      4 use warnings;
      5 use v5.22;
      6 use diagnostics;
      7 
      8 if (@ARGV !=1) {
      9     die "Usage: $0 [input-filename]";
     10 }
     11 
     12 my $input_filename = $ARGV[0];
     13 open my $filehandle, '<', $input_filename or
     14     die "Could not open input file $input_filename: $!";
     15 
     16 chomp( my @input = ( <$filehandle> ) );
     17 
     18 # Part 1
     19 say scalar( grep { $input[$_] > $input[$_ - 1] } (1 .. $#input) );
     20 
     21 # Part 2
     22 say scalar( grep { $input[$_ + 2] > $input[$_ - 1] } (1 .. $#input - 2) );