如何使排列在bash与N!输入? [英] How to make permutation in bash with N! input?
问题描述
我必须做在bash置换以EVAL和序列命令。所以,我不得不做出第一个可能包含相同的号码置换的话,我必须以某种方式进行过滤。
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 somehow.
老师告诉我,我必须使用两个周期/周期,一个在其他。但我不知道该怎么办了。
The teacher told me I have to use two cycle/period, one in the other. But I don't know how to do it.
输入是这样的:
3
输出应该是:
123
132
213
231
312
321
如果有人可以帮助我,这将是伟大的!
If someone could help me, that would be great!
编辑:
我想知道如何使用这些命令做到这一点,我的朋友去到我这个样子: http://pastebin.com/ wM2U1SuT
老师告诉我它太好了,不是在这个层面上..我应该与序列和eval做到这一点,即使它不是那么好。第二个问题是,输入为123,而不是3,如3!..
I want to know how to do it with these commands, my friend made it to me like this: http://pastebin.com/wM2U1SuT the teacher told me its too good, were not on this level.. i should do it with seq and eval, even if its not that good then. The second problem was that the input was 123, not 3, like 3!..
推荐答案
如果某人的好奇,继承人的解决方案:
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
这篇关于如何使排列在bash与N!输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!