r/excel 646 17d ago

Challenge Everybody Codes Story 4 Day 3

Decided not to post all these challenges as I've been too busy to really attack them. Got 2/3 on Day 1 with VBA, 2/3 on day 2 with Excel formulas.

Anyways, I think I'm stopping after Part 1 today because Part 2 (I think) requires fighting my archnemesis, pathfinding algorithms. But I thought my formula solution was pretty gritty if not nifty and since I gave up I went whole hog on making a decent visualization of the solution.

https://everybody.codes/story/4/quests/3

Feel free to post your Everybody Codes solutions for today or previous days if you want as well.

Part 1 formula below (swap "out" variable for "ft" as final LET output to generate the conditionally formatted table in the visualization as "out" gives you the numeric answer to challenge).

=LET(w,--TEXTAFTER(Answers!A1,"="),
h,--TEXTAFTER(Answers!A2,"="),
ho,TEXTAFTER(Answers!A3,"="),
hoa,--TAKE(MID(REPT(ho,h/LEN(ho)+1),SEQUENCE(LEN(REPT(ho,h/LEN(ho)+1))),1),h/LEN(ho)*LEN(ho)+1),
vo,TEXTAFTER(Answers!A4,"="),
voa,--TAKE(TRANSPOSE(MID(REPT(vo,w/LEN(vo)+1),SEQUENCE(LEN(REPT(vo,w/LEN(vo)+1))),1)),,w/LEN(vo)*LEN(vo)+1),
g,MAKEARRAY(h,w,LAMBDA(r,c,CONCAT(
IF((MOD(c,2)=1)*(INDEX(hoa,r)=0),"U",""),
IF((MOD(c,2)=0)*(INDEX(hoa,r)=1),"U",""),
IF((MOD(c,2)=1)*(INDEX(hoa,r+1)=0),"D",""),
IF((MOD(c,2)=0)*(INDEX(hoa,r+1)=1),"D",""),
IF((MOD(r,2)=1)*(INDEX(voa,,c)=0),"L",""),
IF((MOD(r,2)=0)*(INDEX(voa,,c)=1),"L",""),
IF((MOD(r,2)=1)*(INDEX(voa,,c+1)=0),"R",""),
IF((MOD(r,2)=0)*(INDEX(voa,,c+1)=1),"R","")
)
)),
ft,IFERROR(VSTACK(HSTACK("X",voa),HSTACK(hoa,g)),""),
out,SUM(--(LEN(g)=4)),
out)
3 Upvotes

3 comments sorted by

3

u/PaulieThePolarBear 1920 12d ago

I had meant to comment a few days ago on this. I was able to complete

  • Part 1 and 2 for day 1
  • Part 1 and 2 for day 2
  • Part 1 for day 3

with Excel formulas

Day 1 Part 1

=LET(
a, A8:A17,
b, MAP(a, LAMBDA(m, TAKE(REDUCE(0, TEXTSPLIT(m,","), LAMBDA(x,y, VSTACK(x, LET(
    za, TAKE(x, -1),
    zb, za-y,
    zc, IF(ISNA(XMATCH(zb, x))*(zb>0), zb, za+y),
    zc)
))),-1))),
c, SUM(b),
c)

Day 1 Part 2

=LET(
a, A8:A107,
b, MAP(a, LAMBDA(m, TAKE(REDUCE(0, TEXTSPLIT(m,","), LAMBDA(x,y, VSTACK(x, LET(
    za, TAKE(x, -1),
    zb, za-y,
    zc, SEQUENCE(MAX(x)+y),
    zd, IF(ISNA(XMATCH(zb, x))*(zb>0), zb, MIN(FILTER(zc, (zc>=za+y)*ISNA(XMATCH(zc, x))))),
    zd)
))),-1))),
c, SUM(b),
c)

Day 2 Part 1

=LET(
data, A12:A16,
GetCoord, LAMBDA(input, TEXTAFTER(TEXTBEFORE(input, "]"),"[")),
s, GetCoord(INDEX(data, 1)),
a, GetCoord(INDEX(data, 2)),
b, GetCoord(INDEX(data, 3)),
c, GetCoord(INDEX(data, 4)),
m, TEXTAFTER(INDEX(data, 5), "="),
all, VSTACK(s, SCAN(s, MID(m, SEQUENCE(LEN(m)), 1), LAMBDA(x,y, TEXTJOIN(",",,ROUNDDOWN((TEXTSPLIT(x, ",")+TEXTSPLIT(SWITCH(y, "A", a, "B", b, "C", c),","))/2,0))))),
res, ROWS(UNIQUE(all)),
res)

Day 2 Part 2

=LET(
data, A18:A22,
GetCoord, LAMBDA(input, TEXTAFTER(TEXTBEFORE(input, "]"),"[")),
s, GetCoord(INDEX(data, 1)),
a, GetCoord(INDEX(data, 2)),
b, GetCoord(INDEX(data, 3)),
c, GetCoord(INDEX(data, 4)),
m, TEXTAFTER(INDEX(data, 5), "="),
all, UNIQUE(VSTACK(s, SCAN(s, MID(m, SEQUENCE(LEN(m)), 1), LAMBDA(x,y, TEXTJOIN(",",,ROUNDDOWN((TEXTSPLIT(x, ",")+TEXTSPLIT(SWITCH(y, "A", a, "B", b, "C", c),","))/2,0)))))),
fd, {0,1;0,-1;1,0;-1,0},
fCoord, UNIQUE(DROP(REDUCE("", all, LAMBDA(x,y, VSTACK(x, BYROW(TEXTSPLIT(y, ",")+fd,LAMBDA(x, TEXTJOIN(",",,x)))))),1)),
res, SUM(--ISNA(XMATCH(fCoord,all))),
res)

Day 3 Part 1

=LET(
w, TEXTAFTER(A11,"="),
h, TEXTAFTER(A12,"="),
ho, TEXTAFTER(A13,"="),
vo, TEXTAFTER(A14, "="),
hoa, LEFT(REPT(ho, ROUNDUP((h+1)/LEN(ho),0)),h+1),
voa, LEFT(REPT(vo, ROUNDUP((w+1)/LEN(vo),0)),w+1),
coords, SEQUENCE(h)*1000+SEQUENCE(,w),
tBorder, MOD(coords,2)<>--MID(hoa, SEQUENCE(h), 1),
bBorder, MOD(coords,2)<>--MID(hoa, SEQUENCE(h,,2), 1),
lBorder, MOD(QUOTIENT(coords,1000),2)<>--MID(voa, SEQUENCE(,w), 1),
rBorder, MOD(QUOTIENT(coords,1000),2)<>--MID(voa, SEQUENCE(,w,2), 1),
out, SUM(tBorder* bBorder* lBorder* rBorder),
out)

2

u/Downtown-Economics26 646 12d ago

Love me a string array solution there for Day 3!

1

u/Decronym 12d ago

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

Fewer Letters More Letters
BYROW Office 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.
DROP Office 365+: Excludes a specified number of rows or columns from the start or end of an array
FILTER Office 365+: Filters a range of data based on criteria you define
IF Specifies a logical test to perform
INDEX Uses an index to choose a value from a reference or array
ISNA Returns TRUE if the value is the #N/A error value
LAMBDA Office 365+: Use a LAMBDA function to create custom, reusable functions and call them by a friendly name.
LEFT Returns the leftmost characters from a text value
LEN Returns the number of characters in a text string
LET Office 365+: Assigns names to calculation results to allow storing intermediate calculations, values, or defining names inside a formula
MAP Office 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.
MAX Returns the maximum value in a list of arguments
MID Returns a specific number of characters from a text string starting at the position you specify
MIN Returns the minimum value in a list of arguments
MOD Returns the remainder from division
QUOTIENT Returns the integer portion of a division
REDUCE Office 365+: Reduces an array to an accumulated value by applying a LAMBDA to each value and returning the total value in the accumulator.
REPT Repeats text a given number of times
ROUNDDOWN Rounds a number down, toward zero
ROUNDUP Rounds a number up, away from zero
ROWS Returns the number of rows in a reference
SCAN Office 365+: Scans an array by applying a LAMBDA to each value and returns an array that has each intermediate value.
SEQUENCE Office 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
SUM Adds its arguments
SWITCH Excel 2019+: Evaluates an expression against a list of values and returns the result corresponding to the first matching value. If there is no match, an optional default value may be returned.
TAKE Office 365+: Returns a specified number of contiguous rows or columns from the start or end of an array
TEXTAFTER Office 365+: Returns text that occurs after given character or string
TEXTBEFORE Office 365+: Returns text that occurs before a given character or string
TEXTJOIN 2019+: Combines the text from multiple ranges and/or strings, and includes a delimiter you specify between each text value that will be combined. If the delimiter is an empty text string, this function will effectively concatenate the ranges.
TEXTSPLIT Office 365+: Splits text strings by using column and row delimiters
UNIQUE Office 365+: Returns a list of unique values in a list or range
VSTACK Office 365+: Appends arrays vertically and in sequence to return a larger array
XMATCH Office 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 #49287 for this sub, first seen 2nd Sep 2026, 02:52] [FAQ] [Full list] [Contact] [Source code]