PHP, 39 bytes
Shorter md5
variants by Christoph and Benoit Esnard.
<?=[Lizard,Spock,Rock][md5(y.$argn)%3];
Try it online!
<?=[Spock,Rock,Lizard][md5($argn.m)%7];
Try it online!
PHP, 40 bytes
<?=[Rock,Spock,Lizard][md5($argn)[5]%3];
Try it online!
Takes sixth character of md5 of input, which gives unique number of 1
for "Rock" and "Scissors", unique number of 2
for "Spock" and "Paper" and unique number of 9
for "Lizard". A mod 3 on those numbers and we have 0
or 1
or 2
indexes.
| Input | MD5 | 6th char | %3 | Output |
|----------|----------------------------------|----------|----|--------|
| Rock | 4cfbb125e9878528bab91d12421134d8 | 1 | 1 | Spock |
| Spock | 5769c28299713c949cd59d5469e40ace | 2 | 2 | Lizard |
| Paper | d0a662a5235ecde30739fe50cf0de830 | 2 | 2 | Lizard |
| Lizard | 2f7569e00c4d97aef5f2c2b3a4d2213f | 9 | 0 | Rock |
| Scissors | 28204140cee6e34a9843b64e5a490b08 | 1 | 1 | Spock |
PHP, 40 bytes
Alternative 40 bytes, port of Jo King's answer.
<?=[Spock,Lizard,Rock][strlen($argn)%4];
Try it online!
PHP, 41 bytes
This is based on 79037662's answer.
<?=[Lizard,Rock,Paper][ord($argn[-1])%3];
Try it online!
PHP (7.4), 42 bytes
Uses fifth and sixth characters of input to get one of 0, 1 or 2.
fn($s)=>[Rock,Lizard,Paper][!$s[5]+!$s[4]]
Try it online!
PHP, 43 bytes
Uses CRC32 of input and mod to get 0, 1 or 2.
<?=[Rock,Lizard,Paper][crc32($argn)%866%3];
Try it online!
PHP, 43 bytes
Uses second to the last character of input ("Rock" and "Spock" = "c", "Paper" = "e", "Lizard" and "Scissors" = "r").
<?=[c=>Paper,e=>Lizard,r=>Rock][$argn[-2]];
Try it online!
14It's a pity that the two hands that start with
S
have no outputs in common... – Jo King – 2019-10-31T00:38:44.067How about leading or trailing whitespace? – Bubbler – 2019-10-31T05:56:23.847
@Bubbler Nope, sorry. – xnor – 2019-10-31T06:00:15.113
@JoKing Hardly! Necessity is the mother of invention, and your solution is pretty clever. – jpaugh – 2019-10-31T15:54:59.163
V
for "Vulcan" would fix the overloadedS
! – pkamb – 2019-10-31T18:20:25.1602@JoKing: The second letters of the possible inputs are distinct, though. Possibly useful. – dan04 – 2019-11-01T16:45:36.943
@JoKing The two hands that end in <code>k</code> do, though. – Please stop being evil – 2019-11-02T18:15:08.207