所说的排列组合也并不是,举例来说吧
var a="777 3,777 0,888 1,999 3,765 3,765 2,771 3,798 1";
按照排列组合来说,他们要一次组成一个6个位一串的数组
但是 前三个数字相同的元素不得出现两次
例如上数组可得到4个组合:
777 3,888 1,999 3,765 3,771 3,798 3
777 0,888 1,999 3,765 3,771 3,798 3
777 3,888 1,999 3,765 2,771 3,798 3
777 0,888 1,999 3,765 2,771 3,798 3
求方法
var a="777 3,777 0,888 1,999 3,765 3,765 2,771 3,798 1";
按照排列组合来说,他们要一次组成一个6个位一串的数组
但是 前三个数字相同的元素不得出现两次
例如上数组可得到4个组合:
777 3,888 1,999 3,765 3,771 3,798 3
777 0,888 1,999 3,765 3,771 3,798 3
777 3,888 1,999 3,765 2,771 3,798 3
777 0,888 1,999 3,765 2,771 3,798 3
求方法
var r="712 3,713 1,714 1,715 1,716 1,728 1,728 3";
分解成
var r1="712 3,713 1,714 1,715 1,716 1,728 1";
var r2="712 3,713 1,714 1,715 1,716 1,728 3";
这个意思就是说,数组R中如果有某几个元素前三位一样的话,则分解成不通的几个数组……这个理解不
if (n == 0) {
document.write(has.join(","));
document.write("<br/>");
return;
}
if (other.length < n) {
return;
}
var one = other.shift();
if (isIn(has, one)) {
myfind(has, other, n);
} else {
var newhas = has.concat();
var newother = other.concat();
has.push(one);
myfind(has, other, n-1);
myfind(newhas, newother, n);
}
}
function isIn(has, one) {
for (i in has) {
if (has[i].substring(0, 3) == one.substring(0, 3)) {
return true;
}
}
return false;
}var a="777 3,777 0,888 1,999 3,765 3,765 2,771 3,798 1";
myfind(new Array(), a.split(","), 6);</script>
if (n == 0) {
document.write(has.join(","));
document.write("<br/>");
return;
}
if (other.length < n) {
return;
}
var one = other.shift();
if (isIn(has, one)) {
myfind(has, other, n);
} else {
var newhas = has.concat();
var newother = other.concat();
has.push(one);
myfind(has, other, n-1);
myfind(newhas, newother, n);
}
}
function isIn(has, one) {
for (i in has) {
if (has[i].substring(0, 3) == one.substring(0, 3)) {
return true;
}
}
return false;
}var a="777 3,777 0,888 1,999 3,765 3,765 2,771 3,798 1";
myfind(new Array(), a.split(","), 6);</script>