| 模型 | 模型答案 | 测试结果 |
|---|---|---|
| 金声玉亮2.0 | ```python from math import radians, sin, cos, sqrt, atan2 def distance_lat_long(lat1, lon1, lat2, lon2): R = 6371.0 lat1 = radians(lat1) lon1 = radians(lon1) lat2 = radians(lat2) lon2 = radians(lon2) dlat = lat2 - lat1 dlon = lon2 - lon1 a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2 c = 2 * atan2(sqrt(a), sqrt(1 - a)) distance = R * c return distance ``` |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| deepseekr1 | To solve this problem, we need to calculate the distance between two points on the Earth's surface given their latitude and longitude coordinates. The Haversine formula is the standard method to determine the shortest distance over the Earth's surface, often referred to as the great-circle distance. ### Approach The approach involves using the Haversine formula, which calculates the distance between two points on a sphere from their latitudes and longitudes. The steps are as follows: 1. Convert the latitude and longitude from degrees to radians. 2. Calculate the differences in latitude and longitude. 3. Apply the Haversine formula to compute the great-circle distance. ### Solution Code ```python import math def distance_lat_long(lat1, lon1, lat2, lon2): # Convert degrees to radians lat1_rad = math.radians(lat1) lon1_rad = math.radians(lon1) lat2_rad = math.radians(lat2) lon2_rad = math.radians(lon2) # Differences in coordinates dlat = lat2_rad - lat1_rad dlon = lon2_rad - lon1_rad # Haversine formula a = math.sin(dlat / 2)**2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(dlon / 2)**2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) # Earth radius in kilometers R = 6371 distance = R * c return distance ``` ### Explanation 1. **Conversion to Radians**: The trigonometric functions in Python's math library use radians, so we first convert the latitude and longitude from degrees to radians. 2. **Differences in Coordinates**: Compute the differences in latitude (dlat) and longitude (dlon) between the two points. 3. **Haversine Formula**: - Calculate `a` using the formula: \( a = \sin^2(\Delta \phi / 2) + \cos(\phi_1) \cdot \cos(\phi_2) \cdot \sin^2(\Delta \lambda / 2) \), where \( \phi \) is latitude and \( \lambda \) is longitude. - Compute `c` as \( 2 \cdot \text{atan2}(\sqrt{a}, \sqrt{1-a}) \), which gives the angular distance in radians. - The distance is then calculated using the Earth's radius (R = 6371 km) multiplied by the angular distance `c`. This approach ensures that we accurately compute the great-circle distance between two points on the Earth's surface using their geographic coordinates. |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| gpto1 | ```python import math def distance_lat_long(lat1, lon1, lat2, lon2): # Using the Haversine formula to calculate the great-circle distance between two points R = 6371.0 # Earth's radius in kilometers # Convert latitude and longitude from degrees to radians phi1 = math.radians(lat1) phi2 = math.radians(lat2) delta_phi = math.radians(lat2 - lat1) delta_lambda = math.radians(lon2 - lon1) # Haversine formula a = math.sin(delta_phi / 2.0) ** 2 + \ math.cos(phi1) * math.cos(phi2) * math.sin(delta_lambda / 2.0) ** 2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) distance = R * c return distance ``` |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| GPT-4o | To calculate the distance between two points on the Earth given their latitude and longitude, we can use the Haversine formula. Here's the implementation: ```python import math def distance_lat_long(lat1, lon1, lat2, lon2): # Convert latitude and longitude from degrees to radians lat1 = math.radians(lat1) lon1 = math.radians(lon1) lat2 = math.radians(lat2) lon2 = math.radians(lon2) # Haversine formula dlon = lon2 - lon1 dlat = lat2 - lat1 a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) # Radius of Earth in kilometers. Use 6371 for kilometers or 3956 for miles r = 6371.0 # calculate the result distance = r * c return distance # Test cases assert distance_lat_long(23.5, 67.5, 25.5, 69.5) == 12179.372041317429 assert distance_lat_long(10.5, 20.5, 30.5, 40.5) == 6069.397933300514 assert distance_lat_long(10, 20, 30, 40) == 6783.751974994595 ``` This function should correctly calculate the distance between two points using their latitude and longitude and pass the given tests. |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| llama3.1-70B-Instruct | import math def distance_lat_long(lat1, long1, lat2, long2): # Radius of the earth in km R = 6371.0 # Convert degrees to radians lat_rad1 = math.radians(lat1) long_rad1 = math.radians(long1) lat_rad2 = math.radians(lat2) long_rad2 = math.radians(long2) # Differences in coordinates delta_lat = lat_rad2 - lat_rad1 delta_long = long_rad2 - long_rad1 # Haversine formula a = math.sin(delta_lat / 2)**2 + math.cos(lat_rad1) * math.cos(lat_rad2) * math.sin(delta_long / 2)**2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) # Distance distance = R * c return distance |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| llama3.1-405B-Instruct | import math def distance_lat_long(lat1, lon1, lat2, lon2): # Radius of the earth in km R = 6371.0 # Convert degrees to radians lat_rad1 = math.radians(lat1) lon_rad1 = math.radians(lon1) lat_rad2 = math.radians(lat2) lon_rad2 = math.radians(lon2) # Differences in coordinates delta_lat = lat_rad2 - lat_rad1 delta_lon = lon_rad2 - lon_rad1 # Haversine formula a = math.sin(delta_lat / 2)**2 + math.cos(lat_rad1) * math.cos(lat_rad2) * math.sin(delta_lon / 2)**2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) # Distance distance = R * c return distance |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| DeepSeek-Coder-V2 | ```python from math import radians, sin, cos, sqrt, atan2 def distance_lat_long(lat1, lon1, lat2, lon2): # Radius of the Earth in kilometers R = 6371.0 # Convert latitude and longitude from degrees to radians lat1 = radians(lat1) lon1 = radians(lon1) lat2 = radians(lat2) lon2 = radians(lon2) # Differences in coordinates dlat = lat2 - lat1 dlon = lon2 - lon1 # Haversine formula a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2 c = 2 * atan2(sqrt(a), sqrt(1 - a)) # Distance in kilometers distance = R * c return distance # Test cases assert distance_lat_long(23.5, 67.5, 25.5, 69.5) == 12179.372041317429 assert distance_lat_long(10.5, 20.5, 30.5, 40.5) == 6069.397933300514 assert distance_lat_long(10, 20, 30, 40) == 6783.751974994595 ``` This function calculates the distance between two points on the Earth's surface using their latitude and longitude coordinates. It uses the Haversine formula to compute the great-circle distance between two points. The result is in kilometers. |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| Qwen2-72B-Instruct | 'def distance_lat_long(lat1, long1, lat2, long2): from math import radians, sin, cos, sqrt, asin # Convert latitude and longitude to radians lat1, long1, lat2, long2 = map(radians, [lat1, long1, lat2, long2]) # Haversine formula dlat = lat2 - lat1 dlong = long2 - long1 a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlong/2)**2 c = 2 * asin(sqrt(a)) # Radius of the Earth in meters: 6371000 r = 6371000 return c * r' [DONE] |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| baichuan4 | To calculate the distance between two points on the Earth's surface using latitude and longitude, we can use the Haversine formula. Below is a Python function that implements this formula: ```python import math def distance_lat_long(lat1, lon1, lat2, lon2): # Radius of the Earth in kilometers R = 6371.0 # Convert latitude and longitude from degrees to radians lat1_rad = math.radians(lat1) lon1_rad = math.radians(lon1) lat2_rad = math.radians(lat2) lon2_rad = math.radians(lon2) # Difference in latitude and longitude delta_lat = lat2_rad - lat1_rad delta_lon = lon2_rad - lon1_rad # Haversine formula a = math.sin(delta_lat / 2)**2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(delta_lon / 2)**2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) # Distance in kilometers distance = R * c return distance ``` This function should pass the tests you provided: ```python assert distance_lat_long(23.5, 67.5, 25.5, 69.5) == 12179.372041317429 assert distance_lat_long(10.5, 20.5, 30.5, 40.5) == 6069.397933300514 assert distance_lat_long(10, 20, 30, 40) == 6783.751974994595 ``` The `distance_lat_long` function takes four arguments: the latitude and longitude of the first point (`lat1`, `lon1`) and the latitude and longitude of the second point (`lat2`, `lon2`). It returns the distance between the two points in kilometers. |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| doubao | from math import radians, sin, cos, sqrt, atan2 def distance_lat_long(lat1, lon1, lat2, lon2): R = 6371.0 # Radius of the earth in kilometers lat1_rad = radians(lat1) lon1_rad = radians(lon1) lat2_rad = radians(lat2) lon2_rad = radians(lon2) dlat = lat2_rad - lat1_rad dlon = lon2_rad - lon1_rad a = sin(dlat / 2)**2 + cos(lat1_rad) * cos(lat2_rad) * sin(dlon / 2)**2 c = 2 * atan2(sqrt(a), sqrt(1 - a)) distance = R * c return distance [DONE] |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| minimax | To calculate the distance between two points on the Earth's surface given their latitude and longitude, we can use the Haversine formula. Below is the Python function that implements this formula: ```python from math import radians, cos, sin, asin, sqrt def distance_lat_long(lat1, lon1, lat2, lon2): # Radius of the Earth in kilometers R = 6371.0 # Convert latitude and longitude from degrees to radians lat1_rad = radians(lat1) lon1_rad = radians(lon1) lat2_rad = radians(lat2) lon2_rad = radians(lon2) # Difference in coordinates dlon = lon2_rad - lon1_rad dlat = lat2_rad - lat1_rad # Haversine formula a = sin(dlat / 2)**2 + cos(lat1_rad) * cos(lat2_rad) * sin(dlon / 2)**2 c = 2 * asin(sqrt(a)) # Distance in kilometers distance = R * c return distance # Test cases assert distance_lat_long(23.5, 67.5, 25.5, 69.5) == 12179.*** assert distance_lat_long(10.5, 20.5, 30.5, 40.5) == 6069.*** assert distance_lat_long(10, 20, 30, 40) == 6783.*** ``` This function first converts the latitude and longitude from degrees to radians, then applies the Haversine formula to calculate the great-circle distance between the two points. The distance is returned in kilometers. The test cases should pass if the function is implemented correctly. |
failed 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| kimi | Sure, let's write the function to calculate the distance between two points using latitude and longitude. We'll use the Haversine formula, which calculates the distance between two points on the surface of a sphere given their longitudes and latitudes. Here's the Python function: ```python from math import radians, cos, sin, asin, sqrt def distance_lat_long(lat1, lon1, lat2, lon2): # Radius of the Earth in kilometers R = 6371.0 # Convert latitude and longitude from degrees to radians lat1, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon2]) # Difference in coordinates dlat = lat2 - lat1 dlon = lon2 - lon1 # Haversine formula a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 c = 2 * asin(sqrt(a)) # Distance in kilometers distance = R * c return distance # Test cases assert abs(distance_lat_long(23.5, 67.5, 25.5, 69.5) - 12179.372041317429) < 0.0001 assert abs(distance_lat_long(10.5, 20.5, 30.5, 40.5) - 6069.397933300514) < 0.0001 assert abs(distance_lat_long(10, 20, 30, 40) - 6783.751974994595) < 0.0001 ``` This function should pass the test cases you provided. The `assert` statements are used to check that the calculated distance is very close to the expected value. The `0.0001` is used as a tolerance to account for floating point arithmetic errors. |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| wenxinyiyan | To calculate the distance between two points using latitude and longitude, we can use the Haversine formula. Here's the Python function that implements this formula: ```python import math def distance_lat_long(lat1, lon1, lat2, lon2): # Convert latitude and longitude from degrees to radians lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2]) # Haversine formula dlon = lon2 - lon1 dlat = lat2 - lat1 a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2 c = 2 * math.asin(math.sqrt(a)) r = 6371 # Radius of Earth in kilometers return c * r ``` Now, let's test the function with the provided assertions: ```python assert distance_lat_long(23.5, 67.5, 25.5, 69.5) == 12179.372041317429 assert distance_lat_long(10.5, 20.5, 30.5, 40.5) == 6069.397933300514 assert distance_lat_long(10, 20, 30, 40) == 6783.751974994595 ``` The function should pass all the assertions and calculate the distance between two points using latitude and longitude correctly. Note: The Haversine formula assumes that the Earth is a perfect sphere, which is not entirely true. For more accurate results, you might want to consider using more complex formulas or libraries that take into account the Earth's ellipticity. However, for most applications, the Haversine formula provides a reasonably accurate estimation of the distance. |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| zhipu | To calculate the distance between two points given their latitude and longitude, we can use the Haversine formula. The Haversine formula calculates the distance on a spherical Earth (which is an approximation, as the Earth is not perfectly spherical) as the crow flies. Here's the Python function to do that: ```python import math def distance_lat_long(lat1, lon1, lat2, lon2): # Radius of the Earth in kilometers R = 6371.0 # Convert latitude and longitude from degrees to radians lat1_rad = math.radians(lat1) lon1_rad = math.radians(lon1) lat2_rad = math.radians(lat2) lon2_rad = math.radians(lon2) # Difference in coordinates delta_lat = lat2_rad - lat1_rad delta_lon = lon2_rad - lon1_rad # Haversine formula a = math.sin(delta_lat / 2)**2 + math.cos(lat1_rad) * math.cos(lat2_rad) * math.sin(delta_lon / 2)**2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) # Distance in kilometers distance = R * c return distance # Test cases assert distance_lat_long(23.5, 67.5, 25.5, 69.5) == 12179.372041317429 assert distance_lat_long(10.5, 20.5, 30.5, 40.5) == 6069.397933300514 assert distance_lat_long(10, 20, 30, 40) == 6783.751974994595 ``` This function first converts the latitude and longitude values from degrees to radians, as the trigonometric functions in Python's `math` library expect radian inputs. It then calculates the differences in the latitudes and longitudes, applies the Haversine formula, and finally returns the distance in kilometers. You can run this code with the provided test cases to verify that it works as expected. The `assert` statements should pass if the function is implemented correctly. |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| gpto1 | ```python import math def distance_lat_long(lat1, lon1, lat2, lon2): # Using the Haversine formula to calculate the great-circle distance between two points R = 6371.0 # Earth's radius in kilometers # Convert latitude and longitude from degrees to radians phi1 = math.radians(lat1) phi2 = math.radians(lat2) delta_phi = math.radians(lat2 - lat1) delta_lambda = math.radians(lon2 - lon1) # Haversine formula a = math.sin(delta_phi / 2.0) ** 2 + \ math.cos(phi1) * math.cos(phi2) * math.sin(delta_lambda / 2.0) ** 2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) distance = R * c return distance ``` |
wrong_answer 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |
| deepseekv3 | server error: Error code: 400 - {'error': {'code': 'RequestTimeOut', 'param': None, 'message': 'Request timed out, please try again later.', 'type': 'RequestTimeOut'}, 'id': 'chatcmpl-9215ceda-6aac-954c-819b-fed94ce36f67', 'request_id': '9215ceda-6aac-954c-819b-fed94ce36f67'} | failed 测试用例:assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429 assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514 assert distance_lat_long(10,20,30,40)==6783.751974994595 |