-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15b.php
47 lines (41 loc) · 1.06 KB
/
15b.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$input = <<<INPUT
INPUT;
$gen_a_seed = 703;
$gen_b_seed = 516;
// $gen_a_seed = 65;
// $gen_b_seed = 8921;
$gen_a_factor = 16807;
$gen_b_factor = 48271;
$mod = 2147483647;
$max = 5000000;
$pair_count = $total = 0;
$format = '(%1$2d = %1$032b) = (%2$2d = %2$032b)'
. ' %3$s (%4$2d = %4$032b)' . "\n";
while ($pair_count < $max) {
if ($pair_count % 1000 == 0) {
print "{$pair_count}\n";
}
if (!isset($gen_a_pair)) {
$gen_a_seed = ($gen_a_seed * $gen_a_factor) % $mod;
if ($gen_a_seed % 4 == 0) {
$gen_a_pair = $gen_a_seed;
}
}
if (!isset($gen_b_pair)) {
$gen_b_seed = ($gen_b_seed * $gen_b_factor) % $mod;
if ($gen_b_seed % 8 == 0) {
$gen_b_pair = $gen_b_seed;
}
}
// print "{$gen_a_seed} {$gen_b_seed}\n";
// If lowest 16 binary bits match on new seeds, increment total.
if (isset($gen_a_pair) && isset($gen_b_pair)) {
$pair_count++;
if (substr(decbin($gen_a_pair), -16) == substr(decbin($gen_b_pair), -16)) {
$total++;
}
unset($gen_a_pair, $gen_b_pair);
}
}
print "total = $total\n";