Two fishing vessels are sailing the open ocean, both on a joint ops fishing mission.

On a high stakes, high reward expidition - the ships have adopted the strategy of hanging a net between the two ships.

The net is **40 miles long**. Once the straight-line distance between the ships is greater than 40 miles, the net will tear, and their valuable sea harvest will be lost! We need to know how long it will take for this to happen.

Given the bearing of each ship, find the time **in minutes** at which the straight-line distance between the two ships reaches **40 miles**. Both ships travel at **90 miles per hour**. At time 0, assume the ships have the same location.

Bearings are defined as **degrees from north, counting clockwise**.
These will be passed to your function as integers between **0 and 359** degrees.
Round your result to **2 decmal places**.


If the net never breaks, return float('inf')

Happy sailing!

Source: codewars | Difficulty: EASY
Tags: Mathematics

Starter code: def find_time_to_break(bearing_A, bearing_B):
	

Solutions:
from math import sin, radians

def find_time_to_break(bearing_A, bearing_B):
	a = radians(abs(bearing_A - bearing_B) / 2)
	return 40 / (3 * sin(a)) if a else float('inf')


def find_time_to_break(bearing_A, bearing_B):
	import math
	if bearing_A == bearing_B:
		return float('inf')
	return round(math.sqrt(40 ** 2 / (2 * (1 - math.cos(math.radians(abs(bearing_A - bearing_B)))))) * 2 / 3, 2)


import math

def find_time_to_break(bearing_A, bearing_B):
	ships_angle = abs(bearing_A - bearing_B) * (math.pi / 180)
	time_to_40 = float('inf')
	if ships_angle > 0:
		den = 1.5 * math.sqrt(2 * (1 - round(math.cos(ships_angle), 5)))
		time_to_40 = round(40 / den, 2)
	return time_to_40


def find_time_to_break(bearing_A, bearing_B):
	import math
	bear = abs(bearing_A - bearing_B) / 2
	angle = math.sin(math.radians(bear))
	if angle != 0:
		return round(20 * 60 / (angle * 90), 2)
	else:
		return float('inf')


from math import sin, radians

def find_time_to_break(b1, b2):
	return round(40 / sin(radians(abs(b1 - b2)) / 2) / 3, 2) if b1 - b2 != 0 else float('inf')


from math import cos, hypot, radians, sin

def find_time_to_break(a, b):
	(a, b) = (radians(a), radians(b))
	d = hypot(cos(a) - cos(b), sin(a) - sin(b))
	return 40 / (90 / 60) / d if d else float('inf')


from math import cos, radians, inf

def find_time_to_break(bearing_A, bearing_B):
	theta = bearing_A - bearing_B
	return inf if theta == 0 else 18.86 / (1 - cos(radians(theta))) ** 0.5


from math import *

def find_time_to_break(a, b):
	(vShips, netLength) = (90 / 60, 40)
	return float('inf') if a == b else netLength / 2 / (vShips * sin(radians(abs(b - a) / 2)))


from math import sin, pi

def find_time_to_break(bearing_A, bearing_B):
	return float('inf') if abs(bearing_A - bearing_B) == 0 else 20 / sin(abs(bearing_A - bearing_B) * pi / 180 / 2) * 60 / 90


from math import cos, pi, sin
SHIP_MPH = 90
NET_LENGTH = 40

def find_time_to_break(bearing_A, bearing_B):
	(ba, bb) = (bearing_A + 360, bearing_B + 360)
	alpha = min(abs(ba - bb), abs(bb - ba))
	if alpha > 180:
		alpha = 360 - alpha
	if alpha == 0:
		return float('inf')
	theta = alpha / 2 / 180 * pi
	s1 = (SHIP_MPH * sin(theta), SHIP_MPH * cos(theta))
	s2 = (SHIP_MPH * sin(-theta), SHIP_MPH * cos(-theta))
	mph = ((s1[0] - s2[0]) ** 2 + (s1[1] - s2[1]) ** 2) ** 0.5
	return NET_LENGTH / mph * 60