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!
-p
would be counted as 3 bytes: one for the-
, one for thep
, and one more the necessary whitespace. However, many other competitions on CG.SE have counted each option as a single byte. It's usually up to the author of the question to decide which system to honor. \$\endgroup\$