SHARE
TWEET

aoc 2019-8 python

Funguu Dec 8th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def main():
  2.     with open("input/day8.txt") as file:
  3.         data = [int(x) for x in file.read()]
  4.     width = 25
  5.     height = 6
  6.    
  7.     best = float("inf")
  8.     i = 0
  9.     while i < len(data):
  10.         values = {}
  11.         for _ in range(width*height):
  12.             values[data[i]] = 1 + values.get(data[i], 0)
  13.             i += 1
  14.         if values[0] < best:
  15.             best = values[0]
  16.             part1 = values[1] * values[2]
  17.     print("part 1", part1)
  18.    
  19.     part2 = ""
  20.     for y in range(height):
  21.         for x in range(width):
  22.             for i in range(int(len(data)/width/height)):
  23.                 pixel = data[x + y * width + i * width * height]
  24.                 if pixel == 0: # black
  25.                     part2 += " "
  26.                     break
  27.                 elif pixel == 1: # white
  28.                     part2 += "X"
  29.                     break
  30.         part2 += "\n"
  31.     print("part 2")
  32.     print(part2)
  33.    
  34. main()
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
 
Top