summaryrefslogtreecommitdiff
path: root/2016/1b.py
blob: cc24f76c2b6f6345edef873e5b9beafbd9f7e970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python3
import sys, re

ins=[({"R":-1j,"L":1j}[s[0]],int(s[1:])) for s in re.findall(r"[RL]\d+",sys.stdin.readline())]
hits={}
p=0
d=1
for i in ins:
	d*=i[0]
	for _ in range(i[1]):
		p+=d
		hits[p]=hits.get(p,0)+1
		if hits[p]>=2:
			print(int(abs(p.real)+abs(p.imag)))
			sys.exit(0)