r/excel • 647 • Dec 01 '25

Discussion Advent of Code 2025 Day 1

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

Today's puzzle "Secret Entrance" link below.

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

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.

37 Upvotes

20 comments sorted by

3

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

Part 1:

=LET(vals,SCAN(50,FILTER(A.:.A,A.:.A<>""),LAMBDA(a,v,

LET(dir,LEFT(v,1),

turns,--RIGHT(v,LEN(v)-1),

MOD(a+IF(dir="L",turns*-1,turns),100)))),

SUM(--(vals=0)))

Part 2:

For part 2, I couldn't quite figure out how to do in one formula easily. So I used part 1 solution and made it give the position for each move in column C and then put number of turns in column D. In column E in cell D2 i put this value and dragged down, it has a ref error for first row. This gave me number of 0s per instruction which I then summed.

=LET(sq,SEQUENCE(,D2+1,IF(ROW(A2)=1,50,C1),IF(LEFT(A2,1)="L",-1,1)),

ans,SUM(--(DROP(MOD(sq,100),,1)=0)),

ans)

Edit: posted the wrong function orginally with the #REF from a relative reference in the first.

Edit 2: Fixed Part 1 solution I actually used instead of the modified part 2 version of it.

3

u/PaulieThePolarBear 1927 Dec 01 '25

I've completed Part 1 and will post my solution as a top level comment. Part 2 will need to wait for later in my day.

For your part 1, this appears to return the position after each movement, rather than the count of times that this was 0. Do you have a COUNTIFS (or similar) to return this result?

2

u/Downtown-Economics26 647 Dec 01 '25

Ahhh, I accidentally posted the wrong thing (adapted for my not elegant part 2 solution)

I put in what I actually used now in the edited post.

2

u/ExtraordinaryKaylee Dec 01 '25

I clearly need to practice some of these functions, because doing part 2 in Excel has me frustrated :smile_sweat:

I'm about to go build a whole state machine, and I'm mad at myself for resorting to that.

2

u/Perohmtoir 51 Dec 01 '25 edited Dec 01 '25

Part 1:

=LET(res,SCAN(50,A1:A4432,LAMBDA(x,rng,LET(tmp,x+(1-2*(LEFT(rng,1)="L"))*MOD(INT(RIGHT(rng,LEN(rng)-1)),100),MOD(IF(tmp<0,100+tmp,IF(tmp>100,tmp-100,tmp)),100)))),COUNT(FILTER(res,res=0)))

Part 2. Doing it into a single formula required an inelegant trickery.

=SUM(LET(res,SCAN("50;0",A1:A4432,LAMBDA(txt,rng,LET(x,INT(INDEX(TEXTSPLIT(txt,";"),1,1)),
tmp,x+(1-2*(LEFT(rng,1)="L"))*MOD(INT(RIGHT(rng,LEN(rng)-1)),100),
tmpb,MOD(IF(tmp<0,100+tmp,IF(tmp>100,tmp-100,tmp)),100),tmpb&";"&INT(RIGHT(rng,LEN(rng)-1)/100)+IF(x=0,0,IF(tmpb=0,1,IF(tmp<0,1,IF(tmp>100,1,IF(tmp=100,1,0)))))))),
MAP(res,LAMBDA(y,INT(INDEX(TEXTSPLIT(y,";"),1,2))))))

Part 2 without the single formula constraint (less time spent on trickery), using columns B and C:

B1:

=VSTACK(50,LET(res,SCAN(50,A1:A4432,LAMBDA(x,rng,LET(tmp,x+(1-2*(LEFT(rng,1)="L"))*MOD(INT(RIGHT(rng,LEN(rng)-1)),100),MOD(IF(tmp<0,100+tmp,IF(tmp>100,tmp-100,tmp)),100)))),res))

C2, extended down, summed.

=LET(tmp,B1+(1-2*(LEFT(A1,1)="L"))*MOD(INT(RIGHT(A1,LEN(A1)-1)),100),INT(RIGHT(A1,LEN(A1)-1)/100)+IF(B1=0,0,IF(B2=0,1,IF(tmp<0,1,IF(tmp>100,1,IF(tmp=100,1,0))))))

2

u/Downtown-Economics26 647 Dec 01 '25

Very nice! I was trying to refactor my solution into a single formula and was heading this direction and got tired of trying to figure it out.

2

u/Perohmtoir 51 Dec 01 '25 edited Dec 01 '25

During last year AoC I am pretty sure some exercice had working solutions using arrays for SCAN initial_value argument. I might take a look at it again: it might be easier to handle compared to my method. Although this might be entering "science has gone too far" territory.

2

u/Downtown-Economics26 647 Dec 01 '25

Yeah, I mean, I figured I had to be able to do Day 1 in only formulas, if not a single formula. It's funny that Excel functions can express some algorithms so succinctly but anything that needs even one nested for loop within another becomes a frankenformula.

5

u/TooCupcake Dec 01 '25

This is a lot of fun, I feel like an accomplished Excel user now lol.

Thank you for sharing, I’ll be following along.

4

u/Anonymous1378 1542 Dec 02 '25 edited Dec 03 '25

Part one:

=SUM(--(SCAN(50,--SUBSTITUTE(SUBSTITUTE(A31:A4134,"R",""),"L","-"),LAMBDA(x,y,MOD(x+y,100)))=0))

Part two

=LET(_a,SCAN(50,--SUBSTITUTE(SUBSTITUTE(A31:A4134,"R",""),"L","-"),LAMBDA(x,y,x+y)), REDUCE(0,SEQUENCE(ROWS(_a)-1)+1,LAMBDA(v,w,v+ABS((FLOOR.MATH(INDEX(_a,w),100)-FLOOR.MATH(INDEX(_a,w-1),100))/100))))

Hindsight EDIT - REDUCE is not needed here:

=LET(_a,SCAN(50,--SUBSTITUTE(SUBSTITUTE(A31:A4134,"R",""),"L","-"),LAMBDA(x,y,x+y)),

SUM(ABS((FLOOR.MATH(DROP(_a,1),100)-FLOOR.MATH(DROP(_a,-1),100))/100)))

Part two did get me the answer required, but I'm not entirely sure how robust it is. I have a sneaking suspicion that it doesn't cover some edge cases, but perhaps I got lucky.

1

u/InspectorGreen4547 Dec 03 '25

I am confused how you have a range of A31:A4134, but there are 4,545 items in the input list. Were we each given a different number of input values?

2

u/Anonymous1378 1542 Dec 03 '25

Yes, everyone has different puzzle inputs, by design.

3

u/Lalo_ATX Dec 01 '25 edited Dec 01 '25

I don't like cramming all the logic into a single cell, so I did it with stepwise array columns. You could put each of these steps into a single LET() statement, I just don't prefer that.

Assume your input is in column A. All the formulas are in columns B through G. Columns B through F are just setup, the magic is in column G.

B1: =MAP(A:.A,LAMBDA(x,IF(LEFT(x,1)="L",-1,1)))
C1: =MAP(A:.A,LAMBDA(x,RIGHT(x,LEN(x)-1)+0))
D1: =B1#*C1#
E1: =VSTACK({50},DROP(F1#,-1))
F1: =SCAN(50,D1#,LAMBDA(a,b,a+b))
G1: =LET(_bq,MAP(B1#*E1#,LAMBDA(x,FLOOR.MATH(x/100))),_aq,MAP(B1#*F1#,LAMBDA(x,FLOOR.MATH(x/100))),ABS(_aq-_bq))

and the answer is the sum of column G =SUM(G1#)

My friend figured out the elegant math in column G, I'm genuinely impressed by it, it naturally avoids double-counting when a turn begins on a zero, without an IF.

2

u/PaulieThePolarBear 1927 Dec 01 '25

Part 1

=LET(
a,A1:A4503,
b, SCAN(50, a, LAMBDA(x,y, MOD(x+IF(LEFT(y)="R",1,-1)*REPLACE(y, 1, 1,),100))),
c, SUM(--(b=0)),
c)

Part 2 to follow later in my day

2

u/Altruistic-Worry-919 Dec 01 '25

skills hitting different now lol keep at it

2

u/PaulieThePolarBear 1927 Dec 02 '25

Part 1 here

Part 2

=LET(

a, A1:A4503,

b, 50,

c, LEFT(a),

d, --REPLACE(a, 1, 1,),

e, SCAN(b, SEQUENCE(ROWS(a)), LAMBDA(x,y, MOD(x+IF(INDEX(c,y)="R",1,-1)*INDEX(d, y),100))),

f, VSTACK(b, DROP(e,-1)),

g, QUOTIENT(d, 100) + (f<>0)*IF(c="R", e<f, (e>f)+(e=0)),

h, SUM(g),

h

)

1

u/Decronym Dec 01 '25 edited Dec 03 '25

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

Fewer LettersMore Letters
ABSReturns the absolute value of a number
COUNTCounts how many numbers 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
FLOORRounds a number down, toward zero
IFSpecifies a logical test to perform
INDEXUses an index to choose a value from a reference or array
INTRounds a number down to the nearest integer
LAMBDAOffice 365+: Use a LAMBDA function to create custom, reusable functions and call them by a friendly name.
LEFTReturns the leftmost characters from a text value
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.
MIDReturns a specific number of characters from a text string starting at the position you specify
MODReturns the remainder from division
ORReturns TRUE if any argument is TRUE
QUOTIENTReturns the integer portion of a division
REDUCEOffice 365+: Reduces an array to an accumulated value by applying a LAMBDA to each value and returning the total value in the accumulator.
REPLACEReplaces characters within text
RIGHTReturns the rightmost characters from a text value
ROUNDRounds a number to a specified number of digits
ROWReturns the row number of a reference
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.
SEQUENCEOffice 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
SIGNReturns the sign of a number
SUBSTITUTESubstitutes new text for old text in a text string
SUMAdds its arguments
TEXTSPLITOffice 365+: Splits text strings by using column and row delimiters
VSTACKOffice 365+: Appends arrays vertically and in sequence to return a larger array

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 #46425 for this sub, first seen 1st Dec 2025, 18:03] [FAQ] [Full list] ^[Contact] [Source code]

1

u/SheepiCagio 1 Dec 03 '25

P1:

=SUM(--(SCAN(50;A13:A4420;LAMBDA(a;v;LET(x;IF(LEFT(v)="L";-1;1);MOD(a+--MID(v;2;10)*x;100))))=0))

P2:

=SUM(LET(in;A13:A4420;

pos;SCAN(50;in;LAMBDA(a;v;LET(x;IF(LEFT(v)="L";-1;1);MOD(a+--MID(v;2;10)*x;100))));

chng;MID(in;2;10)*IF(LEFT(in)="R";1;-1);prev;MOD(pos+chng*-1;100);

MAP(prev;chng;INT(ABS(chng)/100);LAMBDA(a;b;d;

d+IF(a=0;0;

IF(OR(ROUND(a+(b/100-INT(ABS(b/100))*SIGN(b))*100;0)>=100;

ROUND(a+(b/100-INT(ABS(b/100))*SIGN(b))*100;0)<=0);1;0))))))

1

u/RackofLambda 12 Dec 03 '25

Part 1:

=SUM(N(NOT(SCAN(50,-SUBSTITUTE(SUBSTITUTE(A:.A,"R","-"),"L",),LAMBDA(a,v,MOD(SUM(a,v),100))))))

Part 2:

=LET(VALS,LAMBDA(a,[b],LAMBDA(x,CHOOSE(x,a,b))),REDUCE(VALS(50),-SUBSTITUTE(SUBSTITUTE(A:.A,"R","-"),"L",),LAMBDA(a,v,LET(i,MOD(a(1)+SEQUENCE(ABS(v))*SIGN(v),100),VALS(TAKE(i,-1),SUM(a(2),N(NOT(i)))))))(2))

0

u/Party-Sherbet-2063 Dec 01 '25

is the best for feeling smart without trying too hard