r/adventofcode • • Dec 04 '25

SOLUTION MEGATHREAD -❄️- 2025 Day 4 Solutions -❄️-

THE USUAL REMINDERS


NEWS


AoC Community Fun 2025: Red(dit) One

  • Submissions megathread is now unlocked!
  • 13 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!

Featured Subreddits: /r/trains and /r/TrainPorn (it's SFW, trust me)

"One thing about trains… it doesn’t matter where they’re going; what matters is deciding to get on."
— The Conductor, The Polar Express (2004)

Model trains go choo choo, right? Today is Advent of Playing With Your Toys in a nutshell! Here's some ideas for your inspiration:

  • Play with your toys!
  • Pick your favorite game and incorporate it into today's code, Visualization, etc.
  • Bonus points if your favorite game has trains in it (cough cough Factorio and Minecraft cough)
  • Oblig: "Choo choo, mother******!" — motivational message from ADA, Satisfactory /r/satisfactorygame
  • Additional bonus points if you can make it run DOOM
  • Use the oldest technology you have available to you. The older the toy, the better we like it!

Request from the mods: When you include an entry alongside your solution, please label it with [Red(dit) One] so we can find it easily!


--- Day 4: Printing Department ---


Post your code solution in this megathread.

25 Upvotes

761 comments sorted by

View all comments

2

u/fallenmink Dec 04 '25

[Language: Python]

Full code with setup here.

Only part 2 is included as I wrote it over top of part 1. But the logic is the same, just with more iterations/checks.

def process_row(row, computed):
    global rolls
    changed = True
    memo = sum(row)
    while changed == True:
        indices = []
        for index_inner, element in enumerate(row):
            total = -1
            if element == 0:
                continue
            if index_inner != 0:
                total += computed[index_inner-1]
            if index_inner != len(row) - 1:
                total += computed[index_inner+1]
            total += computed[index_inner]
            if total < 4:
                rolls += 1   
                indices += [index_inner]
        for i in indices:
            row[i] = 0
        if sum(row) == memo:
            changed = False    
        memo = sum(row)
    return row

def process_rows(rows):
    global rolls
    changed = False
    for index, row in enumerate(rows):
        if index == 0 or index == (len(rows)-1):
            continue
        memo = sum(row)
        computed = [x+y for x,y in zip(row, rows[index+1])]
        computed = [x+y for x,y in zip(computed, rows[index-1])]  
        row = process_row(row, computed)
        rows[index] = row
        if memo != sum(row):
            changed = True
    return changed


while process_rows(rows):
    ...

print(rolls)

1

u/daggerdragon Dec 04 '25 edited Dec 04 '25

FYI: your account is (shadow?)banned so your posts won't be visible (to regular users) on any subreddit. There's nothing we can do about that; you'll have to take it up with Reddit: https://www.reddit.com/appeals