This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_program(data): | |
for i in range(0, len(data), 4): | |
if i == 0 or i%4 == 0: | |
if data[i] == 99: | |
return data[0] | |
elif data[i] == 1: | |
data[data[i+3]] = data[data[i+1]] + data[data[i+2]] | |
elif data[i] == 2: | |
data[data[i+3]] = data[data[i+1]] * data[data[i+2]] | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_fuel(mass): | |
return (int(mass.strip()) // 3) - 2 | |
## Load Data | |
with open("input.txt", "r") as f: | |
module_weights = f.readlines() | |
## Find Required Fuel | |
fuel = sum([calc_fuel(x) for x in module_weights]) | |
print("Day1, Part1 --", fuel) |