推 lovesnake:重複是因為我誤會你的想法~那個沒事了~ 140.121.216.68 04/14 12:23
→ lovesnake:Erlang...看不懂 糟糕了XD 140.121.216.68 04/14 12:23
→ lovesnake:方便寫PrusudoCode嗎>"< 140.121.216.68 04/14 12:23
→ lovesnake:錯字= =Presudo 140.121.216.68 04/14 12:24
→ lovesnake:那個Elang感覺好高階...我還在用C++ 140.121.216.68 04/14 12:25
→ lovesnake:又錯字= =Erlang 140.121.216.68 04/14 12:26
perms([], _) -> [[]];
perms(_, 0) -> [[]];
perms(L, N) -> [[H|T] || H <- L, T <- perms(L, N-1) ].
意思是:
function perms( List, Number, Set )
if List = {} then Set := {{}}, return
if Number = 0 then Set := {{}}, return
for i := 1 to length(List)
Set1 := {}
perms( List, (Number - 1), Set1 )
for j := 1 to length(Set1)
Set := union(Set, concat(List[i], Set1[j]))
return
[L || L<-test:perms(lists:seq(1,6), 3), lists:sum(L) == 8]
意思是:
function take_the_set()
Set := {}
Set1 := {}
perms( {1,2,3,4,5,6}, 3, Set1 )
for i := 1 to length(Set1)
if sum(Set1[i]) = 8 then Set := union(Set, Set1[i])
return Set
※ 編輯: yauhh 來自: 61.231.67.34 (04/14 12:43)
推 lovesnake:有點複雜= =" 待我研究一下 先謝過了 140.121.216.68 04/14 12:43