如何在 NetLogo 中将列表项转换为不带方括号的唯一数字?
How to transform the items of a list into a unique number without square brackets in NetLogo?
我有以下疑问:
由于结合了 5 种栖息地类型,我有 31 种海龟资料。即:
profile1: turtles are only born in habitat 1
profile2: turtles are only born in habitat 2
profile3: turtles are only born in habitat 3
profile4: turtles are only born in habitat 4
profile5: turtles are only born in habitat 5
profile6: turtles are only born in habitats 1 and 2
profile7: turtles are only born in habitats 1 and 3
... until you reach profile 31: where the turtles are born in habitats 1, 2, 3, 4 and 5
我想得到列表的信息,并将每个列表的项目去掉括号和空格转换成一个代码。
For example:
I am turtle: 0 the possible habitats: [1] my code: 1M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 9 the possible habitats: [2] my code: 2M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 45 the possible habitats: [1 2] my code: 12M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 135 the possible habitats: [1 2 3] my code: 123M1R1 my code reproduction level: R1 my code metabolism level: M1
但是我有的是:
I am turtle: 0 the possible habitats: [1] my code: [1]M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 9 the possible habitats: [2] my code: [2]M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 45 the possible habitats: [1 2] my code: [1 2]M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 135 the possible habitats: [1 2 3] my code: [1 2 3]M1R1 my code reproduction level: R1 my code metabolism level: M1
是否可以如我所愿?
提前致谢
请看下面代码的指挥中心:
globals [ ValidHabs ]
to setup
clear-all
read
end
to read
set ValidHabs [ ]
; the ValidHabs in the original code is a list created from a .csv file. Here I created a list in the code to exemplify...
set ValidHabs [ [1] [2] [3] [4] [5] [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] [1 2 3] [1 2 4] [1 2 5] [1 3 4] [1 3 5] [1 4 5] [2 3 4] [2 3 5] [2 4 5] [3 4 5] [1 2 3 4] [1 2 3 5] [1 2 4 5] [1 3 4 5] [2 3 4 5] [1 2 3 4 5] ]
show ValidHabs
end
您可以使用 reduce
和 word
制作一个洞列表的字符串
例如:
to go
show reduce_list [1 2 3 4 5] ; shows "12345"
end
to-report reduce_list [a_list]
report reduce word a_list
end
我有以下疑问:
由于结合了 5 种栖息地类型,我有 31 种海龟资料。即:
profile1: turtles are only born in habitat 1
profile2: turtles are only born in habitat 2
profile3: turtles are only born in habitat 3
profile4: turtles are only born in habitat 4
profile5: turtles are only born in habitat 5
profile6: turtles are only born in habitats 1 and 2
profile7: turtles are only born in habitats 1 and 3
... until you reach profile 31: where the turtles are born in habitats 1, 2, 3, 4 and 5
我想得到列表的信息,并将每个列表的项目去掉括号和空格转换成一个代码。
For example:
I am turtle: 0 the possible habitats: [1] my code: 1M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 9 the possible habitats: [2] my code: 2M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 45 the possible habitats: [1 2] my code: 12M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 135 the possible habitats: [1 2 3] my code: 123M1R1 my code reproduction level: R1 my code metabolism level: M1
但是我有的是:
I am turtle: 0 the possible habitats: [1] my code: [1]M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 9 the possible habitats: [2] my code: [2]M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 45 the possible habitats: [1 2] my code: [1 2]M1R1 my code reproduction level: R1 my code metabolism level: M1
I am turtle: 135 the possible habitats: [1 2 3] my code: [1 2 3]M1R1 my code reproduction level: R1 my code metabolism level: M1
是否可以如我所愿?
提前致谢
请看下面代码的指挥中心:
globals [ ValidHabs ]
to setup
clear-all
read
end
to read
set ValidHabs [ ]
; the ValidHabs in the original code is a list created from a .csv file. Here I created a list in the code to exemplify...
set ValidHabs [ [1] [2] [3] [4] [5] [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] [1 2 3] [1 2 4] [1 2 5] [1 3 4] [1 3 5] [1 4 5] [2 3 4] [2 3 5] [2 4 5] [3 4 5] [1 2 3 4] [1 2 3 5] [1 2 4 5] [1 3 4 5] [2 3 4 5] [1 2 3 4 5] ]
show ValidHabs
end
您可以使用 reduce
和 word
例如:
to go
show reduce_list [1 2 3 4 5] ; shows "12345"
end
to-report reduce_list [a_list]
report reduce word a_list
end