Update day 13 solution
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-12-13 11:54:40 +01:00
parent d2d338ab16
commit 5b693a6ac1

View File

@@ -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)])