Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- with open('input.txt') as file :
- moves = re.findall('\w\d+', file.read())
- AMoves = moves[:len(moves)//2]
- BMoves = moves[len(moves)//2 :]
- print(len(AMoves), len(BMoves))
- def update(move) :
- if move[0] == 'R' :
- return [int(move[1:]),0]
- if move[0] == 'U' :
- return [0, int(move[1:])]
- if move[0] == 'D' :
- return [0, -1*int(move[1:])]
- if move[0] == 'L' :
- return [-1*int(move[1:]),0]
- def evolve(AMoves = AMoves, BMoves = BMoves) :
- apos , bpos = [0,0] , [0,0]
- atraj, btraj = [apos],[bpos]
- for i in range(len(AMoves)) :
- apos[0] += update(AMoves[i])[0]
- bpos[0] += update(BMoves[i])[0]
- apos[1] += update(AMoves[i])[1]
- bpos[1] += update(BMoves[i])[1]
- atraj.append(apos)
- btraj.append(bpos)
- print(atraj[-1], btraj[-1])
- if apos in btraj :
- print("Intersect")
- try :
- mindist = min(mindist, abs(apos[0]) + abs(apos[1]))
- except:
- mindist = abs(apos[0]) + abs(apos[1])
- if bpos in atraj :
- print("Intersect")
- try :
- mindist = min(mindist, abs(apos[0]) + abs(apos[1]))
- except:
- mindist = abs(apos[0]) + abs(apos[1])
- print(mindist)
- evolve()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement