Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- path = raw_input("Введіть шлях!")
- x = 0
- y = 0
- l = 0
- pt = []
- count = 0
- k = 0
- class Position:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- for p in path:
- a = x
- b = y
- if k == 0:
- c = str(p)
- if c == 'r':
- x = x + 1
- count = count + 1
- elif c == 'l':
- x = x - 1
- count = count + 1
- elif c == 'u':
- y = y + 1
- count = count + 1
- elif c == 'd':
- y = y - 1
- count = count + 1
- t = Position(x, y)
- pt.append(t)
- l = 0
- if pt:
- k = 1
- while l <= count - 1:
- ins = pt[l]
- l = l + 1
- if x == ins.x and y == ins.y:
- k = 1
- else:
- k = 0
- else:
- t = 1
- if k == 1:
- print 'finish', count
Add Comment
Please, Sign In to add comment