Advertisement
musifter

AoC 2021 day 1 (Perl)

Dec 1st, 2021
1,637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.36 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my @Depths = <>;
  7.  
  8. sub count_incs {
  9.     my $window = shift @_;
  10.  
  11.     my $res = 0;
  12.     for (my $i = 0; $i <= $#Depths - $window; $i++) {
  13.         $res++  if ($Depths[$i + $window]  > $Depths[$i]);
  14.     }
  15.  
  16.     return ($res);
  17. }
  18.  
  19. print "Part 1: ", &count_incs(1), "\n";
  20. print "Part 2: ", &count_incs(3), "\n";
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement