China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-22 22:04
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Joint Participation][Challenge Your Thinking] Find the sums of all different combinations in a column of numbers DigestI View 12,297 Replies 21
Floor 16 Posted 2007-01-05 15:20 ·  中国 广东 湛江 电信
高级用户
★★★
Credits 959
Posts 311
Joined 2006-04-11 14:08
20-year member
UID 53665
Gender Male
From 广东-LianJiang
Status Offline
The idea behind the code in the 9th-floor post is really strong, definitely deserves points.
I'll slowly break down this piece of code.
Floor 17 Posted 2007-01-05 23:55 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  The code in the 15th-floor post really does run much more efficiently than the one in the 9th-floor post. Both are worth learning from, added points.
Floor 18 Posted 2007-01-07 13:13 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Long time no visit. Turns out this problem has already been solved perfectly. Brother qzwqzw's recursion in the 9th-floor post really is the best algorithm for solving this problem, and brother tao0610's improved code in the 15th-floor post greatly raises the efficiency. Excited, one word: awesome...

When I first discussed this with brother namejm, I also wrote a piece, but it missed some combination items. Later I thought of quite a few algorithms, and in the end found that only recursion could solve the missing-item problem well. Recursion needs a stack, a kind of data structure. Batch processing can't possibly implement this stack data structure, so in the end I dropped that algorithm too.

Brother qzwqzw's study of algorithms is really deep enough, admirable. I just got here and haven't looked carefully at the code yet; when I have time I'll digest it properly.
业精于勤而荒于嬉,形成于思而毁于随。
Floor 19 Posted 2007-01-08 00:01 ·  中国 辽宁 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
I wonder whether some expert could write one in VBS, thanks!
Floor 20 Posted 2007-01-26 07:40 ·  中国 江苏 南京 电信
初级用户
★★
Credits 138
Posts 50
Joined 2007-01-23 10:59
19-year member
UID 77428
Gender Male
Status Offline
dim msg,ss,ans
ss="12345"
For k=2 to len(ss)
Combine ss,k,""
next
arr=split(left(msg,Len(msg)-1),";")
for j=0 to ubound(arr)
rep="":res=0
for k=1 to len(arr(j))
rep=rep&mid(arr(j),k,1)&"+"
res=res + Cstr(mid(arr(j),k,1))
next
ans=ans&Cstr(j+1)&":"&Left(rep,Len(rep)-1)&"="&CStr(res)&vbCrLf
next
msgbox ans,0,"Result"
Sub Combine(sar,num,str)
If num=0 Then
msg=msg&str&";"
Else
For i=1 To Len(sar)
Call Combine(Right(sar,Len(sar)-i),num-1,str&Mid(sar,i,1))
Next
End If
End Sub
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
jmz573515 +4 2007-01-26 07:51
Floor 21 Posted 2007-01-26 07:51 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Good, learned something.
Floor 22 Posted 2007-02-01 02:54 ·  中国 湖南 长沙 联通
社区乞丐
★★
gaoshou
Credits -16
Posts 77
Joined 2007-01-30 09:11
19-year member
UID 78105
Gender Male
Status Offline
Excellent
This little brother needs to start digesting it now
:cool:
Forum Jump: