procedure - How to call a list for update multiple times until a condition is fulfilled in Netlogo -
i new netlogo , still learning , want call list after update done , update until condition reached , if have list
let xy [[-2 6][-1 6][0 6][-1 6][-2 6][1 5][2 5][-3 9][-4 9][-5 9][-6 9][-3 9]] let same true
i trying remove list first sublist between 2 same elements [-2 6 ][-1 6][0 6][-1 6][-2 6] want remove sublist between other 2 same elements [-3 9][-4 9][-5 9][-6 9][-3 9] until there no more elements repeat in case result should [[1 5] [2 5]] , control list after removing sublists condition:
if length xy = length remove-duplicates xy [ set same false ]
i have done removal code below , removes first sublist might have lot of sublists , , want know how after 1 removal can again updated list (in these case should somehow take final-list in code) , control again these condition. thinking to-report procedure , while loop , example (maybe wrong this)
to-report update-list [list] while [same != false ] [ ; removal stuff set list-xy item position (first modes xy) xy xy let first-pos position (first modes xy) xy set list-temp remove-item first-pos xy set sec-pos position list-xy list-temp + 1 set sublist-1 sublist xy 0 first-pos set sublist-2 sublist xy sec-pos length xy set final-list sentence sublist-1 sublist-2 set xy final-list ; condition if don't have duplicates size of 2 lists should have same size , no duplicates if length xy = length remove-duplicates xy [ set same false ] ] report update-list xy
i not sure report @ end of procedure , how recall list again, can remove sublists.
any ideas appreciated, thank
this easiest solve using recursion:
to-report remove-fenced-sublists [xs] if empty? xs [ report [] ] let pos position first xs butfirst xs if not is-number? pos [ report fput first xs remove-fenced-sublists butfirst xs ] report remove-fenced-sublists sublist xs (pos + 2) length xs end
sample run:
observer> show remove-fenced-sublists [[-2 6][-1 6][0 6][-1 6][-2 6][1 5][2 5][-3 9][-4 9][-5 9][-6 9][-3 9]] observer: [[1 5] [2 5]]
Comments
Post a Comment