Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- from typing import DefaultDict
- universe = DefaultDict(bool)
- with open("day17.txt", "r") as f:
- for i, line in enumerate(f):
- for j, c in enumerate(line):
- if c == "#":
- universe[(j,i,0,0)] = True
- print(universe)
- def shuffle(universe, iteration):
- newuniverse = DefaultDict(bool)
- for a in range(0-iteration,8+iteration):
- for b in range(0-iteration,8+iteration):
- for c in range(0-iteration,8+iteration):
- for d in range(0-iteration,8+iteration):
- numtrue = 0
- for i in range(-1,2):
- for j in range(-1,2):
- for k in range(-1,2):
- for l in range(-1,2):
- if i == 0 and j == 0 and k == 0 and l == 0:
- continue
- if universe[(a+i,b+j,c+k,d+l)]:
- numtrue += 1
- if universe[(a,b,c,d)]:
- if numtrue == 2 or numtrue == 3:
- newuniverse[(a,b,c,d)] = True
- else:
- if numtrue == 3:
- newuniverse[(a,b,c,d)] = True
- return newuniverse
- for mycounter in range(1,7):
- universe = shuffle(universe,mycounter)
- starcounter = 0
- for k in universe.keys():
- if universe[k]:
- starcounter += 1
- print(starcounter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement