3楼题目的解题powershell代码,某牛人写的,不是我,呵呵,他是我请的做作业的枪手,我验证通过。3楼题我之所以发出来,是想用powershell+excel解。当然了,这种解法(powershell+excel)很麻烦。但这正是我想提供给各位的解题思路。可惜一直没空闲时间,唉,半年内争取做完此作业。
------------------------------------------------------- #根据条件列出可能的组合
- $jgg=New-Object system.collections.arraylist
- $sudu=New-Object psobject|select id,numble
- $sudu.id=1,1
- $sudu.numble=2,4,6,8
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=1,2
- $sudu.numble=2,4,6,8
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=1,3
- $sudu.numble=3,5,7,9
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=2,1
- $sudu.numble=2,4,6,8
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=2,2
- $sudu.numble=2,4,6,8
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=2,3
- $sudu.numble=3,5,7,9
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=3,1
- $sudu.numble=3,5,7,9
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=3,2
- $sudu.numble=3,5,7,9
- $jgg.add($sudu)|out-null
- $sudu=New-Object psobject|select id,numble
- $sudu.id=3,3
- $sudu.numble=1
- $jgg.add($sudu)|out-null
- $jgg
-
- #设置校验方法
- function csan($j0,$j1,$j2,$j3,$j4,$j5,$j6,$j7,$j8){
- if(
- $j0*100+$j1*10+$j2+
- $j3*100+$j4*10+$j5+
- $j6*100+$j7*10+$j8+
- $j0*100+$j3*10+$j6+
- $j1*100+$j4*10+$j7+
- $j2*100+$j5*10+$j8 -eq 4446){$outs.add($($j0,$j1,$j2,$j3,$j4,$j5,$j6,$j7,$j8 -join ","))}
- }
- #开始排列
- $global:outs=New-Object system.collections.arraylist
- foreach($j0 in $jgg[0].numble){
- foreach($j1 in $jgg[1].numble){
- foreach($j2 in $jgg[2].numble){
- foreach($j3 in $jgg[3].numble){
- foreach($j4 in $jgg[4].numble){
- foreach($j5 in $jgg[5].numble){
- foreach($j6 in $jgg[6].numble){
- foreach($j7 in $jgg[7].numble){
- $j8=1
- csan $j0 $j1 $j2 $j3 $j4 $j5 $j6 $j7 $j8
- }}}}}}}}
- #删除数据重复的结果
- $global:outs|?{$($_.split(",")|group).count -eq 9}
复制代码
|