]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/27.pl
The rest of Year 2016
[aoc.git] / 2016 / 27.pl
diff --git a/2016/27.pl b/2016/27.pl
new file mode 100755 (executable)
index 0000000..1238c82
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+use Digest::MD5 qw(md5_hex);
+
+my $salt = 'zpqevtbw';
+# my $salt = 'abc';
+
+my $i = -1001;
+my $count = 0;
+my %five;
+while (1) {
+       ++$i;
+       my $j = $i+1000;
+       my $f = md5_hex($salt.$j);
+       $five{$1} = $j for $f =~ /(.)\1\1\1\1/g;
+       next if $i < 0;
+       my $h = md5_hex($salt,$i);
+       if ($h =~ /(.)\1\1/) {
+               next if !$five{$1} || $five{$1} <= $i;
+               say ++$count, " $i $1 in $h, also at $five{$1} ", md5_hex($salt.$five{$1});;
+               exit 0 if $count >= 64;
+       }
+}