A repro for all my Advent of ode tasks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

12 lines
561 B

import time
import codecs
start = time.time()
file = codecs.open('input.txt', encoding='ascii')
count = {'literals': 0, 'representations': 0, 'escaped': 0}
for line in file:
line = line.strip()
count['literals'] += len(line)
count['representations'] += len(codecs.decode(line.encode('ascii'), 'unicode_escape'))-2
count['escaped'] += len(line.encode('unicode_escape').replace('"', '\\"'))+2
print("Part 1: " + str(count['literals'] - count['representations']) + " Part 2: " + str(count['escaped'] - count['literals']))
print(time.time() - start)