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 a specific statistical measure based on the provided input.", "input": "A collection of numerical values.", "output": "The median value of the input collection.", "examples": [ { "input": "[10, 20, 30, 40, 50]", "output": "30", "explanation": "The median of the sorted collection [10, 20, 30, 40, 50] is 30." }, { "input": "[1, 2, 3, 4, 5]", "output": "3", "explanation": "The median of the sorted collection [1, 2, 3, 4, 5] is 3." }, { "input": "[100, 200, -50, 25, 75]", "output": "75", "explanation": "The median of the sorted collection [-50, 25, 75, 100, 200] is 75." }, { "input": "[0, 0, 0, 0]", "output": "0", "explanation": "The median remains 0 for a sorted collection of zeros [0, 0, 0, 0]." }, { "input": "[4, 1, 6, 3]", "output": "3.5", "explanation": "The median of the sorted collection [1, 3, 4, 6] is the average of 3 and 4, which is 3.5." } ], "function_signature": "def calculate_median(data):", "solution": { "code": " if not data:\n return 0\n data.sort()\n n = len(data)\n mid = n // 2\n if 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.