# List logic, increment from previous value

Hello!

I’m trying to modify a list based on the following condition:

if a number is added to the list 1 from list 2 at index x, then the number after index x should begin with the next number.

So in the watch node, the number at index 5 should continue from 7 instead of 6. Is there a simple way to go about this?

@Dynamo_Noob This is the easiest way I could think of.
The List.Scan node is performing a cumulative sum down the list.

2 Likes

Unfortunately, it’s not just 1 that the input list has. It might also have other numbers, and the resulting list must add those numbers in the specific index and the series should continue from the next indices. I hadn’t shown that in my first snip. Here is what happened when I followed your method…:

Index 4 should be continuing from 7, then 8, 9, 10 and so on until and unless there’s another number to add to it.

Maybe i’m following a convoluted way to acheive this…!?

Hi @Dynamo_Noob,

I am trying to understand what you are trying to achieve but i am having a really hard time.
Could you further elaborate (maybe with the correct output and how you would get that) how you see the correct solution? (PS: English is not my first language)

Do you want `[0,0,1,1,3,3,3,3,3];` ? Because i don’t understand how you would count your list

Regards,
Daan

Try this
Do with the second list what needs to be done
List.Create to put them back together and Flatten

1 Like

Hi @Daan

What I’m trying is, to add reserved room numbers for rooms that are of specific sizes.

So, like I explained in the previous replies, I need to reserve that much amount of number for the rooms. The problem is that after adding, there might be duplicate numbers. I thought this might be solved by using some kind of list condition, since the list structure that I’m having currently is sorted according to the location and levels of the rooms.

I hope you could understand now.

Hello!

Thank you for the reply. I tried this out. Lost what you were saying after IndexOf step?

I might be wrong but, looks like this requires a bit of manual intervention if the lengths of the list changes?

Try this, (but keep lacing in mind)

list_noob.dyn (19.2 KB)

@Dynamo_Noob Something like this?

hello again!

Sorry that i could not explain my needs correctly. The script that you’ve given there, is not my goal. Adding the things in code block into the flattened node at the end and continue the numbers from there is. I’ve added snip below to explain this, with my required goal at the end:

Adding item to front and Reserving Number code block(Remove item from last) is just added so that, the reserving number is added to the next room in series.

I think number 3 in the index 4, block is changed to 1 in the first watch node? but it should’nt, the numbers must be passed, and added, and the next value in the list should continue from that number…

Cant you use this logic? List logic, increment from previous value - #2 by AmolShah
What is the difference between what you want and cumulative counting and then adding those values?
What is the logic to go from your current list to your required list because i dont understand the pattern.

1 Like

Hello!

Sorry for the late update. But this is the exact solution that I was looking for.

When I tested with the big numbers, I had incorrectly compared the list.

@Daan you were right, this is the correct workflow.

@Marcel_Rijsmus thanks for your inputs as well!

2 Likes