21
8
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 ║ ║ 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 ║ ║ Shmiddty ║ javascript ║ 87 ║ 3 ║ ║ Fors ║ Befunge ║ 107 ║ 3 ║ ║ Briguy37 ║ javascript ║ 117 ║ 2 ║ ║ Vi. ║ Clojure ║ 129 ║ 1 ║ ║ Henrik ║ C# ║ 167 ║ 4 ║ ║ dystroy ║ Go ║ 169 ║ 1 ║ ║ Praveen ║ javascript ║ 250 ║ 0 ║ ║ ryan ║ javascript ║ 256 ║ 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!
You could add the script that automatically updates the scoreboard. – ghosts_in_the_code – 2016-03-24T08:24:30.370
2You might consider adding a clause that all outcomes - Win, Lose, Draw - must be possible. – primo – 2013-04-10T05:14:22.130
Since this is popularity, I decided to go with the LOLZ – jdstankosky – 2013-04-10T15:24:19.533
I edited the rules before you submitted your answer. Popularity will only be the tie breaker. – jsedano – 2013-04-10T15:27:14.963
I don't understand the point of this question. The spec seems to be: 1) get a random number 2) see if your random number is better than the one input by the user. Where's the challenge? – Gareth – 2013-04-10T15:31:30.190
@Gareth I guess if you don't want to participate you may choose not doing so, or looking for other questions that better suit your interest – jsedano – 2013-04-10T15:35:38.783
1Pfft, it's not popularity anymore? Boring. – jdstankosky – 2013-04-10T15:38:38.613
@anakata It's not like I site here hitting the refresh button every 10 seconds when I'm writing code to make sure the rules don't suddenly change. I submitted appropriately for the rules that existed when I started writing my code. You edited the rules during the creation of my submitted answer. – jdstankosky – 2013-04-10T15:49:34.403
@jdstankosky you are right, I'm sorry, I made a mistake, but, for fairness you were writing something that a) can not be executed b) It was only an exploitation of the rules I posted before – jsedano – 2013-04-10T15:58:07.697
@anakata If I could be bothered to check the syntax (the lolcode language spec site is broken), there are compilers and parsers. OTherwise I could just adjust the language slightly and use LOLpython. It's a completely valid language. There's a few other ESOlangs I was considering, but this is my favorite. – jdstankosky – 2013-04-10T16:12:43.683
Wouldn't this be better as a [king-of-the-hill] or [ai-palyer]? – dmckee --- ex-moderator kitten – 2013-04-11T19:59:06.880
@dmckee If that were the case, I would DEFINITELY change my guessing methods. Also, didn't somebody already make an RPS king-of-the-hill? – jdstankosky – 2013-04-11T20:03:02.083
1
@anakata By traditional Perlgolf rules (compiled by none other than Ton Hospel himself)
– primo – 2013-04-12T09:15:18.120-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.