
Cheat at Rock-Paper-Scissors-Lizard-Spock - HeinZawHtet
https://codegolf.stackexchange.com/questions/195083/cheat-at-rock-paper-scissors-lizard-spock
======
geocar

        &/"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.

------
reaperducer
If nothing else, that was a very satisfying read because it shows the
incredible diversity of programming languages available today.

------
giancarlostoro
I am still wondering how the two Perl ones work with two missing words in the
code.

~~~
maxander
Since each hand beats two other hands, you only need three possible outputs to
beat any opposing hand.

~~~
avip
The conclusion does not follow...

(the missing condition is that every hand is beatable)

~~~
personjerry
There are 5 possible hands

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

~~~
avip
And yet...

    
    
      A --> D | E
      B --> D | E
      C --> D | E
      D --> C | E
      E --> D | C
    

QED

~~~
personjerry
Um, this isn't a general math problem; We're not solving for all possible
sets. We're solving this problem in particular:

    
    
      A --> B | C
      B --> C | D
      C --> D | E
      D --> E | A
      E --> A | B

------
tedunangst
Apparently you don't actually need to print "Rock or Spock" although it
sounded like that's a requirement.

