Cs50 Tideman Solution [TRUSTED – Review]
# Eliminate the candidate(s) with the fewest votes eliminated_candidates = [] while len(min_vote_candidates) > 0: eliminated_candidate = min_vote_candidates[0] eliminated_candidates.append(eliminated_candidate) candidates.remove(eliminated_candidate)
Here is a C solution to the CS50 Tideman problem: Cs50 Tideman Solution
def tideman(candidates, pairs): # Count first-choice votes vote_counts = {candidate: 0 for candidate in candidates} for pair in pairs: vote_counts[pair[0]] += 1 # Eliminate the candidate(s) with the fewest votes
# Find the candidate with the fewest votes min_votes = min(vote_counts.values()) min_vote_candidates = [candidate for candidate, count in vote_counts.items() if count == min_votes] for (int i = 0
if __name__ == "__main__": main()
# Update preferences pairs = update_preferences(pairs, eliminated_candidate)
// Get the names of the candidates Candidate candidates[num_candidates]; for (int i = 0; i < num_candidates; i++) { printf("Enter candidate %d: ", i+1); scanf("%s", candidates[i].name); candidates[i].votes = 0; }