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 04:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to find out which numbers in the text add up to a specified value View 3,747 Replies 48
Floor 31 Posted 2007-03-03 22:05 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Just give one randomly? Then it can only be that replacing the 39th one with 4764... Then there is a unique solution...

This depends on the situation. Otherwise, the amount of calculation is too large. You see the number of accumulation times I mentioned! Tens of powers of 2...

The method I think is the most economical is:
1. Sorting
2. Judging the number of numbers at least and at most.
3. Enumerating the numbers in these 2...
( I'll find this enumeration process later, too lazy to think again, but the more numbers, the more the operation...)
Floor 32 Posted 2007-03-04 00:21 ·  中国 山东 济南 电信
初级用户
Credits 125
Posts 44
Joined 2007-01-24 15:31
19-year member
UID 77555
Gender Female
Status Offline
Here comes permutations and combinations again!

There is no simple algorithm.

n = number of numbers in the array
r = from 1 to the sum of numbers in the array
Enumerate in nCr to see if there is a match.....


This kind of program is not suitable to run on a 32-bit system after being written...

--------------------------------------
If only to solve this problem, the recursive code of brother qzwqzw can be slightly modified.
But the calculation speed still depends on luck........

@ECHO %DBG% OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET /A THE=171780
FOR /F %%n IN (TEST.TXT) DO (
SET /A i+=1
SET gn!i!=%%n
)
FOR /L %%j IN (1,1,%i%) DO CALL :REC %%j
GOTO :EOF

:REC
SETLOCAL

CALL SET tmp=%%gn%1%%
SET /A sum+=%tmp%
IF %sum% GTR %THE% GOTO :EOF
SET /A lvl+=1
IF %lvl% GTR 1 (
SET exp=%exp%+%tmp%
SET /A idx+=1
CLS & ECHO 第 !idx! 次计算
IF !sum! EQU %THE% (
ECHO !exp!=%sum%
ECHO 继续计算请按任意键&PAUSE>NUL
)
) ELSE (
SET exp=%tmp%
)

SET /A nxt=%1+1
FOR /L %%j IN (%nxt%,1,%i%) DO CALL :REC %%j

ENDLOCAL & SET idx=%idx%
GOTO :EOF

Good luck!
Got the first result when performing the 103rd calculation:

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+4238+5104=171780


Still that sentence, this problem is not suitable to be solved in a 32-bit system environment.
The following attachment is 321 results obtained after 220,000 calculations!!!!!!

[ Last edited by qjbm on 2007-3-3 at 02:29 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
ccwan +5 2007-03-04 22:02
Attachments
结果.txt (60.98 KiB, Credits to download 1 pts, Downloads: 9)
Floor 33 Posted 2007-03-04 01:21 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
TO 26F:
If considering repeated numbers,
The largest number combination is only 35, not 38!
The smallest number combination requires 38.
So, the actual number of digits can be 35, 36, 37, 38, etc.
If following the conventional method, according to the permutation and combination rules, the number will be extremely large! I have announced my withdrawal and look forward to experts.
Floor 34 Posted 2007-03-04 01:31 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Originally posted by youxi01 at 2007-3-3 12:21:
TO 26F:
If considering repeated numbers,
The largest number combination only has 35, not 38!
The smallest number combination needs 38
So, the real number of digits has cases such as 35, 36, 37, 38, etc.
Such as...



Oh, got the meaning......

[ Last edited by slore on 2007-3-3 at 12:47 PM ]
Floor 35 Posted 2007-03-04 03:12 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
No way, the efficiency is so low. Then when I get old, it might not be fully calculated yet
Floor 36 Posted 2007-03-04 03:41 ·  中国 北京 联通
初级用户
Credits 83
Posts 34
Joined 2006-11-24 10:50
19-year member
UID 71574
Gender Male
Status Offline
Under ideal conditions, filter from these results.
72!/(35!(72-35)!) + 72!/(36!(72-36)!) + 72!/(37!(72-37)!) + 72!/(38!(72-38)!)
Floor 37 Posted 2007-03-04 03:48 ·  中国 山东 济南 电信
初级用户
Credits 125
Posts 44
Joined 2007-01-24 15:31
19-year member
UID 77555
Gender Female
Status Offline
72!/35!(72-35)! + 72!/36!(72-36)! + 72!/37!(72-37)! + 72!/38!(72-38)!

n = number of elements in the array
r = from 35 to 38
Enumerate in nCr to see if there are eligible ones.....

The same. Massive calculation mode!!
Floor 38 Posted 2007-03-04 03:50 ·  中国 北京 联通
初级用户
Credits 83
Posts 34
Joined 2006-11-24 10:50
19-year member
UID 71574
Gender Male
Status Offline
Batch processing should be something that can't be completed...
Floor 39 Posted 2007-03-04 05:26 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Gave up...
The enumeration code has been written... It's too slow for the operation.
No response... Closed. Too many numbers..
Floor 40 Posted 2007-03-04 05:28 ·  中国 河北 廊坊 三河市 移动
初级用户
Credits 41
Posts 19
Joined 2006-12-15 00:10
19-year member
UID 73540
Gender Male
Status Offline
Why doesn't the person upstairs publish the code so that we can learn from it?
Floor 41 Posted 2007-03-04 05:41 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Not written with p...
The P operation is even slower...

It's recursion and so on... Search online for combination recursion. There are many algorithms, for Delphi, C, VB...
Floor 42 Posted 2007-03-04 06:19 ·  中国 河北 廊坊 三河市 移动
初级用户
Credits 41
Posts 19
Joined 2006-12-15 00:10
19-year member
UID 73540
Gender Male
Status Offline
Then can the brother provide the C language code?
Floor 43 Posted 2007-03-04 06:35 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Floor 44 Posted 2007-03-04 07:34 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
I don't know why, the 36-digit combinations I wrote out are much more numerous than the groups of 32F?! The code is more efficient than 32F, but it's still not enough. I'm testing it and will post it later.
Floor 45 Posted 2007-03-04 07:48 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
The code is as follows, welcome to test and give corrections.

@echo off
setlocal enabledelayedexpansion
set num=0
for /f %%n in (test.txt) do (
set /a i+=1
set gn!i!=%%n
)
for /l %%i in (1,1,36) do call :rec %%i
pause
goto :eof

:rec
setlocal
set tmp=!gn%1!
set/a flag+=1
if %flag% EQU 1 (set str=%tmp%) else set str=%str%+%tmp%
set/a sum=%sum%+%tmp%
set /a nxt1=%1+1,nxt2=%1+36
if %nxt2% gtr 72 set/a nxt2=72
set /a lvl+=1
if %lvl% lss 36 (
for /l %%j in (%nxt1%,1,%nxt2%) do call :rec %%j
) else (
set/a idx+=1
title Detecting group number %idx% %num% groups detected
if %sum% EQU 171780 echo %str%=171780 is in group number %idx% & set/a num+=1
)
endlocal & set idx=%idx% & set num=%num%

Description: This section of code is for the situation when there are 36 number combinations. Other situations are not considered. Please change it yourself if needed.

[ Last edited by youxi01 on 2007-3-4 at 07:50 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
ccwan +5 2007-03-04 22:02
Forum Jump: