solved day 6, part 1!
parent
4e20ede3d1
commit
d2ea29cb62
|
|
@ -0,0 +1,45 @@
|
|||
input = open('input.txt', 'r').read().splitlines()
|
||||
|
||||
nums = []
|
||||
|
||||
current_num = ''
|
||||
|
||||
for line in input:
|
||||
if current_num != '':
|
||||
if column_index > len(nums) - 1:
|
||||
nums.append([current_num])
|
||||
else:
|
||||
nums[column_index].append(current_num)
|
||||
current_num = ''
|
||||
column_index = 0
|
||||
for char in line:
|
||||
if char == ' ':
|
||||
if current_num != '':
|
||||
if column_index > len(nums) - 1:
|
||||
nums.append([current_num])
|
||||
column_index += 1
|
||||
else:
|
||||
nums[column_index].append(current_num)
|
||||
column_index += 1
|
||||
current_num = ''
|
||||
else:
|
||||
current_num += char
|
||||
|
||||
answer = 0
|
||||
|
||||
for column in nums:
|
||||
column_combo = 0
|
||||
if column[-1] == '+':
|
||||
for num in column[:-1]:
|
||||
column_combo += int(num)
|
||||
answer += column_combo
|
||||
elif column[-1] == '*':
|
||||
for num in column[:-1]:
|
||||
if column_combo == 0:
|
||||
column_combo += int(num)
|
||||
else:
|
||||
column_combo *= int(num)
|
||||
answer += column_combo
|
||||
|
||||
print(answer)
|
||||
|
||||
Loading…
Reference in New Issue