INDEX with MATCH with FIND/SEARCH & position - arrays

I have a fairly complex issue where I need to find matches of a short string within a long string, with the search being limited to the first few characters of the long string.
A long search turned up this array formula:
{=IFERROR(INDEX($A$8:$A$9,MATCH(1,--NOT(NOT(FIND($A$8:$A$9,A1))),0)),"no match")}
With that I was able to get part of the way, but don't want to get matches if the value is not found within the first few characters, and I can't figure out how to accomplish this.
How can I adapt the above formula to limit the search to within the first few characters of the value, thus getting the formula to not match the values in cells A3 and A6, returning the desired result in Col-C? Or is there a different formula I should be using?
Here is a sample of the data (my data is quite complex, but the principle is the same):
A (value) B (result with current formula) C (desired result)
1 1apple1234567890 apple apple
2 12apple123456789 apple apple
3 123456apple12345 apple no match
4 1peach1234567890 peach peach
5 12peach123456789 peach peach
6 123456peach12345 peach no match
7
8 apple
9 peach
screenshot
EDIT:
After playing around to learn how the formula works, I was able to achieve the desired result using an IF criteria for the FIND array:
{=IFERROR(INDEX($A$8:$A$9,MATCH(1,--NOT(NOT(IF(FIND($A$8:$A$9,A2)>3,0,1))),0)),"no match")}

use Search and Left:
=IFERROR(INDEX(A:A,AGGREGATE(15,7,ROW($A$9:$A$10)/(ISNUMBER(SEARCH($A$9:$A$10,LEFT(A2,4+LEN($A$9:$A$10))))),1)),"no match")
Replace the 4+ with the number of characters that would satisfy: the first few characters of the value

This array formula (use Ctrl+Shift+Enter) works perfectly:
{=IFERROR(INDEX($A$8:$A$9,MATCH(1,--NOT(NOT(IF(FIND($A$8:$A$9,A2)>3,0,1))),0)),"no match")}

Related

Google spreadsheet how to count data if contains a value

been trying to solve this but am struggling. Hopefully this is the right place to ask.
What I need to do is search a row for a certain word, say "cat". If that word is found within that row then take the value of another cell ("Gain") in that row and add this to a total. Then what I need to do is take that total, and divide it by the number of times "cat" was found within a group of rows. Is this possible?
Hopefully that explains what I am trying to do.
For example my data looks likething like this -
1 2 3 4 5 Gain
1/6/22 cat bear elephant sheep 7
2/6/22 dog cat mouse cow 12
3/6/33 cat cow horse goat 5
Cow total: 2
Rows containing cow / gain (2/12+5) = 8.5
EDIT: What I have noticed it if I use SUMIF it will work ASLONG as the value I am search for is across a single column. However, if it is spreadout across multiple columns I get a value that isn't correct.
try:
=COUNTIFS(B1:E3, A6)
and then:
=INDEX(SUM(IF(B1:E3=A6, F1:F3, ))/COUNTIFS(B1:E3, A6))
This is the formula I use when I need to count how many cells have specific values in it within a range:
=COUNTif($J56:$J956,"=Cat")

(excel) How to return an array from a sum of ranges?

I'm setting up a morphological table that will have to go through potentially a couple hundred items, so it's desirable for this process to not be done by hand.
Here's a small summary of the situation:
fin
eng
op
fli
A
2
4
6
8
B
1
3
5
4
C
1
2
3
5
D
1
4
7
2
The first column holds named ranges A through D which have associated values from the 4 categories in row 1.
In a second table we create configurations based on which features are selected, something like this:
Config 1
Config 2
A
B
C
D
What I'm looking for is a formula that would read for each configuration which named range is selected, add the score for each category and return it in a simple array. Something like
Config 1 {3,6,9,13}, Config 2 {2,7,12,6}
So far I've found that the Indirect formula works exactly the way I want but I have to manually input each range. Something like:
=INDIRECT(A1)+INDIRECT(A2)
I've played around with different permutations of sum functions but instead of returning the arrays it returns the sum of the first values.
=SUM(INDIRECT(A1:A2))
Amy suggestion would be welcome.
I know this would probably be much simpler with code but this study needs to be done in excel..
I'm not sure if this answers your question as it doesn't use named ranges, but you could try something like this:
=MMULT(SEQUENCE(1,4,1,0),$B$2:$E$5*COUNTIF(INDEX($H$2:$I$3,0,ROW()-ROW($A$7)+1),$A$2:$A$5))

How to check n-puzzle with two blanks is Solvable?

I have modified the question on n-puzzle. In this scenario, the puzzle has two blanks instead of one blank.
Initial State
3 5 1
4 6 -
7 2 -
Goal State
- 1 7
3 2 -
5 6 4
Is there any algorithm that I can use for this?
All existing algorithms that solve the regular sliding tile puzzle (such as A* or IDA*) can solve this variant as well. The puzzle with multiple blanks is equivalent to a pattern database for the sliding-tile puzzle - the exact solution to the puzzle with some pieces replaced with blanks can be used as a heuristic for the original puzzle with only a single blank.
(To be precise they are equivalent to additive pattern databases. You can combine several together and add their heuristic values as long as the action cost of swapping two blanks is 0 and none of the tiles are duplicated.)

How do I find the index of the first occurrence of a score in a sorted Redis set?

I'm writing a search engine using Dewey Decimal call numbers to categorize information. The scheme is as follows:
123.45
2 is a sub-category of 1.
3 is a sub-category of 2.
4 a sub-category of 3. Etc.
It's the same numbering system libraries use to sort their books. 200 for example is religion. 210 is Philosophy & Theory of Religion. 211 is Concepts of God.
The site is one continuous catalog that goes from one subject to the next. Each link is given a score in Redis (the link's Dewey Decimal call no.). The site is setup for 50 links per page. I've got a function which calculates the zrange to pull from the server depending on the page the user's accessing.
Is there a way that I can specify a score and find the index of the first occurrence matching said score -- that way I don't have to iterate the entire database looking for scores when users enter a call no?
You can use ZCOUNT from negative infinity to your specific score to find the index.
For example, in following sorted set:
> ZADD dewey 1 first 3 second 8 third 21 fourth 55 fifth
(integer) 5
To find the index of 21 (the fourth number):
> ZCOUNT dewey -inf (21
3
Just keep in mind that this is 0-based index.

Aggregate Values of Multiple Lookups in Excel

I'm looking for a non-VBA solution to this problem.
Say I have a graph (in the computer science sense) in a spreadsheet as follows:
A B C D
1 Vertex Neighbors Degree Avg Nghbr Deg
2 A B,C 2 2.5
3 B A,C 2 2.5
4 C A,B,D 3 1.666666667
5 D C 1 3
I've entered columns C and D by hand but I want them to be calculated automatically. I've found reasonable solutions for column C that essentially count the commas and add 1. But for column D, I can't find a solution. I've found countless articles that explain how to lookup one value multiple times in one column, and countless articles that explain how to look up multiple values once in multiple columns, but I can't figure out how to look up multiple values in ONE column, get back an array of values, and then take the average of that array. I'm sure this can be done in VBA but I'd prefer a native Excel solution if one exists.
Obviously I'd like to extend this so that I can do other analyses of a vertex's neighbors. Presumably once I know the method to analyze a "looked-up array" I will be able to use it in other functions as well.
Any help is greatly appreciated.
To get column C:
=LEN(B2)-LEN(SUBSTITUTE(B2,",",""))+1
To get column D use SUMPRODUCT with SEARCH:
=SUMPRODUCT((ISNUMBER(SEARCH("," & $A$2:$A$5 & ",","," & B2 & ",")))*$C$2:$C$5)/C2

Resources