SHARE
TWEET

Untitled

a guest Dec 8th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with open('input') as f:
  2.     img = f.read().strip('\n')
  3.  
  4. w = 25
  5. h = 6
  6. s = len(img)
  7. layers = [img[i:i+w*h] for i in range(0, s, w*h)]
  8.  
  9. def no_elems(x, a):
  10.     return x.count(str(a))
  11.  
  12. # Part 1
  13. zeros = [no_elems(x, 0) for x in layers]
  14. index = zeros.index(min(zeros))
  15. print(no_elems(layers[index], 1)*no_elems(layers[index], 2))
  16.  
  17. # Part 2
  18. result = ''
  19. for i in range(w*h):
  20.     j = 0
  21.     while True:
  22.         if int(layers[j][i]) == 1:
  23.             result += 'x'
  24.             break
  25.         elif int(layers[j][i]) == 0:
  26.             result += ' '
  27.             break
  28.         else:
  29.             j += 1
  30.  
  31. for i in range(0, w*h, w):
  32.     print(result[i:i+w])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top