You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
1.1 KiB

#!/usr/bin/env python3
import sys
def printi(dots):
st = ''
for y in range(max(dots,key=lambda x: x[1])[1]+1):
for x in range(max(dots,key=lambda x: x[0])[0]+1):
if (x,y) in dots: st += '#'
else: st += '.'
print(st)
st = ''
def fold(f, dots):
ndots, c = set(), f[1]
if f[0] == 'x': r = 0
elif f[0] == 'y': r = 1
for dot in dots:
if dot[r] < c: ndots.add(dot)
elif dot[r] > c: ndots.add([(c-(dot[0]-c),dot[1]), (dot[0],c-(dot[1]-c))][r])
return ndots
if __name__ == '__main__':
lines = open(sys.argv[1]).read().split('\n\n')
dots = set([tuple(map(int, line.split(','))) for line in lines[0].split('\n')])
folds = [i for i in map(lambda x: (x[0],int(x[1])), [tuple(line.strip('fold along ').split('=')) for line in lines[1].split('\n')[:-1]])]
# challenge 1
res1 = str(sum(1 for dot in fold(folds[0], dots)))
print("challenge 1:" + "\n" + res1 + "\n")
# challenge 2
for f in folds: dots = fold(f,dots)
printi(dots)
res2 = "read yourself please xD"
print("challenge 2:" + "\n" + res2 + "\n")