Created
June 16, 2017 19:11
-
-
Save skidvis/d5f9378806f1a276e524f2c4e83d2719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var guards = []; | |
guards.push(!true); //guard 0, always lies | |
guards.push(true); //guard 1, always true | |
var doors = []; | |
doors.push("certain doom"); //door 0, certain doom | |
doors.push("the castle"); //door 1, the castle | |
//Does door 0 lead to the castle? | |
var theTruth = (doors[0] == "the castle"); //false | |
//What would the guards say if asked directly? | |
var guard0Answer = (guards[0] == theTruth); //true (a lie!) | |
var guard1Answer = (guards[1] == theTruth); //false | |
//What would the guards say the other guard would say? | |
var guard0SaysGuard1WouldSay = (guards[0] == guard1Answer); //true (a lie!) | |
var guard1SaysGuard0WouldSay = (guards[1] == guard0Answer); //true (he lies!) | |
console.log("Does Door 0 lead to the castle? " + theTruth); | |
console.log("Guard 0, does Door 0 lead to the castle? " + guard0Answer); | |
console.log("Guard 1, does Door 0 lead to the castle? " + guard1Answer); | |
console.log("Guard 0, Would Guard 1 say that Door 0 leads to the castle? " + guard0SaysGuard1WouldSay); | |
console.log("Guard 1, Would Guard 0 say that Door 0 leads to the castle? " + guard1SaysGuard0WouldSay); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment