]> www.fi.muni.cz Git - aoc.git/blob - 2016/28.pl
Day 25: examining the input
[aoc.git] / 2016 / 28.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use v5.30;
5
6 use Digest::MD5 qw(md5_hex);
7
8 my $salt = 'zpqevtbw';
9 # my $salt = 'abc';
10
11 my $i = -1001;
12 my $count = 0;
13 my %five;
14 while (1) {
15         ++$i;
16         my $j = $i+1000;
17         my $f = md5_hex($salt.$j);
18         $f = md5_hex($f) for 1 .. 2016;
19         $five{$1} = $j for $f =~ /(.)\1\1\1\1/g;
20         next if $i < 0;
21         my $h = md5_hex($salt,$i);
22         $h = md5_hex($h) for 1 .. 2016;
23         if ($h =~ /(.)\1\1/) {
24                 next if !$five{$1} || $five{$1} <= $i;
25                 say ++$count, " $i $1 in $h, also at $five{$1} ", md5_hex($salt.$five{$1});;
26                 exit 0 if $count >= 64;
27         }
28 }