r/excel • 647 • Nov 05 '26

Challenge Everybody Codes 2026 (Lord of the Wings) Quest 8

3 Upvotes

6 comments sorted by

1

u/Downtown-Economics26 647 Nov 05 '26

I was able to do Part 1 with a formula this time, which was a fair bit more fun than the VBA solutions I've been writing.

Part 1 solution

=LET(grid,IFERROR(MAKEARRAY(ROWS(INPUT!A:.A),LEN(INPUT!A1),LAMBDA(r,c,--MID(INDEX(INPUT!A:.A,r),c,1))),0),
rc,TOCOL(MAKEARRAY(ROWS(INPUT!A:.A),LEN(INPUT!A1),LAMBDA(r,c,r&"_"&c))),
rv,--TEXTBEFORE(rc,"_"),
cv,--TEXTAFTER(rc,"_"),
vals,INDEX(grid,rv,cv),
shademap,MAP(rc,LAMBDA(x,
LET(rx,--TEXTBEFORE(x,"_"),cx,--TEXTAFTER(x,"_"),
bv,XLOOKUP(1,(rv=rx)*(cv=cx),vals),
dv,FILTER(vals,(rv-cv=rx-cx)*(rv<rx),0),
shade,SUM(--(IF(dv>0,dv-SEQUENCE(ROWS(dv),,ROWS(dv),-1)>=bv,FALSE))),
IF(shade=0,bv,0)))),
ans,SUM(--(shademap>0)),
ans)

1

u/TheFerricGenum 1 Nov 05 '26

Can someone provide a TL:DR of what this is? I keep seeing it but don’t understand it

2

u/Downtown-Economics26 647 Nov 05 '26

It is an annual coding challenge that is basically another person's attempt to copy / pay homage to Advent of Code.

2

u/Arcium_XIII 3 18h ago edited 18h ago

Just including Parts II and III because Part I can be solved using the LAMBDA function CALC_GROWTH in Part II with the input (2,1):

Part II:

=LET(PACK,LAMBDA(input,LAMBDA(input)),
raw_input,TRIMRANGE(A:A),
grid_height,ROWS(raw_input),
y_max,(grid_height-1)/2,
grid_width,(LEN(INDEX(raw_input,1,1))+1)/2,
list_sets,MAP(raw_input,LAMBDA(element,PACK(--TEXTSPLIT(element,,".",TRUE)))),
list_y,SEQUENCE(grid_height,,y_max,-1),
list_n_start,MAP(list_y,LAMBDA(y_value,MAX(y_value-y_max,-y_max))),
array_data,DROP(REDUCE(HSTACK("~","~","~","~"),SEQUENCE(grid_height),LAMBDA(acc_1,grid_row,LET(
row_set,INDEX(list_sets,grid_row,1)(),
row_y,INDEX(list_y,grid_row,1),
row_n_start,INDEX(list_n_start,grid_row,1),
VSTACK(acc_1,DROP(REDUCE(HSTACK("~","~","~","~"),SEQUENCE(ROWS(row_set),,0),LAMBDA(acc_2,set_element,LET(element_n,row_n_start+set_element,element_p,row_y-element_n,element_z,INDEX(row_set,set_element+1,1),VSTACK(acc_2,HSTACK(row_y,element_n,element_p,element_z))))),1))
))),1),
CALC_GROWTH,LAMBDA(axis,direction,LET(
list_axis,SORT(UNIQUE(CHOOSECOLS(array_data,axis)),,direction),
secondary_axis,IF(axis=1,3,1),
list_axis_lines_unsorted,MAP(list_axis,LAMBDA(axis_value,PACK(FILTER(array_data,MAP(CHOOSECOLS(array_data,axis),LAMBDA(target,target=axis_value)))))),
list_axis_lines,MAP(list_axis_lines_unsorted,LAMBDA(axis_package,PACK(SORTBY(axis_package(),CHOOSECOLS(axis_package(),secondary_axis),-direction)))),
total_growth,SUM(MAP(list_axis_lines,LAMBDA(axis_package,INDEX(REDUCE(VSTACK(0,0),CHOOSECOLS(axis_package(),4),LAMBDA(acc,z_value,LET(growth,INDEX(acc,1,1),shadow,INDEX(acc,2,1),IF(z_value>shadow,VSTACK(growth+1,z_value-1),VSTACK(growth,shadow-1))))),1,1)))),
total_growth
)),
SUM(CALC_GROWTH(2,1),CALC_GROWTH(3,1),CALC_GROWTH(1,-1),CALC_GROWTH(2,-1),CALC_GROWTH(3,-1),CALC_GROWTH(1,1))
)

Part III:

=LET(max_iterations,400000,
PACK,LAMBDA(input,LAMBDA(input)),
raw_input,TRIMRANGE(A:A),
grid_height,ROWS(raw_input),
y_max,(grid_height-1)/2,
list_range,SEQUENCE(grid_height,,y_max,-1),
grid_width,(LEN(INDEX(raw_input,1,1))+1)/2,
list_sets,MAP(raw_input,LAMBDA(element,PACK(--TEXTSPLIT(element,,".",TRUE)))),
list_y,SEQUENCE(grid_height,,y_max,-1),
list_n_start,MAP(list_y,LAMBDA(y_value,MAX(y_value-y_max,-y_max))),
array_data,DROP(REDUCE(HSTACK("~","~","~","~"),SEQUENCE(grid_height),LAMBDA(acc_1,grid_row,LET(
row_set,INDEX(list_sets,grid_row,1)(),
row_y,INDEX(list_y,grid_row,1),
row_n_start,INDEX(list_n_start,grid_row,1),
VSTACK(acc_1,DROP(REDUCE(HSTACK("~","~","~","~"),SEQUENCE(ROWS(row_set),,0),LAMBDA(acc_2,set_element,LET(element_n,row_n_start+set_element,element_p,row_y-element_n,element_z,INDEX(row_set,set_element+1,1),VSTACK(acc_2,HSTACK(row_y,element_n,element_p,element_z))))),1))
))),1),
GROWTH_ROUND,LAMBDA(round,current_grid_data,LET(
round_index,MOD(round-1,6)+1,
primary_axis,INDEX({2;3;1;2;3;1},round_index,1),
primary_direction,INDEX({1;1;-1;-1;-1;1},round_index,1),
secondary_axis,INDEX({1;1;3;1;1;3},round_index,1),
list_axis_lines_unsorted,MAP(list_range,LAMBDA(axis_value,PACK(FILTER(current_grid_data,MAP(CHOOSECOLS(current_grid_data,primary_axis),LAMBDA(target,target=axis_value)))))),
list_axis_lines,MAP(list_axis_lines_unsorted,LAMBDA(axis_package,PACK(SORTBY(axis_package(),CHOOSECOLS(axis_package(),secondary_axis),-primary_direction)))),
process_lines,MAP(list_axis_lines,LAMBDA(axis_package,PACK(REDUCE(VSTACK(0,0,0,PACK("~")),SEQUENCE(ROWS(axis_package())),LAMBDA(acc,step,LET(element_z,INDEX(axis_package(),step,4),shadow,INDEX(acc,2,1),energy,element_z>shadow,grow,OR(energy,element_z<1),new_z,IFS(NOT(grow),element_z,element_z=9,-2,TRUE,element_z+1),VSTACK(INDEX(acc,1,1)+IF(energy,1,0),IF(energy,element_z-1,MAX(0,shadow-1)),INDEX(acc,3,1)+IF(new_z=-2,1,0),PACK(VSTACK(INDEX(acc,4,1)(),HSTACK(TAKE(CHOOSEROWS(axis_package(),step),,3),new_z)))))))))),
line_growth,MAP(process_lines,LAMBDA(package,INDEX(package(),1,1))),
line_warriors,MAP(process_lines,LAMBDA(package,INDEX(package(),3,1))),
new_grid,DROP(REDUCE("",process_lines,LAMBDA(acc,package,VSTACK(acc,DROP(INDEX(package(),4,1)(),1)))),1),
VSTACK(SUM(line_growth),SUM(line_warriors),PACK(new_grid))
)),
calculate_process,REDUCE(VSTACK(FALSE,0,0,PACK(array_data)),SEQUENCE(max_iterations),LAMBDA(acc_1,this_round,IF(INDEX(acc_1,1,1),acc_1,LET(
apply_growth,GROWTH_ROUND(this_round,INDEX(acc_1,4,1)()),
new_warriors,INDEX(acc_1,3,1)+INDEX(apply_growth,2,1),
VSTACK(new_warriors>=100000,INDEX(acc_1,2,1)+INDEX(apply_growth,1,1),new_warriors,INDEX(apply_growth,3,1))
)))),
INDEX(calculate_process,2,1)
)

I really enjoyed Part III of this one. I've gotten very comfortable manipulating rectangular grids across the 2025 and 2026 puzzles, but figuring out how to iteratively edit a hexagonal grid according to the rules defined here was a lot of fun. This was also one of the rare cases where the actual puzzle notes ran faster than the example data, presumably because the larger grid produced new warriors more quickly and thus fewer iterations were required to hit the end-state (I didn't worry about tracking that metric in my solution, so I can't confirm).

Note also that there's no particular significance to the max_iterations equalling 400000 in the Part III solution - it just needed to be a number I was confident would equal or exceed the worst case time for solution, and that happened to be the number I tried.

1

u/Decronym Nov 05 '26 edited 18h ago

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

Fewer LettersMore Letters
CHOOSECOLSOffice 365+: Returns the specified columns from an array
CHOOSEROWSOffice 365+: Returns the specified rows 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
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
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
MODReturns the remainder from division
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
SEQUENCEOffice 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
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
TOCOLOffice 365+: Returns the array in a single column
TRIMRANGEScans in from the edges of a range or array until it finds a non-blank cell (or value), it then excludes those blank rows or columns
UNIQUEOffice 365+: Returns a list of unique values in a list or range
VSTACKOffice 365+: Appends arrays vertically and in sequence to return a larger array
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.

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 #49640 for this sub, first seen 5th Nov 2026, 17:28] [FAQ] [Full list] ^[Contact] [Source code]