This commit is contained in:
2020-12-28 18:45:07 +01:00
parent b7489ef1ce
commit 2cdc62f52e
4 changed files with 116 additions and 4 deletions

View File

@@ -1,6 +1,42 @@
import numpy as np
def solve(index, line):
val = 0
while index < len(line):
print(index)
if line[index] == '(':
val += solve(index + 1, line)
elif line[index] == ')':
return val
elif line[index] == '+':
if line[index + 1] == '(':
val += solve(index + 2, line)
else:
val += int(line[index + 1])
elif line[index] == '*':
val *= solve(index + 1, line)
else:
val += line[index]
index += 1
return val
def part1():
file = open("../day3/input.txt")
print(f"Part 1:")
file = open("input_test.txt")
lines = [line.strip() for line in file.readlines()]
sum = 0
for line in lines:
sum += solve(0, line.split(' '))
print(f"Part 1: {sum}")
def part2():