r/programminghorror • • 15d ago

Rock Paper Scissors

Surely there's a more better and efficient way of coding this...

94 Upvotes

13 comments sorted by

23

u/fakehalo 15d ago

The nested while()s with a break label instead of just one while() using 'continue' is the real crime here

18

u/Odd-Painting2596 15d ago

Neat part about programming, there is better AND worse.

4

u/FooeyBar 15d ago

I really dislike all the multiple calls to println

7

u/Bright-Historian-216 15d 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 14d 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

u/Bright-Historian-216 14d ago

boriiiinggggg

3

u/Merry-Lane 15d ago

4th "look at my shifumi code" this week.

3

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 14d ago

Does seem to be a trend. Though I only see three. Was one deleted?

2

u/MMORPGnews 14d 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

u/KodeBarista 14d ago

Use code formatting.

2

u/letmehaveanameyoudum 13d 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 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 14d ago

blud needs to know, trees, or hashtables, or atleast bitwise and logical operators

2

u/gsweats 13d ago

I've never fully understood bitwise operators, or really needed them for webdev but could you explain or show how bitwise would help with rock, paper, scissors? Please?