Cheat at Rock-Paper-Scissors-Lizard-Spock(codegolf.stackexchange.com) |
Cheat at Rock-Paper-Scissors-Lizard-Spock(codegolf.stackexchange.com) |
&/"ki"?
It's incredible how seven little characters can pack so much power, but this level of cuteness also demands some explanation as to why it's correct (given the input domain).The first thing we might observe is that every input has two possible outputs, and the output domain is the same as the input domain. That means that if we select our outputs carefully, we may be able to find a property of the input that differentiates them.
q){x!x in/:\:k}distinct raze k:string`Rock`Spock`Paper`Lizard`Scissors
R| 10000b
o| 11001b
c| 11001b
k| 11000b
S| 01001b
p| 01100b
P| 00100b
a| 00110b
e| 00100b
r| 00111b
L| 00010b
i| 00011b
z| 00010b
d| 00010b
s| 00001b
We can see several options: "k" gets us Paper, "i" gets us Rock, "a" gets us Scissors, "p" gets us "Lizard". There are a few red herrings though: "S" doesn't get us any single output (Scissors and Spock don't have a shared winning response). The pairs I can see that differentiate all states are "ki", "ka", "ip". Let us use "ki": Roc<k> | Spock <Paper>
Spoc<k> |<Paper> Lizard
Paper | Lizard Scissors
L<i>zard | Scissors<Rock>
Sc<i>ssors|<Rock> Spock
The only remaining item we can choose (Lizard or Scissors), and if we choose the latter then our game can play traditional Rock-Paper-Scissors as well! `Paper`Rock`Scissors@&/"ki"?
Of course if you're not using q, you could use a different mapping function. Many of the responses looked at the lengths or a critical bit of a hash (like md5), all with the aims of producing this kind of compression function, and this isn't uncommon in high performance systems, but if you're going to depend on such a function, you should explain carefully how you came up with these magic characters so if someone wants to extend the game in the future they know how to reconstruct your function.(the missing condition is that every hand is beatable)
Paper: 5-letters (Mod4 == 1)
Spock: 5-letters (Mod4 == 1)
Lizard: 6-letters (Mod 4 == 2)
Scissors: 8-letters (Mod 4 == 0)
----------
There are no 3-letter or 7-letter words (aka: Blah % 4 != 3 given the inputs). So they just left the 3rd index (4th word) empty.
Each hand beats 2 distinct hands
With 3 distinct hands you can cover up to 6 distinct hands which is a superset of all possible hands
3 * 2 > 5
A --> D | E
B --> D | E
C --> D | E
D --> C | E
E --> D | C
QED A --> B | C
B --> C | D
C --> D | E
D --> E | A
E --> A | B