[Question]
  [
Implement the classic rock paper scissors.
Conditions:
* user will input 'r', 'p' or 's'
* program will output 'r', 'p' or 's' and the result
* program choice ('r', 'p' or 's') has to be pseudo random (**I'm looking at you Howard**)
* result can be represented with any printable character, there should always be three possible results for what the user has input (the user wins, lose or is a tie).
* what happens if the user inputs nothing, or something different that 'r', 'p' or 's' should be not important.
You need to:
* Provide the golfed code.
* The ungolfed code
* How do you invoke the program
* A sample run
**I will choose the answer with less characters, if a tie presents the most up voted answer will be chosen.**
Good golfing and may luck be ever in your favor.
I will be posting an answer my self, in Java.
For the ones that live in a mountain under a rock:
> 
> r = rock
> 
> 
> p = paper
> 
> 
> s = scissors
> 
> 
> rock: wins to scissors, loses with paper, a tie with rock.
> 
> 
> paper: wins to rock, loses with scissors, a tie with paper.
> 
> 
> scissors: wins to paper, loses with rock, a tie with scissors.
> 
> 
> 
Current Positions:
* UN: Username
* PL: Programming Language
* CC: Character Count
* UV: Up votes
> 
> 
> ```
> ╔══════════════════╦════════════╦══════╦════╗
> ║        UN        ║     PL     ║  CC  ║ UV ║
> ╠══════════════════╬════════════╬══════╬════╣
> ║ Howard           ║ GolfScript ║    6 ║ 15 ║
> ║ primo            ║ Perl       ║   27 ║  7 ║
> ║ TwiNight         ║ APL        ║   31 ║  4 ║
> ║ primo            ║ Perl       ║   33 ║  7 ║
> ║ marinus          ║ APL        ║   36 ║  5 ║
> ║ primo            ║ Perl       ║   38 ║  7 ║
> ║ primo            ║ Perl       ║   48 ║  7 ║
> ║ yehuda-schwartz  ║ javascript ║   49 ║  1 ║
> ║ manatwork        ║ Ruby       ║   54 ║ 13 ║
> ║ w0lf             ║ GolfScript ║   62 ║  4 ║
> ║ tmartin          ║ K          ║   67 ║  2 ║
> ║ Abhijit          ║ Python 3   ║   74 ║  5 ║
> ║ beary605         ║ Python 3   ║   76 ║  4 ║
> ║ rlemon           ║ javascript ║   85 ║  4 ║
> ║ ugoren           ║ C          ║   86 ║  3 ║
> ║ Egor Skriptunoff ║ LUA        ║   87 ║  4 ║
> ║ Fors             ║ Befunge    ║  107 ║  3 ║
> ║ Vi.              ║ Clojure    ║  129 ║  1 ║
> ║ Henrik           ║ C#         ║  167 ║  4 ║
> ║ dystroy          ║ Go         ║  169 ║  1 ║
> ║ primo            ║ ferNANDo   ║  259 ║  5 ║
> ║ anakata          ║ Java       ║  259 ║  1 ║
> ║ epoch            ║ Java       ║  387 ║  1 ║
> ║ jdstankosky      ║ LOLCODE    ║ 1397 ║ 15 ║
> ╚══════════════════╩════════════╩══════╩════╝
> 
> ```
> 
> 
I can't select Howards answer, since it was a (successful) attempt to bend the rules, but I change them, to make them extra explicit.
primo 27 character answer can't be selected because it's not pseudo random per se
primo -p answer, I'm gonna go with "-p would be counted as 3 bytes: one for the -, one for the p, and one more the necessary whitespace."
**Thanks to all who answered, I hope you have had a good time!**
***NOTE: I will be trying to edit this every other week, to adjust the table, and change my selected answer if someone beats the current one, so If you just got here, post your answer if you want!***
  
[Answer]
# LOLCODE, 1397
***Note:** I submitted this before I noticed the winning requirement was changed from popularity with golf tie-break to golf with popularity tie-break.*
There's not really any strict syntax, but I'm sure this is acceptable.
```
HAI
    I HAS A CRAZY, LUCKY, CHALLENGE, TREAT
    I HAS YUMMY ITZ "LOL U LOZED"
    I HAS MEH ITZ "NOWAI TIED"
    I HAS GROSS ITZ "OMG U WONNED"
    I HAS BURNT ITZ "LAME"
    GIMMEH CHALLENGE
    BTW I HOPE I R TEH WINZ
    LOL CRAZY IZ BETWEEN 1 AN 3
    I HAS A SUPA ITZ A BUKKIT
    LOL SUPA'Z 1 R "ROCK"
    LOL SUPA'Z 2 R "PAPER"
    LOL SUPA'Z 3 R "SCIZZORS"
    LOL LUCKY R SUPA'Z CRAZY
    GOT CHALLENGE, WTF?
        OMG "Rock"
            GOT LUCKY, WTF?
                OMG ROCK, LOL TREAT R MEH, GTFO
                OMG PAPER, LOL TREAT R YUMMY, GTFO
                OMG SCIZZORS, LOL TREAT R GROSS, GTFO
            OIC
        OMG "Paper"
            GOT LUCKY, WTF?
                OMG ROCK, LOL TREAT R GROSS, GTFO
                OMG PAPER, LOL TREAT R MEH, GTFO
                OMG SCIZZORS, LOL TREAT R YUMMY, GTFO
            OIC
        OMG "Scissors"
            GOT LUCKY, WTF?
                OMG ROCK, LOL TREAT R YUMMY, GTFO
                OMG PAPER, LOL TREAT R GROSS, GTFO
                OMG SCIZZORS, LOL TREAT R MEH, GTFO
            OIC
        OMGWTF
            VISIBLE "WHAT U SAYZ?", LOL TREAT R BURNT
            GTFO
    OIC
        BOTH SAEM TREAT AN BURNT, O RLY?
            YARLY
                VISIBLE "YOU BURNTED MAH TREAT!"
            NOWAI
                VISIBLE SMOOSH "I GUESSED " AN LUCKY
                VISIBLE TREAT
        KTHX
KTHXBAI
```
If this were to be successfully executed as `RockPaperScissors.LOL`, here's what some possible random outcomes could be:
* Input: `Rock` - Output: `I GUESSED SCIZZORS U WONNED`
* Input: `Paper` - Output: `I GUESSED PAPER NOWAI TIED`
* Input: `Scissors` - Output: `I GUESSED ROCK LOL U LOZED`
* Input: `Tuna` - Output: `WHAT U SAYZ? YOU BURNTED MAH TREAT!`
[Answer]
### GolfScript
```
n"Draw"
```
Above code implements the required functionality. Additionally, it ensures that the player will never be left angry because of a (perceived) unfairness of computer's strategy.
**Ungolfed version**
```
n"Draw"
```
**How to invoke the program**
The input (a single character of 'r', 'p', 's') has to be provided on STDIN, possibly terminated with newline.
**A sample run**
```
> echo r | ruby golfscript.rb rockpaperscissors.gsc
r
Draw
```
**Explanation of the code**
For all those not familiar with GolfScript I'll add an detailed explanation of how this code works. The code essentially exists of three parts.
```
### Computer's strategy ###
# The strategy used to play r/p/s. 
# The computer is so fast, it can really guess in an instance 
# what the player has played. Since the computer should 
# not play unfair, the best strategy is to always go for a 
# draw and choose the same move.
        # on the stack is player's move
        # choose to play the same -> now the computer's move is on the stack
### Fiddle with input ###
# The input may of may not be delimited by newline.
# In order to make the output readable, we'll give
# a newline here.
n       # Push a newline onto the stack
### Give the result ###
# We can skip a complicated calculation of the result
# since we chose to play draw anyways.
"Draw"  # Push the result onto the stack
# Output is printed automatically when GolfScript code terminates.
```
**Notes**
Since this is not code-golf but popularity contest I didn't choose the shortest version. Maybe in case of a tie a shorter code will knock out my solution. Nevertheless, for those interested in golfing, the following possibilities are given:
* Deal only with proper input and force user to provide a newline. This will save one character.
* The rules have a small insufficiency which allows to save another character by bending the rules. The result can always be printed as "Win" - it was not specified that the correct result has to be printed. But note that players will soon get angry if you choose to implement a cheating program.
* The output format is not well specified. We can choose `0` as output for draw. Thus, the shortest valid program is the single-character code `0`.
[Answer]
# Ruby: ~~61~~ 54 characters
```
o="rps";p o[c=rand(3)],%w{Draw Win Lose}[c.-o.index$_]
```
Somehow explained:
The entire problem is reduced to calculating the following results:
```
  ╲ machine
h  ╲| 0 1 2
u ──┼──────
m 0 │ 0 1 2 
a 1 │ 2 0 1
n 2 │ 1 2 0
```
Where the numbers mean:
* choice: 0 rock, 1 paper, 2 scissor
* result: 0 draw, 1 win, 2 lose
For this I used the formula: machine\_choice - human\_choice. This occasionally results negative value, but as it is only used as index and negative index is counted backward, will pick the correct array element.
```
# ┌── choosable object type
# │           ┌── machine's choice numeric code
# │           │                  ┌── result type
# │           │                  │                   ┌── human's choice
# │           │          ┌───────┴───────┐           │
  o="rps";p o[c=rand(3)],%w{Draw Win Lose}[c.-o.index$_]
#           └─────┬────┘                   └─────┬────┘  
#                 └── machine's choice letter    │
#                                                └── result numeric code
```
Used methods (others then `Fixnum`'s obvious ones):
* [Kernel.p(obj) → obj](http://ruby-doc.org/core-2.0/Kernel.html#method-i-p) – “For each object, directly writes *obj*.`inspect` followed by a newline to the program’s standard output.”
* [Kernel.rand(max=0) → number](http://ruby-doc.org/core-2.0/Kernel.html#method-i-rand) – “If called without an argument, or if `max.to_i.abs == 0`, rand returns a pseudo-random floating point number between 0.0 and 1.0, including 0.0 and excluding 1.0.”
* [String.index(substring [, offset]) → fixnum or nil](http://ruby-doc.org/core-2.0/String.html#method-i-index) – “Returns the index of the first occurrence of the given *substring* or *pattern* (regexp) in *str*.”
Ungolfed:
```
object_type = "rps";
result_type = %w{Draw Win Lose}
machine_choice = rand(3)
human_choice = $_
p object_type[machine_choice]
result_code = machine_choice - object_type.index(human_choice)
p result_type[result_code]
```
Sample run:
```
bash-4.2$ ruby -nle 'o="rps";p o[c=rand(3)],%w{Draw Win Lose}[c.-o.index$_]'
r
"p"
"Win"
p
"p"
"Draw"
s
"p"
"Lose"
```
[Answer]
## APL, 31
```
'TWL'[1+3|-/x⍳⎕←⍞,(?3)⌷x←'rps']
```
`x←'rps'` Assign string `'rps'` to `x`
`(?3)⌷` Choose random integer 1~3, choose that index of `x`
`⍞,` Prepend user input to machine choice
`⎕←` Output resulting string
`x⍳` Convert to numerical array by indexOf in `x`
`-/` Difference of the two numbers
`1+|3` Modulus 3 and plus 1
`'TWL'[...]` indexing from `'TWL'`
**Sample**
```
r
rp
L
```
User choose rock, program choose paper: Lose
[Answer]
## C# (167 characters)
My very first try at golfing.
**Golfed**
`using System;class P{static void Main(string[] i){var m="rspr";var a=m[Environment.TickCount%3];Console.WriteLine(a+" "+(i[0][0]==a?"T":m.Contains(i[0]+a)?"W":"L"));}}`
**Un-golfed**
```
using System;
class P
{
    static void Main(string[] i)
    {
        var m = "rspr";
        var a = m[Environment.TickCount % 3];
        Console.WriteLine(a + " " + (i[0][0] == a ? "T" : m.Contains(i[0] + a) ? "W" : "L"));
    }
}
```
**Sample Run**
The app requires single char inputs as argument 1 to the application, either `r`, `s` or `p`.
```
cmd > app.exe r
```
**All possible outcomes**
* `cmd > app.exe r` gives output `r T` (rock, tie)
* `cmd > app.exe r` gives output `p L` (paper, lost)
* `cmd > app.exe r` gives output `s W` (scissors, win)
* `cmd > app.exe p` gives output `r W` (rock, win)
* `cmd > app.exe p` gives output `p T` (paper, tie)
* `cmd > app.exe p` gives output `s L` (scissors, lost)
* `cmd > app.exe s` gives output `r L` (rock, lost)
* `cmd > app.exe s` gives output `p W` (paper, win)
* `cmd > app.exe s` gives output `s T` (scissors, tie)
[Answer]
## Perl 48 bytes
```
$%=rand 3;print"$%
"^B,(Draw,Lose,Win)[$%-=<>^B]
```
The script prints the result from the computer's perspective, for example if the player chooses `r` and the computer chooses `s`, the result is `Lose`. `$%` (format page number) is used to store the computer's move, as it may only contain an integer value, which saves an int cast.
Ungolfed:
```
# choose a random move index 0, 1, or 2
$cindex = int(rand 3);
# convert this index to a move
# 0 => r, 1 => s, 2 => p
$cmove = "$cindex" ^ B;
# read the player's move
$pmove = <>;
# convert this move to its index
$pindex = $pmove ^ B;
# print computer's move
print $cmove, $/;
# compare indices, and output result
@result = (Draw, Lose, Win);
print $result[$cindex - $pindex];
```
Sample usage:
```
$ echo p | perl rps.pl
s
Win
$ echo r | perl rps.pl
r
Draw
$ echo s | perl rps.pl
p
Lose
```
The script may also be run interactively, by typing your move followed by `Enter`:
```
$ perl rps.pl
r
s
Lose
```
---
## Rule Stretching
### Perl 35 +3 bytes
```
$_=($%=rand 3).(D,L,W)[$%-($_^B)]^B
```
Requires the `-p` command line switch (counted as 3 bytes). Each of the outcomes `Win`, `Lose` and `Draw` have been mapped to `W`, `L`, `D`. The newline between the computer's choice and the result has been excluded.
Sample usage:
```
$ echo r | perl -p rps.pl
sL
```
---
### Perl 30 +3 bytes
```
$_=($%=rand 3).($%-($_^B))%3^B
```
Once again requires `-p`. Here `Win`, `Lose` and `Draw` have been mapped to `2`, `1` and `0` respectively. This is still technically compliant, as they are printable characters.
Sample usage:
```
$ echo r | perl -p rps.pl
s1
```
---
### Perl 24 +3 bytes
```
$_=$^T%3 .($^T-($_^B))%3^B
```
Requires `-p`, WLD mapped to `2`, `1`, `0` as before. Each `^T` should be replaced with a literal ascii character 20. This one is admittedly a bit of a stretch; `$^T` returns the number of seconds since epoch from when the script was started. All outcomes are possible, but it doesn't quite qualify as pseudo-random.
Sample usage:
```
$ echo r | perl -p rps.pl
s1
```
[Answer]
## APL (~~38~~ 36)
```
c[i],(⌽↑⌽∘'TWL'¨⍳3)[⍞⍳⍨c←'rps';i←?3]
```
Outputs 'T', 'W' and 'L' for tie, win and lose.
Sample run:
```
      c[i],(⌽↑⌽∘'TWL'¨⍳3)[⍞⍳⍨c←'rps';i←?3]
p    
rW
```
(User types 'p' for paper. Computer chooses 'r' (rock), user wins)
Explanation:
* `⌽↑⌽∘'TWL'¨⍳3`: generates the following matrix:
```
TLW
WTL
LWT
```
* `⍞⍳⍨c←'rps'`: set `c` to the string `'rps'`, read user input and get the index of the user input in the string (this will be a value from 1 to 3). This index is used as the Y coordinate into the matrix.
* `i←?3`: get a random number from 1 to 3 and store it in `i`, this is the computer's choice. This is used as the X coordinate into the matrix.
* `c[i]`: use `i` as an index into `c`, displaying the computer's choice as 'r', 'p', or 's'.
[Answer]
## [ferNANDo](http://esolangs.org/wiki/FerNANDo) 1184 (259 golfed) bytes
*An interpreter written in Python can be found at the bottom of the linked page.*
ferNANDo is a esoteric language which supports only one variable type, boolean, and only one operation, NAND. As you might imagine, this can lead to some fairly long logic to accomplish seemingly simple tasks. It has support for reading from stdin (one byte at a time), writing to stdout (also one byte at a time), conditional loops, and also a random boolean generator.
There are no keywords whatsoever; everything is a variable. A statement's function is determined solely by the number of variables it contains. There are also no comments, so I've done my best to make the code self-commenting. The last four lines might be a bit confusing, but it will probably suffice to say that it prints `Win!`, `Lose`, or `Draw` depending on the outcome.
```
not sure, but right now i'm guessing you're_not_paper you're_scissors
you're_paper not you're_not_paper
you're_not_scissors not you're_scissors
you're_rock you're_not_paper you're_not_scissors
you're_rock you're_rock
o_shi-
i'm_not_paper right ?
i'm_scissors right ?
i'm_paper not i'm_not_paper
i'm_not_scissors not i'm_scissors
o_shi- i'm_paper i'm_scissors
o_shi- o_shi-
o_shi-
i'm_rock i'm_not_paper i'm_not_scissors
i'm_rock i'm_rock
print right now but only if i'm_not_paper i'm_scissors
print a newline here, not more, not less
i_win_if i'm_scissors you're_paper
or_if i'm_rock you're_scissors
or_even_if i'm_paper you're_rock
i_win i_win_if or_if
i_win i_win
i_win or_even_if
i_lose_if i'm_paper you're_scissors
or_if i'm_scissors you're_rock
or_even_if i'm_rock you're_paper
i_lose i_lose_if or_if
i_lose i_lose
i_lose or_even_if
i_don't_win not i_win
i_don't_lose not i_lose
we_tie i_don't_win i_don't_lose
we_tie we_tie
we_don't_tie not we_tie
print now if i_win i_lose not i_win i_win
print but not we_tie we_don't_tie i_lose i_don't_win we_don't_tie
print right now i_lose i_win i_win we_don't_tie i_don't_win
print i_don't_win but we_tie or i_don't_win we_tie now
```
The script can be run interactively, by typing your move followed by `Enter`.
Sample usage (assuming you've named the interpreter `nand.py`):
```
$ python nand.py rps.nand
p
s
Win!
$ python nand.py rps.nand
r
r
Draw
$ python nand.py rps.nand
s
p
Lose
```
---
**Edit:** Just to prove that ferNANDo can compete with Java, here's a 'golfed' version at **259 bytes**. The logic is sightly different; it checks `not win` and `not tie`, which saves a few NAND gates (because then I only need the `not` versions of the player's moves, and because `not lose` wasn't required for the output). Not nearly as interesting to read, though.
```
1 _ _ _ _ _ _ A b
B 1 b
C A B
o
P 1 ?
s 1 ?
p 1 P
S 1 s
o p s
o o
o
r P S
r r
0 1 1 1 0 0 P s
0 0 0 0 1 0 1 0
t s A
u r B
v p C
W t u
W W
W v
t p A
u s B
v r C
D t u
D D
D v
w 1 W
d 1 D
l W D
l l
0 1 0 w l 1 w w
0 1 1 d D l W D
0 1 1 l w w D W
0 W 1 d 0 W d 1
```
[Answer]
# [Python 3](https://docs.python.org/3/), 55 bytes
```
q={*'rps'}.pop()
print(q,'rrppssrpsr'.count(q+input()))
```
[Try it online!](https://tio.run/##FYyxDsIgGAZ3noKwAGq6uJF0rKuLL6D4JyUa@PsBsY3x2ZGud7njrcwpnptPTxqVUm0ZvwcNzvo3cGJjBSPEYpaTBphz7gp68Knu8Bgi12Ksta234jOHN8kbKjkhZcHmJK3kzT63ndDqiYucrpcJSHDyAbq/GgSL/Ac "Python 3 – Try It Online")
With the [release of Python 3.3](https://www.python.org/downloads/release/python-330/) came default hash randomization. As such, we can use the `set.pop` method to get a random character from the string `'rps'`.
The program appends the input character to the randomly generated character and counts how often the combination appears in the string `'rrppssrpsr'`.
Outputs `0` for program win, `1` for tie and `2` for player win.
[Answer]
**Python 3.x: 74 Characters**
```
import time
A,f="psr",time.gmtime()[5]%3
print(A[(A.find(input())+f)%3],f)
```
How it works
```
Before Machine Proceeds it determines the outcome of the game and based 
on the outcome, it determines the choice which would result in the outcome
viz Human's choice
\     Outcome
 \    0  1  2
  \_____________
H  | 
U 0|  0  1  2
M 1|  1  2  0
A 2|  2  0  1
N  |
Where Choices are represented as 
0 --> Paper
1 --> Scissor
2 --> Rock
Outcome (From Computer's Perspective)
0 --> Draw
1 --> Win
2 --> Fail
Given the sequence of choices as a string
"psr"
So its easy to see, if computer needs to win, it needs to choose the character
next to what human chooses. 
If computer needs to loose, it needs to choose the previous character to what
human chooses
MACHINE's|      CHOICES    |  Formulation
FATE     |-----------------|  For Machine's
         |  P     S      R |  Choice
---------|-----------------|-----------------------------
WIN(1)   |        H ---> M | (CHOICE+1) % 3 = (CHOICE+WIN)%3 
---------|-----------------|-----------------------------
LOSS(2)  |  M     H -----\ | (CHOICE+2)%3   = (CHOICE+LOSS)%3 
         |  ^            | |
         |  |____________| |
---------|-----------------|------------------------------       
DRAW(0)  |        H        | (CHOICE+0)%3   = (CHOICE+DRAW)%3
         |        M        |  
---------|-----------------|         
Combining all the above we have
MACHINE's CHOICE = (HUMAN CHOICE + MACHINE's FATE) % 3
```
Based on the fate, it determines what should it's choice be based on the formula
```
result = (User_choice + machines_fate) % no_of_choices
machine_choice = "psr"[result]
```
Un-golfed Version
```
import time
choices = "psr"
#time.gmtime() returns the time structure in gmt
#time.gmtime()[5] is the current second tick
fate = time.gmtime()[5]%3
user_choice = input()
result = (choices.find(user_choice)+fate)%len(choices)
machine_choice = choices[result]
print(machine_choice, fate)
```
Sample run
```
D:\temp\rivalry>rps.py
r
r 0
D:\temp\rivalry>rps.py
r
p 1
D:\temp\rivalry>rps.py
p
r 2
D:\temp\rivalry>rps.py
p
r 2
D:\temp\rivalry>rps.py
p
s 1
D:\temp\rivalry>rps.py
p
s 1
D:\temp\rivalry>rps.py
p
p 0
```
[Answer]
## Lua, 87
```
c,n=os.time()%3+1,'rps'print(n:sub(c,c),({'Draw','Win','Defeat'})[(n:find(...)-c)%3+1])
```
Usage: 
```
$ lua rps.lua p
s   Defeat
```
Ungolfed: 
```
names = 'rps'
comp_idx = os.time()%3 + 1                -- 1, 2 or 3 (depends on timer)
comp_move = names:sub(comp_idx, comp_idx) -- 'r', 'p' or 's'
user_move = ...                           -- input parameter: 'r', 'p' or 's'
user_idx = names:find(user_move)          -- 1, 2 or 3
delta_idx = (user_idx - comp_idx) % 3     -- 0, 1 or 2
all_results = {'Draw', 'Win', 'Defeat'}   -- [1]=='Draw', [2]=='Win', [3]=='Defeat'
game_result = all_results[delta_idx + 1]
print(comp_move, game_result)
```
[Answer]
## GolfScript 62
An alternative GolfScript solution, much more boring than [Howard's](https://codegolf.stackexchange.com/a/11193/3527) :).
The program chooses a move randomly and displays the result from the perspective of the user.
### The Code
```
'rssppr'.[6rand=]''+:§@+..&,({?)§\'Lose''Win'if}{;;§'Draw'}if`
```
### Sample run
> 
> > echo s | ruby golfscript.rb rps.gs
> 
> 
> r"Lose"
> 
> 
> 
### Online test
You can run the program and experiment with different inputs here: <http://golfscript.apphb.com/?c=OydzJwoKJ3Jzc3BwcicuWzZyYW5kPV0nJys6wqdAKy4uJiwoez8pwqdcJ0xvc2UnJ1dpbidpZn17OzvCpydEcmF3J31pZmA%3D>
Note, however, that the parameter (user move) that's usually passed in the command line is now added to the stack in the code itself (there's no way to provide "real" command line parameters in this online tool).
### "Ungolfed" version
I don't have any idea what *ungolfed* means when it comes to GolfScript, so I tried to add comments. Hopefully that will clarify how the code works and make it a bit more readable:
```
# initially, the input (user's move) is on the stack
'rssppr'                # push the string 'rsspr' on the stack...
.                       # ...twice.
[
    6rand               # get a pseudo-random integer in the [0-5] range
    =                   # use the random index to get 
                        # a letter from the string above
]''+                    # workaroud to get the actual letter instead of the
                        # ASCII code
:§                      # assign the randomly chosen letter (computer's move)
                        # to a nice variable called "§"
@                       # rotates last 3 elements on the stack, bringing
                        # the user input in the uppermost position
                        # So, now we have: "rssppr" <computer_move> <user_move>
                        # on the stack
+                       # concatenate the two moves, so now we have a string
                        # that contains both (ex: "rs")
..                      # copy the move string twice
&                       # do a setwise AND to get the DISTINCT elements
,(                      # get the length of the resulting string and subtract 1
                        # (now we have 0 if the letters were equal and non-zero otherwise)
{                       # beginning of block to execute when the moves are different:
                        # now we have on the stack two strings:
                        #     - the string 'rssppr'
                        #     - the string containing the moves (ex: 'rs')
    ?                   # find the second string inside the first one,
                        # and get the index at which it occurs
                        # (or -1 if it does not)
    )                   # increment that number (we now get 0 if no occurrence, 1 otherwise)
    §                   # recall the § variable (so we display the computermove)
    \                   # rotate the uppermost two stack entries
    'Lose''Win'if       # if the move pair is found in the 'rssppr' string, 
                        # then print 'Lose', otherwise print 'Win'
}
{                       # beginning of block to execute when the moves are identical:
    ;;                  # discard the latest two stack items (not needed in this case)
    §                   # display computer's move
    'Draw'              # display the text 'Draw'
}
if                      # if computer's and user's moves were NOT equal, 
                        # execute the first block.
                        # if they were, execute the second block
`                       # put the last word in quotes to separate it from computer's move
```
[Answer]
## C, 92 86 chars
```
main(y){
    srand(time(0));
    y="rps"[rand()%3];
    printf("%c%c\n",y,"LWWTLLW"[getchar()-y+3]);
}
```
Prints the computer's choice, and the result from the user's point of view - W=you win, L=you lose, T=tie.  
The simple formula `x-y`, given the ASCII values of the choices, gives 0 on draw (obviously) and a unique value in each other case.
[Answer]
## Python 2 (~~86~~ ~~84~~ ~~80~~ 78), Python 3 - 76 chars
0 - tie, 1 - lose, 2 - win
```
from random import*
a=raw_input()
b=choice('psr')
print(a!=b)+(b+a in'rpsr'),b
from random import*
a=input()
b=choice('psr')
print((a!=b)+(b+a in'rpsr'),b)
```
Ungolfed
```
from random import*
moves = 'psr'
inp   = raw_input()
comp  = choice(moves)
match = comp+inp
is_not_tie = inp!=comp
wins = 'r' + moves         #rpsr; rock beats scissors, scissors beats paper, paper beats rock
print is_not_tie + (match in wins), comp
```
How to run:
`python file_name_here.py`
Problems:   
Computer AI: 35 characters
[Answer]
First try without reviewing others. 
golfed: 107 85 bytes
```
i=prompt(),c="rps"[new Date%3],w={r:"s",p:"r",s:"p"};alert(c+(i==w[c]?2:w[i]==c?1:3))
```
output is [npc-choice][1:win, 2:loss, 3:tie]
ungolfed:
```
var input = prompt(),
    choices = ["r","p","s"],
    computer_choice = choices[Math.floor(Math.random() * 3)],
    outcomes = {'r':'s','p':'r','s':'p'},
    winner;
    if( input == outcomes[computer_choice] ) {
        winner = 'NPC';
    } else if ( computer_choice == outcomes[input] ) {
        winner = 'You';
    } else {
        winner = 'No one, it was a Tie!';
    }
    alert('Computer chose: ' + computer_choice + '\n' +
          'The winner is: ' + winner);
```
[Answer]
## PowerShell: 144 133 117 111 92 73
> 
> **Changes from original:**
> 
> 
> * Completely re-wrote script after seeing [Danko Durbic's three-player even or odd solution](https://codegolf.stackexchange.com/a/15550/9387).
> * Changed $s to a single string instead of a character array.
> * Used IndexOf as a direct method on $s, instead of spelling out the .NET class & method.
> * Removed redundant `%3`s.
> 
> 
> All told, nearly cut the length in half from my original answer!
> 
> 
> 
**Golfed code:**
```
$p=($s='rps').IndexOf((read-host));$s[($c=Random 3)];"TWLLTWWLT"[$p+$c*3]
```
Can be run straight from the console.
**Ungolfed, with comments:**
```
# Variable $p will store the player's selection as a ternary digit by finding its position in a string containing the possible choices.
$p=(
    # Possible choices will be stored in a variable, $s, for later reuse.
    $s='rps'
# Get the position of the player's choice from $s.
).IndexOf((read-host));
# Express the computer's choice by outputting the appropriate character from $s.
$s[(
    # Computer's choice will be stored as a ternary digit in $c.
    $c=Random 3
)];
# Outcome for the player will be chosen from a string of possible outcomes by looking up the decimal repesentation of a two-digit ternary number.
# The threes digit is represented by $c, ones digit by $p.
"TWLLTWWLT"[$p+$c*3]
# Variable cleanup - do not include in golfed code.
rv p,s,c
```
Some sample runs at the console:
![enter image description here](https://i.stack.imgur.com/CwDVC.jpg)
[Answer]
**JAVA 259 :(**
```
class c {public static void main(String[]a){char y=a[0].charAt(0);char m="rps".charAt(new java.util.Random().nextInt(3));if(y==m)a[0]="T";else if((y=='r'&& m=='s')||(y=='s'&& m=='p')||(y=='p'&& m=='r'))a[0]="1";else a[0]="0";System.out.println(m+":"+a[0]);}}
```
Highly ungolfed code:
```
class c {
    public static void main(String[] a) {
        char y = a[0].charAt(0);
        char m = "rps".charAt(new java.util.Random().nextInt(3));
        if (y == m) {
            a[0] = "T";
        } else if ((y == 'r' && m == 's') || (y == 's' && m == 'p') || (y == 'p' && m == 'r')) {
            a[0] = "1";
        } else {
            a[0] = "0";
        }
        System.out.println(m + ":" + a[0]);
    }
}
```
Sample runs:
> 
> C:>java c r
> 
> 
> s:1
> 
> 
> C:>java c p
> 
> 
> p:T
> 
> 
> C:>java c s
> 
> 
> s:T
> 
> 
> 
[Answer]
# Befunge: 107 characters
```
~v@,"w"<   <   <  <
v?v3.14159265@,"l"<
"""358979323846>3-|
rps26433832>:1+|
"""7950>:2+|
>>>:,-:|
28@,"t"<
```
Slightly clunky. It is shrinkable, the question is by how much.
[Answer]
## JavaScript (87)
Golfed:
```
o='LDW'[2*((a=prompt())+(b='prs'[new Date%3])!='ps'&a<b|a+b=='sp')+ +(a==b)];alert(b+o)
```
Ungolfed:
```
var player = prompt(), 
    computer = 'prs'[new Date%3], // Date mod 3 "pseudo-random"
    outcome = 'LDW'[2*(player+computer != 'ps' 
                    & player < computer 
                    | player + computer == 'sp') // convert boolean W/L outcome to int (0,2)
              +
              +(player == computer)]; // convert D outcome to int (0,1)
alert(computer + outcome);
```
You can simply paste the code in your browser's javascript console to run it.
If I'm allowed to print the result before printing the computer's selection **(83)**:
```
alert('LDW'[2*((a=prompt())+(b='prs'[new Date%3])!='ps'&a<b|a+b=='sp')+ +(a==b)]+b)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
```
“rps”ɓ3XṄ+i@ị
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw5yiguJHDXNPTjaOeLizRTvT4eHu7v@H24FslUdNa/7/LyoqKigoKC4uBgA "Jelly – Try It Online")
Decides and prints the outcome (3 for a tie, 2 for a win, 1 for a loss) *before* determining its own move, so the validity might be somewhat dubious.
```
“rps”            Set the left argument to "rps",
     ɓ           then start a dyadic link with reversed arguments:
      3X         choose 1, 2, or 3,
        Ṅ        print that number with a newline,
         +       add it to
          i@     the index of the left argument in the right argument,
            ị    and take the element of the right argument at that modular index.
```
Without going backwards:
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
“rps”ðXṄ⁸i_i%3
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw5yiguJHDXMPb4h4uLPlUeOOzPhMVeP/h9uBPJVHTWv@/y8qKiooKCguLgYA "Jelly – Try It Online")
0 for tie, 2 for win, 1 for loss.
```
“rps”             Set the left argument to "rps",
     ð            then start a dyadic link:
      X           choose a random element of the left argument,
       Ṅ          print it,
        ⁸i        find its index in the left argument,
          _       subtract
           i      the right argument's index in the left argument,
            %3    and mod 3.
```
[Answer]
## x86-64 machine code (Linux), 98 bytes
```
00000000  54 5d 31 c0 31 ff 48 8d  75 f0 6a 02 5a 0f 05 8a  |T]1.1.H.u.j.Z...|
00000010  5d f0 b8 3e 01 00 00 48  8d 7d f0 6a 01 5e 31 d2  |]..>...H.}.j.^1.|
00000020  0f 05 8a 45 f0 6a 03 59  48 f7 f1 8a 8a 58 00 00  |...E.j.YH....X..|
00000030  00 88 4d f0 28 cb 80 c3  03 8a 8b 5b 00 00 00 88  |..M.(......[....|
00000040  4d f1 6a 01 58 6a 01 5f  48 8d 75 f0 6a 02 5a 0f  |M.j.Xj._H.u.j.Z.|
00000050  05 6a 3c 58 31 ff 0f 05  72 70 73 6c 77 77 64 6c  |.j<X1...rpslwwdl|
00000060  6c 77                                             |lw|
         
```
Disassembly:
```
   0:   54                      push   rsp
   1:   5d                      pop    rbp ; Setup basic frame pointer
   2:   31 c0                   xor    eax,eax
   4:   31 ff                   xor    edi,edi
   6:   48 8d 75 f0             lea    rsi,[rbp-0x10]
   a:   6a 02                   push   0x2
   c:   5a                      pop    rdx
   d:   0f 05                   syscall ; Read 2 bytes from STDIN into RBP-0x10 (input char + newline)
   f:   8a 5d f0                mov    bl,BYTE PTR [rbp-0x10] ; Move input into BL
  12:   b8 3e 01 00 00          mov    eax,0x13e
  17:   48 8d 7d f0             lea    rdi,[rbp-0x10]
  1b:   6a 01                   push   0x1
  1d:   5e                      pop    rsi
  1e:   31 d2                   xor    edx,edx
  20:   0f 05                   syscall ; Get 1 random byte
  22:   8a 45 f0                mov    al,BYTE PTR [rbp-0x10]
  25:   6a 03                   push   0x3
  27:   59                      pop    rcx
  28:   48 f7 f1                div    rcx
  2b:   8a 8a 58 00 00 00       mov    cl,BYTE PTR [rdx+0x58]
  31:   88 4d f0                mov    BYTE PTR [rbp-0x10],cl ; Get random throw
  34:   28 cb                   sub    bl,cl
  36:   80 c3 03                add    bl,0x3
  39:   8a 8b 5b 00 00 00       mov    cl,BYTE PTR [rbx+0x5b]
  3f:   88 4d f1                mov    BYTE PTR [rbp-0xf],cl ; Decide win/lose/draw
  42:   6a 01                   push   0x1
  44:   58                      pop    rax
  45:   6a 01                   push   0x1
  47:   5f                      pop    rdi
  48:   48 8d 75 f0             lea    rsi,[rbp-0x10]
  4c:   6a 02                   push   0x2
  4e:   5a                      pop    rdx
  4f:   0f 05                   syscall ; Print 2 chars to STDOUT (the computer's throw (r/p/s) and the winner (w/l/d))
  51:   6a 3c                   push   0x3c
  53:   58                      pop    rax
  54:   31 ff                   xor    edi,edi
  56:   0f 05                   syscall ; Exit with return code 0
  58:   727073 6c7777646c6c77 (data)
```
Outputs 'w' for win, 'l' for lose, and 'd' for draw.
Example run:
```
$ ./rps
r
sw
```
User picked rock and computer picked scissors. User wins.
[Answer]
## K, 67
```
{-1'f:x,*1?"rps";$[f in b:("pr";"rs";"sp");"W";f in|:'b;"L";"D"]}
```
Prints W,L,D for win/lose/draw.
Ungolfed:
```
rps:{[x]
    res:x,*1?"rps";        // join user input to random selection of r,p,s
    -1'f;                  // print the user input and the program selection to stdout
    wins:("pr";"rs";"sp"); // the universe of winning combinations
    losses:|:'wins;        // reverse each win to the get losses
    $[f in wins;    
        "win";
    f in losses;
        "lose";
    "draw"]
    }
```
Or in Q, which is more readable:
```
rps:{[x]
    res:x,rand["rps"];        // join user input to random selection of r,p,s
    -1 each f;                // print the user input and the program selection to stdout
    wins:("pr";"rs";"sp");    // the universe of winning combinations
    losses:reverse each wins; // reverse each win to the get losses
    $[f in wins;    
        "win";
    f in losses;
        "lose";
    "draw"]
    }
```
Sample Run:
```
k){-1'f:x,*1?"rps";$[f in b:("pr";"rs";"sp");"W";f in|:'b;"L";"D"]}"r"
r
s
"W"
k){-1'f:x,*1?"rps";$[f in b:("pr";"rs";"sp");"W";f in|:'b;"L";"D"]}"s"
s
s
"D"
k){-1'f:x,*1?"rps";$[f in b:("pr";"rs";"sp");"W";f in|:'b;"L";"D"]}"p"
p
s
"L"
```
[Answer]
## Javascript, 117 characters
Here's a data-driven approach to the problem. This can probably be optimized by generating the win/lose/draw data instead of mapping it manually, but it's a start :)
Golfed:
```
alert((r=[{v:"r",r:d="D",p:w="W",s:l="L"},{v:"p",r:l,p:d,s:w},{v:"s",r:w,p:l,s:d}][Math.random()*3|0]).v+r[prompt()])
```
Ungolfed:
```
//Output the result to the user
alert(
    (
        //Store the random computer outcome data
        randomRPSData =
            //Create the data for if the computer chooses r, p, or s
            [
                {
                    value: "r",
                    r: (d = "Draw"),
                    p: (w = "Win"),
                    s: (l = "Lose")},
                {
                    value: "p",
                    r: l,
                    p: d,
                    s: w},
                {
                    value: "s",
                    r: w,
                    p: l,
                    s: d}
            ]
            //Have the computer pick a random variable
            [Math.random() * 3 | 0]
    //Output the value the computer chose
    ).value
    //Output whether the user won or not
    + r[prompt()]
);
```
Finally, [here's a fiddle](http://jsfiddle.net/briguy37/NJyma/) with both.
[Answer]
Javascript: **256**
golfed:
```
i=prompt(),a=['p','r','s'];a=a[Math.floor(Math.random()*(3-1+1))+1];if(i==a){alert('d');}else if(i=='p'){if(a=='s'){alert('l');}else{alert('w');}}else if(i=='r'){if(a=='s'){alert('w');}else{alert('l');}}else if(i=='s'){if(a=='r'){alert('l');}else{alert('w')}}
```
ungolfed:
```
i=prompt(),a=['p','r','s'];
a=a[Math.floor(Math.random()*(3-1+1))+1];
if(i==a){
    alert('d');
}
else if(i=='p'){
    if(a=='s'){
        alert('l');
    }else{alert('w');}
}else if(i=='r'){
    if(a=='s'){
        alert('w');
    }else{alert('l');}
}else if(i=='s'){
    if(a=='r'){
        alert('l');
    }else{alert('w')}
} 
```
[Answer]
Clojure:
```
(def r 0) (def s 1) (def p 2)
(def object-name #(get {'p "Paper", 's "Scissors", 'r "Rock"} %))
(def result-name #(get {\d "Draw", \w "Win", \l "Lose"} %))
(defn computer-choice [] (nth ['r 's 'p] (int (rand 3))))
(defn game [a b] (get "dwlldwwld" (+ (* 3 a) b) ))
(defn print-game [user comp result] (print (format
  "User: %s\nComputer: %s\nResult: %s\n" 
  (object-name user) (object-name comp) (result-name result))))
(println "Enter 'p', 's' or 'r' and press return")
(let [comp (computer-choice),  user (read)]  (print-game user comp (game (eval user) (eval comp))))
```
Mini version (129 code characters):
```
java -jar clojure.jar -e \
"(def r 0)(def s 1)(def p 2)(let[u(read),c(nth['r 's 'p](int(rand 3)))](print c)(print (get \"dwlldwwld\"(+(* 3(eval u))(eval c)))))"
```
[Answer]
**JAVA (387)** first code golf!
```
import java.util.HashMap;public class _ {public static void main(String i[]){HashMap l = new HashMap(){{put('r',0);put('p',1);put('s',2);put(0,'T');put(1,'L');put(2,'W');}};char u =i[0].charAt(0);char c ="rps".charAt((int)(Math.random()*3)%3);int[][] m =new int[][]{{0,1,2},{2,0,1},{1,2,0}};System.out.println("U"+u+"C"+c+"R"+(Character)l.get(m[(Integer)l.get(u)][(Integer)l.get(c)]));}}
```
---
**Ungolfed**
```
import java.util.HashMap;
public class _ {
    public static void main(String[] input) {
       input = new String[] {"s"};
       HashMap lookup = new HashMap(){{
           put('r', 0);
           put('p', 1);
           put('s', 2);
           put(0, 'T');
           put(1, 'L');
           put(2, 'W');
       }};
       char user = input[0].charAt(0);
       char computer = new char[] {'r', 'p', 's'}[(int)(Math.random()*3)%3];
       int[][] matrix = new int[][] {{0,1,2}, {2,0,1}, {1,2,0}};
       Integer userChoice = (Integer) lookup.get(user);
       Integer computerChoice = (Integer) lookup.get(computer);
       Character result = (Character) lookup.get(matrix[userChoice][computerChoice]);
       System.out.println("u:" + user + ",c:" + computer + ",r:" + result);
    }
    /*
     t = 0, l = 1, w = 2
     *
        +---------------+
        | * | r | p | s |
        +---------------+
        | r | 0 | 1 | 2 |
        +---------------+
        | p | 2 | 0 | 1 |
        +---------------+
        | s | 1 | 2 | 0 |
        +---------------+
     */
}
```
---
**Golfed (Spacing/Indentation)**
```
import java.util.HashMap;
public class _ {
public static void main(String i[]) {
    HashMap l = new HashMap(){{
        put('r',0);put('p',1);put('s',2);put(0,'T');put(1,'L');put(2,'W');
    }};
    char u =i[0].charAt(0);char c = "rps".charAt((int)(Math.random()*3)%3);
    int[][] m =new int[][]{{0,1,2},{2,0,1},{1,2,0}};
    System.out.println("U"+u+"C"+c+"R:"+(Character)l.get(m[(Integer)l.get(u)][(Integer)l.get(c)]));
}}
```
---
Not the shortest code, but my first try
[Answer]
**Go (169)**
Golfed :
```
package main
import("fmt";"os")
func main(){v:=map[uint8]int{114:0,112:1,115:2}
u:=os.Args[1][0]
c:="rps"[os.Getpid()%3]
fmt.Printf("%c\n%c\n",c,"TWL"[(3+v[c]-v[u])%3])}
```
Ungolfed (as formatted by `go fmt`):
```
package main
import (
    "fmt"
    "os"
)
func main() {
    v := map[uint8]int{114: 0, 112: 1, 115: 2}
    u := os.Args[1][0]
    c := "rps"[os.Getpid()%3]
    fmt.Printf("%c\n%c\n", c, "TWL"[(3+v[c]-v[u])%3])
}
```
Run :
> 
> go run main.go p
> 
> 
> s
> 
> 
> W
> 
> 
> 
[Answer]
**Groovy, 89**
```
v='rps'
r=new Random().nextInt(3)
print"${v[r]}${'TLW'[((r-v.indexOf(this.args[0]))%3)]}"
```
Takes user choice as argument. Example:
```
groovy rps.groovy p
sL
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth/blob/master/pyth.py), 23
```
J"rps"K+wOJK%-XJ'KXJtK3
```
Output is in the form:
Tie: 0
Win: 1
Loss: 2
Explanation:
```
J"rps"             J="rps"
K+wOJ              K=input()+random_choice(J)
K                  print K
  XJ'K             index of K[0] in J
      XJtK         index of K[1] in J
 -XJ'KXJtK         difference of above indexes
%-XJ'KXJtK3        above difference mod 3
```
Run as follows:
```
$ cat rps
J"rps"K+wOJK%-XJ'KXJtK3
s
$ cat rps | python3 pyth.py
< Extraneous debug output removed>
sp
1
```
---
For only 4 more characters, we can use T for tie, W for win and L for loss:
```
J"rps"K+wOJKr@"TWL"-XJ'KXJtK
```
Everything is the same up until the difference of indexes, at which point we use the difference as the index into the string`"TWL"`.
---
Note: while I did develop this language after the challenge was posted, I had not seen the challenge until today. The challenge did not influence any aspect of the language.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
“rsp”
¢i¢ṙi¢XṄ¤
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw5yi4oJHDXO5Di3KPLTo4c6ZQDLi4c6WQ0v@H25/1LTm/3@lAiUA "Jelly – Try It Online")
This returns:
* 3 if you tie
* 2 if you lose
* 1 if you win
and expects input as one of `r`, `p` or `s`
## How it works
```
“rsp” - Helper link. Return "rsp"
¢i¢ṙi¢XṄ¤ - Main link. Takes a character C on the left e.g. "r"
¢         - "rsp"
 i        - Get the 1-index of C in "rsp", i           e.g. 1
  ¢       - "rsp"
   ṙ      - Rotate "rsp" i steps to the left           e.g. "spr"
        ¤ - Create a nilad:
     ¢    -   "rsp"
      X   -   Random element, X                        e.g. "r", "s", "p"
       Ṅ  -   Print
    i     - 1-Index of X in the rotated "rsp"          e.g.  3 ,  1 ,  2
```
]