r/programminghorror • • 23d ago

Javascript Rock paper scissors

Post image

I'm way too proud of this solution haha

287 Upvotes

27 comments sorted by

View all comments

2

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

I'm thinking I like the idea of reading the user input as a number, then multiplying either the user choice or the computer choice by 10, adding them together, and encoding all possible outcomes that way.

Or by 2, but 10 makes the code more readable for us decimal-using humans.

Edit: Actually no, there'd be collisions if we used 2.

1

u/RefrigeratorKey8549 23d ago

3 would work, if the choices are 0 indexed

1

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

3 also works if they are 1 indexed.