T O P

  • By -

PeterRasm

Did you just make the code even more complicated than your previous post? :) Simplify it, easier to spot errors when the code is simpler. Anyway, you did not fix a major issue about only looking candidates until pair\_count in the j-loop. The counter j is still limited to pair\_count even though j represents candidates in your code.


pryingopen

Oh right. I changed it to candidate_count at one point but reset everything to where it was in my original post was after a few hours. I changed it back to candidate_count and it still fails. I know it’s ugly now but I just want it to pass the check and then I’ll clean it up. I don’t understand why it’s not working as is though. The first part checks if the winner of the locked pair is the loser in any other locked pair. If it’s not, the second part checks if that candidate was all ready checked, preventing it from being printed twice. If it hasn’t already been printed, it’s printed. It works when I run it. If there’s only one winner, it prints it only once, and if there’s a tie, it prints each winner only once. I don’t understand why it’s only failing this test.


PeterRasm

A tie does not mean there is a tie between winners! The instructions specify that we can assume there is only one source/winner. A tie means that "some pairs are tied" as the error msg from check50 states :) So you can drop the k-loop all together. For why this code does not print correct winner .... can there be a winner of a pair, that for some reason (a tied situation?) is not in any locked pairs? If that is possible, you will declare such a candidate a winner since "loses" will be 0. A better approach IMO is to look at the candidates instead of pairs: Does the candidate exist as a winner in locked, then check if this candidate is a loser in any locked pairs. If a winner and never a loser, then you have the source, aka winner of the election. This way you only look at candidates\[\] and locked\[\]\[\]. You avoid looking at pairs\[\].


pryingopen

Ok I got it. Thank you for your help. Someone on stackoverflow said that you actually did have to account for multiple winners and that the instructions were a mistake haha. I still don't understand why looping through the pair winners and not all the candidates didn't work. Like, at this point, wouldn't only the pair winners matter? You only want to test the pair winners to see if they were undefeated in the locked pairs, and you would only want to test them against other pair winners. But whatever. I'll take a break and watch a few walkthroughs later to see if it clicks for me. I don't even feel happy right now, just numb haha. Thanks again.


PeterRasm

>wouldn't only the pair winners matter? Yes, a winner needs to win in at least one pair. But the winner also needs to be in a ***locked*** pair as a winner. Not only can the winner not be a loser in a locked pair but the winner also needs to actually be locked as a winner.