[Meta] !movies@lemmy.world mod removing comment suggesting consolidation of that community with this one as their moderation community is spread too thin, thankfully modlog is public
That's fair.
So no one wants to close their community, let's just move on then.
[Meta] !movies@lemmy.world mod removing comment suggesting consolidation of that community with this one as their moderation community is spread too thin, thankfully modlog is public
My Python solution for part 1 and part 2. I really practice my regex skills.
#!/usr/bin/python3
import re
value_re = '(\d+)'
symbol_re = '[^\d.]'
gear_re = '(\*)'
def main():
input = list()
with open("input.txt", 'r') as in_file:
for line in in_file:
input.append(line.strip('\n'))
length = len(input)
width = len(input[0])
value_sum = 0
for idx, line in enumerate(input):
for match in re.finditer(value_re, line):
for line_mask in input[max(idx - 1, 0):min(idx + 2, length)]:
valid_chars = line_mask[max(match.span()[0] - 1, 0):min(match.span()[1] + 1, width)]
if re.search(symbol_re, valid_chars):
value_sum += int(match[0])
break
print(f"Value sum = {value_sum}")
gear_ratio = 0
for idx, line in enumerate(input):
for match in re.finditer(gear_re, line):
valid_lines = input[max(idx - 1, 0):min(idx + 2, length)]
min_range = max(match.span()[0] - 1, 0)
max_range = min(match.span()[1], width)
num_of_adjacent = 0
temp_gear_ratio = 1
for valid_line in valid_lines:
for match in re.finditer(value_re, valid_line):
if match.span()[0] in range(min_range,max_range + 1) or match.span()[1] - 1 in range(min_range,max_range + 1):
num_of_adjacent += 1
temp_gear_ratio *= int(match[0])
if num_of_adjacent == 2:
gear_ratio += temp_gear_ratio
print(f"Gear ratio = {gear_ratio}")
if __name__ == '__main__':
main()
Care to elaborate on Mrs Doubtfire? Not sure I've ever watched it as an adult, and don't recall it being dark.