Skip to content

Instantly share code, notes, and snippets.

@EZLiang
Last active March 3, 2021 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EZLiang/14be354ddff42810cd9e0c6ceed047b1 to your computer and use it in GitHub Desktop.
Save EZLiang/14be354ddff42810cd9e0c6ceed047b1 to your computer and use it in GitHub Desktop.
Vote tabulator for POTY 2020
import re, json
names = ["Beehive push catalyst", "Natural loafers", "34-bit still life enumeration", "c/61 near-spaceship", "p9 heavyweight emulator", "p5 lightweight emulator/catalyst", "New c/5 diagonal spaceships", "New growing spaceships", "New longest 16x16 methuselah", "New c/10 orthgonal technology", "Better universal regulator", "19-bit still life syntheses", "c/5 and c/6 guns", "Cheaper universal construction", "Width-12 c/6 orthogonal spaceship", "New small Corderships", "p10 glider shuttle", "New agar technology", "Speed Demonoid", "LoM hasslers", "New c/6 diagonal pushalong", "New 2c/7 technology", "4×N block agar construction", "Rob's p16", "Loafer bitmap printer", "Cordercolumn", "Stable L122", "Stable barge-crosser", "Small c/5 diagonal puffer", "New grayship technology", "Glider syntheses from Glider_stdin", "New XWSS signal technology", "Silverfish", "Bandersnatch", "Spaceship eaters and spaceship-to-G converters", "Record-setting diehards", "Smaller 3c/7 spaceships", "p28 gun", "Spaceship glider syntheses"]
def get_name(i):
return names[int(i) - 1]
def blank_votes():
r = {}
for i in names:
r[i] = 0
return r
def tabulate(s):
s = s.splitlines()
r = blank_votes()
reg = re.compile("^\*+$")
for i in s:
if not i.startswith("#"):
continue
j = i[1:].split(" ")
if reg.match(j[1]):
r[get_name(j[0])] += len(j[1])
return r
def sortdict(d):
return {key: value for key, value in sorted(d.items(), key=lambda item: item[1])}
def dict_add(d1, d2):
r = {}
for i in names:
r[i] = d1[i] + d2[i]
return r
def pretty_print(d):
print(json.dumps(d, ensure_ascii=False, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment