|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 DevilW 于 2021-10-20 16:53 编辑
- Sub test()
- 't 选7组合, s 差值, n 差组合
- Set reg = CreateObject("vbscript.regexp")
- reg.Global = True
- reg.Pattern = "\b(\d+)\b.*?\b\1\b"
- Dim br(1 To 120000, 1 To 7) '已跑一遍计数算出组合数量
- For i1 = 1 To 13
- For i2 = 1 To 13
- t1 = i1 & "," & i2: If reg.test(t1) Then GoTo npi2 '7组合重复跳
- s1 = Abs(i1 - i2): If s1 > 7 Then GoTo npi2 '差值>7跳
- For i3 = 1 To 13
- t2 = t1 & "," & i3: If reg.test(t2) Then GoTo npi3
- s2 = Abs(i3 - i2): If s2 > 7 Then GoTo npi3
- n1 = s1 & "," & s2: If reg.test(n1) Then GoTo npi3 '差组合重复跳
- For i4 = 1 To 13
- t3 = t2 & "," & i4: If reg.test(t3) Then GoTo npi4
- s3 = Abs(i3 - i4): If s3 > 7 Then GoTo npi4
- n2 = n1 & "," & s3: If reg.test(n2) Then GoTo npi4
- For i5 = 1 To 13
- t4 = t3 & "," & i5: If reg.test(t4) Then GoTo npi5
- s4 = Abs(i5 - i4): If s4 > 7 Then GoTo npi5
- n3 = n2 & "," & s4: If reg.test(n3) Then GoTo npi5
- For i6 = 1 To 13
- t5 = t4 & "," & i6: If reg.test(t5) Then GoTo npi6
- s5 = Abs(i5 - i6): If s5 > 7 Then GoTo npi6
- n4 = n3 & "," & s5: If reg.test(n4) Then GoTo npi6
- For i7 = 1 To 13
- t6 = t5 & "," & i7: If reg.test(t6) Then GoTo npi7
- s6 = Abs(i7 - i6): If s6 > 7 Then GoTo npi7
- n5 = n4 & "," & s6: If reg.test(n5) Then GoTo npi7
- '==========================================================
- n = n + 1
- br(n, 1) = i1
- br(n, 2) = i2
- br(n, 3) = i3
- br(n, 4) = i4
- br(n, 5) = i5
- br(n, 6) = i6
- br(n, 7) = i7
- '==========================================================
- npi7:
- Next
- npi6:
- Next
- npi5:
- Next
- npi4:
- Next
- npi3:
- Next
- npi2:
- Next
- Next
- [a1].Resize(n, 7) = br
- End Sub
复制代码 |
|