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.
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":
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 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.
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": 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! 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.