Guest User

Untitled

a guest
Dec 13th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. def foldx(xvalue):
  2.     global coords
  3.     global maxx
  4.     maxx=xvalue
  5.     for line in coords:
  6.         if line[0]>xvalue:
  7.             line[0]=2*xvalue-line[0]
  8.  
  9. def foldy(yvalue):
  10.     global coords
  11.     global maxy
  12.     maxy=yvalue
  13.     for line in coords:
  14.         if line[1]>yvalue:
  15.             line[1]=2*yvalue-line[1]
  16.  
  17.  
  18. with open('input13') as f:
  19.     lines = f.read().splitlines()
  20.  
  21. coords=[]
  22. folds=[]
  23. isFoldsList=False
  24. for line in lines:
  25.     if isFoldsList==True:
  26.         folds.append(line)
  27.     elif line!='':
  28.         tmp = line.split(',')
  29.         coords.append([int(tmp[0]),int(tmp[1])])
  30.     else:
  31.         isFoldsList=True
  32.  
  33. maxx=0
  34. maxy=0
  35. for fold in folds:
  36.     tmp=fold.split('=')
  37.     if 'x' in tmp[0]:
  38.         foldx(int(tmp[1]))
  39.     else:
  40.         foldy(int(tmp[1]))
  41.  
  42. answer=[bytearray(' '*(maxx),'ascii') for i in range(maxy)]
  43. for line in coords:
  44.     answer[line[1]][line[0]]=ord('#')
  45.  
  46. print(answer)
Advertisement
Add Comment
Please, Sign In to add comment