Here are two procedures associated with a clock with hands. I think they are interesting not only for fun, but will be useful for teachers in schools in the preparation of such tasks.
The first procedure called ClockHandsAngle finds the angle between the hands of the clock at any time.
The second procedure called TimeFromAngle , for a given angle finds all times in a given time range. The first procedure is used in the code of the second procedure, so the first procedure must be pre-initialized.
ClockHandsAngle:=proc(H, M) # H and M - time in hours (0
local A1,A2;
A1:=(irem(H,12)+M/60)*30; A2:=M*6;
min(abs(A1-A2),360-abs(A1-A2)); # Angle between the hands of the clock
end proc:
Examples of woks:
ClockHandsAngle(3,15);
ClockHandsAngle(19,10);
15/2
155
TimeFromAngle:=proc(Angle::numeric, Range::range) # Angle and Range - angle between the hands (in degrees) and time period (in hours), in which we seek solutions
local F, L, i;
if Angle <0 or Angle >180 then error "Should be 0<=Angle<=180"; fi;
if lhs(Range)<0 or rhs(Range)>24 or not type(lhs(Range), nonnegint) or not type(rhs(Range), nonnegint) then error "The left and right sides of the Range should be non-negative integers and less or equal than 24"; fi;
F:=[seq(convert(ClockHandsAngle(H,M), piecewise), H=0..23)];
L:=[];
for i from lhs(Range) to rhs(Range)-1 do
[solve({F[i+1]=Angle, M>=0, M<60})]; L:=[op(L), seq([i, rhs(op(%[j]))], j=1..nops(%))];
od;
L;
end proc:
Examples of works:
1) The clock shows 1 PM. After a few minutes minute hand coincide with the hour hand. How many time is it in this moment?
TimeFromAngle(0, 1..2);
[[1, 60/11]] # Time is 1 hour and 5 and 5/11 minutes
2) How many times in 24 hours, hour and minute hands form an angle of 90 degrees?
TimeFromAngle(90, 0..24);
nops(%);
[[0, 180/11], [0, 540/11], [1, 240/11], [1, 600/11], [2, 300/11], [3, 0], [3, 360/11], [4, 60/11], [4, 420/11], [5, 120/11], [5, 480/11], [6, 180/11], [6, 540/11], [7, 240/11], [7, 600/11], [8, 300/11], [9, 0], [9, 360/11], [10, 60/11], [10, 420/11], [11, 120/11], [11, 480/11], [12, 180/11], [12, 540/11], [13, 240/11], [13, 600/11], [14, 300/11], [15, 0], [15, 360/11], [16, 60/11], [16, 420/11], [17, 120/11], [17, 480/11], [18, 180/11], [18, 540/11], [19, 240/11], [19, 600/11], [20, 300/11], [21, 0], [21, 360/11], [22, 60/11], [22, 420/11], [23, 120/11], [23, 480/11]]
44
Two_procedures.mws