作者magiccat (~米雪~)
看板Programming
标题Re: [请益] 排列组合的程式逻辑
时间Tue Aug 19 21:49:33 2008
这个逻辑始终搞不清楚, 所以决定把我的程式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