Netlogo makes a list of itself for a certain length

I want to create a list of eigenvalues ​​for a given length.

For example, given the list [0 1]and the desired length of the list of 7, the output will be [0 1 0 1 0 1 0]. The length is determined populationand determined by the slider. I declared a variable xthat should iterate over the list. If the list length is shorter than the value population, it must be set to again 0.

I tried it with the loop command, but it works endlessly:

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]
    ]
  ]
]
+4
source share
2 answers

modand n-valuesare your friends here:

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

Usage example:

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: , , ! n-values n [ ... ] n, 0 n - 1 . ? ( NetLogo task). . mod. i i mod <length of original list>. , , n-values n [ item (? mod length lst) lst ] n, lst.

+5

, .

if length exp-dif-li = 7 [stop]

. Loop , .

. , .

while length exp-dif-li < 7
  [
   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]
  ]  

Netlogo , . [repeat]

  repeat 7  [
            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]
            ]
+1

Source: https://habr.com/ru/post/1624516/


All Articles