Netlogo making a list out of itself for a given length -


i want create list out of own values given length.

for example, given list [0 1] , desired list length of 7, output [0 1 0 1 0 1 0]. length defined population, , defined slider. declared variable x should iterate through list. if length of list shorter value of population should set 0 again.

i tried loop command runs infinitely:

let x 0   loop[     if length exp-dif-li <= population[       ifelse x < length exp-dif-li[         set x 0]       [ set exp-dif-li lput item x exp-dif-li exp-dif-li         set x x + 1]     ]   ] ] 

mod , n-values friends here:

to-report continue-list [ lst n ]   report n-values n [ item (? mod length lst) lst ] end 

example uses:

observer> show continue-list [0 1] 7 observer: [0 1 0 1 0 1 0] observer> show continue-list [0 1] 1 observer: [0] observer> show continue-list [0 1 2 3 4] 22 observer: [0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1] 

edit: realized talk why works! n-values n [ ... ] creates list of length n sending numbers 0 through n - 1 given reporter. reporter accesses number ? (this netlogo task syntax). want keep repeating items in original list. function repeatedly cycling through numbers mod. in general, item i of new list should item i mod <length of original list>. so, putting together, n-values n [ item (? mod length lst) lst ] creates new list of length n repeating items list lst necessary.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -