I. Find the acute angle between the minute and hour needle of a clock for a given time H:M?
Minute needle angle, m = M * (360/60) = 6M
Hour needle Angle, h = H * (360/12) + M * ( (360/12) / 60) = 30H + M/2
Solution 1:
Acute Angle = arccos(cos(h-m))
Hint: Cos() will bring all angle from -1 to 1 range and arccos() will bring that to 0 to 180(pi)
Solution 2:
Difference in angle, d = |h-m|
or
d = (h-m)%360
Opposite angle, od = 360 - d
Acute angle = 180 - x
Obtuse angle = 180 + x
where x = |(od - d)/2| = |180 - d|
i.e, Acute Angle = 180 - |180-d|
II. Given a circular queue of size n (0..n-1). Other variables are front and rear of the queue. Find a formula to find number of elements in queue from n, front and rear?
Solution:
number of elements = (rear - front) % n
That is the magic of mod operator.
Subscribe to:
Post Comments (Atom)
A History of the Arab Peoples
Albert Hourani’s A History of the Arab Peoples is a fascinating exploration of Arab history, spanning from the rise of Islam to the late...
-
Albert Hourani’s A History of the Arab Peoples is a fascinating exploration of Arab history, spanning from the rise of Islam to the late...
-
Linux Command Line and Shell Scripting Bible, 4th Edition, by Richard Blum and Christine Bresnahan is a complete guide for software profess...
-
This is a book on patterns used in object-oriented design. Quite a classic one! Enjoyed reading book cover to cover. It has 23 design patter...
No comments:
Post a Comment