# Finding where a list of numbers falls within a range

I’m struggling with one section in a script, pretty sure it has to do with levels/lacing but I’ve played around with that a bit and haven’t reached the intended output yet…

The goal is to to take a list of numbers and find where each number falls within a list of ranges and then associate a percentage to it based on where it is in the range. I have a range of 0-1000, which is then chopped into 11 sublists (0-90, 91-181, etc). These ranges correspond to another list of 11, the percentages (100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0).

Then I have the list that I need to find what range they fall within, which is 7 items right now (but could be more or less depending on the results of the previous section of the graph). This list is 2, 33, 81, 81, 152, 258, 22.

So the expected output at the end of associating percentages would be a list reading 100, 100, 100, 100, 90, 80, 100.

I’m able to get the correct answer when I try just one from the list, but haven’t been able to work out doing the whole list at once. Figuring my problem lies in the list.contains and list.indexof nodes but every way I’ve tried changing the lacing and levels hasn’t produced what I want

“new user” so i can’t upload the script Something like this?

Divide your main list by, in this case, 90,9 (1000/11).
Then simply just round those values to get a value from 0 to 10.
Afterwards just do *10 to get the percentages.

I.e:

• 200
• 200/ 90,9 = 2,2…
• Round = 2
• 2*10 = 20 I’ll give that a try! The only problem is that the range could change depending on project (may be 0-5000 instead which would change the start/end values for the 11 ranges) so I was trying to limit the number times I would have to retype values.

Thanks!

1 Like

See my edit, this approach is way better Don’t think that’ll get the numbers I need. Based on the ranges I have set up, a 200 value would be in the 80% group

Add “100 - value” at the end.

2 Likes

Slightly different than what my intended outcome was using the ranges (100, 100, 100, 100, 90, 80, 100) But close enough I could settle for it if what I was trying to do isn’t possible.

This is also another option ``````//Percentage calculation from 0..1000 values
p = (v/1000)*100;
associated = p <11 ? 10 :
(p >10 && p <19) ? 20 :
(p >20 && p <29) ? 30 :
(p >30 && p <39) ? 40 :
(p >40 && p <49) ? 50 :
(p >50 && p <59) ? 60 :
(p >60 && p <69) ? 70 :
(p >70 && p <79) ? 80 :
(p >80 && p <89) ? 90 :
(p >90) ? 100 : null;``````
4 Likes

A node approach and its equivalent Design Script

rng-1.dyn (16.1 KB)

``````d = (c<1>) < (b<2>);
e = List.IndexOf(d<1>,true)-1;
f = List.GetItemAtIndex(a,e);
``````
4 Likes