Another Python hack...
Part 1
from collections import Counter with open("day08.txt") as file: raw = file.read().strip() chunks = [] for idx in range(0, len(raw), 150): chunks.append(raw[idx:idx+150]) zero_counts = [Counter(chunk)["0"] for chunk in chunks] least_zero_layer = counts.index(sorted(zero_counts)[0]) cnt = Counter(chunks[least_zero_layer]) result = cnt["1"] * cnt["2"] print("Solution Pt.1:", result)
Part 2
image = [] for idx in range(150): if idx!= 0 and idx % 25 == 0: image.append("\n") layer = 0 while True: pixel = int(chunks[layer][idx]) if pixel == 0 or pixel == 1: image.append(str(pixel)) break layer +=1 print("".join(image).replace("0", " "))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Another Python hack...
Part 1
Part 2