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,752 Replies 48
Floor 16 Posted 2007-03-03 06:50 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Comrade, it seems that among these 72 numbers, 8 numbers are repeated:


4730
5134
4828
4724
4720
4742
4760
4754

Do we only need to consider the other 64 numbers?!
Floor 17 Posted 2007-03-03 06:54 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
It's not like that. For example: 4078 + 4078 + 4078 + 4052 + 4650 = 20936. If there are 3 4078s in test.txt, the above formula is allowed to appear.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 18 Posted 2007-03-03 07:01 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
This further increases the difficulty!

If only considering 64 non - repeating numbers, according to the calculation, at least 35 numbers are needed, and at most 37 numbers
Floor 19 Posted 2007-03-03 07:05 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
This is an inevitable situation in practical applications. That is to say, if the code doesn't calculate the repeated numbers, it's just to practice everyone's hands, not to solve my problem. Please understand.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 20 Posted 2007-03-03 07:16 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
In fact, excluding the number of combined numbers between 35 and 37, according to the conventional method, the possible number of combinations is still an extremely large number.
Floor 21 Posted 2007-03-03 07:18 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
It seems to take a lot of time, hehe, not tested


SETLOCAL ENABLEDELAYEDEXPANSION
for /f %%i in (data.txt) do (
set /a a1+=1
set _data!a1!=%%i)

for /l %%a in (1,3,%a1%) do (
set /a b=%%a+1
for /l %%b in (!b!,1,!b!) do (
set /a c=!b!+1
for /l %%c in (!c!,1,!c!) do (
set /a d=!c!+1
for /l %%d in (!d!,1,%a1%) do (
set /a z="1/(171780-!_data%%a!-!_data%%b!-!_data%%c!-!_data%%d!)"||echo !_data%%a!+!_data%%b!+!_data%%c!+!_data%%d!^=171780&&set /a _data%%a=0,_data%%b=0,_data%%c=0,_data%%d=0)
)
)
)

set
pause


[ Last edited by everest79 on 2007-3-2 at 06:33 PM ]
Floor 22 Posted 2007-03-03 07:39 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Oh, it turned out to be a four-digit number, I mistook it for a five-digit number
Floor 23 Posted 2007-03-03 08:15 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Can't write anymore, too much
Floor 24 Posted 2007-03-03 09:20 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Such a difficult question is finally posted. Oh~ I can't figure it out, looking forward to experts
Floor 25 Posted 2007-03-03 11:03 ·  中国 浙江 绍兴 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
Just a single math problem can kill a lot of brain cells, let alone designing an algorithm. -_-!
Floor 26 Posted 2007-03-03 21:18 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Sorted:

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



Sum of the largest 38 numbers
5348+5282+5266+5234+5224+5218+5206+5194+5174+5168+5164+5150+5134+5134+5130+5104+5076+5008+4948+4942+4896+4838+4830+4828+4828+4826+4824+4816+4808+4792+4784+4782+4776+4770+4762=175264

Sum of the smallest 39 numbers
3800+3858+4072+4162+4168+4188+4238+4240+4262+4270+4272+4322+4324+4498+4520+4616+4632+4682+4684+4704+4710+4712+4720+4720+4724+4724+4730+4730+4732+4742+4742+4744+4746+4754+4754+4760+4760+4762+4770=176548>171780
Then what does this indicate? It can only be 38 digits. (I casually calculated that the sum of the smallest 38 is 171778)


Thus, the number of digits is limited! The number of operations is reduced from 2^72 - 1 to 396561735952215036840 times, which is approximately 344 * 2^60 times... Although it is very large, you should know that 2^72 is about 11.9 times of it!
And the number of operations can be further reduced...
Floor 27 Posted 2007-03-03 21:28 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
The sum of the smallest 38 numbers has a difference of 2 from the required number (171780 - 171778 = 2)

3800 + 3858 + 4072 + 4162 + 4168 + 4188 + 4238 + 4240 + 4262 + 4270 + 4272 + 4322 + 4324 + 4498 + 4520 + 4616 + 4632 + 4682 + 4684 + 4704 + 4710 + 4712 + 4720 + 4720 + 4724 + 4724 + 4730 + 4730 + 4732 + 4742 + 4742 + 4744 + 4746 + 4754 + 4754 + 4760 + 4760 + 4762

And the 39th number is 4770. The number closest to it is the 38th one (I sorted them in order). And this number 4762 has a difference from 4770 that is greater than 2.

That is to say, if 39 is replaced with 38, the number becomes larger by 6 (171786). And this number is the 2nd smallest number among the 38 numbers. All the subsequent numbers are larger than it!

So the final answer comes out!!!!!


No qualifying combination
Floor 28 Posted 2007-03-03 21:49 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
re slore
There won't be no qualifying combinations as you said, because I got this result after a selection and then made the question.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 29 Posted 2007-03-03 21:53 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Originally posted by ccwan at 2007-3-3 08:49:
re slore
There won't be no combination that meets the requirements as I got this result after a selection, and then made the question.


Is your number 38?

Send me the short message with your number.
I think the analysis is not wrong... It won't be a calculation issue~
Floor 30 Posted 2007-03-03 21:59 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Sorry,Irandomlyselectedsomenumbers,gotaresultandsentitout,withoutrecordingwhichnumberstheywere,buttheremustbesuchcombinations.

Ifduetomyoversighttherereallyaren'tany,youcandefineoneyourselfaslongasitworks.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Forum Jump: