Code Golf - Rock Paper Scissors
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
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])
@mat1 tfw ruby is shorter than python
nice!
TypeError: Cannot read property '0' of null
at /script.js:7:20
lmao some of these are literally 1/10 the size of mine
these were some amazing responses actually
Raku (99 bytes): https://repl.it/@theangryepicbanana/WeightyMildDeveloper
not golfed btw
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.
41 bytes (Python 3)
https://repl.it/@MrEconomical/rps-golf-python
@MrEconomical
very clever i never thought of doing it this way