Guest User

Untitled

a guest
Dec 13th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import numpy as np
  2. import sys
  3.  
  4. lines = open(sys.argv[1]).readlines()
  5. equations_count = round((len(lines) / 4))
  6.  
  7. x = 0
  8. tokens = 0
  9.  
  10. for i in range(equations_count):
  11.     btn_a = lines[x].strip()
  12.     btn_b = lines[x + 1].strip()
  13.     prize = lines[x + 2].strip()
  14.  
  15.     eq1 = btn_a[btn_a.find(':') + 2:].split(',')
  16.     eq2 = btn_b[btn_b.find(':') + 2:].split(',')
  17.    
  18.     X0 = int(eq1[0][eq1[0].find('+') + 1:].strip())
  19.     Y0 = int(eq1[1][eq1[1].find('+') + 1:].strip())
  20.     X1 = int(eq2[0][eq2[0].find('+') + 1:].strip())
  21.     Y1 = int(eq2[1][eq2[1].find('+') + 1:].strip())
  22.  
  23.     prize =  prize[prize.find(':') + 1:].split(',')
  24.     prizeX = int(prize[0][prize[0].find('=') + 1:]) + 10000000000000
  25.     prizeY = int(prize[1][prize[1].find('=') + 1:]) + 10000000000000
  26.  
  27.     a = np.array([[X0, X1], [Y0, Y1]]).astype(int)
  28.     b = np.array([prizeX, prizeY]).astype(int)
  29.     s = np.linalg.solve(a, b)
  30.  
  31.     if np.all(np.abs(s - np.round(s)) < 1e-3):
  32.         tokens += s[0] * 3 + s[1] * 1
  33.  
  34.     x += 4
  35.  
  36. print(tokens)
Advertisement
Add Comment
Please, Sign In to add comment