SHARE
TWEET

Untitled

kirich2323 Dec 8th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data = list(map(int,open("input.txt", "r").read().split(',')))
  2.  
  3. def f(arr):
  4.     i = 0
  5.     while 1:
  6.         op = arr[i]
  7.         if op == 1:
  8.             arr[arr[i+3]] = arr[arr[i+2]] + arr[arr[i+1]]
  9.             i+=4
  10.         elif op == 2:
  11.             arr[arr[i+3]] = arr[arr[i+2]] * arr[arr[i+1]]
  12.             i+=4
  13.         elif op == 99:
  14.             return
  15.  
  16. def p1():
  17.     d=data[:]
  18.     d[1] = 12
  19.     d[2] = 2
  20.     f(d)
  21.     print(d[0])
  22.  
  23. def p2():
  24.     global data
  25.  
  26.     for n in range(0, 100):
  27.         for v in range(0, 100):
  28.             d=data[:]
  29.             d[1] = n
  30.             d[2] = v
  31.             f(d)
  32.             if d[0] == 19690720:
  33.                 print(n*100+v)
  34.                 return
  35.  
  36. p1()
  37. p2()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top