Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import numpy as np
- fname = sys.argv[1]
- with open(fname, "r") as f:
- jolts = f.read().split("\n")
- jolts = [int(x) for x in jolts]
- jolts = sorted(jolts)
- jolts = [0]+jolts+[max(jolts) + 3]
- # Part 2
- adjacencies = [[0 for x in range(len(jolts))] for y in range(len(jolts))]
- for i in range(len(jolts)):
- for j in range(i+1, len(jolts)):
- if jolts[j] <= jolts[i] + 3:
- adjacencies[i][j] = 1
- adj = np.array(adjacencies)
- curr = adj
- total = 0
- for i in range(len(jolts)):
- curr = np.matmul(curr, adj)
- total += curr[0][-1]
- print(total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement