Re: [請益] 排列組合的程式邏輯
這個邏輯始終搞不清楚, 所以決定把我的程式PO上來,
請版上的高手幫我看看, 我是錯在哪?
除了組合不對, 值填到表的位置也不對, (還在努力找問題中)
謝謝大家提供的程式, 我自己也有找到一些, 但是不知道腦袋是裝漿糊
還是壞掉了, 一直搞不懂>"< 拜託了
tb_test表出現的結果:
2
3
4
5
3
4
5
4
5
5
scalar initial=1
scalar end=5
scalar bstrap=3
scalar jj=0
'這是檢查TB_TEST這個table是否存在, 存在的話就刪除
if @isobject("tb_test") then
delete tb_test
endif
table(100, 100) tb_test
!row=0
!col=0
for !j=initial to end
call combination(initial, end, bstrap, jj)
next
subroutine combination(scalar initial, scalar end, scalar bstrap, scalar jj)
for jj= !j+1to end
!row=!row+1
!col=!col+1
if jj>bstrap-1 then
!col=!col-1
endif
call combination(jj+1, initial, end, bstrap)
show tb_test
tb_test(!row, !col)=jj
next
endsub
※ 引述《magiccat (~米雪~)》之銘言:
: dear all,
: 目前有一個排列組合的程式要寫,
: 例如:C5取3(看得懂我在寫什麼嗎?)
: 應該會有10種組合,
: 那麼我應該要怎樣透過程式自動排列出來並記錄成下列的格式呢?
: 1 2 3
: 1 2 4
: 1 2 5
: 1 3 4
: 1 3 5
: 1 4 5
: 2 3 4
: 2 3 5
: 2 4 5
: 3 4 5
: 目前的想法是迴圈+副程式(副程式再CALL副程式自己)(但就是一直有盲點)>"<
: 希望有人指點一下, 謝謝!!我用的是E-views的統計軟體在寫程式
: E-views的程式寫法跟VB比較像(C語言的寫法我看不懂, 謝謝!)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.241.28
討論串 (同標題文章)