r/excel • 647 • Dec 05 '25

Discussion Advent of Code 2025 Day 5

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

Today's puzzle "Cafeteria" link below.

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

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.

3 Upvotes

7 comments sorted by

1

u/Downtown-Economics26 647 Dec 05 '25

Was able to do Part 1 in a single formula, not sure if I'll get Part 2 that way:

=LET(nums,--FILTER(A.:.A,(LEN(A.:.A)>0)*(NOT(ISNUMBER(SEARCH("-",A.:.A))))),

rngs,FILTER(A.:.A,(LEN(A.:.A)>0)*(ISNUMBER(SEARCH("-",A.:.A)))),

rs,--TEXTBEFORE(rngs,"-"),

rf,--TEXTAFTER(rngs,"-"),

out,SUM(BYROW(nums,LAMBDA(x,--ISNUMBER(XMATCH(1,(x>=rs)*(x<=rf),0))))),

out)

2

u/Anonymous1378 1542 Dec 05 '25

Part 1

=LET(rng,--TEXTAFTER(TEXTBEFORE(A4140:A4324,"-",SEQUENCE(,2),,1),"-",-1,,1),
SUM(BYROW(A4326:A5325,LAMBDA(x,SIGN(SUM((x>=CHOOSECOLS(rng,1))*(x<=CHOOSECOLS(rng,2))))))))

Part 2

=LET(rng,--TEXTAFTER(TEXTBEFORE(A4140:A4324,"-",SEQUENCE(,2),,1),"-",-1,,1),
loop,LAMBDA(u,oldv,oldw,v,w,IF(AND(oldv=v,oldw=w),HSTACK(v,w),u(u,v,w,
BYROW(v,LAMBDA(x,XLOOKUP(1,(CHOOSECOLS(SORT(rng),1)<=x)*(CHOOSECOLS(SORT(rng),2)>=x),CHOOSECOLS(SORT(rng),1)))),
BYROW(w,LAMBDA(y,XLOOKUP(1,(CHOOSECOLS(SORT(rng,2,-1),1)<=y)*(CHOOSECOLS(SORT(rng,2,-1),2)>=y),CHOOSECOLS(SORT(rng,2,-1),2))))))),
result,UNIQUE(loop(loop,,,CHOOSECOLS(rng,1),CHOOSECOLS(rng,2))),
SUM(CHOOSECOLS(result,2)-CHOOSECOLS(result,1)+1))

2

u/RackofLambda 12 Dec 05 '25

Part 1:

=LET(
rng, A:.A,
_br, XMATCH(,rng),
one, TAKE(rng,_br-1),
two, --TOROW(TAKE(rng,_br-ROWS(rng))),
low, --TEXTBEFORE(one,"-"),
upp, --TEXTAFTER(one,"-"),
SUM(--BYCOL((two>=low)*(two<=upp),OR))
)

Part 2:

=LET(
cId, {1,2},
BTWN, LAMBDA(val,a,b,AND(val>=a,val<=b)),
VALS, LAMBDA([a],[b],LAMBDA(x,CHOOSE(x,a,b))),
XARR, LAMBDA(vec,MAP(IFNA(vec,cId),IFNA(cId,vec),LAMBDA(f,x,f(x)))),
fn, LAMBDA(me,arr,[acc],
IF(IFERROR(AND(arr=acc),0),
SUM(DROP(arr,,1)-TAKE(arr,,1)+1),
me(me, UNIQUE(SORT(XARR(
SCAN(VALS(), MAP(TAKE(arr,,1),DROP(arr,,1),VALS), LAMBDA(a,v,
IF(BTWN(v(1),a(1),a(2)),
IF(BTWN(v(2),a(1),a(2)), VALS(a(1),a(2)), VALS(a(2)+1,v(2))),
VALS(v(1),v(2)))))), cId)), arr))),
fn(fn, SORT(--TEXTSPLIT(TEXTAFTER("-"&A1:A200,"-",cId),"-"),cId))
)

1

u/RackofLambda 12 Dec 06 '25

After taking a second look at this, I noticed that 2 of the unpacking/repacking VALS calls are redundant and can be simplified by replacing VALS(a(1),a(2)) with a and VALS(v(1),v(2)) with v.

Originally, I had prepared a simple SEQUENCE-based solution but had to throw that out the window after receiving my input dataset. I guess that's why it's called a challenge, lol.

2

u/Way2trivial 475 Dec 05 '25

The damn elves have 100's of trillions.. omfg.... I can't believe I worked it out.

I wound up MIN(filtering) the low side of each range against all ranges for a min if included, and manually pasting the result it recursively over the min range...
then doing it again for the maximums, the uniqueing all the ranges..

there are 8 ranges that had me stuck for a moment, as they are a same number-same number range.. urgh....

2

u/SheepiCagio 1 Dec 05 '25

P1:

=SUM(--(MAP(C176:C1175;LAMBDA(a;
REDUCE(0;C1:C174;LAMBDA(x;y;
x+AND(a>=--TEXTBEFORE(y;"-");a<=--TEXTAFTER(y;"-"))))))>0))

P2:

=LET(start;--TEXTBEFORE(C1:C174;"-");

end;--TEXTAFTER(C1:C174;"-");

sorted;SORTBY(HSTACK(start;end);start;1;end;1);

ans;SCAN(0;SEQUENCE(ROWS(start));LAMBDA(a;v;(

IF(INDEX(sorted;v;2)<=IFERROR(MAX(TAKE(sorted;v-1;-1));0);0;

IF(INDEX(sorted;v;1)<=MAX(IFERROR(TAKE(sorted;v-1;-1);0));INDEX(sorted;v;2)-MAX(IFERROR(TAKE(sorted;v-1;-1);0));

INDEX(sorted;v;2)-INDEX(sorted;v;1)+1)))

));

1

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

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

Fewer LettersMore Letters
ANDReturns TRUE if all of its arguments are TRUE
BYCOLOffice 365+: Applies a LAMBDA to each column and returns an array of the results
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.
CHOOSEChooses a value from a list of values
CHOOSECOLSOffice 365+: Returns the specified columns from an array
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
IFNAExcel 2013+: Returns the value you specify if the expression resolves to #N/A, otherwise returns the result of the expression
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
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
MINReturns the minimum value in a list of arguments
NOTReverses the logic of its argument
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.
ROWSReturns the number of rows in a reference
SCANOffice 365+: Scans an array by applying a LAMBDA to each value and returns an array that has each intermediate value.
SEARCHFinds one text value within another (not case-sensitive)
SEQUENCEOffice 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
SIGNReturns the sign of a number
SORTOffice 365+: Sorts the contents of a range or array
SORTBYOffice 365+: Sorts the contents of a range or array based on the values in a corresponding range or array
SUMAdds its arguments
TAKEOffice 365+: Returns a specified number of contiguous rows or columns from the start or end of an array
TEXTAFTEROffice 365+: Returns text that occurs after given character or string
TEXTBEFOREOffice 365+: Returns text that occurs before a given character or string
TEXTSPLITOffice 365+: Splits text strings by using column and row delimiters
TOROWOffice 365+: Returns the array in a single row
UNIQUEOffice 365+: Returns a list of unique values in a list or range
XLOOKUPOffice 365+: Searches a range or an array, and returns an item corresponding to the first match it finds. If a match doesn't exist, then XLOOKUP can return the closest (approximate) match.
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.
[Thread #46488 for this sub, first seen 5th Dec 2025, 14:04] [FAQ] [Full list] ^[Contact] [Source code]