A sailing app splits a race into legs. For every leg it knows the boat's course (the direction it sails, as a vector [east, north]) and the wind (the direction the air moves, also [east, north]). It labels each leg:
"tail"if the wind pushes the boat forward, even partly (it points more with the course than against it),"head"if it pushes the boat back, even partly,"cross"if it blows exactly at right angles to the course,"calm"if the wind vector is[0, 0].
Write wind_labels(legs) where legs is a list of pairs (course, wind), and return the list of labels in the same order. The vectors may also have three components (the third is up and down); the same rules apply.
Examples
Input: legs = [([1, 0], [3, 1]), ([0, 2], [1, -5]), ([2, 2], [3, -3]), ([4, 1], [0, 0])]
Output: ["tail", "head", "cross", "calm"]
Explanation: sailing east with a wind towards the east-north-east helps; sailing north into a
wind towards the south hurts; [2, 2] and [3, -3] are at right angles.
Constraints
1 <= len(legs) <= 10**4- every vector has 2 or 3 whole-number components between
-1000and1000, both vectors of a leg have the same length, and no course is[0, 0](or[0, 0, 0])
Goals
- Use the sign of a dot product to tell whether two directions agree
- Recognise that a dot product of zero means perpendicular
- Treat the zero vector as a special case