3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Riddle: Bit Play #1 * ------------------- * This riddle may move, add, remove, compair, and evaluate bit values. It is * suggested that you brush up on your binary and bitwise operators before * starting. */ $answer = 1; // put your answer here and run to check if you are right // The Setup function luhn($number) { settype($number, 'string'); $sumTable = array( array(0,1,2,3,4,5,6,7,8,9), array(0,2,4,6,8,1,3,5,7,9)); $sum = 0; $flip = 0; for ($i = strlen($number) - 1; $i >= 0; $i--) { $sum += $sumTable[$flip++ & 0x1][$number[$i]]; } return $sum % 10 === 0; } settype($answer, 'integer'); $s = (string) $a = &$answer; $ns = (string) $n = (isset($s[1])) ? ($a >> 1)+$s[1] : ($a >> 1)+$s[0]; $f = ((int) $ns[0] ^ (int) $s[1]); // The Riddle function riddle($a, $n, $s, $f, $ns) { if ( ($a != 0 && luhn($a)) && (!$f) && (($n | $a) == 63) && (!isset($s[2])) ) { return TRUE; } return FALSE; } // The Result if (riddle($a, $n, $s, $f, $ns)) { echo "You got the correct answer! ($a)"; } else { echo "Sorry, wrong answer. ($a)"; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Uninitialized string offset 1 in /in/c9Snn on line 29 Sorry, wrong answer. (1)
Output for 5.2.10 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Uninitialized string offset: 1 in /in/c9Snn on line 29 Sorry, wrong answer. (1)
Output for 7.3.32 - 7.3.33
Sorry, wrong answer. (1)
Output for 4.3.3 - 4.3.11, 4.4.0 - 4.4.9, 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.9
Notice: Uninitialized string offset: 1 in /in/c9Snn on line 29 Sorry, wrong answer. (1)
Output for 4.3.0 - 4.3.2, 5.0.0 - 5.0.1
Notice: Uninitialized string offset: 1 in /in/c9Snn on line 28 Notice: Uninitialized string offset: 1 in /in/c9Snn on line 29 Sorry, wrong answer. (1)

preferences:
375.89 ms | 402 KiB | 459 Q