Advertisement
musifter

AoC 2022, day 6 (Perl)

Dec 5th, 2022
1,479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.32 KB | Source Code | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $input = <>;
  7.  
  8. my $part1;
  9. my $part2;
  10.  
  11. for (my $i = 0; !defined($part2); $i++) {
  12.     $part1 //= $i +  4 if (substr($input, $i,  4) !~ m#(\w).*\1#);
  13.     $part2 //= $i + 14 if (substr($input, $i, 14) !~ m#(\w).*\1#);
  14. }
  15.  
  16. print "Part 1: $part1\n";
  17. print "Part 2: $part2\n";
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement