Welcome back. Get a good night’s sleep? Great.
Hopefully you had freshly-picked brain-function-enhancing blueberries for breakfast, and a red bull or five, because you’re gonna need it. Why? Because today, my friends, we peek inside the multi-dimensional mind of Sajan the Excel Magician. As you’ll keenly recall from yesterday’s gripping episode of “When good formulas go GREAT”, Sajan claimed Bronze in our inaugural formula challenge at Formula Challenge 001 – Return everything in string after first block of numbers By way of a quick refresher, this formula challenge calls for a formula to return a substring from a longer string. Those strings look something like this:
Specifically, we need a formula to return only the second country and associated number …in the case of Monaco7190Australia1484 it’s that bit in bold i.e. Australia1484 Sajan the Magician split those strings with this award-winning beauty: =MID(A1,MODE(MMULT((N( How does this wizardly wonder work? Let’s find out… 1. Sajan splits apart the source string into it’s charactersThis is as I did in the last post, albeit using a slightly different formula than I did:=MID(A1,ROW(INDIRECT(“1:”&LEN( =MID(A1,{1;2;3;4;5;6;7;8;9;10; ={“M”;”o”;”n”;”a”;”c”;”o”;”7″; 2. Then he adds zero to the arrayThis coerces any numbers stored as text into numbers, while causing the text bits to throw errors={“M”;”o”;”n”;”a”;”c”;”o”;”7″; ={#VALUE!;#VALUE!;#VALUE!;# 3. Wrap an ISNUMBER around this unsightly spawn of Satan,This turns numbers to True, and turns those hideously unnatural errors of nature to better-behaved booleans:=ISNUMBER({#VALUE!;#VALUE!;#={FALSE;FALSE;FALSE;FALSE; 4. Turn this array into Ones and Zeros, and checks if it equals either One or Zero.I know…me too. But let’s give him the benefit of the doubt for now, and see what rabbit hole he’s leading us down…we might yet pop out of a magicians’ hat:=N({FALSE;FALSE;FALSE;FALSE; ={0;0;0;0;0;0;1;1;1;1;0;0;0;0; ={FALSE,TRUE;FALSE,TRUE;FALSE, What this has done in effect is create a 2D array – with one column of the array being the inverse of the other. So one column records whether something is a number, and the other records whether something isn’t a number. I know…me too. But maybe it would help if we saw what this would look like if entered over an Excel range, with our original string down the side so we can try and work out what spell this Wizard is whipping together: 5. He then creates a second 2d array with this bit:=(ROW(INDIRECT(“1:”&LEN(A16)))={1,0;2,1;3,2;4,3;5,4;6,5;7,6; …which if we were to enter over an Excel range would look like this: 6. He then throws this array into his wizard’s cauldron together with the array in 5 – along with generous portions of Eye of newt, toe of frog, wool of bat and tongue of dog. (This simply means Multiply the two previous Arrays)This gives us the following:={FALSE,TRUE;FALSE,TRUE;FALSE, ={0,0;0,1;0,2;0,3;0,4;0,5;7,0; …which again would look like this if entered over an Excel range (with our original string down the side by way of reference): Well mess up my hair, and call me Einstein. Because now I see what all that was about. The only time that the same number in that first array also appears in that second array is that magical place where the first block of numbers ends, and the second block of letters begins. That is some serious sorcery! 7. Multiply the arraysNext he conjures this 2D array into 1D, with the help of MMULT.Microsoft tells us that MMULT “…returns the matrix product of two arrays. The result is an array with the same number of rows as array1 and the same number of columns as array2.” If that’s got you scratching your head, then try this alternate explanation: The M in MMULT stands for Magic. The way Sajan is using MMULT is to basically add across each row to find out what the total is for each row. Or another way of thinking about it is that because there’s ether a zero or a number in each row, he’s zipping up these two lists into one to just get the numbers and to ignore the zeros: =MMULT({0,0;0,1;0,2;0,3;0,4;0, = {0;1;2;3;4;5;7;8;9;10;10;11;12 8. Work out the most common number in that array and add one to itNow he’s got the start position of our desired substring.=MODE({0;1;2;3;4;5;7;8;9;10; =11 9. Lastly, he uses this trickery to tease out our answer string=MID(A16,MODE({0;1;2;3;4;5;7;=MID(A16,11,LEN(A16)) =Australia1484 Austrailia1484. Crikey dick. Strewth, mate! That bonza beaut has more bounce than a Boomer! Makes me feel a couple of tinnies short of a slab. And that’s the formula that got the lowly Bronze! Tune in tomorrow, and we’ll see what the Silver-medal winner, Haseeb,has to offer. If you dare….. About the Author.Jeff Weir – a local of Galactic North up there in Windy Wellington, New Zealand – is more volatile than INDIRECT and more random than RAND. In fact, his state of mind can be pretty much summed up by this:=NOT(EVEN(PROPER(OR(RIGHT( That’s right, pure #VALUE! |
Wednesday, July 17, 2013
Formula Challenge 001 – Return everything from a string after the first block of numbers (Part 2.)
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment