0

vb.net的陣列排列組合迴圈問題

Dim i() as Integer = {1,2,3,4}

1
1+2
1+3
1+4
1+2+3
1+2+4
1+2+3+4
1+3+4
2
2+3
2+4
...

Dim myfunc As Func(Of Integer,Integer) = Function(ByVal num As Integer) As Integer
Dim res As Integer
[我沒有概念的地方]
Return res
End Function
arg=myfunc(i)

2 個回答

0

iT邦大神 1 級 ‧ 2019-04-24 09:12:27

froce iT邦大師 1 級 ‧ 2019-04-24 10:29:46 檢舉

python：

``````from itertools import combinations
testList = [1, 2, 3, 4]

for i in range(1, len(p)+1):
for c in combinations(testList, i):
print(c, "sum:", sum(c))
``````

``````(1,) sum: 1
(2,) sum: 2
(3,) sum: 3
(4,) sum: 4
(1, 2) sum: 3
(1, 3) sum: 4
(1, 4) sum: 5
(2, 3) sum: 5
(2, 4) sum: 6
(3, 4) sum: 7
(1, 2, 3) sum: 6
(1, 2, 4) sum: 7
(1, 3, 4) sum: 8
(2, 3, 4) sum: 9
(1, 2, 3, 4) sum: 10
``````

j2ian iT邦新手 5 級 ‧ 2019-04-24 13:21:39 檢舉
``````        For i = 0 To arrList.Count - 1
c = i + 1
str2 = arrList(i)
Console.WriteLine(str2)
For c = c To arrList.Count - 1
Console.WriteLine(arrList(i) + "+" + arrList(c))
str2 = str2 + "+" + arrList(c)
d = c + 1
For d = d To arrList.Count - 1
Console.WriteLine(str2 + "+" + arrList(d))
'str2 = str2 + "+" + arrList(c)
Next
Next
Next
``````

1
1+2
1+2+3
1+2+4
1+3
1+2+3+4
1+4
2
2+3
2+3+4
2+4
3
3+4
4

0
a5502008
iT邦新手 5 級 ‧ 2019-04-25 10:12:28