Advertisement
rpsjab

AoC 2020 Day 17

Dec 17th, 2020
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import collections
  2. from typing import DefaultDict
  3.  
  4. universe = DefaultDict(bool)
  5.  
  6. with open("day17.txt", "r") as f:
  7.     for i, line in enumerate(f):
  8.         for j, c in enumerate(line):
  9.             if c == "#":
  10.                 universe[(j,i,0,0)] = True
  11.  
  12. print(universe)
  13.  
  14. def shuffle(universe, iteration):
  15.     newuniverse = DefaultDict(bool)
  16.  
  17.     for a in range(0-iteration,8+iteration):
  18.         for b in range(0-iteration,8+iteration):
  19.             for c in range(0-iteration,8+iteration):
  20.                 for d in range(0-iteration,8+iteration):
  21.                     numtrue = 0
  22.                     for i in range(-1,2):
  23.                         for j in range(-1,2):
  24.                             for k in range(-1,2):
  25.                                 for l in range(-1,2):
  26.                                     if i == 0 and j == 0 and k == 0 and l == 0:
  27.                                         continue
  28.                                     if universe[(a+i,b+j,c+k,d+l)]:
  29.                                         numtrue += 1
  30.                     if universe[(a,b,c,d)]:
  31.                         if numtrue == 2 or numtrue == 3:
  32.                             newuniverse[(a,b,c,d)] = True
  33.                     else:
  34.                         if numtrue == 3:
  35.                             newuniverse[(a,b,c,d)] = True
  36.  
  37.     return newuniverse
  38.  
  39. for mycounter in range(1,7):
  40.     universe = shuffle(universe,mycounter)
  41.  
  42. starcounter = 0
  43. for k in universe.keys():
  44.     if universe[k]:
  45.         starcounter += 1
  46. print(starcounter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement