-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_12_b.py
58 lines (50 loc) · 996 Bytes
/
puzzle_12_b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
def turn_right(num):
global wayx
global wayy
tmp = 0
while num:
tmp = wayx
wayx = wayy
wayy = -tmp
num -=1
def turn_left(num):
global wayx
global wayy
tmp = 0
while num:
tmp = wayy
wayy = wayx
wayx = -tmp
num -=1
def move(inst):
global x
global y
global wayx
global wayy
global dirn
print inst
if inst[0:1] == 'F':
x += (int(inst[1:]) * wayx)
y += (int(inst[1:]) * wayy)
if inst[0:1] == 'N':
wayx -= int(inst[1:])
if inst[0:1] == 'S':
wayx += int(inst[1:])
if inst[0:1] == 'W':
wayy -= int(inst[1:])
if inst[0:1] == 'E':
wayy += int(inst[1:])
if inst[0:1] == 'R':
turn_right( int(inst[1:])/90)
if inst[0:1] == 'L':
turn_left( int(inst[1:])/90)
print x,y,wayx,wayy,"==="
x = 0
y = 0
wayx = -1
wayy = 10
for line in sys.stdin:
line = line.strip()
move(line)
print abs(x) + abs(y)