deleted unnecessary operations
This commit is contained in:
parent
8542b29e2e
commit
e254b9601b
26
day06.py
26
day06.py
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# https://adventofcode.com/2025/day/5
|
||||
# https://adventofcode.com/2025/day/6
|
||||
|
||||
import re, operator
|
||||
from functools import reduce
|
||||
@ -54,33 +54,13 @@ def part2(data: list[str]) -> int:
|
||||
num_lengths[-1] += 1
|
||||
|
||||
ops = prep_data([data[-1]])[0]
|
||||
|
||||
total = 0
|
||||
r_left = re.compile("(^\s+)")
|
||||
r_right = re.compile("(\s+$)")
|
||||
|
||||
for j in range(len(num_lengths)):
|
||||
stripes = []
|
||||
for i in range(len(data) - 1):
|
||||
|
||||
# cut out correct part of data line
|
||||
d = data[i][:num_lengths[j]]
|
||||
|
||||
# replace spaces with dummy character at the start of the substring
|
||||
m = r_left.search(d)
|
||||
if m:
|
||||
a, b = m.span()
|
||||
d = "X" * (b - a) + d[b:]
|
||||
|
||||
# replace spaces with dummy character at the end of the substring
|
||||
m = r_right.search(d)
|
||||
if m:
|
||||
a, b = m.span()
|
||||
d = d[:a] + "X" * (b - a)
|
||||
|
||||
# store the prepped substring
|
||||
stripes.append(d)
|
||||
|
||||
stripes.append(data[i][:num_lengths[j]])
|
||||
# clip substring from data line
|
||||
data[i] = data[i][num_lengths[j]+1:]
|
||||
|
||||
@ -88,7 +68,7 @@ def part2(data: list[str]) -> int:
|
||||
actual_nums = []
|
||||
for i in range(len(stripes[0])):
|
||||
num = "".join([stripes[k][i] for k in range(len(stripes))])
|
||||
actual_nums.append(int(num.strip("X")))
|
||||
actual_nums.append(int(num.strip()))
|
||||
# print(actual_nums)
|
||||
# print(f"{j}\t{ops[j]}\t{get_op(ops[j])}\t{reduce(get_op(ops[j]), actual_nums)}")
|
||||
total += reduce(get_op(ops[j]), actual_nums)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user