r/excel • 647 • Dec 04 '25

Discussion Advent of Code 2025 Day 4

It's back. Only 12 days of puzzles this year.

Today's puzzle "Printing Department" link below.

https://adventofcode.com/2025/day/4

Three requests on posting answers:

Please try blacking out / marking as spoiler with at least your formula solutions so people don't get hints at how to solve the problems unless they want to see them.

The creator of Advent of Code requests you DO NOT share your puzzle input publicly to prevent others from cloning the site where a lot of work goes into producing these challenges.

There is no requirement on how you figure out your solution (many will be trying to do it in one formula, possibly including me) besides please do not share any ChatGPT/AI generated answers as this is a challenge for humans.

7 Upvotes

7 comments sorted by

1

u/Downtown-Economics26 647 Dec 04 '25 edited Dec 04 '25

For Part 1 I went mostly old school excel and split out the input into a grid then just did the old and reliable relative reference to get a count and summed:

=IFERROR(IF(Input!B3="@",--(COUNTIFS(Input!A2:C4,"@")<5),"."),0)

Part 2 -- just don't have the patience to figure out all your guys' clever formula iteration methods, although I'm duly impressed looking at them, VBA answer below.

Sub AOC2025D04P02()

Dim grid As Variant
Dim newgrid As Variant
xcount = Len(Range("a1"))
ycount = Application.CountA(Range("a:a"))

ReDim grid(xcount + 1, ycount + 1)
ReDim newgrid(xcount + 1, ycount + 1)

For y = 0 To ycount + 1
If y > 0 And y <= ycount Then
ys = Range("a" & y)
End If
    For x = 0 To xcount + 1
    If x > 0 And x <= xcount And y > 0 And y <= ycount Then
        If Mid(ys, x, 1) = "@" Then
        grid(x, y) = 1
        Else
        grid(x, y) = 0
        End If
    Else
    grid(x, y) = 0
    End If
    Next x
Next y

picked = -1
tpicked = 0
Do Until picked = 0
picked = 0
    For y = 1 To ycount
        For x = 1 To xcount
        If grid(x, y) = 1 Then
            nsum = grid(x - 1, y - 1) + grid(x, y - 1) + grid(x + 1, y - 1) + grid(x - 1, y) + grid(x + 1, y) + grid(x - 1, y + 1) + grid(x, y + 1) + grid(x + 1, y + 1)
            If nsum < 4 Then
            newgrid(x, y) = 0
            picked = picked + 1
            Else
            newgrid(x, y) = 1
            End If
        Else
        newgrid(x, y) = grid(x, y)
        End If
        Next x
    Next y
tpicked = tpicked + picked
grid = newgrid
Loop

Debug.Print tpicked

End Sub

2

u/Way2trivial 475 Dec 04 '25 edited Dec 04 '25

laugh.. I'm so decaffeinated-

I missed the ! and was trying to figure out what the hell the input function is.

do wish I'd thought of using all 9 cells and summing from 5 instead I built a kludgy 8 box list and looked for 4..... =HSTACK(A1:C1,A2,C2,A3:C3) equivalent

2

u/khosrua 16 Dec 05 '25

just did the old and reliable relative reference to get a count and summed:

The questions so far has been basically learning a crap ton of dynamic range that i havent needed for work yet and resist the urge just use relative reference and drag as the real input is much bigger

2

u/SheepiCagio 1 Dec 04 '25

Input in A1:A139

P1:

=LET(

map;TOCOL(DROP(REDUCE(0;A1:A139;LAMBDA(a;v;VSTACK(a;MID(v;SEQUENCE(LEN(v));1))));1));

addr;FILTER(TOCOL(SEQUENCE(LEN(A1);;10000;10000)+SEQUENCE(;LEN(A1)));map="@");

remainingaddr;FILTER(addr;MAP(addr;LAMBDA(a;--(SUM(--(ISNUMBER(

XMATCH(a+{10000;-10000;1;-1;10001;-10001;-9999;9999};addr;0))))>=4))));

rows(addr)-rows(remainingaddr))

P2:

=LET(

map;TOCOL(DROP(REDUCE(0;A1:A139;LAMBDA(a;v;VSTACK(a;MID(v;SEQUENCE(LEN(v));1))));1));

addr;FILTER(TOCOL(SEQUENCE(LEN(A1);;10000;10000)+SEQUENCE(;LEN(A1)));map="@");

remainingaddr;REDUCE(addr;SEQUENCE(55);LAMBDA(acc;v;

FILTER(acc;MAP(acc;LAMBDA(a;--(SUM(--(ISNUMBER(

XMATCH(a+{10000;-10000;1;-1;10001;-10001;-9999;9999};acc;0))))>=4))))));

ROWS(addr)-ROWS(remaining))

2

u/Anonymous1378 1542 Dec 04 '25 edited Dec 04 '25

Part 1

=LET(data,A13:A151,size,MAX(LEN(data)),
buffer,MID(VSTACK(REPT(".",size+2),"."&data&".",REPT(".",size+2)),SEQUENCE(,size+2),1),
check,MAKEARRAY(ROWS(data),size,LAMBDA(r,c,IF(INDEX(buffer,r+1,c+1)="@",SUM(--((INDEX(buffer,r+1+{-1,-1,-1;0,0,0;1,1,1},c+1+{-1,0,1;-1,0,1;-1,0,1}))="@")),""))),
SUM(--(check<=4)))

Part 2 (where I had to throw my Part 1 approach in the trash as MAKEARRAY(INDEX()) wasn't optimized enough for excel for the web)

=LET(data,A13:A151,size,MAX(LEN(data)),grid,{1,1,1,1;1,1,1,-1;1,-1,1,-1;1,-1,-1,-1;-1,1,1,1;-1,1,-1,1;-1,-1,-1,1;-1,-1,-1,-1},
matrix,SUBSTITUTE(SUBSTITUTE(data,"@","1"),".","0"),
loop,LAMBDA(a,b,c,LET(
buffer,--MID(VSTACK(REPT(0,size+2),0&b&0,REPT(0,size+2)),SEQUENCE(,size+2),1),
check,REDUCE(0,SEQUENCE(8),LAMBDA(x,y,x+DROP(DROP(buffer,INDEX(grid,y,1),INDEX(grid,y,2)),INDEX(grid,y,3),INDEX(grid,y,4)))),
IF(c=0,b,a(a,BYROW(IF(check<4,0,DROP(DROP(buffer,1,1),-1,-1)),CONCAT),SUM(--(DROP(DROP(buffer,1,1),-1,-1)*(check<4))))))),
result,loop(loop,matrix,1),
SUM(--(MID(result,SEQUENCE(,size),1)<>MID(matrix,SEQUENCE(,size),1))))

2

u/RackofLambda 12 Dec 04 '25

Part 1:

C2: =MID(A:.A,SEQUENCE(,MAX(LEN(A:.A))),1)

N2: =SUM(--MAP(C2#,OFFSET(C2#,-1,-1),OFFSET(C2#,1,1),LAMBDA(v,a,b,IF(v="@",SUM(N(a:b="@"))<5))))

Part 2:

=LET(
fn, LAMBDA(me,arr,[acc], LET(
h, ROWS(arr)+1,
w, COLUMNS(arr)+1,
i, EXPAND("",h+1,,""),
j, EXPAND("",,w,""),
a, HSTACK(i,VSTACK(j,EXPAND(arr,h,w,""))),
v, MAP({0;2;1;1;-2;2;-2;2},{1;1;0;2;-2;-2;2;2},{-2;0;-1;-1;0;0;0;0},{-1;-1;-2;0;0;0;0;0},
LAMBDA(_r1,_c1,_r2,_c2, LET(x, DROP(DROP(a,_r1,_c1),_r2,_c2)="@", LAMBDA(x)))),
b, IF(arr="@",REDUCE((@v)(),DROP(v,1),LAMBDA(acc,cur,acc+cur()))<4),
c, SUM(--b),
IF(c,me(me,IF(b,"",arr),acc+c),acc) )
),
fn(fn,MID(A:.A,SEQUENCE(,MAX(LEN(A:.A))),1))
)

1

u/Decronym Dec 04 '25 edited Dec 05 '25

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:

Fewer LettersMore Letters
BYROWOffice 365+: Applies a LAMBDA to each row and returns an array of the results. For example, if the original array is 3 columns by 2 rows, the returned array is 1 column by 2 rows.
CONCAT2019+: Combines the text from multiple ranges and/or strings, but it doesn't provide the delimiter or IgnoreEmpty arguments.
COUNTACounts how many values are in the list of arguments
COUNTIFSExcel 2007+: Counts the number of cells within a range that meet multiple criteria
DROPOffice 365+: Excludes a specified number of rows or columns from the start or end of an array
FILTEROffice 365+: Filters a range of data based on criteria you define
HSTACKOffice 365+: Appends arrays horizontally and in sequence to return a larger array
IFSpecifies a logical test to perform
IFERRORReturns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula
IFS2019+: Checks whether one or more conditions are met and returns a value that corresponds to the first TRUE condition.
INDEXUses an index to choose a value from a reference or array
ISNUMBERReturns TRUE if the value is a number
LAMBDAOffice 365+: Use a LAMBDA function to create custom, reusable functions and call them by a friendly name.
LENReturns the number of characters in a text string
LETOffice 365+: Assigns names to calculation results to allow storing intermediate calculations, values, or defining names inside a formula
MAKEARRAYOffice 365+: Returns a calculated array of a specified row and column size, by applying a LAMBDA
MAPOffice 365+: Returns an array formed by mapping each value in the array(s) to a new value by applying a LAMBDA to create a new value.
MAXReturns the maximum value in a list of arguments
MIDReturns a specific number of characters from a text string starting at the position you specify
OFFSETReturns a reference offset from a given reference
ORReturns TRUE if any argument is TRUE
REDUCEOffice 365+: Reduces an array to an accumulated value by applying a LAMBDA to each value and returning the total value in the accumulator.
REPTRepeats text a given number of times
ROWSReturns the number of rows in a reference
SEQUENCEOffice 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
SUBSTITUTESubstitutes new text for old text in a text string
SUMAdds its arguments
TAKEOffice 365+: Returns a specified number of contiguous rows or columns from the start or end of an array
TOCOLOffice 365+: Returns the array in a single column
VSTACKOffice 365+: Appends arrays vertically and in sequence to return a larger array
XMATCHOffice 365+: Returns the relative position of an item in an array or range of cells.

Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.


Beep-boop, I am a helper bot. Please do not verify me as a solution.
31 acronyms in this thread; the most compressed thread commented on today has 24 acronyms.
[Thread #46473 for this sub, first seen 4th Dec 2025, 13:27] [FAQ] [Full list] ^[Contact] [Source code]