|
@@ -1,18 +1,22 @@
|
|
|
-
|
|
|
|
|
-def getFuel(mass):
|
|
|
|
|
- fuel = mass / 3
|
|
|
|
|
- fuel = round(fuel,0)
|
|
|
|
|
- fuel -= 2
|
|
|
|
|
- fuel = int(fuel)
|
|
|
|
|
- print(fuel)
|
|
|
|
|
- if fuel > 0:
|
|
|
|
|
- return fuel + getFuel(fuel)
|
|
|
|
|
- else:
|
|
|
|
|
- return 0
|
|
|
|
|
-
|
|
|
|
|
-fuel = 0
|
|
|
|
|
-file = open("1.txt","r")
|
|
|
|
|
-masses = file.readlines()
|
|
|
|
|
-for mass in masses:
|
|
|
|
|
- fuel += getFuel(int(mass))
|
|
|
|
|
-print(fuel)
|
|
|
|
|
|
|
+file = open("3.txt","r")
|
|
|
|
|
+input = file.read()
|
|
|
|
|
+code = input.split(",")
|
|
|
|
|
+print(code)
|
|
|
|
|
+print("\n\n")
|
|
|
|
|
+i = 0
|
|
|
|
|
+while i < len(code):
|
|
|
|
|
+ print("pos: " + str(i))
|
|
|
|
|
+ print("val: "+str(code[i]))
|
|
|
|
|
+ if code[i] == "1":
|
|
|
|
|
+ print("add")
|
|
|
|
|
+ code[int(code[i + 3])] = int(code[int(code[i + 2])]) + int(code[int(code[i + 1])])
|
|
|
|
|
+ i += 4
|
|
|
|
|
+ if code[i] == "2":
|
|
|
|
|
+ print("mult")
|
|
|
|
|
+ code[int(code[i + 3])] = int(code[int(code[i + 2])]) * int(code[int(code[i + 1])])
|
|
|
|
|
+ i += 4
|
|
|
|
|
+ if code[i] == "99":
|
|
|
|
|
+ for v in range(len(code)):
|
|
|
|
|
+ code[v] = int(code[v])
|
|
|
|
|
+ print(code)
|
|
|
|
|
+ exit()
|