43 lines
942 B
Python
43 lines
942 B
Python
import numpy as np
|
|
|
|
LINES_NUM = 5
|
|
|
|
count = 0
|
|
|
|
probs = np.array([])
|
|
|
|
with open('input.txt', 'r') as file:
|
|
cols_num = len(file.readline()[:-1])
|
|
file.seek(0)
|
|
for line in file:
|
|
line = line[:-1]
|
|
for char in line:
|
|
probs = np.append(probs, char)
|
|
|
|
probs = probs.reshape((LINES_NUM, cols_num))
|
|
|
|
nums = []
|
|
skip_col = False
|
|
for col in probs.T[::-1]:
|
|
|
|
if skip_col:
|
|
skip_col = False
|
|
continue
|
|
|
|
nums.append(int(col[0].strip() + col[1].strip() + col[2].strip() + col[3].strip()))
|
|
|
|
if col[4] == '+':
|
|
print("Adding:", nums)
|
|
count += sum(nums)
|
|
nums = []
|
|
skip_col = True
|
|
elif col[4] == '*':
|
|
print("Multiplying:", nums)
|
|
prod = 1
|
|
for n in nums:
|
|
prod *= n
|
|
count += prod
|
|
nums = []
|
|
skip_col = True
|
|
print(count)
|