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 13:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Resolved] List all three-digit numbers composed of different numbers View 2,158 Replies 7
Original Poster Posted 2007-01-27 02:00 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
I want to write a combination of three-digit numbers (such as 001, 002...999), excluding combinations where two digits are equal (such as 001, 112, 313, 449, etc.) and combinations where all three digits are equal (such as 000, 111...999).

Note: For 012, 021, 120, 102, 210, 201, only one of them is taken, and the rest are similar.

[ Last edited by jmz573515 on 2007-1-26 at 06:41 PM ]
Floor 2 Posted 2007-01-27 02:10 ·  中国 江苏 南京 电信
初级用户
★★
Credits 138
Posts 50
Joined 2007-01-23 10:59
19-year member
UID 77428
Gender Male
Status Offline
```vb
dim msg
combine "0123456789",3,""
msgbox msg
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 ( 2 in total) Click for details
RaterScoreTime
ccwan +5 2007-01-27 02:37
jmz573515 +4 2007-01-27 08:11
Floor 3 Posted 2007-01-27 02:13 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Okay, learned it.

(Currently restricted from adding points, will make up later.)
Floor 4 Posted 2007-01-27 02:40 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
I am using the idea of combinations with a BAT version:

@echo off
set str=0123456789
cd.>result.txt
setlocal enabledelayedexpansion
for /l %%i in (0,1,7) do (
set /a num1=%%i+1
for /l %%j in (!num1!,1,8) do (
set /a num2=%%j+1
for /l %%k in (!num2!,1,9) do (
set /a count+=1
echo !str:~%%i,1!!str:~%%j,1!!str:~%%k,1!>>result.txt
)
)
)
echo The three-digit numbers where the digits at each position are all different and the digits forming the number are not completely the same as those in other numbers have %count% in total>>result.txt
start result.txt

Following ccwan's suggestion, the statistical result is added.

[ Last edited by namejm on 2007-1-26 at 11:08 PM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
ccwan +5 2007-01-27 02:46
jmz573515 +4 2007-01-27 23:45
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2007-01-27 03:01 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Banban's code is always so wonderful, appreciate it~~
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 6 Posted 2007-01-27 03:01 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Floor 7 Posted 2007-04-19 10:02 ·  中国 陕西 西安 电信
初级用户
★★
Credits 112
Posts 50
Joined 2007-04-15 00:59
19-year member
UID 85191
Gender Male
Status Offline
The second floor is written in C, relatively simple! I like the code given by the fourth floor, thank you two!
Floor 8 Posted 2007-05-08 10:37 ·  中国 广东 中山 电信
初级用户
★★
Credits 127
Posts 62
Joined 2007-04-19 12:43
19-year member
UID 85744
Gender Male
Status Offline
Forum Jump: