Advertisement
Guest User

AoC Day 10

a guest
Dec 10th, 2020
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import sys
  2. import numpy as np
  3. fname = sys.argv[1]
  4.  
  5. with open(fname, "r") as f:
  6. jolts = f.read().split("\n")
  7. jolts = [int(x) for x in jolts]
  8.  
  9. jolts = sorted(jolts)
  10. jolts = [0]+jolts+[max(jolts) + 3]
  11.  
  12. # Part 2
  13. adjacencies = [[0 for x in range(len(jolts))] for y in range(len(jolts))]
  14. for i in range(len(jolts)):
  15. for j in range(i+1, len(jolts)):
  16. if jolts[j] <= jolts[i] + 3:
  17. adjacencies[i][j] = 1
  18.  
  19. adj = np.array(adjacencies)
  20. curr = adj
  21. total = 0
  22. for i in range(len(jolts)):
  23. curr = np.matmul(curr, adj)
  24. total += curr[0][-1]
  25.  
  26. print(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement