Mar 27 2013 | 9:32 pm

Hi,

My problem is a bit complicated, especially since I'm not so used to visual programming.

I have a list (it doesn't have to be a qlist) with predefined 128 entries/lines. Each entry has three integer values. They range from 0 to 127.

Here is an example:

33 50 40

61 30 53

etc.

I want to enter three integer values, find the one which is the closest and return it.

An example:

My entered number 37 52 42 would be really close to entry 1, so the output would be entry 1: 33 50 40

I first thought about summing up all the values:

33 50 40 = 123

61 30 53 = 144

Entered number: 37 52 42 = 131

And than subtract the sum of the entries of the list with the sum of the entered number to find the smallest number:

131-123 = 8

131-144 = -13

The first entry is the closest.

Unfortunately this isn't working. Imagine the following case:

55 27 40 = 122

95 3 2 = 100

My entry: 44 25 42 = 100

The second value of the list would be the perfect fit according to the algorithm, but it isn't. The first entry would be a a lot better, as the individual integer values are much closer to the integers of my entry.

So If I'm right, than I must find the entry with the smallest deviation of the individual integers.

Like:

55 27 40 deviation of: -11 2 -2 to my entry 44 25 42 --- Highest number: 11

95 3 2 deviation of: 51 -24 38 to my entry 44 25 42 ------Highest number: 51

First entry wins, how it should be.

But how can I do this? Especially as it should be as fast as possible.

This is a probably a complex problem, but I simply don't know how to start and where to look, as I´m not so used to max msp.

I would appreciate every help! Thanks!