- function main(){
- let data=Range('c4:c83').CurrentRegion.Value2.flat().map(x=>Number(x));
- Range('I11:S1000').ClearContents();
-
- function 筛选(a,b,c,d,e){ //5个条件进行筛选
- let nums=data.filter(x=>Math.floor(x/10)==a);
- let res=[],n=b;
- let [c1,c2]=c.split('~');
- let [d1,d2]=d.split('~');
- let [e1,e2]=e.split('~');
- function dg(nums,n,path){ //递归生成
- if(path.length==n){
- res.push(path)
- //Debug.Print(path.join(','))
- return;
- }
- for(let x of nums){
- let restnums=nums.filter(y=>y>x)
- let nextpath=[...path,x]
- dg(restnums,n,nextpath)
- }
- }
-
- dg(nums,n,[]) //生成res
- let finalres=[]
- for(let x of res){
- if(test1(x,c1,c2) && test2(x,d1,d2) && test3(x,e1,e2)) {
- finalres.push(x)
- }
- }
- return finalres;
- }
-
- let [a,b,c,d,e]=[5,4,'9~11','3~5','2~3']
- let res=筛选(a,b,c,d,e)
-
- let [a1,b1,c1,d1,e1]=[6,3,'10~18','2~5','2~3']
- let res1=筛选(a1,b1,c1,d1,e1)
-
- let [a2,b2,c2,d2,e2]=[3,3,'14~24','2~5','0~0']
- let res2=筛选(a2,b2,c2,d2,e2)
-
- let finalres=[];
- for(let x of res){ //符合条件的三个数组相合
- for (let x1 of res1){
- for(let x2 of res2){
- finalres.push([...x,...x1,...x2])
- }
- }
- }
- Range('I11').Resize(finalres.length,finalres[0].length).Value2=finalres
- }
- function test1(arr,t1,t2){ //组合结果个位数字和值是否在t1,t2之间
- if(t1=='' && t2=='') return true;
- let n=arr.reduce((s,x)=>s+=x%10,0) ;
- return (n>=Number(t1) && n<=Number(t2));
- }
- function test2(arr,t1,t2){ //组合结果个位数字跨度是否在t1,t2之间
- if(t1=='' && t2=='') return true;
- let tmpar=arr.map(x=>x%10);
- let n=Math.max(...tmpar)-Math.min(...tmpar);
- return (n>=Number(t1) && n<=Number(t2));
- }
- function test3(arr,t1,t2){ //个位质数个数是否在t1,t2之间
- if(t1=='' && t2=='') return true;
- let n=0;
- for(let x of arr){
- let t=x%10;
- if(t==1 || t==2 || t==3 || t==5 || t==7) n+=1
- }
- return (n>=Number(t1) && n<=Number(t2));
- }
复制代码 |