How to make permutation in bash with N! input?

后端 未结 3 1115
你的背包
你的背包 2021-01-15 14:44

I have to make a permutation in bash with \"eval\" and \"seq\" commands. So I have to make first a permutation that could contain the same numbers, then I have to filter it

3条回答
  •  一向
    一向 (楼主)
    2021-01-15 15:33

    If someones curious, heres the solution:

    input=3
    for i in $(eval echo " {1..$input}{1..$input}{1..$input} "); do
        OK=yes
        for pos1 in $(seq 0 $((x,1)) ); do
            for pos2 in $(seq 0 $((x,1)) ); do
                if [ $pos1 != $pos2 ]; then
                    if [ ${i:$pos1:1} == ${i:$pos2:1} ]; then
                        OK=no
                    fi
                fi
            done
        done
        if [ $OK = yes ]; then
            echo $i
        fi
    
    done
    

提交回复
热议问题