Skip to content

Instantly share code, notes, and snippets.

@HamsterofDeath
Created October 15, 2012 22:16
Show Gist options
  • Save HamsterofDeath/3895974 to your computer and use it in GitHub Desktop.
Save HamsterofDeath/3895974 to your computer and use it in GitHub Desktop.
zombies
package fromtheafricanwoman
import collection.immutable.BitSet
/**
* Developed with pleasure
* User: hamsterofdeath
* Date: 15.10.12
* Time: 22:29
*/
object Zombies {
def main(args: Array[String]) {
val x = 0
val y = 1
val z = 2
val all =
for (doorFlags <- 0 to Integer.parseInt("111", 2); zombieFlags <- 0 to Integer.valueOf("11111111", 2))
yield (doorFlags, zombieFlags)
val asBools = all.map(e => BitSet.fromBitMask(Array(e._1.toLong)) -> BitSet.fromBitMask(Array(e._2.toLong)))
val noParadox = asBools.filter({
case (apocalypseDoors, truthTellingZombies) => {
/*
[22:25:26] Riddle: 1: X is the door of apocalypse
[22:25:47 | Bearbeitet 22:25:53] Riddle: 2: At least, one of the doors Y or Z causes apocalypse
[22:26:07] Riddle: 3: 1 and 2 both say the truth
[22:26:25] Riddle: 4: X and Y are both apocalypse doors
[22:26:52] Riddle: 5: X and Z are both apocalypse doors
[22:27:19] Riddle: 6: 4 or 5 is a truth teller
[22:27:43] Riddle: 7: if 3 is a truth teller, then 6 too is one!
[22:28:05] Riddle: 8: if 7 and me say the truth, then 1 is a truth teller too.
*/
val condition1 = apocalypseDoors(x) && truthTellingZombies(0) || !apocalypseDoors(x) && !truthTellingZombies(0)
val condition2 = (apocalypseDoors(y) || apocalypseDoors(z)) && truthTellingZombies(1) ||
!(apocalypseDoors(y) || apocalypseDoors(z)) && !truthTellingZombies(1)
val condition3 = truthTellingZombies(0) && truthTellingZombies(1) && truthTellingZombies(2) ||
(!(truthTellingZombies(0) && truthTellingZombies(1)) && !truthTellingZombies(2))
val condition4 = (apocalypseDoors(x) && apocalypseDoors(y) && truthTellingZombies(3)) ||
(!(apocalypseDoors(x) && apocalypseDoors(y)) && !truthTellingZombies(3))
val condition5 = (apocalypseDoors(x) && apocalypseDoors(z) && truthTellingZombies(4)) ||
(!(apocalypseDoors(x) && apocalypseDoors(z)) && !truthTellingZombies(4))
val condition6 = (truthTellingZombies(3) || truthTellingZombies(4)) && truthTellingZombies(5) ||
(!(truthTellingZombies(3) || truthTellingZombies(4))) && !truthTellingZombies(5)
val condition7 =
if (truthTellingZombies(2)) (truthTellingZombies(5) && truthTellingZombies(6) || !truthTellingZombies(6))
else true
val condition8 = truthTellingZombies(6) && truthTellingZombies(7) && truthTellingZombies(0)
condition1 && condition2 && condition3 && condition4 && condition5 && condition6 && condition7 && condition8
}
})
val nice = noParadox.map(e => e._1.toList.map(_ + 'x').map(_.toChar) -> e._2.toList.map(_ + 1))
println(nice.map(e => e._1.mkString -> e._2.mkString).mkString("\n"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment