Skip to content
← Back to Community
Code Golf - Rock Paper Scissors
Profile icon
mwilki7

I know this has been done on other sites before but I thought this would be a fun one to play with non-code-golfing languages.

Code Golf:

Write the smallest program possible within the constraints:
Edit: I wish I put this in the 'Ask' section so I could choose a correct answer
Thanks, everyone, for your submissions, this was awesome.

Objective:

Write a rock paper scissors program with as few characters as you can using the repl programming language of your choice (it must be on repl).

Rock Paper Scissors:

Your program must take a single input
Input will be one of these strings: 'rr' 'rp' 'rs' 'pp' 'pr' 'ps' 'ss' 'sr' 'sp'
r - rock
p - paper
s - scissors

'rp' - means player 1 chooses rock, player 2 chooses paper
'pr' - means player 1 chooses paper, player 2 chooses rock
and so on

Program will output one of the following:
D for draw
L for player 1 lose
W for player 1 win

Submission format:

The number of bytes used (you can find this by pasting your code in https://mothereff.in/byte-counter )
Your repl
See my example in the comments @mwilki7

Rules:

It must be in a repl
Output must be either 'D', 'L', or 'W'
It must be able to run from the mini-repl window (in your comment/post)

Given the input, you must match the output:
input: rr output: D
input: rp output: L
input: rs output: W

input: pr output: W
input: pp output: D
input: ps output: L

input: sr output: L
input: sp output: W
input: ss output: D

Exceptions:

HTML5 repls: code in html won't count towards byte count (unless you put your javascript in a

Voters
Profile icon
MrEconomical
Profile icon
zaidan
Profile icon
pyelias
Profile icon
mat1
Profile icon
CodeSalvageON
Profile icon
theangryepicbanana
Profile icon
AdCharity
Profile icon
SilentShadowBla
Profile icon
mwilki7
Comments
hotnewtop
Profile icon
MrEconomical

41 bytes (Python 3)

https://repl.it/@MrEconomical/rps-golf-python

print("DLDLDLW"["rrppssr".find(input())])
Profile icon
mwilki7

@MrEconomical
very clever i never thought of doing it this way

Profile icon
pyelias

28 bytes (Ruby)

https://repl.it/@pyelias/KindlyFabulousMolecule

x,y=gets.bytes;p"DWWLL"[y-x]

40 bytes (Python 3)

lmao gotem mat
https://repl.it/@pyelias/PunyScornfulSystemsoftware

x,y=input().encode();print("DWWLL"[y-x])
Profile icon
mat1

@pyelias bruh moment

Profile icon
theangryepicbanana

@mat1 tfw ruby is shorter than python

Profile icon
SilentShadowBla

nice!

Profile icon
mat1

47 bytes

https://repl.it/@mat1/rps-code-golf

x,y=input();print('LDW'[(x==y)-(x+y in'rspr')])
Profile icon
MrEconomical

23 bytes (𝔼𝕊𝕄𝕚𝕟 3)

"LWWDLLW"[î⒞-í⒞+3]

run here: https://bennyboy.tech/ESMin/interpreter3.html?eval=false&input=rr&code=%22LWWDLLW%22%5B%C3%AE%E2%92%9E-%C3%AD%E2%92%9E%2B3%5D

Profile icon
kindred

TypeError: Cannot read property '0' of null
at /script.js:7:20

Profile icon
mwilki7

80 bytes (JavaScript)

var x=prompt(),g={r:'s',p:'r',s:'p'};alert(g[x[0]]==x[1]?'W':x[1]==x[0]?'D':'L')
Profile icon
AdCharity

lmao some of these are literally 1/10 the size of mine

Profile icon
mwilki7

these were some amazing responses actually

Profile icon
theangryepicbanana
Profile icon
AdCharity

Code

https://repl.it/@AdCharity/Code-Golf-M

Info

Size: 298 bytes
Lang: Node.js
Version: Minified
I'm pretty sure it works, but if it doesn't, let me know.
Is this the best way? Hell nah.

Profile icon
[deleted]

73 Bytes

https://repl.it/@sugarfi/Codegolf

Profile icon
mwilki7

951 bytes

https://repl.it/@mwilki7/codegolf

A naive solution, just for an example

Profile icon
AdCharity

@mwilki7 btw if u mangle all of the names + minify it it's probably shorter than mine (I didn't use cases cause I thought it wouldn't be worth the extra letters; but now I see that's not the case)