Handle ballots of uneven length
This commit is contained in:
parent
d1ffb55f08
commit
c45e514bfc
6
app.py
6
app.py
|
@ -354,11 +354,17 @@ def runoff(ballots):
|
||||||
candidates = {}
|
candidates = {}
|
||||||
for ballot in ballots:
|
for ballot in ballots:
|
||||||
for r in ballot:
|
for r in ballot:
|
||||||
|
if r.id not in count or len(count[r.id]) < len(ballot):
|
||||||
|
log.debug("count[%d] <- %d elements", r.id, len(ballot))
|
||||||
count[r.id] = [0] * len(ballot)
|
count[r.id] = [0] * len(ballot)
|
||||||
candidates[r.id] = r
|
candidates[r.id] = r
|
||||||
for ballot in ballots:
|
for ballot in ballots:
|
||||||
for pos, r in enumerate(ballot):
|
for pos, r in enumerate(ballot):
|
||||||
|
log.debug("count = %s", count)
|
||||||
|
log.debug("r.id = %s", r.id)
|
||||||
|
log.debug("pos = %s", pos)
|
||||||
count[r.id][pos] += 1
|
count[r.id][pos] += 1
|
||||||
|
log.debug("count[%d][%d]) = %d", r.id, pos, count[r.id][pos])
|
||||||
result = sorted(count.keys(), key=lambda i: count[i])
|
result = sorted(count.keys(), key=lambda i: count[i])
|
||||||
log.debug("result of this round:")
|
log.debug("result of this round:")
|
||||||
for r in result:
|
for r in result:
|
||||||
|
|
Loading…
Reference in New Issue