• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Dec 3rd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import re
2.
3. with open('input.txt') as file :
5.
6. AMoves = moves[:len(moves)//2]
7. BMoves = moves[len(moves)//2 :]
8.
9. print(len(AMoves), len(BMoves))
10.
11. def update(move) :
12.     if move == 'R' :
13.         return [int(move[1:]),0]
14.     if move == 'U' :
15.         return [0, int(move[1:])]
16.     if move == 'D' :
17.         return [0, -1*int(move[1:])]
18.     if move == 'L' :
19.         return [-1*int(move[1:]),0]
20.
21.
22. def evolve(AMoves = AMoves, BMoves = BMoves) :
23.     apos , bpos = [0,0] , [0,0]
24.     atraj, btraj = [apos],[bpos]
25.     for i in range(len(AMoves)) :
26.         apos += update(AMoves[i])
27.         bpos += update(BMoves[i])
28.         apos += update(AMoves[i])
29.         bpos += update(BMoves[i])
30.
31.         atraj.append(apos)
32.         btraj.append(bpos)
33.         print(atraj[-1], btraj[-1])
34.
35.         if apos in btraj :
36.             print("Intersect")
37.             try :
38.                 mindist = min(mindist, abs(apos) + abs(apos))
39.             except:
40.                 mindist = abs(apos) + abs(apos)
41.
42.         if bpos in atraj :
43.             print("Intersect")
44.             try :
45.                 mindist = min(mindist, abs(apos) + abs(apos))
46.             except:
47.                 mindist = abs(apos) + abs(apos)
48.
49.     print(mindist)
50.
51. evolve()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top