Create a programming task related to common algorithms and data…
- User
Assistant: User: Create a programming task related to common algorithms and data structures. The task should follow this format:
{ "problem_description": "You are tasked with designing a function that processes a collection of numerical data. The goal is to determine a specific statistical measure based on the provided input.", "input": "A collection of numerical values.", "output": "A specific statistical measure derived from the input collection.", "examples": [ { "input": "[10, 20, 30, 40, 50]", "output": "30", "explanation": "The statistical measure (e.g., average) of the collection is 30." }, { "input": "[1, 2, 3, 4, 5]", "output": "3", "explanation": "The statistical measure of the collection is 3." }, { "input": "[100, 200, -50, 25, 75]", "output": "75", "explanation": "The statistical measure calculated from the collection is 75." }, { "input": "[0, 0, 0, 0]", "output": "0", "explanation": "The statistical measure remains 0 for a collection of zeros." } ], "function_signature": "def calculate_statistical_measure(data):", "solution": { "code": " total = sum(data) count = len(data) return total / count if count > 0 else 0" } }
Assistant:
- Assistant
{ "problem_description": "You are tasked with designing a function that processes a collection of numerical data. The goal is to determine the median value based on the provided input.", "input": "A collection of numerical values.", "output": "The median value derived from the input collection.", "examples": [ { "input": "[10, 20, 30, 40, 50]", "output": "30", "explanation": "The median of the sorted collection is 30." }, { "input": "[1, 2, 3, 4, 5]", "output": "3", "explanation": "The median of the collection is 3." }, { "input": "[100, 200, -50, 25, 75]", "output": "75", "explanation": "The sorted collection is [-50, 25, 75, 100, 200], and the median is 75." }, { "input": "[0, 0, 0, 0]", "output": "0", "explanation": "The median remains 0 for a collection of zeros." }, { "input": "[1, 3, 3, 6, 7, 8, 9]", "output": "6", "explanation": "The sorted collection is [1, 3, 3, 6, 7, 8, 9]. The median is 6 (the fourth element)." }, { "input": "[1, 2, 3, 4, 5, 6, 8, 9]", "output": "4.5", "explanation": "The sorted collection is [1, 2, 3, 4, 5, 6, 8, 9]. The median is (4+5)/2 = 4.5." } ], "function_signature": "def calculate_median(data):", "solution": { "code": " if not data:\n return 0\n sorted_data = sorted(data)\n n = len(sorted_data)\n middle = n // 2\n if n % 2 == 0:\n return (sorted_data[middle - 1] + sorted_data[middle]) / 2\n else:\n return sorted_data[middle]" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.