Dataset Viewer
Auto-converted to Parquet Duplicate
input
stringlengths
156
4.05k
output
stringlengths
75
8.22k
llm_judgement
stringlengths
402
1.68k
unit_tests
stringlengths
241
8.71k
tests_execution_status
stringclasses
11 values
average_test_score
stringclasses
2 values
You are tasked with implementing a higher-order function named `invert_result`. This function accepts another function `func` as its parameter. Your goal is to create and return a new function that mirrors the behavior of `func` but inverts its boolean return value. If `func` does not return a boolean, the new function...
```python def invert_result(func): """ Returns a new function that inverts the boolean return value of the given function `func`. If `func` does not return a boolean, raises a TypeError. :param func: A function that takes any number of arguments and returns a boolean. :return: A new function wi...
{"requirement_conformance": {"score": 4, "justification": "The solution meets the basic requirements of inverting the boolean result of the input function and raising a TypeError if the result is not a boolean. However, it does not handle functions with arbitrary return types as specified in the new instruction."}, "lo...
["\nassert invert_result(lambda x: x > 0)(-1) == True\n", "\nassert invert_result(lambda x: x > 0)(1) == False\n", "\nassert invert_result(lambda x: x == 5)(5) == False\n", "\nassert invert_result(lambda x: x == 5)(10) == True\n", "\nassert invert_result(lambda x, y: x == y)(1, 1) == False\n", "\nassert invert_result(l...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given two points in a 2D plane. Each point is represented as a tuple of two integers, where the first integer is the x-coordinate and the second integer is the y-coordinate. Your task is to write a function `calculate_distance` that computes and returns the Euclidean distance between these two points. **Input:...
```python import math def calculate_distance(point1, point2): """ Calculate and return the Euclidean distance between two points in 2D space. :param point1: A tuple (x1, y1) representing the first point :param point2: A tuple (x2, y2) representing the second point :return: The Euclidean distan...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by correctly implementing the Euclidean distance calculation for two points in a 2D plane."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and follows the mathematical formula for...
["\nassert calculate_distance((0, 0), (0, 0)) == 0.0\n", "\nassert calculate_distance((1, 2), (4, 6)) == 5.0\n", "\nassert calculate_distance((1, 1), (1, 1)) == 0.0\n", "\nassert calculate_distance((0, 0), (3, 4)) == 5.0\n", "\nassert calculate_distance((-1, -1), (1, 1)) == 2.8284271247461903\n", "\nassert calculate_di...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a Python class named `Employee` to manage employee details within a company. The class should support the following functionalities: - **Initialization**: Create an `Employee` object with attributes `name`, `position`, and `salary`. - **Salary Adjustment**: Provide a method to increase...
```python class Employee: def __init__(self, name, position, salary): """ Initialize an Employee object with a name, position, and salary. :param name: The name of the employee (string). :param position: The position of the employee (string). :param salary: The salary of the...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing the required attributes and methods in the Employee class."}, "logical_correctness": {"score": 5, "justification": "The logic of the solution is completely correct. The methods work as intended...
["\nassert str(Employee(\"John Doe\", \"Software Engineer\", 75000)) == \"Employee(name='John Doe', position='Software Engineer', salary=75000)\"\n", "\nassert str(Employee(\"Jane Smith\", \"Project Manager\", 85000)) == \"Employee(name='Jane Smith', position='Project Manager', salary=85000)\"\n", "\nassert str(Employe...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given the task of implementing a function to retrieve a network service by its unique identifier (UUID). To optimize performance, implement a caching mechanism that stores up to 128 most recently accessed services. Your function should efficiently handle repeated requests for the same service. **Input:** - A U...
```python import uuid from functools import lru_cache def fetch_service_from_source(service_uuid): """ Simulates fetching a network service from a database or external API. Args: service_uuid (uuid.UUID): The UUID of the service to fetch. Returns: dict or None: The service det...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing a caching mechanism using LRU cache for efficient retrieval of network services by UUID."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured....
["\nassert get_service_by_uuid(uuid.UUID('12345678-1234-5678-1234-567812345678')) == {'name': 'service1', 'details': 'Details for service1'}\n", "\nassert get_service_by_uuid(uuid.UUID('12345678-1234-5678-1234-567812345679')) == {'name': 'service2', 'details': 'Details for service2'}\n", "\nassert get_service_by_uuid(u...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a `BookInventory` class to manage a collection of books in a library system. The class should support the following operations: - `add_book(title, author, quantity)`: Adds a book to the inventory. If the book already exists, it should update the quantity. - `remove_book(title, quantity...
```python class BookInventory: def __init__(self): """Initialize an empty dictionary to store book information.""" self.books = {} def add_book(self, title, author, quantity): """ Adds a book to the inventory. If the book already exists, updates the quantity. :p...
{"requirement_conformance": {"score": 4, "justification": "The class meets the basic requirements by providing methods to add, remove, find, and list books. However, it does not specify any additional requirements such as input validation or error handling."}, "logical_correctness": {"score": 4, "justification": "The l...
["\nassert BookInventory().list_books() == []\n", "\nassert BookInventory().find_book(\"The Great Gatsby\") == None\n", "\ninventory = BookInventory()\ninventory.add_book(\"The Great Gatsby\", \"F. Scott Fitzgerald\", 3)\nassert inventory.find_book(\"The Great Gatsby\") == {'author': 'F. Scott Fitzgerald', 'quantity': ...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a string `sentence` consisting of words separated by spaces. Your task is to write a function `reverse_sentence(sentence)` that returns a new string with the words in the original sentence in reverse order. **Input:** - A single string `sentence` (1 ≤ len(sentence) ≤ 1000) containing words separated by ...
```python def reverse_sentence(sentence): """ Reverses the order of words in the given sentence. Parameters: sentence (str): A string containing words separated by spaces. Returns: str: A new string with the words in the original sentence in reverse order. """ return ' '.join(sentence....
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by reversing the words in the sentence as specified."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It splits the sentence into words, reverses the list...
["\nassert reverse_sentence(\"Hello world\") == \"world Hello\"\n", "\nassert reverse_sentence(\"Python is fun\") == \"fun is Python\"\n", "\nassert reverse_sentence(\"OpenAI GPT-4\") == \"GPT-4 OpenAI\"\n", "\nassert reverse_sentence(\"a b c d e\") == \"e d c b a\"\n", "\nassert reverse_sentence(\"single\") == \"singl...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a function `normalize_input(val)` that processes an input value `val` according to the following rules: - If `val` is `None`, return an empty list. - If `val` is not a list, return a list containing `val` as its only element. - If `val` is a list, return a new list containing only the ...
```python def normalize_input(val): """ Processes the input value according to specified rules: - Returns an empty list if the input is None. - Returns a list containing the input value if it is not a list. - Returns a sorted list of integers if the input is a list, filtering out non-integer element...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements: it returns an empty list for None, wraps non-list inputs in a list, and filters and sorts list inputs as required."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and ...
["\nassert normalize_input(None) == []\n", "\nassert normalize_input(42) == [42]\n", "\nassert normalize_input(\"hello\") == [\"hello\"]\n", "\nassert normalize_input([1, 2, 3]) == [1, 2, 3]\n", "\nassert normalize_input([3, 1, 2]) == [1, 2, 3]\n", "\nassert normalize_input([1, \"a\", 2, \"b\", 3]) == [1, 2, 3]\n", "\n...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of events, where each event is represented as a tuple consisting of the event name, start time, and end time. Your task is to implement a function `generate_schedule(events)` that returns a dictionary. The keys of the dictionary should be the event names, and the values should be the durations of t...
```python def generate_schedule(events): """ Generates a schedule with event durations in minutes. Parameters: events (list of tuples): A list where each tuple contains an event name, start time, and end time. Returns: dict: A dictionary with event names as keys and their durations in minutes ...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements. It generates a schedule with event names as keys and their durations in minutes as values, handling cases where the start time is later than the end time by setting the duration to 0."}, "logical_correctness"...
["\nassert generate_schedule([(\"Event1\", \"10:00\", \"11:00\")]) == {\"Event1\": 60}\n", "\nassert generate_schedule([(\"Event2\", \"11:30\", \"11:30\")]) == {\"Event2\": 0}\n", "\nassert generate_schedule([(\"Event3\", \"12:45\", \"13:15\")]) == {\"Event3\": 30}\n", "\nassert generate_schedule([(\"Event4\", \"23:59\...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a string `ip`. Your task is to determine whether it represents a valid IPv4 address. A valid IPv4 address consists of exactly four octets, separated by dots. Each octet must be a number between 0 and 255 (inclusive) and must not have leading zeros unless it is exactly "0". **Input:** - A single string `i...
```python def is_valid_ipv4_address(ip: str) -> bool: """ Determines if the given string is a valid IPv4 address. :param ip: A string representing the IP address. :return: True if the IP address is valid, False otherwise. """ parts = ip.split('.') if len(parts) != 4: return Fals...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements for validating an IPv4 address, including checking the number of octets, ensuring each octet is a number between 0 and 255, and handling leading zeros."}, "logical_correctness": {"score": 5, "justification...
["\nassert is_valid_ipv4_address(\"192.168.1.1\") == True\n", "\nassert is_valid_ipv4_address(\"255.255.255.255\") == True\n", "\nassert is_valid_ipv4_address(\"0.0.0.0\") == True\n", "\nassert is_valid_ipv4_address(\"256.256.256.256\") == False\n", "\nassert is_valid_ipv4_address(\"192.168.1\") == False\n", "\nassert ...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a string that represents a JSON object. Your task is to write a Python function that parses this string and returns a dictionary with the JSON keys as keys and the JSON values as values. If the input string is not a valid JSON, the function should return `None`. **Sample Input:** ``` {"name": "John", "ag...
```python import json def json_to_dict(json_string): """ Parses a JSON string and returns a dictionary. Parameters: json_string (str): A string representing a JSON object. Returns: dict or None: A dictionary with JSON keys and values, or None if the input is invalid. """ try: ...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by converting a JSON string to a dictionary and handling invalid JSON input gracefully."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct, using the json.loads method to parse the J...
["\nassert json_to_dict('{\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}') == {\"name\": \"John\", \"age\": 30, \"city\": \"New York\"}\n", "\nassert json_to_dict('{\"key\": \"value\"}') == {\"key\": \"value\"}\n", "\nassert json_to_dict('{}') == {}\n", "\nassert json_to_dict('{\"numbers\": [1, 2, 3, 4]}') ==...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a string `s` consisting of characters, including parentheses `(` and `)`. Your task is to determine if the parentheses in the string are balanced. A string with balanced parentheses means that every opening parenthesis `(` has a corresponding closing parenthesis `)` and they are correctly nested. **Input...
```python def is_balanced_parentheses(s): """ Check if the parentheses in the string are balanced. :param s: A string containing characters, including parentheses. :return: True if the parentheses are balanced, False otherwise. """ stack = [] for char in s: if char == '(': ...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement of checking if a string contains balanced parentheses and handles strings with other characters correctly."}, "logical_correctness": {"score": 5, "justification": "The logic used in the function is completely correct and...
["\nassert is_balanced_parentheses(\"((a + b) * (c + d))\") == True\n", "\nassert is_balanced_parentheses(\"(a + b * (c + d)\") == False\n", "\nassert is_balanced_parentheses(\")a + b(\") == False\n", "\nassert is_balanced_parentheses(\"a + b\") == True\n", "\nassert is_balanced_parentheses(\"()\") == True\n", "\nasser...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a string `s` consisting of lowercase English letters and spaces. Your task is to write a function `capitalize_words` that capitalizes the first letter of each word in the string. Words are defined as sequences of characters separated by spaces. Return the modified string. **Input:** - A single string `s`...
```python def capitalize_words(input_string): """ Capitalizes the first letter of each word in the input string. Parameters: input_string (str): The input string consisting of words separated by spaces. Returns: str: The modified string with the first letter of each word capitalized. """ ...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by capitalizing the first letter of each word in the input string and handling words separated by spaces."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured....
["\nassert capitalize_words(\"hello world\") == \"Hello World\"\n", "\nassert capitalize_words(\"python programming\") == \"Python Programming\"\n", "\nassert capitalize_words(\"capitalize every word\") == \"Capitalize Every Word\"\n", "\nassert capitalize_words(\"a quick brown fox\") == \"A Quick Brown Fox\"\n", "\nas...
["pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass"]
0.9
You are tasked with writing a program that reads a CSV file and prints the contents of the file. The CSV file contains three columns: `id`, `name`, and `email`. Your program should handle cases where the file might not exist or be unreadable. **Input:** - The first line of input is the path to the CSV file. **Output...
```python import csv def read_and_print_csv(file_path): """ Reads a CSV file and prints its contents. Handles cases where the file might not exist or be unreadable. :param file_path: str - The path to the CSV file. """ try: with open(file_path, mode='r', newline='') as file: re...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by reading a CSV file and printing its contents, handling cases where the file might not exist or be unreadable."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and opt...
["\nassert read_and_print_csv('non_existent_file.csv') == None\n", "\nassert read_and_print_csv('unreadable_file.csv') == None\n", "\nassert read_and_print_csv('empty_file.csv') == None\n", "\nassert read_and_print_csv('single_row.csv') == None\n", "\nassert read_and_print_csv('multiple_rows.csv') == None\n", "\nassert...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a singly linked list. Implement a function `findMiddleNode` that returns the middle node of the linked list. If the number of nodes in the list is even, return the second middle node. Your solution must use the two-pointer technique to achieve a time complexity of O(n) and a space complexity of O(1). **I...
```python class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def findMiddleNode(head): """ Returns the middle node of a singly linked list. If the list has an even number of nodes, returns the second middle node. :param head: ListNode, t...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It includes the class definition for the singly linked list node and implements the `findMiddleNode` function using the two-pointer technique with O(n) time complexity and O(1) space complexity."}, "logical_c...
["\nassert findMiddleNode(ListNode(1)).value == 1\n", "\nassert findMiddleNode(ListNode(1, ListNode(2))).value == 2\n", "\nassert findMiddleNode(ListNode(1, ListNode(2, ListNode(3)))).value == 2\n", "\nassert findMiddleNode(ListNode(1, ListNode(2, ListNode(3, ListNode(4))))).value == 3\n", "\nassert findMiddleNode(List...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of integers. Your task is to implement a function that returns a list of the 5 largest unique integers from the input list. If the list contains fewer than 5 unique integers, return all unique integers sorted in descending order. The function should be optimized for performance, even with large inp...
```python def find_largest_unique_integers(lst): """ Returns a list of the 5 largest unique integers from the given list. If there are fewer than 5 unique integers, returns all unique integers sorted in descending order. :param lst: List of integers :return: List of integers """ uni...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all the specified requirements. It returns the 5 largest unique integers or all unique integers if there are fewer than 5, sorted in descending order."}, "logical_correctness": {"score": 5, "justification": "The logic is completely corr...
["\nassert find_largest_unique_integers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [10, 9, 8, 7, 6]\n", "\nassert find_largest_unique_integers([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [10, 9, 8, 7, 6]\n", "\nassert find_largest_unique_integers([5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == [5]\n", "\nassert find_largest_unique_integers([1, 1,...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given two non-empty strings `str1` and `str2` consisting of lowercase English letters. Your task is to compute the Levenshtein distance between these two strings. The Levenshtein distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one ...
```python def levenshtein_distance(str1, str2): """ Computes the Levenshtein distance between two strings. Parameters: str1 (str): The first string. str2 (str): The second string. Returns: int: The Levenshtein distance between str1 and str2. """ m, n = len(str1), len(str2) ...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing the Levenshtein distance algorithm correctly for two non-empty strings containing only lowercase English letters with lengths between 1 and 100 characters."}, "logical_correctness": {"score": 5, "justifi...
["\nassert levenshtein_distance(\"kitten\", \"sitting\") == 3\n", "\nassert levenshtein_distance(\"flaw\", \"lawn\") == 2\n", "\nassert levenshtein_distance(\"intention\", \"execution\") == 5\n", "\nassert levenshtein_distance(\"abc\", \"abc\") == 0\n", "\nassert levenshtein_distance(\"abc\", \"def\") == 3\n", "\nasser...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a JSON string representing a list of products. Each product is a dictionary with the keys "name", "price", and "quantity". Your task is to write a Python function that calculates the total price of all products. The function should validate the JSON string to ensure it represents a list of dictionaries wi...
```python import json def calculate_total_price(json_string): """ Calculate the total price of products from a JSON string. Args: json_string (str): A JSON string representing a list of products. Returns: float: The total price of all products. Raises: ValueError: If the ...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It accepts a JSON string, validates it, and calculates the total price of the products."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It ha...
["\nassert calculate_total_price('[{\"name\": \"apple\", \"price\": 0.5, \"quantity\": 10}]') == 5.0\n", "\nassert calculate_total_price('[{\"name\": \"banana\", \"price\": 0.3, \"quantity\": 5}]') == 1.5\n", "\nassert calculate_total_price('[{\"name\": \"apple\", \"price\": 0.5, \"quantity\": 10}, {\"name\": \"banana\...
["pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
You are given two strings, `str1` and `str2`. Your task is to determine the minimum number of operations required to transform `str1` into `str2`. The allowed operations are: - Insert a character - Delete a character - Replace a character Implement the function `min_operations(str1, str2)` that takes two strings as i...
```python def min_operations(str1, str2): """ Computes the minimum number of operations required to transform str1 into str2. Parameters: str1 (str): The original string. str2 (str): The target string. Returns: int: The minimum number of operations required. """ m, n = len(...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing the function `min_operations` that calculates the minimum number of operations required to transform `str1` into `str2` using dynamic programming. It also handles the constraint of the combined length of...
["\nassert min_operations(\"kitten\", \"sitting\") == 3\n", "\nassert min_operations(\"flaw\", \"lawn\") == 2\n", "\nassert min_operations(\"intention\", \"execution\") == 5\n", "\nassert min_operations(\"abc\", \"abc\") == 0\n", "\nassert min_operations(\"\", \"\") == 0\n", "\nassert min_operations(\"abc\", \"\") == 3...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a function `parse_library_url` that processes URLs representing a hierarchical structure of an online library. The URL format is `https://library.com/author/series/[sub-series]/book`, where the sub-series part is optional. Your function should parse the URL and return a tuple containing...
```python from urllib.parse import urlparse def parse_library_url(url): """ Parses a library URL and returns a tuple containing the author's name, series name, sub-series name (if present), and book name. :param url: A string representing the URL of the book in the library. :return: A tuple (autho...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the specified requirements by handling both URLs with and without a sub-series and returning the correct tuple structure."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently handles ...
["\nassert parse_library_url(\"https://library.com/author/series/sub-series/book\") == ('author', 'series', 'sub-series', 'book')\n", "\nassert parse_library_url(\"https://library.com/author/series/book\") == ('author', 'series', None, 'book')\n", "\nassert parse_library_url(\"https://library.com/author/onlybook\") == ...
["pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
You are given a floor of dimensions 2 x W and an unlimited supply of tiles of dimensions 2 x 1. Your task is to determine the number of distinct ways to completely tile the floor. Note that rotations and reflections of previously counted arrangements are considered different. **Input:** - The first line contains an in...
```python def tile_floor(width): """ Calculate the number of distinct ways to tile a floor of dimensions 2 x W using tiles of dimensions 2 x 1, considering rotations and reflections as different. :param width: An integer representing the width of the floor (1 ≤ width ≤ 1000). :return: An integer re...
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the basic requirement of calculating the number of distinct ways to tile a 2xW floor using 2x1 tiles. However, it does not explicitly state that rotations and reflections of previously counted arrangements are considered different, which ...
["\nassert tile_floor(0) == 1\n", "\nassert tile_floor(1) == 1\n", "\nassert tile_floor(2) == 2\n", "\nassert tile_floor(3) == 3\n", "\nassert tile_floor(4) == 5\n", "\nassert tile_floor(5) == 8\n", "\nassert tile_floor(6) == 13\n", "\nassert tile_floor(7) == 21\n", "\nassert tile_floor(8) == 34\n", "\nassert tile_floo...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given an unsorted list of integers and an integer `k`. Your task is to find the `k`th smallest element in the list. The list may contain duplicate elements. Assume that `1 ≤ k ≤ n`, where `n` is the number of elements in the list. **Sample Input:** ``` nums = [3, 2, 1, 5, 6, 4] k = 2 ``` **Sample Output:** ``...
```python def partition(nums, low, high): """ Partitions the list around a pivot element such that elements less than or equal to the pivot are on the left, and elements greater than the pivot are on the right. :param nums: List of integers to be partitioned. :param low: Starting index of the p...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by correctly implementing a function to find the kth smallest element in an unsorted list and handling edge cases like invalid k values."}, "logical_correctness": {"score": 5, "justification": "The logic is completely c...
["\nassert find_kth_smallest([3, 2, 1, 5, 6, 4], 2) == 2\n", "\nassert find_kth_smallest([7, 10, 4, 3, 20, 15], 3) == 7\n", "\nassert find_kth_smallest([7, 10, 4, 3, 20, 15], 4) == 10\n", "\nassert find_kth_smallest([12, 3, 5, 7, 4, 19, 26], 3) == 5\n", "\nassert find_kth_smallest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1) ==...
["pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass"]
0.9
You are given a list of sentences, where each sentence consists of words separated by spaces. Your task is to identify and print the longest sentence(s) based on the number of words. If there are multiple sentences with the same maximum number of words, print all of them. **Input:** - A list of strings, where each str...
```python def find_longest_sentences(sentences): """ Identifies and prints the longest sentence(s) based on the number of words. If there are multiple sentences with the same maximum number of words, prints all of them. :param sentences: List of sentences (strings) """ sentence_word_counts = [(...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It identifies and prints the longest sentence(s) based on the number of words and handles the case where multiple sentences have the same maximum number of words."}, "logical_correctness": {"score": 5, "justi...
["\nassert find_longest_sentences([\"a\", \"bb\", \"ccc\", \"dddd\"]) == None\n", "\nassert find_longest_sentences([\"hello world\", \"hi there\", \"hey\"]) == None\n", "\nassert find_longest_sentences([\"short\", \"longer sentence\", \"even longer sentence here\"]) == None\n", "\nassert find_longest_sentences([\"equal...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of integers and a boolean value. Your task is to implement a function `sort_list` that sorts the list in ascending order if the boolean value is `True`, and in descending order if the boolean value is `False`. The function should return the sorted list. **Input:** - A list of integers `numbers` (1...
```python def sort_list(numbers, ascending): """ Sorts a list of numbers in ascending or descending order based on the ascending flag. :param numbers: List of integers to be sorted. :param ascending: Boolean flag indicating the sort order (True for ascending, False for descending). :return: Sorted ...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by sorting the list in ascending or descending order based on the boolean flag and returning the sorted list."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally struct...
["\nassert sort_list([3, 1, 2], True) == [1, 2, 3]\n", "\nassert sort_list([3, 1, 2], False) == [3, 2, 1]\n", "\nassert sort_list([5, 4, 3, 2, 1], True) == [1, 2, 3, 4, 5]\n", "\nassert sort_list([5, 4, 3, 2, 1], False) == [5, 4, 3, 2, 1]\n", "\nassert sort_list([], True) == []\n", "\nassert sort_list([], False) == []\...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of tuples representing roads between cities, where each tuple is in the format `(City1, City2, Length)`. Your task is to write a function `rank_roads` that takes this list as input and returns a new list of tuples in the format `(City1, City2, Length, Distance_Rank)`. The `Distance_Rank` is determ...
```python def rank_roads(roads): """ Assigns a Distance_Rank to each road based on its length relative to other roads and returns a sorted list of roads with their ranks. :param roads: List of tuples, where each tuple is (City1, City2, Length) :return: List of tuples, where each tuple is (City1, Ci...
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirements of ranking the roads and sorting them as specified. However, it does not handle the case where all road lengths are the same, which should result in a Distance_Rank of 0 for all roads."}, "logical_correctness": {"sco...
["\nassert rank_roads([]) == []\n", "\nassert rank_roads([(\"CityA\", \"CityB\", 100)]) == [(\"CityA\", \"CityB\", 100, 1)]\n", "\nassert rank_roads([(\"CityA\", \"CityB\", 100), (\"CityC\", \"CityD\", 100)]) == [(\"CityA\", \"CityB\", 100, 0), (\"CityC\", \"CityD\", 100, 0)]\n", "\nassert rank_roads([(\"CityA\", \"Cit...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass"]
0.9
You are given an integer `n`. Your task is to determine whether `n` is a palindrome. A number is considered a palindrome if it reads the same backward as forward. **Input:** - The first line contains an integer `n` (0 ≤ n ≤ 10^9). **Output:** - Print `True` if `n` is a palindrome, otherwise print `False`. **Sample I...
```python def is_palindrome(number): """ Check if the given number is a palindrome. Args: number (int): The number to check. Returns: bool: True if the number is a palindrome, False otherwise. """ num_str = str(number) return num_str == num_str[::-1] # Test the function with the n...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement of checking if a given number is a palindrome by converting it to a string and comparing it with its reverse."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structu...
["\nassert is_palindrome(12321) == True\n", "\nassert is_palindrome(12345) == False\n", "\nassert is_palindrome(1) == True\n", "\nassert is_palindrome(22) == True\n", "\nassert is_palindrome(123321) == True\n", "\nassert is_palindrome(10) == False\n", "\nassert is_palindrome(1221) == True\n", "\nassert is_palindrome(10...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a function to parse a JSON string that represents the configuration settings for a web application. Your function should handle potential errors in the JSON format and return the configuration as a Python dictionary. If the JSON string is malformed, your function should return `None`. ...
```python import json def parse_config(json_str): """ Parses a JSON string into a Python dictionary. Parameters: json_str (str): A string in JSON format representing the configuration. Returns: dict or None: A Python dictionary containing the configuration settings if the JSON is valid, other...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by parsing a JSON string and returning a dictionary. It also handles JSON decoding errors gracefully."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The function uses the json.l...
["\nassert parse_config('{\"host\": \"localhost\", \"port\": 8080}') == {\"host\": \"localhost\", \"port\": 8080}\n", "\nassert parse_config('{\"debug\": true, \"use_ssl\": false}') == {\"debug\": True, \"use_ssl\": False}\n", "\nassert parse_config('{\"allowed_hosts\": [\"localhost\", \"127.0.0.1\"]}') == {\"allowed_h...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of strings, `strings`, where each string is intended to represent a valid JSON object. Your task is to implement a function `parse_json_objects` that processes this list and returns a new list of dictionaries. Each dictionary should be the result of parsing a JSON object from the corresponding stri...
```python import json def parse_json_objects(strings): """ Parses a list of strings, each representing a JSON object, and returns a list of dictionaries. Invalid JSON strings are ignored. :param strings: List of strings, each string is a JSON object. :return: List of dictionaries, each dictionary ...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by parsing each string in the list and returning a list of dictionaries. It also skips invalid JSON strings as specified."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The fun...
["\nassert parse_json_objects(['{\"name\": \"John\", \"age\": 30}', '{\"city\": \"New York\"}']) == [{'name': 'John', 'age': 30}, {'city': 'New York'}]\n", "\nassert parse_json_objects(['{\"invalid json\"}']) == []\n", "\nassert parse_json_objects(['{\"key\": \"value\"}', '{\"another_key\": \"another_value\"}']) == [{'...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of integers `array`, an integer `x`, and an index `index`. Your task is to insert the integer `x` into the list at the specified index. If the index is negative, it should be wrapped around to the front of the list in a circular manner. If the list is empty, return a list containing only the intege...
```python def insert_at_index(array, x, index): """ Inserts an integer x into the list at the specified index, handling negative indices by wrapping them to the front of the list in a circular manner. If the list is empty, returns a list containing only the integer x. If the index is out of bounds after...
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements, handles negative indices by wrapping them, and returns an array with only the integer x if the array is empty. However, it does not handle the case where the index is equal to the length of the array, which should be a...
["\nassert insert_at_index([1, 2, 3, 4], 5, -1) == [1, 2, 3, 5, 4]\n", "\nassert insert_at_index([1, 2, 3, 4], 5, 4) == [1, 2, 3, 4, 5]\n", "\nassert insert_at_index([], 5, 0) == [5]\n", "\nassert insert_at_index([1, 2, 3, 4], 5, -2) == [1, 2, 5, 3, 4]\n", "\nassert insert_at_index([1, 2, 3, 4], 5, -5) == [5, 1, 2, 3, ...
["pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass"]
0.9
You are given an undirected graph represented as an adjacency list. Each node is a unique integer. Your task is to implement a function that performs a depth-first search (DFS) starting from a specified node. The function should return a list of all nodes reachable from the starting node, ensuring that no node is visit...
```python def dfs(graph, start): """ Perform a depth-first search on an undirected graph starting from a given node. :param graph: A dictionary representing the graph as an adjacency list. :param start: The starting node for the DFS. :return: A list of nodes reachable from the starting node. ""...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements. It performs a DFS on the graph starting from a given node, avoids cycles, and ensures no node is visited more than once."}, "logical_correctness": {"score": 5, "justification": "The logic is completely co...
["\nassert dfs({0: [1, 2], 1: [2], 2: [0, 3], 3: [3]}, 2) == [0, 1, 2, 3]\n", "\nassert dfs({0: [1, 2], 1: [2], 2: [0, 3], 3: [3]}, 0) == [0, 1, 2, 3]\n", "\nassert dfs({0: [1, 2], 1: [2], 2: [0, 3], 3: [3]}, 1) == [0, 1, 2, 3]\n", "\nassert dfs({0: [1, 2], 1: [2], 2: [0, 3], 3: [3]}, 3) == [3]\n", "\nassert dfs({0: [1...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a binary tree represented as a nested list. Your task is to write a function that computes the diameter of the tree. The diameter of a binary tree is defined as the length of the longest path between any two nodes in the tree. This path may or may not pass through the root. **Input:** - A nested list rep...
```python class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def parse_tree(data): """ Parses a nested list representation of a binary tree into a TreeNode object. :param data: A nested list representin...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by correctly computing the diameter of a binary tree represented by a nested list. It includes a function to parse the tree and another to calculate the diameter."}, "logical_correctness": {"score": 5, "justification": ...
["\nassert diameter_of_binary_tree(parse_tree([1, [2, [4], [5]], [3]])) == 3\n", "\nassert diameter_of_binary_tree(parse_tree([1, [2, [4, [6]], [5]], [3, [7]]])) == 4\n", "\nassert diameter_of_binary_tree(parse_tree([1])) == 0\n", "\nassert diameter_of_binary_tree(parse_tree([])) == 0\n", "\nassert diameter_of_binary_t...
["pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
You are given a Python dictionary where each key maps to a list of values. Your task is to write a function that converts this dictionary into a CSV file. The keys of the dictionary should serve as the column headers, and the corresponding lists should provide the data for each row. Ensure that the CSV file is correctl...
```python import csv def dict_to_csv(input_dict, filename): """ Converts a dictionary to a CSV file. Parameters: input_dict (dict): A dictionary where keys are column headers and values are lists of data. filename (str): The name of the CSV file to be created. """ fieldnames = input_di...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by converting a dictionary to a CSV file with keys as column headers and values as data rows."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses th...
["\nassert dict_to_csv({\"name\": [\"Alice\", \"Bob\"], \"age\": [25, 30]}, 'test1.csv') is None\n", "\nassert dict_to_csv({\"fruit\": [\"apple\", \"banana\"], \"color\": [\"red\", \"yellow\"]}, 'test2.csv') is None\n", "\nassert dict_to_csv({\"animal\": [\"dog\", \"cat\"], \"sound\": [\"bark\", \"meow\"]}, 'test3.csv'...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
In the 2-D world of Flatland, the Circles are participating in a sports day and wish to end it with a perfect formation. Mr. Sphere from Spaceland arranges them into the largest possible square formations using each Circle only once. Each Circle can participate in forming one square, and no Circle can be reused. Find t...
```python def count_squares(circles): """ Counts the maximum number of squares that can be formed using the given circles. Each square must be formed using circles with strictly increasing radii. :param circles: List of integers representing the radii of the circles. :return: Integer representi...
{"requirement_conformance": {"score": 3, "justification": "The solution addresses the basic requirement of forming squares with strictly increasing radii but does not ensure that each subsequent square is formed from the remaining circles optimally. It only checks for the next four circles and does not consider forming...
["\nassert count_squares([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2\n", "\nassert count_squares([1, 2, 3, 4]) == 1\n", "\nassert count_squares([1, 2, 3]) == 0\n", "\nassert count_squares([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) == 3\n", "\nassert count_squares([1, 3, 5, 7, 9, 11, 13, 15]) == 0\n", "\nassert count_squares([1...
["pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass"]
0.9
You are given a list of temperatures recorded over a week. Your task is to compute the standard deviation of these temperatures. Write a Python function `calculate_standard_deviation` that takes a list of floating-point numbers as input and returns the standard deviation as a floating-point number. Assume the list will...
```python import math def calculate_standard_deviation(temperatures): """ Calculate the standard deviation of a list of temperatures. Parameters: temperatures (list of float): A list containing 7 temperature readings. Returns: float: The standard deviation of the temperatures. """ n =...
{"requirement_conformance": {"score": 5, "justification": "The function correctly calculates the standard deviation of the given list of temperatures and meets all the specified requirements."}, "logical_correctness": {"score": 5, "justification": "The logic for calculating the standard deviation is completely correct ...
["\nassert calculate_standard_deviation([22.5, 23.1, 21.9, 24.0, 22.8, 23.5, 22.2]) == 0.8192319205190403\n", "\nassert calculate_standard_deviation([10, 10, 10, 10, 10]) == 0.0\n", "\nassert calculate_standard_deviation([1, 2, 3, 4, 5]) == 1.4142135623730951\n", "\nassert calculate_standard_deviation([5, 5, 5, 5, 5, 5...
["fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
You are given a nested dictionary `data` representing information about a book and a list of keys `keys`. Each key in `keys` may represent a nested path in `data` using dot notation. Your task is to implement the function `extract_info` that extracts the values from `data` corresponding to the keys in `keys`. If a key ...
```python def extract_info(data, keys): """ Extracts values from a nested dictionary based on a list of dot-separated keys. Parameters: data (dict): The nested dictionary to extract information from. keys (list): A list of dot-separated strings representing paths to values in data. Ret...
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements of extracting nested keys using dot notation and returns a dictionary with the extracted values. However, it does not handle cases where the keys list contains duplicate keys or where the keys list contains keys that ar...
["\nassert extract_info({\"a\": 1, \"b\": {\"c\": 2}}, [\"a\", \"b.c\"]) == {\"a\": 1, \"c\": 2}\n", "\nassert extract_info({\"x\": {\"y\": {\"z\": 3}}}, [\"x.y.z\"]) == {\"z\": 3}\n", "\nassert extract_info({\"key1\": \"value1\", \"key2\": \"value2\"}, [\"key1\", \"key3\"]) == {\"key1\": \"value1\"}\n", "\nassert extr...
["pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass"]
0.9
You are given a string `s`. Your task is to write a function that removes all spaces from the string and returns the modified string. **Input:** - A single string `s` (1 ≤ |s| ≤ 1000), where |s| denotes the length of the string. **Output:** - A string with all spaces removed from the input string. **Sample Input:** ...
```python def remove_spaces(input_string): """ Removes all spaces from the input string and returns the modified string. :param input_string: A string from which spaces need to be removed. :return: A string with all spaces removed. """ return input_string.replace(" ", "") # Example usage: outp...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by removing all spaces from the input string."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and the function consistently removes all spaces from any given string."}, "edge_case...
["\nassert remove_spaces(\"Remove all spaces\") == \"Removeallspaces\"\n", "\nassert remove_spaces(\" Leading and trailing \") == \"Leadingandtrailing\"\n", "\nassert remove_spaces(\"Multiple spaces here\") == \"Multiplespaceshere\"\n", "\nassert remove_spaces(\"NoSpaces\") == \"NoSpaces\"\n", "\nassert remove_sp...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of integers. Implement a function `find_max_min` that takes this list as input and returns a tuple containing the maximum and minimum values in the list. If the list is empty, the function should return `None`. The function should handle any potential errors that may occur during the processing of ...
```python def find_max_min(numbers): """ Finds the maximum and minimum values in a list of integers. Parameters: numbers (list): A list of integers. Returns: tuple: A tuple containing the maximum and minimum values in the list. Returns None if the list is empty. Rai...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements: it returns a tuple with the maximum and minimum values, returns None for an empty list, and handles invalid data types by raising a ValueError."}, "logical_correctness": {"score": 5, "justification": "The log...
["\nassert find_max_min([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == (9, 1)\n", "\nassert find_max_min([10, 20, 30, 40, 50]) == (50, 10)\n", "\nassert find_max_min([-10, -20, -30, -40, -50]) == (-10, -50)\n", "\nassert find_max_min([0, 0, 0, 0, 0]) == (0, 0)\n", "\nassert find_max_min([]) == None\n", "\nassert find_max_min([4...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of digits (0-9) where each digit can appear multiple times. Your task is to rearrange these digits to form two integers such that the sum of these two integers is maximized. The first integer must be formed using digits at odd indices (1-based), and the second integer must be formed using digits at...
```python def max_sum_from_digits(digits): """ Rearranges the given digits to form two integers such that the sum of these two integers is maximized. The first integer is formed using digits at odd indices (1-based), and the second integer is formed using digits at even indices (1-based). The function p...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by correctly separating the digits based on their 1-indexed positions and forming two integers from them."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently handles...
["\nassert max_sum_from_digits([1, 2, 3, 4, 5, 6]) == (135, 246)\n", "\nassert max_sum_from_digits([9, 8, 7, 6, 5, 4, 3, 2, 1]) == (97531, 8642)\n", "\nassert max_sum_from_digits([0, 0, 0, 0]) == (0, 0)\n", "\nassert max_sum_from_digits([1, 1, 1, 1, 1, 1]) == (111, 111)\n", "\nassert max_sum_from_digits([9, 0, 8, 0, 7,...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a function `calculate_average_grade` that computes the average grade from a given dictionary. The dictionary contains course names as keys and grades as values. Grades can be either numeric (float or int) or alphabetic ('A', 'B', 'C', 'D', 'F'). Convert alphabetic grades to their numeri...
```python def calculate_average_grade(grades): """ Calculate the average grade from a dictionary of grades. Parameters: grades (dict): A dictionary where keys are course names and values are grades (numeric or alphabetic). Returns: float: The average grade. Raises: ValueEr...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements, including handling both numeric and alphabetic grades, converting alphabetic grades to numeric values, and returning 0.0 for an empty dictionary."}, "logical_correctness": {"score": 5, "justification": "The l...
["\nassert calculate_average_grade({'Math': 'A', 'Science': 'B', 'History': 3.5}) == 3.6666666666666665\n", "\nassert calculate_average_grade({'Math': 'A', 'Science': 'A', 'History': 'A'}) == 4.0\n", "\nassert calculate_average_grade({'Math': 'F', 'Science': 'F', 'History': 'F'}) == 0.0\n", "\nassert calculate_average_...
["fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
You are tasked with implementing a `BankAccount` class in Python. The class should support the following operations: - **Initialization**: Create a bank account with an initial balance of 0. - **Deposit**: Add a specified amount to the account balance if the amount is positive. - **Withdraw**: Subtract a specified amo...
```python class BankAccount: def __init__(self): """Initialize a new bank account with a balance of 0.""" self.__balance = 0 def deposit(self, amount): """Deposit a positive amount into the bank account.""" if amount > 0: self.__balance += amount def withdraw(se...
{"requirement_conformance": {"score": 3, "justification": "The class meets basic requirements by implementing deposit, withdraw, and get_balance methods. However, it does not include any additional features or specifications that might have been expected, such as account holder information or transaction history."}, "l...
["\nassert BankAccount().get_balance() == 0\n", "\nassert BankAccount().deposit(100) is None\n", "\nassert BankAccount().withdraw(100) is None\n", "\naccount = BankAccount(); account.deposit(100); assert account.get_balance() == 100\n", "\naccount = BankAccount(); account.deposit(100); account.withdraw(50); assert acco...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of `n` intervals, where each interval is represented as a tuple `(start, end)`. The intervals may overlap or be disjoint. Your task is to write a function `merge_intervals` that takes in a list of intervals and returns a list of merged intervals. The merged intervals should be represented as tuples...
```python def merge_intervals(intervals): """ Merges a list of intervals and returns a list of merged intervals. :param intervals: List of tuples, where each tuple represents an interval (start, end). :return: List of tuples representing the merged intervals, sorted by the starting values. """ ...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by correctly merging overlapping intervals and returning a sorted list of merged intervals."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The interval...
["\nassert merge_intervals([(1, 3), (2, 6), (8, 10), (15, 18)]) == [(1, 6), (8, 10), (15, 18)]\n", "\nassert merge_intervals([(1, 4), (4, 5)]) == [(1, 5)]\n", "\nassert merge_intervals([(1, 2), (3, 4)]) == [(1, 2), (3, 4)]\n", "\nassert merge_intervals([(1, 2), (2, 3)]) == [(1, 3)]\n", "\nassert merge_intervals([(1, 3)...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"]
0.9
You are tasked with implementing a class `Employee` that models an employee's details and salary management. The class should have the following functionalities: - A constructor that initializes the employee's `name`, `position`, and `salary`. - A method `give_raise` that increases the employee's salary by a given per...
```python class Employee: def __init__(self, name, position, salary): """ Initializes an Employee object with the given name, position, and salary. :param name: str, the name of the employee :param position: str, the position of the employee :param salary: float, the salary ...
{"requirement_conformance": {"score": 5, "justification": "The code snippet fully meets all the specified requirements by creating an `Employee` class with a constructor that initializes `name`, `position`, and `salary` attributes, and includes a `give_raise` method that increases the salary by a specified percentage."...
["\nassert Employee(\"Alice\", \"Engineer\", 70000).name == \"Alice\"\n", "\nassert Employee(\"Bob\", \"Manager\", 80000).position == \"Manager\"\n", "\nassert Employee(\"Charlie\", \"Designer\", 60000).salary == 60000\n", "\nemp = Employee(\"David\", \"Analyst\", 65000)\nemp.give_raise(5)\nassert emp.salary == 68250.0...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a `Book` class and a `Library` class to manage a collection of books. The `Book` class should have the following attributes: `title`, `author`, `year_published`, and `ISBN`. Implement a method `get_description` in the `Book` class that returns a formatted string containing all the book'...
```python class Book: def __init__(self, title, author, year_published, ISBN): """ Initializes a new Book instance. :param title: The title of the book. :param author: The author of the book. :param year_published: The year the book was published. :param ISBN: The IS...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements. It includes the `Book` class with the required attributes and the `get_description` method. The `Library` class includes methods to add a book, remove a book, find a book by ISBN, and list all books."}, "...
["\nassert Book(\"1984\", \"George Orwell\", 1949, \"1234567890\").get_description() == \"Title: 1984, Author: George Orwell, Year Published: 1949, ISBN: 1234567890\"\n", "\nassert Library().list_books() == \"Library is empty\"\n", "\nlib = Library()\nlib.add_book(Book(\"1984\", \"George Orwell\", 1949, \"1234567890\")...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given two integers `n` and `k`. Your task is to compute the number of ways to partition a set of `n` elements into `k` non-empty subsets. The function should be optimized to handle large input sizes efficiently. **Constraints:** - `1 ≤ n ≤ 100` - `1 ≤ k ≤ n` **Sample Input:** ``` n = 5 k = 2 ``` **Sample Ou...
```python def partition(n, k): """ Computes the number of ways to partition a set of n elements into k non-empty subsets. :param n: Number of elements in the set. :param k: Number of non-empty subsets. :return: Number of ways to partition the set. """ if n == 0 or k == 0 or k > n: ...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement to optimize the function for large input sizes using dynamic programming and still returns the correct number of ways to partition a set of n elements into k non-empty subsets."}, "logical_correctness": {"score": 5, "jus...
["\nassert partition(0, 0) == 0\n", "\nassert partition(5, 0) == 0\n", "\nassert partition(0, 5) == 0\n", "\nassert partition(5, 6) == 0\n", "\nassert partition(1, 1) == 1\n", "\nassert partition(5, 1) == 1\n", "\nassert partition(5, 5) == 1\n", "\nassert partition(5, 2) == 15\n", "\nassert partition(6, 3) == 90\n", "\...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are tasked with implementing a simple library management system using a Python class. The system should support the following operations: 1. **Add a Book**: Add a book to the library with its title and author. The system should handle case-insensitivity for book titles. 2. **Remove a Book**: Remove a book from the...
```python from typing import List class Library: def __init__(self): self.books = set() def add_book(self, title: str, author: str) -> None: """Add a book to the library with its title and author.""" self.books.add(title.lower()) def remove_book(self, title: str) -> None: ...
{"requirement_conformance": {"score": 3, "justification": "The class meets basic requirements but misses some details. It does not handle authors in any way, and the list_books method returns titles in lowercase, which may not be the original format."}, "logical_correctness": {"score": 3, "justification": "The logic is...
["\nassert Library().list_books() == []\n", "\nassert Library().search_book(\"The Great Gatsby\") == False\n", "\nlibrary = Library()\nlibrary.add_book(\"The Great Gatsby\", \"F. Scott Fitzgerald\")\nassert library.search_book(\"The Great Gatsby\") == True\n", "\nlibrary = Library()\nlibrary.add_book(\"The Great Gatsby...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a nested list, which is a list that may contain other lists, and your task is to write a function `flatten_list` that returns a new list with all the elements flattened into a single list. The function should be able to handle lists of arbitrary depth. **Input:** - A nested list of integers. **Output:*...
```python def flatten_list(nested_list): """ Flattens a nested list of arbitrary depth into a single list of integers. :param nested_list: List of integers or nested lists of integers. :return: A single flattened list of integers. """ flat_list = [] for item in nested_list: if isins...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by correctly flattening nested lists of arbitrary depth and handling the provided example inputs as expected."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally struct...
["\nassert flatten_list([[1, 2, 3], [4, 5, [6, 7]], 8, [9, [10]]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", "\nassert flatten_list([1, [2, [3, [4, [5]]]]]) == [1, 2, 3, 4, 5]\n", "\nassert flatten_list([]) == []\n", "\nassert flatten_list([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert flatten_list([[[[1]]]]) == [1]\n"...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of unique integers. Your task is to generate all possible permutations of these integers. Implement a function `generate_permutations` that takes a list of integers as input and returns a list of all permutations. Note that you are not allowed to use any built-in functions for generating permutatio...
```python def generate_permutations(elements): """ Generate all permutations of a list of unique integers. :param elements: List of unique integers. :return: List of lists, where each inner list is a permutation of the input list. """ if len(elements) == 0: return [[]] first_element...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by generating all possible permutations of a list of unique elements without using itertools.permutations."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured...
["\nassert generate_permutations([1, 2, 3]) == [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]\n", "\nassert generate_permutations([1]) == [[1]]\n", "\nassert generate_permutations([]) == [[]]\n", "\nassert generate_permutations(['a', 'b', 'c']) == [['a', 'b', 'c'], ['b', 'a', 'c'], ['b', 'c', 'a'], ...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass"]
0.9
You are given a string representing a mathematical expression consisting of non-negative integers and the operators `+`, `-`, `*`, and `/`. Your task is to write a function that evaluates the expression and returns the result as an integer. The division operator `/` should perform floor division. Assume that the input ...
```python def evaluate_expression(expression: str) -> int: """ Evaluates a mathematical expression consisting of non-negative integers and the operators +, -, *, and /. The division operator performs floor division. :param expression: A string representing the mathematical expression. :return: ...
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirement of evaluating a mathematical expression with addition, subtraction, multiplication, and division. However, it does not specify handling of invalid inputs or other edge cases explicitly."}, "logical_correctness": {"score"...
["\nassert evaluate_expression(\"3 + 5 * 2\") == 13\n", "\nassert evaluate_expression(\"10 - 2 * 3\") == 4\n", "\nassert evaluate_expression(\"8 / 4 + 2\") == 4.0\n", "\nassert evaluate_expression(\"7 * (3 + 2)\") == 35\n", "\nassert evaluate_expression(\"100 / 25 - 3\") == 1.0\n", "\nassert evaluate_expression(\"5 + 5...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a string `s` consisting of various whitespace characters (spaces, tabs, newlines) and non-whitespace characters. Your task is to write a function `compress_whitespace` that processes the string `s` and returns a new string where all consecutive whitespace characters are replaced by a single space. Additio...
```python def compress_whitespace(input_string): """ Compresses consecutive whitespace characters in the input string to a single space and removes leading and trailing whitespace characters. :param input_string: The input string to be processed. :return: A new string with compressed whitespace and...
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements of compressing consecutive whitespace characters into a single space and removing leading and trailing whitespace. However, it uses the `isspace` method, which is a built-in string method for whitespace checking, which ...
["\nassert compress_whitespace(\" This is a test \") == \"This is a test\"\n", "\nassert compress_whitespace(\"\\t\\tHello\\tWorld\\t\\t\") == \"Hello World\"\n", "\nassert compress_whitespace(\"Line1\\nLine2\\nLine3\") == \"Line1 Line2 Line3\"\n", "\nassert compress_whitespace(\" Leading and trailing spaces...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of integers. Your task is to write a Python function that identifies and returns the two largest distinct numbers in the list. If the list contains fewer than two distinct numbers, the function should return a message indicating that the list must contain at least two distinct elements. **Input:**...
```python def find_two_largest_numbers(numbers): """ Finds and prints the two largest distinct numbers in a list. If the list contains fewer than two distinct numbers, prints an error message. :param numbers: List of integers """ if len(numbers) < 2: print("The list must contain at ...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by finding and printing the two largest numbers in the list and handling the case where the list contains fewer than two elements."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct...
["\nassert find_two_largest_numbers([1, 2]) == None\n", "\nassert find_two_largest_numbers([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == None\n", "\nassert find_two_largest_numbers([100]) == None\n", "\nassert find_two_largest_numbers([]) == None\n", "\nassert find_two_largest_numbers([5, 5]) == None\n", "\nassert find_two_lar...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a list of books, where each book is represented as an object with the following attributes: `title` (a string), `authors` (a list of strings), and `genres` (a list of strings). Your task is to implement a function `filter_books_by_genre_and_author_count` that takes this list of books, a genre, and a thres...
```python class Book: def __init__(self, title, authors, genres): self.title = title self.authors = authors self.genres = genres def filter_books_by_genre_and_author_count(books, genre, threshold): """ Filters books by a specified genre and a minimum number of authors. Paramete...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It takes a list of books, a genre, and a threshold value as input, and returns a new list containing only the books that belong to the specified genre and have more than the given threshold number of authors....
["\nassert filter_books_by_genre_and_author_count(books, \"Fantasy\", 1) == [books[0], books[3]]\n", "\nassert filter_books_by_genre_and_author_count(books, \"Sci-Fi\", 2) == [books[2]]\n", "\nassert filter_books_by_genre_and_author_count(books, \"Adventure\", 1) == [books[0]]\n", "\nassert filter_books_by_genre_and_au...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Implement a recursive function to compute the nth Fibonacci number without using memoization. The Fibonacci sequence is defined as follows: - F(1) = 0 - F(2) = 1 - F(n) = F(n-1) + F(n-2) for n > 2 **Input:** - A single integer n (1 ≤ n ≤ 30) **Output:** - A single integer representing the nth Fibonacci number. **Sam...
```python def fibonacci(n): """ Compute the nth Fibonacci number using a recursive approach without memoization. Parameters: n (int): The position in the Fibonacci sequence (1 ≤ n ≤ 30). Returns: int: The nth Fibonacci number. """ if n <= 0: return "Input should be a positive i...
{"requirement_conformance": {"score": 4, "justification": "The solution meets the basic requirements of implementing the Fibonacci sequence using recursion. However, it does not explicitly handle non-integer inputs, which could be considered a minor gap."}, "logical_correctness": {"score": 5, "justification": "The logi...
["\nassert fibonacci(1) == 0\n", "\nassert fibonacci(2) == 1\n", "\nassert fibonacci(3) == 1\n", "\nassert fibonacci(4) == 2\n", "\nassert fibonacci(5) == 3\n", "\nassert fibonacci(6) == 5\n", "\nassert fibonacci(7) == 8\n", "\nassert fibonacci(8) == 13\n", "\nassert fibonacci(9) == 21\n", "\nassert fibonacci(10) == 34...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
You are given a string `s` consisting of words separated by spaces. Your task is to implement a function `count_words` that returns a dictionary with each unique word as the key and its frequency as the value. The comparison should be case-insensitive, and the words do not contain any punctuation. **Input:** - A sing...
```python def count_words(input_string): """ Counts the frequency of each unique word in a given string, ignoring case. Parameters: input_string (str): The string containing words separated by spaces. Returns: dict: A dictionary with words as keys and their counts as values. """ ...
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements: it takes a string as input, returns a dictionary with the count of each unique word, is case-insensitive, and assumes words are separated by spaces without punctuation."}, "logical_correctness": {"score": 5, ...
["\nassert count_words(\"Hello world hello Python world\") == {'hello': 2, 'world': 2, 'python': 1}\n", "\nassert count_words(\"A quick brown fox jumps over the lazy dog\") == {'a': 1, 'quick': 1, 'brown': 1, 'fox': 1, 'jumps': 1, 'over': 1, 'the': 1, 'lazy': 1, 'dog': 1}\n", "\nassert count_words(\"Python is great and...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"]
0.9
You are given an array `nums` of `n` distinct integers in the range `[0, n]`. Your task is to determine the missing integer in the range. The array is not necessarily sorted and may contain the integers in any order. Your solution should be efficient, with a time complexity of O(n) and a space complexity of O(1). **In...
```python def find_missing_number(nums): """ Finds the missing number in a list of n distinct numbers taken from the range [0, n]. :param nums: List[int] - A list of n distinct integers. :return: int - The missing number in the range [0, n]. """ n = len(nums) expected_sum = n * (n + 1) ...
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing a function that finds the missing number in a list of distinct numbers from the range [0, n] with O(n) time complexity and O(1) space complexity."}, "logical_correctness": {"score": 5, "justification": "...
["\nassert find_missing_number([3, 0, 1]) == 2\n", "\nassert find_missing_number([9, 6, 4, 2, 3, 5, 7, 0, 1]) == 8\n", "\nassert find_missing_number([0]) == 1\n", "\nassert find_missing_number([1]) == 0\n", "\nassert find_missing_number([0, 1]) == 2\n", "\nassert find_missing_number([1, 2]) == 0\n", "\nassert find_miss...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
14