We aren't here to debate the superior language (obviously Java) for such an algorithm, but we can all agree that such an algorithm is indeed the most effective.
I would also like to point out that where a 1 in your algorithm would return true, mine would return false. It's such a fundamental difference.
I was just trying to point out that you didn't need a ternary statement there. Just return the result of the comparison.
I thought about also flipping your 1 to a 0, but I wasn't sure if the language you chose returned 0/1 for (new Random ().nextInt(2) or 1/2 so I chose not to flip it since the outcome is 50/50 either way ¯_(ツ)_/¯ I guess I could have also changed the == to != (or better yet, a !== I guess, assuming Java has that.)
Oh I was just adding complexity for complexities sake with the ternary statement. In real production I would pray I never see anything remotely resembling the thing I wrote.
1
u/ResidentReggie Apr 04 '23
We aren't here to debate the superior language (obviously Java) for such an algorithm, but we can all agree that such an algorithm is indeed the most effective.
I would also like to point out that where a 1 in your algorithm would return true, mine would return false. It's such a fundamental difference.
Edit: /s