]> www.fi.muni.cz Git - aoc.git/blob - 2016/27.pl
The rest of Year 2016
[aoc.git] / 2016 / 27.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         $five{$1} = $j for $f =~ /(.)\1\1\1\1/g;
19         next if $i < 0;
20         my $h = md5_hex($salt,$i);
21         if ($h =~ /(.)\1\1/) {
22                 next if !$five{$1} || $five{$1} <= $i;
23                 say ++$count, " $i $1 in $h, also at $five{$1} ", md5_hex($salt.$five{$1});;
24                 exit 0 if $count >= 64;
25         }
26 }