r/programminghorror • u/GaMerBoi2465 • Sep 26 '26
Rock Paper Scissors
Surely there's a more better and efficient way of coding this...
97
Upvotes
r/programminghorror • u/GaMerBoi2465 • Sep 26 '26
Surely there's a more better and efficient way of coding this...
23
u/fakehalo Sep 26 '26
The nested while()s with a break label instead of just one while() using 'continue' is the real crime here
18
u/Odd-Painting2596 Sep 26 '26
Neat part about programming, there is better AND worse.
8
u/Bright-Historian-216 Sep 26 '26
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
4
u/FooeyBar Sep 26 '26
I really dislike all the multiple calls to println
4
u/Merry-Lane Sep 26 '26
4th "look at my shifumi code" this week.
3
u/letmehaveanameyoudum Sep 28 '26
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
2
u/MMORPGnews Sep 27 '26
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
u/KodeBarista Sep 27 '26
Use code formatting.
0
u/0xt0bi03 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Sep 27 '26
blud needs to know, trees, or hashtables, or atleast bitwise and logical operators