Share your repls and programming experiences

← Back to all posts
Code Golf - Rock Paper Scissors
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 <script> tag)

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

41 bytes (Python 3)

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

mwilki7

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

pyelias

28 bytes (Ruby)

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

40 bytes (Python 3)

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

mat1

@pyelias bruh moment

theangryepicbanana

@mat1 tfw ruby is shorter than python

SilentShadowBla

nice!

mat1

47 bytes

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

MrEconomical

23 bytes (𝔼𝕊𝕄𝕚𝕟 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

kindred

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

mwilki7

80 bytes (JavaScript)

AdCharity

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

mwilki7

these were some amazing responses actually

theangryepicbanana
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.

sugarfi
mwilki7

951 bytes

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

A naive solution, just for an example

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)