Beispiel #1
0
from func import unescaped_length, encode

totalEscapedLength = 0
totalUnescapedLength = 0 
totalMyEscapedLength = 0

with open("in.txt") as file:
	for line in file:
		line = line.strip()
		totalEscapedLength += len(line)
		totalUnescapedLength += unescaped_length(line)
		totalMyEscapedLength += len(encode(line))

print("Part one: {} - {} = {}".format(totalEscapedLength, totalUnescapedLength, totalEscapedLength - totalUnescapedLength))
print("Part two: {} - {} = {}".format(totalMyEscapedLength, totalEscapedLength, totalMyEscapedLength - totalEscapedLength))
Beispiel #2
0
from func import unescaped_length 

print(0 == unescaped_length('""'))
print(2 == len('""'))
print(3 == unescaped_length('"abc"'))
print(5 == len('"abc"'))
print(1 == unescaped_length('"\\\""'))
print(4 == len('"\\\""'))
print(1 == unescaped_length('"\\\\"'))
print(4 == len('"\\\\"'))
print(7 == unescaped_length('"aaa\\"aaa"'))
print(10 == len('"aaa\\"aaa"'))
print(1 == unescaped_length('"\\xd2"'))
print(6 == len('"\\xd2"'))
print(1 == unescaped_length('"\\x27"'))
print(6 == len('"\\x27"'))
print(2 == unescaped_length('"\\\\\\\\"'))
print(6 == len('"\\\\\\\\"'))
print(23 == unescaped_length('"\\\\qiyirsdrfpmu\\\\\\x15xusifaag"'))
print(30 == len('"\\\\qiyirsdrfpmu\\\\\\x15xusifaag"'))