Skip to content

Instantly share code, notes, and snippets.

Last active Dec 24, 2020
What would you like to do?
from cmath import e, pi
from collections import Counter
import fileinput
def tokenize(s):
prev = None
for i, c in enumerate(s):
if prev is None:
if c in ('s', 'n'):
prev = c
yield c
assert c in ('e', 'w')
yield prev + c
prev = None
assert prev is None
steps = {
'e': 1,
'w': -1,
'ne': e**(1j*pi/3),
'nw': e**(2j*pi/3),
'se': e**(-1j*pi/3),
'sw': e**(-2j*pi/3),
format = lambda c: tuple(round(x, 2) for x in (c.real, c.imag))
counter = Counter(format(sum(steps[t] for t in tokenize(s.rstrip()))) for s in fileinput.input())
print(sum(1 for c in counter.values() if c % 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment