Initial commit
This commit is contained in:
commit
b1394d905a
18 changed files with 6496 additions and 0 deletions
40
day6/2.py
Normal file
40
day6/2.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
def mult(a, b):
|
||||
return a*b
|
||||
|
||||
|
||||
def add(a, b):
|
||||
return a+b
|
||||
|
||||
|
||||
with open(r'day6/input.txt', 'r') as input:
|
||||
lines = input.read().split('\n')[:-1]
|
||||
|
||||
op_pos = []
|
||||
|
||||
for i, char in enumerate(lines[-1]):
|
||||
if char != ' ':
|
||||
op_pos.append(i)
|
||||
op_pos.append(len(lines[-1])+1)
|
||||
|
||||
sum = 0
|
||||
|
||||
for k in range(len(op_pos)-1):
|
||||
|
||||
op = mult if lines[-1][op_pos[k]] == '*' else add
|
||||
res = 1 if op == mult else 0
|
||||
|
||||
for i in range(op_pos[k], op_pos[k+1]-1):
|
||||
|
||||
current_number = ''
|
||||
|
||||
for j in range(len(lines)-1):
|
||||
|
||||
current_number += lines[j][i]
|
||||
|
||||
print(current_number)
|
||||
res = op(res, int(current_number.strip()))
|
||||
|
||||
sum += res
|
||||
|
||||
|
||||
print(sum)
|
||||
Loading…
Add table
Add a link
Reference in a new issue