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-07-31 23:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion][Exploration] Using batch processing to make interesting math problems DigestI View 36,416 Replies 139
Floor 106 Posted 2007-03-20 01:07 ·  中国 湖北 潜江 电信
高级用户
★★★
Credits 894
Posts 411
Joined 2007-02-17 12:15
19-year member
UID 79697
Gender Male
Status Offline
As the title: Display with batch processing

1
121
12321
........................
12345678987654321
Prohibit using the echo command entirely.
@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul


Floor 107 Posted 2007-03-20 01:39 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Try the following code?

@echo off
setlocal enabledelayedexpansion
set "space= "

for /l %%i in (1 1 9) do (
for /l %%a in (1 1 %%i) do (
set str1=!str1!%%a
set str2=%%a!str2!
set str=%space%!str1!!str2:~1!
)
echo !str:~%%i!
set str1=
set str2=
set str=
)
pause>nul
Floor 108 Posted 2007-03-20 02:41 ·  中国 湖北 潜江 电信
高级用户
★★★
Credits 894
Posts 411
Joined 2007-02-17 12:15
19-year member
UID 79697
Gender Male
Status Offline
This is a very simple math problem. Mom bought a basket of apples. The eldest took 1/3, the second eldest took 1/3 of the remaining, the third one took 1/3 of the remaining. At this time, there are still 8 apples. How many apples are there in total?
@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul


Floor 109 Posted 2007-03-20 02:53 ·  中国 湖北 潜江 电信
高级用户
★★★
Credits 894
Posts 411
Joined 2007-02-17 12:15
19-year member
UID 79697
Gender Male
Status Offline
As the title says, N >= 3, no need to display in table form. For example:

2 7 6

9 5 1

4 3 8
@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul


Floor 110 Posted 2007-03-20 03:08 ·  中国 湖北 潜江 电信
高级用户
★★★
Credits 894
Posts 411
Joined 2007-02-17 12:15
19-year member
UID 79697
Gender Male
Status Offline
### Problem 1
Let the number of men be \(x\), the number of women be \(y\), and the number of children be \(z\). Then we have the following system of equations:
\[
\begin{cases}
x + y + z = 36 \quad (1) \\
4x + 3y + \frac{z}{2} = 36 \quad (2)
\end{cases}
\]
Multiply equation \((2)\) by \(2\) to get rid of the fraction: \(8x + 6y + z = 72 \quad (3)\)
Subtract equation \((1)\) from equation \((3)\): \((8x + 6y + z) - (x + y + z) = 72 - 36\)
\(7x + 5y = 36\)
Since \(x\) and \(y\) are positive integers, we can try values for \(x\):
If \(x = 1\), then \(7\times1 + 5y = 36\), \(5y = 29\), \(y\) is not an integer.
If \(x = 2\), then \(7\times2 + 5y = 36\), \(14 + 5y = 36\), \(5y = 22\), \(y\) is not an integer.
If \(x = 3\), then \(7\times3 + 5y = 36\), \(21 + 5y = 36\), \(5y = 15\), \(y = 3\)
Substitute \(x = 3\) and \(y = 3\) into equation \((1)\): \(3 + 3 + z = 36\), \(z = 30\)

So there are 3 men, 3 women, and 30 children.

### Problem 2
Let the number of bullocks be \(x\), the number of cows be \(y\), and the number of calves be \(z\). Then we have:
\[
\begin{cases}
x + y + z = 100 \quad (1) \\
3000x + 4000y + 600z = 100000 \quad (2)
\end{cases}
\]
Simplify equation \((2)\) by dividing by 100: \(30x + 40y + 6z = 1000\), further divide by 2: \(15x + 20y + 3z = 500 \quad (3)\)
Multiply equation \((1)\) by 3: \(3x + 3y + 3z = 300 \quad (4)\)
Subtract equation \((4)\) from equation \((3)\): \((15x + 20y + 3z) - (3x + 3y + 3z) = 500 - 300\)
\(12x + 17y = 200\)
Solve for \(x\): \(x = \frac{200 - 17y}{12}\)
Since \(x\) and \(y\) are positive integers, we try values for \(y\):
If \(y = 4\), then \(x = \frac{200 - 17\times4}{12} = \frac{200 - 68}{12} = \frac{132}{12} = 11\)
Substitute \(x = 11\) and \(y = 4\) into equation \((1)\): \(11 + 4 + z = 100\), \(z = 85\)

So there are 11 bullocks, 4 cows, and 85 calves.
@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul


Floor 111 Posted 2007-03-20 03:52 ·  中国 湖北 潜江 电信
高级用户
★★★
Credits 894
Posts 411
Joined 2007-02-17 12:15
19-year member
UID 79697
Gender Male
Status Offline
There is a group of people buying sheep together. If each person pays 5 taels, there is still a shortage of 45 taels. If each person pays 7 taels, there is still a shortage of 3 taels. Ask how many people are buying sheep and how much the sheep costs.
@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul


Floor 112 Posted 2007-03-20 04:54 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Originally posted by 6622186 at 2007-3-20 02:41 AM:
This is a very simple math problem. Mother bought a basket of apples. The eldest took 1/3, the second took 1/3 of the remaining, the third took 1/3 of the remaining, and there were 8 apples left. How many apples were there in total?


@echo off
setlocal enabledelayedexpansion

for /l %%i in (1 1 10000) do (
title Checking %%i....
set /a tmp=%%i*8/27
if !tmp! EQU 8 echo %%i && goto :exit
)
:exit
pause>nul

Actually, the above code can be simpler (according to mathematical principles), so simple that it's embarrassing (there's not much code to write).
Floor 113 Posted 2007-03-20 11:34 ·  中国 湖北 黄冈 电信
高级用户
★★★
Credits 894
Posts 411
Joined 2007-02-17 12:15
19-year member
UID 79697
Gender Male
Status Offline
This way, you can calculate numbers greater than 2^31. I thought it was impossible, but I don't understand the code. Seeing! gives me a headache.
@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul


Floor 114 Posted 2007-03-20 18:29 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
112th floor

Did you first calculate it and then write it like this?

Your sentence "set/a tem=%%i*8/27&np if !temp! equ 8 echo %%i....." doesn't it mean that %%i is 27?

Then what are you calculating?
Floor 115 Posted 2007-03-20 18:38 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
The complete solution is as follows:

Let the total be Y.

The first time, 1/3 of it is taken, leaving 2/3 * Y;

The second time, 1/3 of the remaining is taken again, leaving 2/3 * (2/3 * Y);

The third time, 1/3 of the remaining after the second time is taken, leaving only 2/3 * (2/3 * (2/3 * Y)).

hehe

This means: 2/3 * (2/3 * (2/3 * Y)) = 8

Then Y is 27.
Floor 116 Posted 2007-03-20 22:21 ·  中国 广东 广州 白云区 电信
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Originally posted by scriptor at 2007-3-20 06:29 PM:
Post 112

Did you calculate first and then write it like this?

Your sentence "set/a tem=%%i*8/27&np if !temp! equ 8 echo %%i....." means that %%i is 27?

Then what are you calculating?

If we say, to completely simulate solving it with a program, it seems simpler. According to the meaning of the problem, this number must be a multiple of 27 (it can be continuously divided by 3 three times). So the code can be written as:

for /l %%i (27 27 100000) do (
....)

It seems simpler, and you can get 27 at once.
Floor 117 Posted 2007-03-21 02:29 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by 6622186 at 2007-3-19 12:07:
As the title says: Display using batch processing

1
121
12321
........................
12345678987654321
Prohibit the use of all echo commands.

  Before leaving, post a code:

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do (
for /l %%j in (9,-1,%%i) do set /p= <nul
for /l %%k in (1,1,%%i) do set /p=%%k<nul
set /a num=%%i-1
for /l %%l in (!num!,-1,1) do set /p=%%l<nul
echo.
)
pause
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 118 Posted 2007-06-13 23:17 ·  中国 浙江 宁波 慈溪市 电信
新手上路
Credits 5
Posts 3
Joined 2007-06-13 14:09
19-year member
UID 91182
Gender Male
Status Offline
@echo off
echo.
Chickens and dogs total 79, with 200 feet on the ground. Think and calculate, how many chickens? How many dogs?
echo.
setlocal enabledelayedexpansion
set /a x=79
set /a y=200
for /l %%i in (1,1,79) do (
for /l %%j in (1,1,50) do (

set /a a=2*%%i
set /a b=4*%%j
set /a sum1=%%i+%%j
set /a sum2=!a!+!b!
if !sum1! equ !x! if !sum2! equ !y! echo %%i %%j
)
)
pause
Floor 119 Posted 2007-06-13 23:28 ·  中国 浙江 宁波 慈溪市 电信
新手上路
Credits 5
Posts 3
Joined 2007-06-13 14:09
19-year member
UID 91182
Gender Male
Status Offline
@echo off
echo.
One hundred monks and one hundred pastries. Each big monk gets four pastries, and four little monks share one pastry. How many big and little monks are there respectively?
echo.
setlocal enabledelayedexpansion
set /a x=100
for /l %%i in (1,1,25) do (
for /l %%j in (1,1,100) do (

set /a a=4*%%i
set /a b=%%j/4
set /a sum1=%%i+%%j
set /a sum2=!a!+!b!
if !sum1! equ !x! if !sum2! equ !x! echo "Big monk" %%i "Little monk" %%j
)
)
pause
Floor 120 Posted 2007-06-27 16:15 ·  中国 北京 联通
新手上路
Credits 4
Posts 2
Joined 2006-11-27 07:59
19-year member
UID 71862
Gender Male
Status Offline
Indeed.
Forum Jump: