A huge warehouse with forklifts moving pallettes with boxes

Day 4: Printing Department

Note: If you’re attempting to read this as a Fediverse post, you might find it rather confusing. I recommend using a web browser to read it properly, following this link.

The challenge

We have a quadratic field filled with the symbols . and @. Our task is to find the number of @ symbols with less than 4 other @ symbols in adjacent positions, up, down, left, right and diagonally.

The idea

I personally find it easier to deal with numbers than with string comparisons, so I replace . and @ with 0 and 1. I also despise checking if I am at a border or not, so I put a frame of zeroes around the field and only look at the inside.

So, we only need a function to count the numbers 1 around a field with the one and to check if this number is less than 4, which leads us to this code:

Perl code
https://codeberg.org/M1na/AOC25/src/branch/main/aoc2504a.pl

The updated challenge

We now want to remove all the fields with few neighbours, those we found before. Once we are ready, we repeat the process until only fields with at least 4 neighbours are left. How many 1 could we remove in total?

The updated idea

We do the same as before, but instead of just counting ones with few neighbours, we’re storing their positions in a list. After each round we set all these positions to 0.

Perl code
https://codeberg.org/M1na/AOC25/src/branch/main/aoc2504b.pl
Fediverse Reactions

Comments

2 responses to “Day 4: Printing Department”

  1. @AdventOfCode Ah, good point. A frame of zeroes would have simplified the code. Thanks 🙂
    I'm sure that'll come in handy soon.

    1. @everythingalsocan

      Always happy, if I could give an idea!

      @AdventOfCode

Leave a Reply

Your email address will not be published. Required fields are marked *