]> www.fi.muni.cz Git - aoc.git/blob - 2017/30.pl
Day 25: examining the input
[aoc.git] / 2017 / 30.pl
1 #!/usr/bin/perl
2
3 use v5.30;
4 use strict;
5
6 my @start = (883, 879);
7 # my @start = (65, 8921);
8 my @f = (16807, 48271);
9
10 sub gen {
11         my ($i,$gen) = @_;
12         do {
13                 $start[$i] = $start[$i] * $f[$i] % 2147483647
14         } while ($start[$i] % (1 << (2+$i)) != 0);
15         return $start[$i] & 0xFFFF;
16 }
17 my $matches = 0;
18 for (1 .. 5_000_000) {
19         $matches++ if gen(0, $_) == gen(1, $_);
20 }
21
22 say $matches;