我有一个包含四个值的列表。然后,我创建了一个由四个1的数组组成的数组,其中包括它们的概率:
set startingcharact (list pricered qualityred innovationred sustainabred)
set probs-impr-red [[1 0.1] [1 0.1] [1 0.3] [1 0.5]]基本上,我想要的是“更新”startingcharact列表,方法是将使用rnd扩展的特定函数选择的1添加到具有相同索引的特性中。因此,例如,如果选择了列表的前1,我希望有: pricered +1。我尝试使用map函数来实现这一点,但是显然我得到了一个错误,因为我试图用一个值对一个列表进行求和。我在这里所做的是:
set startingcharact (map + startingcharact first rnd:weighted-one-of-list probs-impr-red last)发布于 2022-06-25 17:26:03
我可以想到两种方法,但都涉及到改变
set probs-impr-red [[1 0.1] [1 0.1] [1 0.3] [1 0.5]]至
set probs-impr-red [[0 0.1] [1 0.1] [2 0.3] [3 0.5]]当您试图在startingcharact中找到正确的索引时。在那之后,
let z replace-item (first rnd:weighted-one-of-list probs-impr-red [a -> last a]) [0 0 0 0] 1
set startingcharact (map [[a b] -> a + b] startingcharact z)或者,更直接地说,
let idx first rnd:weighted-one-of-list probs-impr-red [a -> last a]
set startingcharact replace-item idx startingcharact (item idx startingcharact + 1)我相信可能会有更优雅的东西,但我认为这是可行的(尽管警告说它没有经过测试)。
https://stackoverflow.com/questions/72752370
复制相似问题