6-01
This commit is contained in:
43
06/06-1.py
Normal file
43
06/06-1.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import numbers
|
||||
import operator
|
||||
from copy import deepcopy
|
||||
|
||||
# file = "./ex.txt"
|
||||
file = "./input.txt"
|
||||
|
||||
def get_column(n_list:list[str], col:int) -> list[int]:
|
||||
res = []
|
||||
for n in n_list:
|
||||
res.append(int(n[col]))
|
||||
return res
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = 0
|
||||
num_list = []
|
||||
operator_list = []
|
||||
input_file = open(file, "r")
|
||||
for line in input_file:
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
continue
|
||||
line = line.split()
|
||||
if line[0].isdigit():
|
||||
num_list.append(line)
|
||||
else:
|
||||
operator_list = deepcopy(line)
|
||||
|
||||
for i in range(len(operator_list)):
|
||||
if operator_list[i] == "+":
|
||||
op_result = 0
|
||||
for op in get_column(num_list, i):
|
||||
op_result += op
|
||||
elif operator_list[i] == "*":
|
||||
op_result = 1
|
||||
for op in get_column(num_list, i):
|
||||
op_result *= op
|
||||
else:
|
||||
op_result = None
|
||||
solution += op_result
|
||||
print(f"Solution: {solution}")
|
||||
Reference in New Issue
Block a user