Update day 13 solution
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -3,29 +3,28 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
def fold(i, dots):
|
def fold(i, dots):
|
||||||
new_dots = []
|
new_dots = set()
|
||||||
if i[0] == 'x':
|
for d in dots:
|
||||||
for d in dots:
|
if i[0] == 'x':
|
||||||
n = (i[1] - abs(d[0] - i[1]), d[1])
|
n = (i[1] - abs(d[0] - i[1]), d[1])
|
||||||
if d[0] != i[1] and n not in new_dots:
|
if d[0] != i[1]:
|
||||||
new_dots.append(n)
|
new_dots.add(n)
|
||||||
elif i[0] == 'y':
|
elif i[0] == 'y':
|
||||||
for d in dots:
|
|
||||||
n = (d[0], i[1] - abs(d[1] - i[1]))
|
n = (d[0], i[1] - abs(d[1] - i[1]))
|
||||||
if d[1] != i[1] and n not in new_dots:
|
if d[1] != i[1]:
|
||||||
new_dots.append(n)
|
new_dots.add(n)
|
||||||
|
|
||||||
return new_dots
|
return new_dots
|
||||||
|
|
||||||
|
|
||||||
def part_1(input):
|
def part_1(input):
|
||||||
result = 0
|
result = 0
|
||||||
dots = []
|
dots = set()
|
||||||
instructions = []
|
instructions = []
|
||||||
for line in input:
|
for line in input:
|
||||||
if ',' in line:
|
if ',' in line:
|
||||||
x, y = line.strip().split(',')
|
x, y = line.strip().split(',')
|
||||||
dots.append((int(x), int(y)))
|
dots.add((int(x), int(y)))
|
||||||
elif 'fold along' in line:
|
elif 'fold along' in line:
|
||||||
d, c = line.strip().split()[-1].split('=')
|
d, c = line.strip().split()[-1].split('=')
|
||||||
instructions.append([d, int(c)])
|
instructions.append([d, int(c)])
|
||||||
@@ -36,12 +35,12 @@ def part_1(input):
|
|||||||
|
|
||||||
def part_2(input):
|
def part_2(input):
|
||||||
result = 0
|
result = 0
|
||||||
dots = []
|
dots = set()
|
||||||
instructions = []
|
instructions = []
|
||||||
for line in input:
|
for line in input:
|
||||||
if ',' in line:
|
if ',' in line:
|
||||||
x, y = line.strip().split(',')
|
x, y = line.strip().split(',')
|
||||||
dots.append((int(x), int(y)))
|
dots.add((int(x), int(y)))
|
||||||
elif 'fold along' in line:
|
elif 'fold along' in line:
|
||||||
d, c = line.strip().split()[-1].split('=')
|
d, c = line.strip().split()[-1].split('=')
|
||||||
instructions.append([d, int(c)])
|
instructions.append([d, int(c)])
|
||||||
|
|||||||
Reference in New Issue
Block a user