Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import sys
- lines = open(sys.argv[1]).readlines()
- equations_count = round((len(lines) / 4))
- x = 0
- tokens = 0
- for i in range(equations_count):
- btn_a = lines[x].strip()
- btn_b = lines[x + 1].strip()
- prize = lines[x + 2].strip()
- eq1 = btn_a[btn_a.find(':') + 2:].split(',')
- eq2 = btn_b[btn_b.find(':') + 2:].split(',')
- X0 = int(eq1[0][eq1[0].find('+') + 1:].strip())
- Y0 = int(eq1[1][eq1[1].find('+') + 1:].strip())
- X1 = int(eq2[0][eq2[0].find('+') + 1:].strip())
- Y1 = int(eq2[1][eq2[1].find('+') + 1:].strip())
- prize = prize[prize.find(':') + 1:].split(',')
- prizeX = int(prize[0][prize[0].find('=') + 1:]) + 10000000000000
- prizeY = int(prize[1][prize[1].find('=') + 1:]) + 10000000000000
- a = np.array([[X0, X1], [Y0, Y1]]).astype(int)
- b = np.array([prizeX, prizeY]).astype(int)
- s = np.linalg.solve(a, b)
- if np.all(np.abs(s - np.round(s)) < 1e-3):
- tokens += s[0] * 3 + s[1] * 1
- x += 4
- print(tokens)
Advertisement
Add Comment
Please, Sign In to add comment