42 lines
2.4 KiB
Python
42 lines
2.4 KiB
Python
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]))
|