diff --git a/day13/generator.py b/day13/generator.py new file mode 100644 index 0000000..f595bf9 --- /dev/null +++ b/day13/generator.py @@ -0,0 +1,41 @@ +from itertools import repeat +from random import random, randrange + +target = """ +# # ####### # # ####### ###### ##### ####### # # # # # ##### ### # # ####### # # ####### # # # # ###### +## # # # # # # # # # # # ## # ## # # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # # ##### # # ##### ###### # #### # # # # # # # # # # # #### # # # ##### # # # # # # # ###### +# # # # # # # # # # # # # # # # # # # ####### # # # # # # # # # # # # # # +# ## # # # # # # # # # # # ## # ## # # # # # # # # # # # # # # # # +# # ####### # ####### # # ##### ####### # # # # # # ##### ### # ####### # ####### ##### ##### # +""" + +points = {(x, y) for y, line in enumerate(target.strip().split('\n')) for x, c in enumerate(line) if c == "#"} +img_x, img_y = max_x, max_y = tuple(map(max, zip(*points))) +instructions = [] + +for _ in range(20): + is_x, fold = (True, randrange(max_x+1, max_x*2))\ + if random() < 0.5\ + else (False, randrange(max_y+1, max_y*2)) + instructions.append((is_x, fold)) + next_max = fold*2 + if is_x: + points = set(v for (x, y), rand in zip(points, iter(random, 2)) for v in [ + (x, y) if rand <= 0.66 or x <= max_x-next_max+fold else None, + (2*fold - x, y) if rand > 0.33 and x > max_x-next_max+fold else None, + ] if v is not None) + max_x = next_max + else: + points = set(v for (x, y), rand in zip(points, iter(random, 2)) for v in [ + (x, y) if rand <= 0.66 or y <= max_y-next_max+fold else None, + (x, 2*fold - y) if rand > 0.33 and y > max_y-next_max+fold else None, + ] if v is not None) + max_y = next_max + +for point in points: + print(','.join(map(str, point))) +print() +for instruction in instructions[::-1]: + print("fold along " + ("x" if instruction[0] else "y") + "=" + str(instruction[1])) diff --git a/day13/part1.py b/day13/part1.py index b8cb133..0db9b19 100644 --- a/day13/part1.py +++ b/day13/part1.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 - lines = (x.strip() for x in open("input.txt")) points = set() diff --git a/day13/part2.py b/day13/part2.py index ae95bef..43d5bb6 100644 --- a/day13/part2.py +++ b/day13/part2.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 - lines = (x.strip() for x in open("input.txt")) points = set()