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 of 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 collection is 30, as it is the middle value when the data is sorted." }, { "input": "[1, 2, 3, 4, 5]", "output": "3", "explanation": "The median of the collection is 3, the middle value when sorted." }, { "input": "[100, 200, -50, 25, 75]", "output": "75", "explanation": "Upon sorting, the collection becomes [-50, 25, 75, 100, 200]. 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 median is 6, as it is the fourth value in a sorted sequence of 7 numbers." }, { "input": "[1, 2, 3, 4, 5, 6, 8, 9]", "output": "4.5", "explanation": "The collection has an even number of elements, so the median is the average of 4 and 5." } ], "function_signature": "def calculate_median(data):", "solution": { "code": " data.sort()\n n = len(data)\n mid = n // 2\n if n == 0:\n return 0\n elif n % 2 == 0:\n return (data[mid - 1] + data[mid]) / 2\n else:\n return data[mid]" } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.