Self-consistency boosts LLM accuracy on reasoning tasks: sample several answers at a non-zero temperature, then take the most common final answer.
Model outputs are messy, so normalise each answer before voting:
"1,000" → "1000"),Implement majority_vote(answers) returning (answer, agreement), where answer is the winning normalised answer and agreement is its share of the non-empty votes. Break ties by the answer that appeared first. If nothing votes, return (None, 0.0).
Example
majority_vote(["42", " 42.", "41", "1,000", "42"]) # ("42", 0.6)