09-24-2013 10:27 PM
Hi guys,
This seems like it should be really easy and obvious... but I want to search a number of 1D arrays for a particular element.
I want to output the other values in the array if the element is found, and nothing if it is not.
eg. Input:
1 2 3,
2 3 5,
5 3 7,
3 8 9
Search for: 5
Output:
2, 3, 7
Even a simple T/F output for each array would be ok, I could probably do the rest.
Thanks!
09-25-2013 12:48 AM - edited 09-25-2013 12:56 AM
Interesting! That was a bit tougher than it looked at first.
I'm almost positive that this code will show up on the Rube-Goldberg Thread. It works though. (There almost has to be a way to do that in one loop)
09-25-2013 03:22 AM
Jeff second for loop where you are using equal function and again building the array of boolean.
Without for loop its same
09-25-2013 04:38 AM
My solution, there's no removal of repeated numbers, i leave that to you.
/Y
09-25-2013 10:20 PM - edited 09-25-2013 10:22 PM
Here's my solution, based on both of yours above, and the fact that each row contains only 3 elements. (If anyone's interested I'm using it to find nearest neighbours in a Delaunay triangulation)
I tried to make it simpler... but I may have just Goldberged this even further...
Thanks guys!
09-25-2013 11:09 PM
MOI_maker wrote:I tried to make it simpler... but I may have just Goldberged this even further...
You know that "index array" is resizeable, right? 😄