Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. import numpy as np
  2.  
  3. filename = "input.txt"
  4. file = open(filename,"r")
  5. data = file.read()
  6.  
  7. b = "<>=xyz"
  8. for char in b:
  9. data = data.replace(char,"")
  10.  
  11. data = data.split("\n")[:-1]
  12. for i in range(len(data)):
  13. pos = data[i].split(",")
  14. for o in range(len(pos)):
  15. pos[o] = int(pos[o])
  16. data[i] = [pos,[0,0,0]]
  17.  
  18. steps = 50000
  19. start = [[],[],[],[]]
  20. startVel = [[],[],[],[]]
  21. values = [[],[],[],[],[],[]]
  22. for i in range(steps):
  23. for moon in data:
  24. vel = moon[1]
  25. pos = moon[0]
  26. if i == 0:
  27. start[data.index(moon)] = pos.copy()
  28. startVel[data.index(moon)] = vel.copy()
  29. for other in data:
  30. if other == moon:
  31. continue
  32. _pos = other[0]
  33.  
  34. if pos[0] < _pos[0]:
  35. vel[0] = vel[0] + 1
  36. elif pos[0] > _pos[0]:
  37. vel[0] = vel[0] - 1
  38.  
  39. if pos[1] < _pos[1]:
  40. vel[1] = vel[1] + 1
  41. elif pos[1] > _pos[1]:
  42. vel[1] = vel[1] - 1
  43.  
  44. if pos[2] < _pos[2]:
  45. vel[2] = vel[2] + 1
  46. elif pos[2] > _pos[2]:
  47. vel[2] = vel[2] - 1
  48. moon[1] = vel
  49.  
  50. totals = [0,0,0,0,0,0]
  51. for o in range(len(data)):
  52. moon = data[o]
  53. pos = moon[0]
  54. vel = moon[1]
  55. pos[0] = pos[0] + vel[0]
  56. pos[1] = pos[1] + vel[1]
  57. pos[2] = pos[2] + vel[2]
  58.  
  59. if pos[0] == start[o][0]:
  60. totals[0] = totals[0] + 1
  61.  
  62. if pos[1] == start[o][1]:
  63. totals[1] = totals[1] + 1
  64.  
  65. if pos[2] == start[o][2]:
  66. totals[2] = totals[2] + 1
  67.  
  68. if vel[0] == startVel[o][0]:
  69. totals[3] = totals[3] + 1
  70.  
  71. if vel[1] == startVel[o][1]:
  72. totals[4] = totals[4] + 1
  73.  
  74. if vel[2] == startVel[o][2]:
  75. totals[5] = totals[5] + 1
  76.  
  77. if totals[0] == 4 and len(values[0]) == 0:
  78. values[0].append(i+2)
  79. if totals[1] == 4 and len(values[1]) == 0:
  80. values[1].append(i+2)
  81. if totals[2] == 4 and len(values[2]) == 0:
  82. values[2].append(i+2)
  83.  
  84.  
  85. if totals[3] == 4 and len(values[3]) == 0:
  86. values[3].append(i+1)
  87. if totals[4] == 4 and len(values[4]) == 0:
  88. values[4].append(i+1)
  89. if totals[5] == 4 and len(values[5]) == 0:
  90. values[5].append(i+1)
  91.  
  92. for i in range(len(values)):
  93. values[i] = values[i][0]
  94. print(values)
  95. print(np.lcm.reduce(values))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement