I’d also suggest OP learn to use a loop to test this. There will be some conditions in the loop that mean you can just break out early. Be a good next step in understanding coding and data structures.
Honestly if the logic is sound and you stuff this away in some file and import this, it ain’t half bad. But if you’re going to do that, you might as well make it more readable so it can be worked on
This approach is however offer more generalizable. E.g. introducing some new options: Rock beats scissors beats paper beats stick beats whatever ... beats rock.
It would take any engineer time and effort to have to read, let alone understand what’s happening here before they can make any changes. From a production quality standpoint it’s not up to snuff. You’re creating technical debt that someone will eventually shave to refactor.
What are the benefits of this approach over writing out the conditions? I’m guessing readability and less chance of error, but is it faster in any way?
Ditto what /u/Kavinci said, but I wanna stress that the main benefit is the readability. "Is it any faster?" can be an important question, but it usually isn't.
33
u/agdolusannbierts Nov 30 '22
Could do just one draw with (p1 === p2) I think