aoc2022

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

day06.pl (393B) - raw


      1 #!/usr/local/bin/perl
      2 # day 2022-06
      3 
      4 use strict;
      5 use warnings;
      6 use v5.32;
      7 
      8 @ARGV = "input" unless @ARGV;
      9 chomp( my $input = do { local $/; <> } );
     10 
     11 my $part1 = 4;
     12 my $i = 0;
     13 
     14 while ( substr( $input, $i, $part1) =~ m/(.).*\1/ ) {
     15     $i++;
     16 }
     17 
     18 say "part 1: ", $i + $part1;
     19 
     20 my $part2 = 14;
     21 $i = 0;
     22 
     23 while ( substr( $input, $i, $part2) =~ m/(.).*\1/ ) {
     24     $i++;
     25 }
     26 
     27 say "part 2: ", $i + $part2;