Okay, so today I’m gonna talk about something I messed around with recently – figuring out who the winners are in a “players” game. It’s not rocket science, but I figured I’d share the process in case it helps someone else out there.

First off, I had this list of players, right? Each player had some kind of score, could be anything really, points in a game, whatever. I wanted to figure out who had the highest score, basically, the winners. Seemed simple enough, right?
Initially, I just went with the super basic approach. I looped through the list of players, kept track of the highest score I’d seen so far, and the player who had it. It was ugly, with a bunch of if statements. Looked something like this (but in code, obviously):
- Set highest_score to zero.
- Set winner to null.
- Loop through all the players
- If the current player’s score is higher than highest_score:
- Update highest_score to the player’s score
- Update winner to the current player
- End Loop
- The winner is whoever the last player was.
It worked, kinda. But it only found one winner, even if there were ties. Plus, it was just plain clunky. I felt like there had to be a better way.
Then I thought, “Why not just sort the players by their score?” Duh! So I used a sorting function, you know, the kind that puts things in order. Sorted the players from highest score to lowest. Suddenly, the player at the very beginning of the list was the winner… or a winner, anyway.
But what about ties? That’s where things got a little trickier. I had to loop through the sorted list again, starting from the top (the highest score), and keep adding players to a “winners” list as long as they had the same score as the top player.

Here’s roughly what I did:
- Sort the players by score (highest to lowest)
- Create a list to store the winners
- Get the highest_score (the score of the first player in the sorted list)
- Loop through the sorted players:
- If the current player’s score is equal to the highest_score:
- Add the current player to the winners list
- Otherwise:
- Stop the loop (since all remaining players have lower scores)
- End Loop
- The winners list now contains all the players with the highest score.
Much cleaner! This way, if there were multiple players with, say, 100 points, they’d all be included in the “winners” list. If only one player had 100 points, and the next highest was 95, then only the player with 100 would be in the list.
Finally, I added some error handling, you know, in case the player list was empty or something. Didn’t want it crashing on me.
So, yeah, that’s how I figured out the “players winners” thing. Nothing groundbreaking, but it’s a good example of how you can start with a simple (and kinda bad) solution and then refine it to be cleaner and more efficient. Hope it helps someone out there!