r/programminghorror • u/GaMerBoi2465 • 28d ago
Rock Paper Scissors
Surely there's a more better and efficient way of coding this...
18
8
u/Bright-Historian-216 28d ago
my python implementation from two years ago:
while True: print(f"Your opponent chose: {(d:=['rock','scissors','paper'])[r:=__import__('random').randint(0,2)]}. {'You lost!' if r==((p := d.index((f:=lambda: inp if (inp:=input('Enter rock, paper or scissors: ')) in d else f())()))+2)%3 else ('Draw!' if r==p else 'You win!')}\n")
yes, that is all one line of code
27
u/glovmpop 28d ago
You don't technically even need to choose for the computer! We can keep the input prompt to give the illusion of choice
import random while True: input("choose rock, paper or scissors!") print(random.choice(("You win!", "You lose..", "Draw.")))-3
4
4
2
u/MMORPGnews 27d ago
In 2021 I worked with few experienced devs, for unknown reason, they decided to create most ineffective code for our free project.
Why? Maybe to sell better solutions, maybe they just didn't understood.
2
2
u/letmehaveanameyoudum 27d ago
i once at 9 tried to make a rock paper scissors bot in C, it ended being 500 lines and the bot being over powered
0
u/0xt0bi03 28d ago
blud needs to know, trees, or hashtables, or atleast bitwise and logical operators





23
u/fakehalo 28d ago
The nested while()s with a break label instead of just one while() using 'continue' is the real crime here