Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This is a PHP riddle, the object of the game is to guess the correct answer
- * based on the code provided, WITHOUT looping through all the possible answers.
- * The code can be tricky to read, however is completely valid.
- *
- * As you decipher the code below, there will be various hints to help you
- * determine the answer. Example: the code may require an answer with a specific
- * number of caracters.
- *
- *
- *
- * RULES:
- * - You may run this through the PHP compiler up to 3 times before you are
- * "wrong"
- * - You may use an online luhn calculator, and php.net; but no other sites
- * - You may not add any valid code to this file (comments and whitespace
- * characters are welcome)
- * - HARDCORE MODE: Both the internet and localhost are off limits for anything
- * but confirming your answer
- * - HARDCORE MODE: You only get 2 tries to get it "right"
- */
- /**
- * 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 = 0; // 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)";
- }
Advertisement
Add Comment
Please, Sign In to add comment