### List with "3 integer" entries – Find the closest entry to 3 entered integers

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!

Have a look to zsa.dist, it finds closest list using various algorithms. Or you can calculate yourself the distances between the input list and all the stored ones.

notwithstanding EJ’s fine work, I’d probably just use pythagorean distance measure:

-- Pasted Max Patch, click to expand. --Copyallof the following text. Then, in Max, selectNew From Clipboard.----------begin_max5_patcher---------- 807.3oc0XtsaiCBDF9ZmmBjUuZUZkAL9vd29brZUkOPRckMjhIsYaUe2W7PN 3rIwwp00M4h3HNX3e97.y.uMwwMUthW6h9I52HGm2l33.U0Tgy5xNtUIqxJS pgt4VwqqSlycmZaSyWog588QDFxmrogEI5rGJDyuWwyz1I.iityaJhgad5G2 7DGbmG5OqeE4RcIWq+6Bts+ttaapHGlDY5i2RnalhYRgVjTA818Wphjx1sTW 7JzB1yLQ1pEKqJDlo.rDxtJsSLTKtox2mLo4wzOIRhYHJpKf3i82ADZzGEH3 qEfvXHRHx2qCjPCnCfOBN9RCIYxpJtPe.RTRotCbPh.DPXg.UH.OhZwi1FcX OLZ07zlZ2Yu8AC3MBTwqMFQhtPJ1yMlZEInUu0O1Jw8gm2.Bu5kUH4LT8SKS LJqGXj.q2hB6DiAeaXD97R7hFYLlWLaFWwEYbTJW+BmKPYRkQjKjhbCHQ7Rd yKtkvkEBdlboP2dMxwvdLrLFGBXGSXf8EeBty9139Z+A5ny8Zchg5c43FhsL CbMXc635+UCvOOJlUJMCRWFrm0fsKXYdGXvGD.vLjIF1hbSSDyOdz.7tITYv hlqtmKRRKggvaPhTbbDQ9.HRvewH5C2q6IUmAJ7radD.DiD1WtcLdMPAOwCV vySfjWKQ0mwYB13gPg+nwmGJM9QGkIQekITLftIOyWsPgto.+CyuNQicyX6e AQ8.MGCKgWItJZTJprKbfsNGDap3j6XmCGvtMmxaIv85XSksdK2dSA47dK3v vOk2B6Z4fJzPSt1ceX1ffA3bJ9CKPNQBNDa3.apDmI+lgjhAXD0CwncleCY. vHcTvHMF9jGDNxXjRM4A08olIsuHgO9MqLVKOgIGNEw+c0Sfo0T+9XpVtTks Q5atCHzNyKmWqKDv2qVchsWednHOmKZmvmI86lb.yOctr8VN3dHmfQSNM29w Ejb5iZv3QSNQ8PNwilZB6gZhFM0v5gZBGM03eQsHmdQsnpYlv8fM3QSMWPaG +E9kxF5JYwhm4p50CIHDSr7GkplhASghEBaQXDcU7mK1z+nIMi16S92V+GMn -----------end_max5_patcher-----------

Wow, thanks so much Terry! Exactly what I need.

Forums > MaxMSP