分组项目组合,不重复

2024-09-29 01:33:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我将项分为3个组,并希望生成如下示例所示的数组:

Group 1 = {m1, m2, m3}
Group 2 = {m4, m5}
Group 3 = {m6, m7, m8, m9}

{m1, m4, m6}
{m2, m5, m7}
{m3, null, m8}
{null, null, m9}

组的每个元素在生成的数组中只能出现一次。 我应该如何处理这个问题?你知道吗


Tags: 元素示例group数组nullm3m5m4
2条回答

您应该考虑这样做(请记住这是伪代码):

group1 = {m1, m2, m3}
group2 = {m4, m5}
group3 = {m6, m7, m8, m9}

len1 = group1.size
len2 = group2.size
len3 = group3.size

max = max(len1, len2, len3)

combination = {}
for i from 0 to max:

    combination = {}
    if(group1(i) exists)
        combination.add(group1(i))
    else combination.add("null")

    if(group2(i) exists)
        combination.add(group2(i))
    else combination.add("null")            

    if(group3(i) exists)
        combination.add(group3(i))
    else combination.add("null")            

    print combination

我就是这样做的,它的maxscript代码可以分析多个材质,可以有其他多个材质,并从每个ID创建新的材质。也许我在第一个问题中有点不清楚抱歉。你知道吗

    local maxSubID = amax arrayNumSubs  it is the count of the array with highest number of items.


    for maxSubCounter = 1 to maxSubID do
    (
        tmpMat = multimaterial numsubs:mainMatIDs
        for subCounter = 1 to mainMatIDs do
        (
            if (rootMat[subCounter] != undefined) then
            (
                tmpMat[subCounter] = rootMat[subCounter][maxSubCounter]
            )else
            (
                tmpMat[subCounter] = undefined
            )
        )
        append materialsToApply tmpMat
    )

相关问题 更多 >