Puzzle du 1 décembre 2016
This commit is contained in:
parent
81b461493a
commit
379e242297
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys, re
|
||||
instructions = re.findall(r"(R|L)([0-9]+)", sys.stdin.readline().strip())
|
||||
headings = [(0, 1), (1, 0), (0, -1), (-1, 0)]
|
||||
h, x, y = 0, 0, 0
|
||||
visited, part2 = [(x, y)], None
|
||||
for i in instructions:
|
||||
if i[0] == 'L':
|
||||
h = (h - 1) % len(headings)
|
||||
elif i[0] == 'R':
|
||||
h = (h + 1) % len(headings)
|
||||
for _ in range(int(i[1])):
|
||||
x = x + headings[h][0]
|
||||
y = y + headings[h][1]
|
||||
if (x, y) in visited and part2 is None:
|
||||
part2 = (x, y)
|
||||
else:
|
||||
visited.append((x, y))
|
||||
print(abs(x) + abs(y), abs(part2[0]) + abs(part2[1]))
|
Loading…
Reference in New Issue