Unable to load image

Day 23 AoC: :marseymerchantelf: Unstable Diffusion :!marseymerchantelf:

postmaxx your solutions in here. @Platybells

19
Jump in the discussion.

No email address required.

Fun, takes about 10 sec to run

f = open('AOC2022Day23.txt')
lines = f.read().strip().split('\n')
elves = set()
#grid = np.zeros((len(lines)+20,len(lines[0])+20))
for y,line in enumerate(lines):
    for x,c in enumerate(line):
        if c == '#':
            elves.add((x,y))
movement = True
for d in range(1000):
    if movement == False:
        print(d)
        break
    movement = False
    proposals = {}
    for (x,y) in elves:
        n = x,y-1
        ne = x+1,y-1
        nw = x-1,y-1
        e = x+1,y
        w = x-1,y
        se = x+1,y+1
        sw = x-1,y+1
        s = x,y+1
        if all([i not in elves for i in [n,ne,nw,e,w,se,sw,s]]):
            continue
        dirs = [[n,ne,nw],[s,se,sw],[w,nw,sw],[e,ne,se]]
        if all([i not in elves for i in dirs[d%4]]):
            pdir = dirs[d%4][0]
            if pdir not in proposals:
                proposals[pdir] = [(x,y)]
            else:
                proposals[pdir].append((x,y))
        elif all([i not in elves for i in dirs[(d+1)%4]]):
            pdir = dirs[(d+1)%4][0]
            if pdir not in proposals:
                proposals[pdir] = [(x,y)]
            else:
                proposals[pdir].append((x,y))
        elif all([i not in elves for i in dirs[(d+2)%4]]):
            pdir = dirs[(d+2)%4][0]
            if pdir not in proposals:
                proposals[pdir] = [(x,y)]
            else:
                proposals[pdir].append((x,y))
        elif all([i not in elves for i in dirs[(d+3)%4]]):
            pdir = dirs[(d+3)%4][0]
            if pdir not in proposals:
                proposals[pdir] = [(x,y)]
            else:
                proposals[pdir].append((x,y))
    for prop in proposals:
        if len(proposals[prop]) == 1:
            movement = True
            elves.add(prop)
            elves.discard(proposals[prop][0])
xs = []
ys = []
for elf in elves:
    xs.append(elf[0])
    ys.append(elf[1])
xsize = max(xs)-min(xs)+1
ysize = max(ys)-min(ys)+1
print(xsize*ysize-len(elves))
Jump in the discussion.

No email address required.

😴😴😴

Jump in the discussion.

No email address required.



Now playing: Simian Segue (DKC).mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.