Miki
Miki

Reputation: 129

Max within a list conteining 2 equal elements

my question is the following: I am using the code set eumax max ( list eu0 eu1 eu2 eu3 eu4 eu5 eu6 eu7 eu8 eu9 eu10 ) to pick the maximum value within the list, but how does Netlogo pick a value if two elements (let say eu0 and eu1) get the same value?

Upvotes: 0

Views: 153

Answers (1)

Jasper
Jasper

Reputation: 2790

In NetLogo max only works with lists of numbers. Since each element of the list is a number value, it does not matter the source of the value (a literal number, a variable, or a reporter). Once the list is made, it contains the values independently of the source. What this means is, it really doesn't matter which element is picked if the values are the same. A number value is a number value.

Hopefully this example will help illustrate why it doesn't matter:

to test-max
  let v1 10
  let v2 5
  let v3 10
  let eumax max (list v1 v2 v3) ; the list's value is then set to [10 5 10]
  show eumax ; shows 10 
  set v1 20
  set v3 25
  show eumax ; still shows 10, it doesn't matter which 10 was picked
             ; or where the 10 values in the list came from
end

Upvotes: 2

Related Questions