]> www.fi.muni.cz Git - aoc.git/blob - 2016/10.pl
Day 25: examining the input
[aoc.git] / 2016 / 10.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 $id = 'ugkcyxxp';
9 my $pass = ' ' x 8;
10 my $i = 0;
11 while ($pass =~ /\s/) {
12         my $h = md5_hex($id.$i);
13         if ($h =~ /\A00000/) {
14                 my $pos = substr($h, 5, 1);
15                 if ($pos =~ /[0-7]/ && substr($pass, $pos, 1) eq ' ') {
16                         substr($pass, $pos, 1) = substr($h, 6, 1);
17                 }
18         }
19         $i++;
20 }
21
22 say $pass;
23