I struggled with reading comprehension tonight 🤦🏼♀️
def calculate(num1, num2, nums):
nums = num1
nums = num2
idx = 0
while nums[idx] != 99:
num = nums[idx]
val1 = nums[nums[idx + 1]]
val2 = nums[nums[idx + 2]]
idx3 = nums[idx + 3]
if num == 1:
nums[idx3] = val1 + val2
elif num == 2:
nums[idx3] = val1 * val2
idx += 4
with open("input.txt") as _file:
for line in _file:
input_values = [int(num) for num in line.split(",")]
# part 1
print(calculate(12, 2, input_values[:]))
# part 2
GOAL = 19690720
for i in range(100):
for j in range(100):
if calculate(i, j, input_values[:]) == GOAL:
print(100 * i + j)
Me too! I spent a good couple minutes trying to figure out why the sum of their test opcode didn't match the answer... 😭
Yeah, the second part's wording was really confusing to me.
Thank you! It really helps me to understand the second part.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.