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-25 05:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problem: How many times do the three hands of a clock coincide in a day? View 6,147 Replies 32
Floor 16 Posted 2009-01-13 12:45 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
19-year member
UID 59307
Status Offline
According to everyone's understanding, the ideal clock should overlap 23 times.
0-24 contains 25 whole hours, 24 hours;
Between 11-13, there is only the 12 o'clock overlap between the two whole hours, and similarly, between 23-24, there is only 24;
0-24 is equivalent to one more second in a whole day, and just this one second is the overlap, so it is 22+1=23 times.
┌───────┐
├→学习→实践→┤
└───────┘
Floor 17 Posted 2009-01-13 18:16 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Time is continuous like flowing water, not in jumps, so the ideal clock should be like what the 8th floor said
Floor 18 Posted 2009-01-14 00:13 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
(Found online, didn't study the proof and don't understand)

Only twice

Assume the angular velocity of the hour hand is ω (ω = π/6 per hour), then the angular velocity of the minute hand is 12ω, and the angular velocity of the second hand is 72ω. Let t be the time when the minute hand and the hour hand coincide again, then 12ωt - ωt = 2π, t = 12/11 hours, converted to hours, minutes and seconds is 1 hour 5 minutes 27.3 seconds. Obviously, the second hand does not coincide with the hour hand and the minute hand. Similarly, it can be calculated that the second hand cannot coincide with them in the other 10 times when the minute hand and the hour hand coincide. Only at exactly 12 o'clock and 0 o'clock do they coincide.

Proof: Treat the hour hand as stationary, and examine the relative speeds of the minute hand and the second hand with respect to it:

Take 12 hours as the time unit "1", and "circles/12 hours" as the speed unit,

then the speed of the minute hand is 11, and the speed of the second hand is 719.

Since 11 and 719 are coprime, let 12 hours / (11*719) be the time unit Δ,

then the minute hand coincides with the hour hand if and only if t = 719kΔ, k ∈ Z

The second hand coincides with the hour hand if and only if t = 11jΔ, j ∈ Z

And the least common multiple of 719 and 11 is 11*719, so if the three hands coincide at t = 0, then the next time the three hands coincide

must be at t = 11*719*Δ, that is, t = 12 o'clock.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
NeverAgain +2 2009-01-19 00:58
Floor 19 Posted 2009-01-14 10:25 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
It is said that if you calculate by angle, you won't get my result. This problem doesn't say the way the needle rotates. There are clocks that always run, and most of the designed needles still jump. The minimum swing amplitude is 1 second... This kind of needle is not in uniform circular motion... The above proof is not applicable.
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 20 Posted 2009-01-14 16:41 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
12-hour overlap

@echo off
for /l %%i in (0 1 11) do (
setlocal
set/a n=%%i*60
call:lp %%i
endlocal
)
pause&goto :eof
:lp
set/a d=%d%%n:~,1%%%11,m=%d%%n:~,1%/11
if "%i%"=="0" set i=
set i=%i%%m%
set n=%n:~1%
if defined n goto lp
set/a d=%1*60-(11*i)
:lp1
set/a m=d*10/11,w+=1
if "%j%"=="0" set j=
if %w% lss 5 set j=%j%%m%&set/a d=d*10%%11&goto lp1
set/a j*=6,h+=%1+i/60,i%%=60
set h=0%h%&set i=0%i%&set j=0%j%
echo %h:~-2%:%i:~-2%:%j:~-5,2%.%j:~-3,2%
goto :eof


[ Last edited by terse on 2009-1-15 at 11:17 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
exzzz +2 2009-01-22 00:23
简单!简单!再简单!
Floor 21 Posted 2009-01-14 23:41 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
Originally posted by terse at 2009-1-14 16:41:
12-hour coincidence

@echo off
for /l %%i in (0 1 11) do (
setlocal
set/a n=%%i*60
call:lp %%i
endlocal
)
pause&goto :eof
:lp
set/a d=%d%%n:~,1%%%11,m=%d%%n:~,1%/11
...

The very version of the moderator can't understand this. Briefly introduce the algorithm.
Floor 22 Posted 2009-01-15 02:40 ·  中国 江苏 常州 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Originally posted by linee at 2009-1-14 23:41:

The super moderator can't understand this. Simply introduce the algorithm.

My thinking is like this. Let's discuss whether it's correct or not.
Suppose the surface has 60 scales. One hour is 5 scales. x scales is x/5 scales after 0 o'clock. Similarly, y minutes is y/60 hours. When reaching the next coincidence point, the two scales are the same after 0 o'clock. That is, x/5 hours - y/60 hours is an integer. Because the minute hand goes one more circle, so it keeps increasing by 1. Because the scales are the same, so I think the result of X/5 - Y/60 should be increasing from 0 to 11. Here, x and y scales are equal, that is, X/5 - X/60.
Just wrote a batch to derive another problem from this question:
That is, at what scales the hour hand and the minute hand can be swapped and are reasonable, for example:
07:43:13.00
07:48:15.10
07:53:17.20
07:58:19.29
08:03:21.39
08:08:23.49
08:13:25.59
08:18:27.69
08:23:29.79
08:28:31.88
08:33:33.98
08:38:36.07
简单!简单!再简单!
Floor 23 Posted 2009-01-15 09:28 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
Originally posted by terse at 2009-1-15 02:40:

My train of thought is like this. Let's discuss whether it's correct or not.
Suppose the surface has 60 scales. One hour is 5 scales. x scales is x/5 scales after 0 o'clock. Similarly, y minutes is y/60 hours. When reaching the next coincidence point...

It should be correct, very similar to my calculation (I calculate it by the fact that the hour hand and minute hand coincide once every 12/11 hours). As follows:

Why is there no picture?

Forget it, just explain in text. Your calculation is very similar to mine (provided earlier). There is only one abnormal moment, which is at 09:49. Your calculation is 09:49:54.540, and what I provided earlier is 09:49:05.45. There's a big difference between 54 and 05. It's a bit strange.

Let's analyze your code first.

[ Last edited by linee on 2009-1-15 at 09:54 ]
Floor 24 Posted 2009-01-15 11:18 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Originally posted by linee at 2009-1-15 09:28:

....One is 54 and the other is 05

The bit position was wrong, has been corrected
简单!简单!再简单!
Floor 25 Posted 2009-01-15 15:10 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
Originally posted by terse at 2009-1-15 02:40:

My thinking is like this. Let's discuss whether it's correct or not.
Assume the surface has 60 scales. One hour is 5 scales. x scales is x/5 scales after 0 o'clock. Similarly, y minutes is y/60 hours. When reaching the next coincidence point...

After analysis, the result of yours should be equivalent to coinciding once every 12/11 hours. Try modifying your code as follows, hope you don't mind.
@echo off
for /l %%i in (0 1 11) do (
setlocal
set/a n=%%i*60
call:lp %%i
endlocal
)
pause&goto :eof
:lp
set/a d=%n%%%11,i=%n%/11
set/a j=d*10000/11
set/a j*=6,h=%1+i/60,i%%=60
set h=0%h%&set i=0%i%&set j=0%j%
echo %h:~-2%:%i:~-2%:%j:~-5,2%.%j:~-3,2%
goto :eof
Floor 26 Posted 2009-01-15 15:26 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
I actually solved the above program. You simplified a lot, which is very good.
Let's discuss again at what scales the hour hand and minute hand can be swapped and be in a reasonable situation. Among them, the coincidence situation has been prompted.

@echo off
for /l %%i in (0 1 11) do (
for /l %%j in (0 1 11) do (
setlocal enabledelayedexpansion
set/a n=^(%%j*12+%%i^)*60
set/a d=n%%143,i=n/143,j=d*10000/143,j*=6,h=%%i+i/60,i%%=60
set h=0!h!&set i=00!i!&set j=00!j!
if %%i equ %%j (echo The hands coincide echo !h:~-2!:!i:~-2!:!j:~-5,2!.!j:~-3,2!
) else echo !h:~-2!:!i:~-2!:!j:~-5,2!.!j:~-3,2!
endlocal
))
pause&goto :eof

The code for coincidence is placed in the for loop for higher efficiency. The previous call was because of considering decimals. Now it's directly okay.

@echo off
for /l %%i in (0 1 11) do (
setlocal enabledelayedexpansion
set/a n=%%i*60,d=n%%11,i=n/11,j=d*10000/11,j*=6,h=%%i+i/60,i%%=60
set h=0!h!&set i=00!i!&set j=00!j!
echo !h:~-2!:!i:~-2!:!j:~-5,2!.!j:~-3,2!
endlocal
)
pause


[ Last edited by terse on 2009-1-18 at 14:51 ]
简单!简单!再简单!
Floor 27 Posted 2009-01-15 17:26 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
What does "hour hand and minute hand exchange" mean?
Floor 28 Posted 2009-01-15 17:33 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Originally posted by linee at 2009-1-15 17:26:
What does "swap the positions of the hour hand and minute hand" mean?

For example, when they overlap, swapping the positions of the hour hand and minute hand must be reasonable. For example, at 3 o'clock, swapping the positions is obviously unreasonable because when the hour hand is at 12 o'clock, the minute hand will never be at 3 o'clock.
简单!简单!再简单!
Floor 29 Posted 2009-01-16 23:03 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
Originally posted by terse at 2009-1-15 17:33:

For example, when the time coincides, swapping the positions of the hour and minute hands is definitely reasonable. For example, at 3 o'clock, swapping the positions is obviously unreasonable because when the hour hand is at 12 o'clock, the minute hand will never be at 3 o'clock.

A bit difficult to understand, don't want to study anymore.
Floor 30 Posted 2009-01-16 23:06 ·  中国 贵州 安顺 电信
初级用户
Credits 94
Posts 49
Joined 2008-12-14 20:47
17-year member
UID 133884
Gender Male
Status Offline
Let me post and see how it goes,
Ashamed, I regret not having read enough books when I need them. I always feel I can't express myself clearly. I've tried my best, just make do with it. Welcome to point out mistakes.
:: Clock three-hand coincidence problem:
::
:: Idea: First find the position s1 where the hour hand and minute hand coincide, then find the position s2 of the second hand at this time,
:: If s2 = s1, then the three hands coincide. Compare from 0 o'clock to 24 o'clock.
::
:: The first coincidence of the hour hand and minute hand occurs between 1 o'clock and 2 o'clock. Let the time at this moment be t.
:: The angular velocity of the hour hand is w. At this time, the hour hand travels wt. The angular velocity of the minute hand is 12 times that of the hour hand.
:: There is that the minute hand travels 12wt. At this time, the minute hand has traveled one full circle (12w) more than the hour hand. So there is:
:: 12wt - wt = 12w, t = 12/11
:: At this time, the position of the hour hand wt = w * 12/11 = (1/11) * 12w, which is equivalent to 1/11 circle, can be taken
:: s1 = 1/11
:: Also, the angular velocity of the second hand is 720 times that of the hour hand. At this time, the second hand travels 720wt. The position of the second hand
:: 720wt = 720w * 12/11 = (65 + 5/11) * 12w
:: Which is equivalent to 65 and 5/11 circles, can be taken
:: s2 = 5/11
:: Compare s1 is not equal to s2, knowing that the three hands do not coincide at this time. Because cmd does not support floating points,
:: The comparison program of s1 and s2 is changed to take the remainder of 11 and then compare.
::
@echo off&setlocal enabledelayedexpansion
for /l %%i in (0,1,22) do (
set/a s1=%%i %%11,s2=%%i*5%%11,i=%%i+1
set/a h=%%i*12/11,m=%%i*60/11%%60,s=%%i*300/11%%60,sh=%%i*300%%11,sh*=100/11
for %%j in (h m s sh i) do if !%%j! lss 10 set %%j=0!%%j!
set /p=Hour-minute hand coincidence_!i! !h!:!m!:!s!.!sh! <nul
if !s1! equ !s2! (set/a j+=1&echo Three-hand coincidence_!j!) else echo.
)
pause


[ Last edited by linee on 2009-1-16 at 23:14 ]
Forum Jump: