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-28 05:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to find out which numbers in the text add up to a specified value View 3,751 Replies 48
Original Poster Posted 2007-03-03 01:42 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
I encountered a problem at work and now post it on the forum to ask everyone to help solve it.

There is test.txt, the content is:


4816
4776
4498
4616
4948
4684
4710
5266
4760
5168
4770
5134
5076
4784
5174
4732
4782
4746
4730
5224
5164
4742
4724
4730
4762
4162
4188
4830
4942
4072
4270
4520
4808
5130
4272
4262
4238
4240
4828
4168
4754
4720
4896
4824
5206
4322
3800
4826
4632
5104
5134
4838
3858
5008
4828
5234
4324
5282
5348
5150
4724
4682
4720
5218
4744
4742
4760
5194
4792
4712
4754
4704


I want to find out which numbers among them add up to 171780
Requirement: If there are multiple combinations, list them in turn; each number in these 72 numbers in each combination can only be used once.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 2 Posted 2007-03-03 01:44 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Floor 3 Posted 2007-03-03 01:47 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
I don't care about efficiency, nor do I care whether to use third-party tools like awk, etc., as long as the requirement is met.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 4 Posted 2007-03-03 02:16 ·  中国 江苏 连云港 电信
高级用户
★★★
前进者
Credits 641
Posts 303
Joined 2007-01-10 02:57
19-year member
UID 76009
Gender Male
Status Offline
This is so troublesome with p, and I definitely can't figure it out at my current level, heh. Looking forward to experts' solutions!
我相信总有一天,总会遇到一个人可以相濡以沫、相吻以湿!
Floor 5 Posted 2007-03-03 02:36 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Add the first data to the subsequent ones one by one, and discard the first number when reaching the second one...
Floor 6 Posted 2007-03-03 04:38 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Bump up, don't let it sink.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 7 Posted 2007-03-03 04:56 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Is it necessary to go through all combination methods one by one
Floor 8 Posted 2007-03-03 05:00 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
It should be. To find all combinations, and finally display the combination whose value equals the desired value.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 9 Posted 2007-03-03 05:02 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
It's a very interesting question, but it seems the difficulty is not small either.
Floor 10 Posted 2007-03-03 05:38 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Refer to this and add "if "Calculation result" == "171780" " for judgment at an appropriate place

Find the sum of all different combinations of a column of numbers
Floor 11 Posted 2007-03-03 05:54 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Floor 12 Posted 2007-03-03 05:55 ·  中国 北京 朝阳区 联通
初级用户
Credits 83
Posts 34
Joined 2006-11-24 10:50
19-year member
UID 71574
Gender Male
Status Offline
72 numbers permutation and combination?

I'm afraid it would take N hours to get the result.

Batch processing doesn't have this computing power yet
Floor 13 Posted 2007-03-03 06:09 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
re zh159

BrothermeansIunderstandthatactuallytheforummoderatorsetupthatthreadpreciselyformypuzzle。Afterusingit,Ididn'tachievethegoalandputitaside。

Recently,Ineedtouseitagain,soImentionitagain,hopingtogetitsolved。
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 14 Posted 2007-03-03 06:13 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
I tried that, but nothing came out after a long time. I'm thinking about using VBS or something like that.
Floor 15 Posted 2007-03-03 06:18 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
It seems that a lot of recursive layers need to be nested.
Forum Jump: