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-08-12 05:08
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] Question about displaying combined variables View 1,046 Replies 7
Original Poster Posted 2009-07-04 13:34 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Floor 2 Posted 2009-07-04 14:01 ·  中国 广东 东莞 电信
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Floor 3 Posted 2009-07-04 17:59 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
After messing with it all night, it actually gave me:
****** B A T C H R E C U R S I O N exceeds STACK limits ******
Recursion Count=495, Stack Usage=90 percent
****** B A T C H PROCESSING IS A B O R T E D ******

Going to sleep now...
Floor 4 Posted 2009-07-05 03:24 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Should it be made like this?
Based on the link in post #2, I learned from it and then adapted it.
@echo off&setlocal enabledelayedexpansion
set in=寒夜孤星
set /p in=输入字符串
set m=0
set svr=abcdefghijklmnopqrstuvwxyz
:rep
if "!in:~%m%,1!" neq "" (set s0=!s0! !in:~%m%,1! &set/a m+=1&goto :rep)
set n=0
for %%a in (!s0!) do (
for %%b in (!n!) do (
set /a n+=1
set "coe1=!coe1!for %%!svr:~%%b,1! in (^!s%%b^!) do (set s!n!=^!s%%b:%%!svr:~%%b,1!=^!^&"
set "coe2=!coe2!%%!svr:~%%b,1!"
set "coe3=!coe3!)"
set doe1%%b=!coe1:~,-16!
set doe2%%b=!coe2!
set doe3%%b=!coe3!
)
)
set n=0
:loop
set coe1=!doe1%n%!
set coe2=!doe2%n%!
set coe3=!doe3%n%!

::dynamic code
%coe1%
echo %coe2%
%coe3%
::dynamic code

set/a n+=1
pause
if !n! neq !m! goto loop


[ Last edited by netbenton on 2009-7-5 at 01:27 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
Hanyeguxing +4 2009-07-05 03:39
精简
=> 个人网志
Floor 5 Posted 2009-07-05 03:50 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Thanks to the friend in the previous post.
What the link given in post #2 produces is permutations, but what I need is combinations.
For combinations, “寒夜孤星” and “寒夜星孤” are the same case, although for permutations they are different. So after generating permutations, they still need to be filtered... that is, filter out all cases that use the same Chinese characters (the same elements).

By the way, celebrating a bit: I can finally give other people 4 points now, haha
Floor 6 Posted 2009-07-05 04:08 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
The general idea would be to list all possible permutations first, then filter them to get the combinations.

According to the requirements I gave in the first post, the possible numbers of permutations and combinations are: (n is the number of characters in the variable)

For combinations: Σ(n)=2(n-1)+2(1)+2(2)+2(3)+......+2(n) Note: in this formula, the values in () are exponents of 2.
   That is: Σ(n)=2(n)-1 Note: in this formula, the values in () are exponents of 2.

For permutations: Σ(n)=n+
        n*(n-1)+
        n*(n-1)*(n-2)+
        n*(n-1)*(n-2)*(n-3)+
        n*(n-1)*(n-2)*(n-3)*(n-4)+
        n*(n-1)*(n-2)*(n-3)*(n-4)*(n-5)+
        ......
        n*(n-1)*(n-2)*(n-3)*(n-4)*(n-5)*......*3+
        n*(n-1)*(n-2)*(n-3)*(n-4)*(n-5)*......*3*2+
        n*(n-1)*(n-2)*(n-3)*(n-4)*(n-5)*......*3*2*1


When there are only four Chinese characters, that is, n=4, then the number of permutations is 64, and the number of combinations is 15. As n increases, the number of combinations grows algebraically, while the number of permutations grows geometrically.

For example, when n=10, the number of combinations is 1023, while the number of permutations is 9183700, an astronomical figure close to ten million. Then having to filter through 9183700 permutation cases to get the 1023 valid combination cases is a pretty terrifying thing...

So I had this idea: is it possible not to use the “permute first, then filter” method?

[ Last edited by Hanyeguxing on 2009-7-5 at 08:15 ]
Floor 7 Posted 2009-07-05 08:42 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Turns out a senior member had already solved this problem perfectly two years ago!
http://www.cn-dos.net/forum/viewthread.php?tid=26180###
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
Hanyeguxing +4 2009-07-05 09:03
精简
=> 个人网志
Floor 8 Posted 2009-07-05 09:05 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
I'm embarrassed...
I've been figuring it out myself for two days and still didn't get it done...
After reading the code in post #15, I really feel ashamed. That's the gap, and also the direction I need to work toward...
Forum Jump: