3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php { // The n-th prime we're aiming for $n = 444; // The first prime is the only even one $primes = array(1 => 2); // Loop counters $c = 1; $p = 3; $cnt =0; while (true) { // Check if $p is prime $prime = true; $sqrt = sqrt($p); for ($i = 1; $i < $c && $primes[$i] <= $sqrt; $i++) { if ($p % $primes[$i] == 0) { $prime = false; break; } } // Record $p if prime if ($prime) { $primes[++$c] = $p; $hexchr = base_convert($p, 10, 16); if (strpos($hexchr,'beef') !== false) { $beefprime[++$cnt]=$p; echo "$p HEX IS $hexchr\n"; } if ($cnt == $n) { break; } } // Next $p to check $p += 2; } echo "444th prime number is $beefprime[$n]"; }
Output for 5.3.18 - 5.3.24, 5.3.26 - 5.4.7, 5.4.11, 5.4.19, 5.5.24 - 7.2.0
179951 HEX IS 2beef 507631 HEX IS 7beef 782071 HEX IS beef7 1162991 HEX IS 11beef
Process exited with code 137.
Output for 5.3.25, 5.4.8 - 5.4.10, 5.4.12 - 5.4.18, 5.4.20 - 5.4.45
179951 HEX IS 2beef 507631 HEX IS 7beef 782071 HEX IS beef7
Process exited with code 137.