Something went wrong. Try again.
My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code
advent-of-code python
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536import reimport fileinputfrom collections import Counter
from utils import parse_line
def decrypt(c, n): if c == '-': return ' '
return chr((((ord(c) - ord('a')) + n) % 26) + ord('a'))
total_sector_id = 0north_pole_sector_id = None
for line in fileinput.input(): name, sector, checksum = parse_line(r'(\S+)-(\d+)\[(\w{5})\]', line) sector = int(sector)
real_name = ''.join(decrypt(c, sector) for c in name)
if 'northpole' in real_name: north_pole_sector_id = sector
occurences = Counter([x for x in name if x.isalpha()]) commons = sorted(occurences.most_common(), key=lambda (x, y): (-y, x))
if ''.join(zip(*commons)[0][:5]) == checksum: total_sector_id += sector
print "Sum of sector IDs of real rooms: %i" % total_sector_idprint "North Pole storage room sector: %i" % north_pole_sector_id