I have two lists (A and B). I have to make a range of points where are values from the list A the start of range and values from list B the end of range ( as in code block “Result”). We have to test if value from list A smaller than value from list B than step is +50 but if is value from list A greater than step is -50.
Thanks in advance,
Take a look at the math and script tab and you will find interesting nodes. But what is the rule when there is noit the same number of values in sublists A and sublists B ?
It will never happen that the numbers are the same in both lists. I tried various options but … That’s why I’m asking for help on the forum.
Maybe you have to choose…or it depends of the context, of the project…Where does these values come from ? What ist he main purpose of the script ?
Maybe this will help :
(edited : no need of list level @3)
Easier with Design Script. You could refer this to attempt with nodes though
range.dyn (9.5 KB)
a = List.AddItemToEnd(y<1><2>,x<1><1>); b = List.Sort(List.Flatten(a,2)); List.FirstItem(b<1>)..List.LastItem(b<1>)..50;
Thanks for the quick answer. In your solution you did not put a range when the value of A> is the value of B. In this situation you have a negative step. The range always starts from list A
Eg. for the following cases it should be step -50:
886 > 621
This numbers are location of the low and high points in the road.
Thanks for help and this I will use for other things but not in this cases.
range.dyn (10.3 KB)
a = List.AddItemToEnd(y<1><2>,x<1><1>); b = List.Flatten(a,2); c = List.FirstItem(b<1>); d = List.LastItem(b<1>); e = c < d ? 50 : -50; c..d..e;
Almost perfect. With this code we have range 70 until 334 and 410 until 142 but that we don’t need. that is not need. We need first greater value (or smaller) in the list B. But not all combinations…
Thanks for help.
Now this is getting a little complicated
range.dyn (11.0 KB)
a = List.AddItemToEnd(y<1><2>,x<1><1>); b = List.FirstItem(a<1><2><3>) < List.LastItem(a<1><2><3>); c = List.Count(List.UniqueItems(b<1><2>)<1><2>); d = List.Flatten(List.TakeItems (a<1><2>,c<1><2>),2); e = List.FirstItem(d<1>); f = List.LastItem(d<1>); g = e < f ? 50 : -50; e..f..g;
Yes. It is a little complicated, but You are almost on the finish line . Can you check (List 5 ) why range 410 go until 142, please? Should stop on 334. This part was only mistake.
Sorry for this and thanks for help
a = List.AddItemToEnd(y<1><2>,x<1><1>); b = List.FirstItem(a<1><2><3>) < List.LastItem(a<1><2><3>); c = List.Count(List.UniqueItems(b<1><2>)<1><2>); d = c * (List.AllFalse(b<1><2>) ? -1 : 1); e = List.Flatten(List.TakeItems (a<1><2>,d<1><2>),2); f = List.FirstItem(e<1>); g = List.LastItem(e<1>); h = f < g ? 50 : -50; f..g..h;
I think I have a solution for you with the result you want.
Not nearly as elegant as @Vikram_Subbaiah’s solution (although what I’ve made can easily be turned into a single code block), but I think each step is quit easy to follow.
I did start with a sort, otherwise it would complicate the code more as well as needing more calculation power.
Second step is creating duplications where every variable can easily be put together with variables they might have to calculate with.
At the filter block I’m checking whether there’s calculations that don’t need to be done, which get cut out in the 4th set of code blocks.
Last Step is finally generating the desired lists.
This work perfect. Thanks for help.
Thanks for help and for other way to solve a problem and for explanation.
This is also goed solution.