diff --git a/day-13/day-13.py b/day-13/day-13.py index 3dc62e4..6fd0457 100644 --- a/day-13/day-13.py +++ b/day-13/day-13.py @@ -3,29 +3,28 @@ from pathlib import Path def fold(i, dots): - new_dots = [] - if i[0] == 'x': - for d in dots: + new_dots = set() + for d in dots: + if i[0] == 'x': n = (i[1] - abs(d[0] - i[1]), d[1]) - if d[0] != i[1] and n not in new_dots: - new_dots.append(n) - elif i[0] == 'y': - for d in dots: + if d[0] != i[1]: + new_dots.add(n) + elif i[0] == 'y': n = (d[0], i[1] - abs(d[1] - i[1])) - if d[1] != i[1] and n not in new_dots: - new_dots.append(n) + if d[1] != i[1]: + new_dots.add(n) return new_dots def part_1(input): result = 0 - dots = [] + dots = set() instructions = [] for line in input: if ',' in line: x, y = line.strip().split(',') - dots.append((int(x), int(y))) + dots.add((int(x), int(y))) elif 'fold along' in line: d, c = line.strip().split()[-1].split('=') instructions.append([d, int(c)]) @@ -36,12 +35,12 @@ def part_1(input): def part_2(input): result = 0 - dots = [] + dots = set() instructions = [] for line in input: if ',' in line: x, y = line.strip().split(',') - dots.append((int(x), int(y))) + dots.add((int(x), int(y))) elif 'fold along' in line: d, c = line.strip().split()[-1].split('=') instructions.append([d, int(c)])