Skip to content

Instantly share code, notes, and snippets.

@snoyes
Created December 4, 2025 16:22
Show Gist options
  • Select an option

  • Save snoyes/530c05b3c3a749a48fcb0d1b5f95859e to your computer and use it in GitHub Desktop.

Select an option

Save snoyes/530c05b3c3a749a48fcb0d1b5f95859e to your computer and use it in GitHub Desktop.
Advent of Code 2025 day 4 with no IF, AND, or OR.
from collections import Counter
from itertools import takewhile, count
def playLife(layout, cycles):
previous = None
living = {(x, y) for x, line in enumerate(layout) for y, _ in filter(lambda c: c[1] == '@', enumerate(line))}
has_changed = takewhile(lambda _: living != previous, count())
getNeighbors = lambda cell: {(cell[0] + x, cell[1] + y) for x in range(-1, 2) for y in range(-1, 2)}
for _ in zip(range(cycles), has_changed):
previous = living
neighbors = Counter(neighbor for cell in living for neighbor in getNeighbors(cell).intersection(living))
living = {cell for cell, _ in filter(lambda x: x[1] > 4, neighbors.items())}
return len(living)
def part1(data, cycles=1):
return playLife(data, cycles=0) - playLife(data, cycles=cycles)
def part2(data):
return part1(data, cycles=100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment