Xlambda
Well-known Member
- Joined
- Mar 8, 2021
- Messages
- 860
- Office Version
- 365
- Platform
- Windows
WR: Word maze Results challenge. Please do see latest (26-Oct-21) YT video of MrExcel Solving Word Search With Excel (FMWC) - 2439
This is a compact set of functions that can solve all lookup scenarios.
Defined names: ar, sample array ( A1:T15 ) ; rw, nr. rows of sample array (15) (width is fixed to 20) ; cs, constant array values for "snake" lookup {-1,1, 20,-20} ; cd, constant array values for "diagonal" lookup {-21,-19,19,21}
WL(l)=LAMBDA(l,LET(x,IF(ar=l,1),y,IF(ar="?",1),z,IF(x+y,1),v,IF(z,SEQUENCE(rw,20)),SMALL(v,SEQUENCE(COUNT(v)))))
WA(a,c)=LAMBDA(a,c,LET(x,a-c,y,IF(x>0,x),UNIQUE(SMALL(y,SEQUENCE(COUNT(y ))))))
WB(a,b)=LAMBDA(a,b,FILTER(a,IFNA(XMATCH(a,b,,2),0)))
WR(w,c,[r],[i ])=LAMBDA(w,c,[r],[i ],LET(n,IF(i,i,LEN(w)),x,MID(w,n,1),y,MID(w,n-1,1),z,IF(AND(r=0),WA(WL(x),c),WA(r,c)),IF(n=1,r,WR(w,c,WB(z,WL(y )),n-1))))
Last one WR is !! recursive !! Define the names, then the functions and we are good to go. (Gaps in [i ] are to keep the text no to turn italics)
Will come back with the "concept" explanation asap.
This is a compact set of functions that can solve all lookup scenarios.
Defined names: ar, sample array ( A1:T15 ) ; rw, nr. rows of sample array (15) (width is fixed to 20) ; cs, constant array values for "snake" lookup {-1,1, 20,-20} ; cd, constant array values for "diagonal" lookup {-21,-19,19,21}
WL(l)=LAMBDA(l,LET(x,IF(ar=l,1),y,IF(ar="?",1),z,IF(x+y,1),v,IF(z,SEQUENCE(rw,20)),SMALL(v,SEQUENCE(COUNT(v)))))
WA(a,c)=LAMBDA(a,c,LET(x,a-c,y,IF(x>0,x),UNIQUE(SMALL(y,SEQUENCE(COUNT(y ))))))
WB(a,b)=LAMBDA(a,b,FILTER(a,IFNA(XMATCH(a,b,,2),0)))
WR(w,c,[r],[i ])=LAMBDA(w,c,[r],[i ],LET(n,IF(i,i,LEN(w)),x,MID(w,n,1),y,MID(w,n-1,1),z,IF(AND(r=0),WA(WL(x),c),WA(r,c)),IF(n=1,r,WR(w,c,WB(z,WL(y )),n-1))))
Last one WR is !! recursive !! Define the names, then the functions and we are good to go. (Gaps in [i ] are to keep the text no to turn italics)
Will come back with the "concept" explanation asap.
Excel Formula:
=LAMBDA(w,c,[r],[i ],LET(n,IF(i,i,LEN(w)),x,MID(w,n,1),y,MID(w,n-1,1),z,
IF(AND(r=0),WA(WL(x),c),WA(r,c)),IF(n=1,r,WR(w,c,WB(z,WL(y)),n-1))
)
)
WORD MAZE.xlsx | |||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | AH | AI | AJ | AK | |||
1 | Z | 1 | S | G | P | E | 2 | T | H | E | D | I | Z | B | A | N | T | S | N | S | defined names | ||||||||||||||||||
2 | S | P | ? | A | K | I | W | K | 1 | F | H | V | Z | G | 2 | I | E | K | A | X | ar: A1:T15 (sample array) | ||||||||||||||||||
3 | ? | I | T | Q | E | ? | L | A | S | I | X | Q | J | N | S | X | 4 | T | J | K | rw: 15 (width is always 20) | ||||||||||||||||||
4 | L | E | N | J | F | X | A | 4 | T | I | K | N | S | B | X | 1 | D | J | C | P | cs: {-1,1,20,-20} (constant array for "snake" type lookup | ||||||||||||||||||
5 | G | D | L | 3 | 3 | D | M | V | L | T | G | K | ? | C | U | 3 | O | Q | O | O | cd: {-21,-19,19,21} (constant array for "diagonal" type lookup | ||||||||||||||||||
6 | I | A | I | U | V | G | Y | L | U | ? | I | E | P | 3 | W | G | K | B | T | P | |||||||||||||||||||
7 | 4 | A | P | A | U | 4 | C | Z | V | F | F | F | A | F | I | P | A | X | T | T | "snake" lookup | "diagonal" lookup | |||||||||||||||||
8 | H | N | ? | 4 | G | C | K | S | 4 | I | D | R | H | N | N | A | J | D | N | S | |||||||||||||||||||
9 | E | C | 3 | X | C | O | D | B | V | Q | O | Y | J | E | R | G | S | K | A | H | =WR("snake",cs) | =WR("diagonal",cd) | |||||||||||||||||
10 | E | X | 1 | Z | ? | P | N | I | 3 | O | W | C | C | N | 2 | U | R | E | G | J | 3 | 82 | |||||||||||||||||
11 | E | O | N | M | E | V | K | A | B | E | P | F | L | Q | N | Z | ? | E | W | 3 | 18 | ||||||||||||||||||
12 | K | A | N | ? | A | I | B | K | L | G | 2 | 4 | ? | N | ? | Z | B | N | Q | E | 20 | =WR("advance",cd) | |||||||||||||||||
13 | S | M | O | 4 | Y | F | B | B | R | E | ? | D | N | E | 1 | A | D | J | M | 4 | 160 | 67 | |||||||||||||||||
14 | C | F | X | 4 | 3 | T | Y | 1 | Z | J | N | I | W | U | Z | 3 | O | W | H | M | 224 | ||||||||||||||||||
15 | T | Y | D | 2 | Y | Z | S | U | D | V | V | F | 4 | O | Z | E | K | A | ? | S | 300 | ||||||||||||||||||
16 | |||||||||||||||||||||||||||||||||||||||
17 | =SEQUENCE(rw,20) | =WR("difficult",cs) | |||||||||||||||||||||||||||||||||||||
18 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 151 | ||||||||||||||||||
19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | |||||||||||||||||||
20 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | =WR("winner",cs) | ||||||||||||||||||
21 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 115 | ||||||||||||||||||
22 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 273 | ||||||||||||||||||
23 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | |||||||||||||||||||
24 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | |||||||||||||||||||
25 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | Note: I left the results in "sequence numbers" representation on purpose, | ||||||||||||||||||
26 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | to be much easier to visualize the results. | ||||||||||||||||||
27 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | To get them to "range" representation we can use PR(a) (print results) | ||||||||||||||||||
28 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | PR(a)=LAMBDA(a,LET(x,QUOTIENT(a-1,20)+1,y,MOD(a-1,20)+1,ADDRESS(x,y,4))) | ||||||||||||||||||
29 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | |||||||||||||||||||
30 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | |||||||||||||||||||
31 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | C1 | B5 | |||||||||||||||||
32 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | R1 | ||||||||||||||||||
33 | T1 | G4 | |||||||||||||||||||||||||||||||||||||
34 | Important Note: Covered here only snake and diagonal search, for being the more complicated ones. | T8 | |||||||||||||||||||||||||||||||||||||
35 | Anyhow, to cover the rest of them the only thing we have to do is defining new constant arrays | D12 | |||||||||||||||||||||||||||||||||||||
36 | cs (constant snake) {-1,1,20,-20} | T15 | |||||||||||||||||||||||||||||||||||||
37 | cd (constant diagonal) {-21,-19,19,21} | ||||||||||||||||||||||||||||||||||||||
38 | For example, for horizontal lookup we have to define | K8 | |||||||||||||||||||||||||||||||||||||
39 | ch {-1,1} and for vertical cv: {-20,20} | ||||||||||||||||||||||||||||||||||||||
40 | O6 | ||||||||||||||||||||||||||||||||||||||
41 | M14 | ||||||||||||||||||||||||||||||||||||||
42 | |||||||||||||||||||||||||||||||||||||||
43 | |||||||||||||||||||||||||||||||||||||||
WM snake diagonal |
Cell Formulas | ||
---|---|---|
Range | Formula | |
W9,W20,W17,A17,AC12,AC9 | W9 | =FORMULATEXT(W10) |
W10:W15 | W10 | =WR("snake",cs) |
AC10 | AC10 | =WR("diagonal",cd) |
AC13 | AC13 | =WR("advance",cd) |
A18:T32 | A18 | =SEQUENCE(rw,20) |
W18 | W18 | =WR("difficult",cs) |
W21:W22 | W21 | =WR("winner",cs) |
W31:W36 | W31 | =PR(W10#) |
AC31 | AC31 | =PR(AC10) |
AC33,W38 | AC33 | =PR(AC13) |
W40:W41 | W40 | =PR(W21#) |
Dynamic array formulas. |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
ar | ='WM snake diagonal'!$A$1:$T$15 | AC13, AC10, W21, W18, W10 |
Upvote
0