input stringlengths 165 4.19k | output stringlengths 90 7.07k | llm_judgement stringlengths 397 2.13k | unit_tests stringlengths 241 8.63k | tests_execution_status stringclasses 11
values | average_test_score stringclasses 2
values |
|---|---|---|---|---|---|
You are tasked with implementing a `BankAccount` class in Python that simulates basic bank account operations. The class should support the following functionalities:
- **Initialization**: Create a bank account with an initial balance of 0.
- **Deposit**: Add a specified amount to the account balance. The deposit amou... | ```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 specified amount into the bank account.
Parameters:
amount (float): The amount to deposit.... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing the BankAccount class with methods to deposit, withdraw, and get the current balance. The initial balance is set to 0, and the withdraw method prevents overdrawing the account."}, "logical_corr... | ["\nassert BankAccount().deposit(100) == \"Deposited $100. New balance is $100.\"\n", "\nassert BankAccount().deposit(-50) == \"Deposit amount must be positive.\"\n", "\nassert BankAccount().withdraw(10) == \"Error: Insufficient funds. Withdrawal not possible.\"\n", "\nassert BankAccount().withdraw(-20) == \"Withdrawal... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of tuples, where each tuple represents a bidirectional edge between two nodes in an undirected graph. The nodes are represented as integers. Your task is to write a function that processes these edges and returns a sorted list of unique edges. Each edge should be represented as a tuple of two nodes... | ```python
def process_edges(edges):
"""
Processes a list of bidirectional edges, normalizes them, removes duplicates,
and returns a sorted list of unique edges.
:param edges: List of tuples, where each tuple contains two integers representing an edge.
:return: Sorted list of unique tuples represent... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements: it removes duplicates, normalizes the edges such that the smaller node comes first, and sorts the edges correctly."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and ... | ["\nassert process_edges([(3, 1), (2, 4), (1, 3), (4, 2), (2, 1), (5, 5)]) == [(1, 3), (2, 1), (2, 4), (4, 2), (5, 5)]\n", "\nassert process_edges([(1, 2), (2, 3), (3, 4), (4, 5)]) == [(1, 2), (2, 3), (3, 4), (4, 5)]\n", "\nassert process_edges([(5, 5), (5, 5), (5, 5)]) == [(5, 5)]\n", "\nassert process_edges([(10, 20)... | ["fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 |
You are given an unordered list of `n` distinct items and a binary encoded integer `x`. Each bit in the binary representation of `x` indicates the presence (1) or absence (0) of an item in a secret list. The least significant bit corresponds to the first item in the list, the second least significant bit to the second ... | ```python
def decode_secret_list(encoded_int, items):
"""
Decodes a secret list from a binary encoded integer and a list of items.
:param encoded_int: An integer representing the binary encoded list.
:param items: A list of strings representing the items.
:return: A list of strings representing... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It correctly decodes the binary encoded integer and constructs the secret list based on the presence of items as indicated by the binary bits."}, "logical_correctness": {"score": 5, "justification": "The logi... | ["\nassert decode_secret_list(0b10110, ['apple', 'banana', 'cherry', 'date', 'elderberry']) == ['banana', 'cherry', 'elderberry']\n", "\nassert decode_secret_list(0b11111, ['apple', 'banana', 'cherry', 'date', 'elderberry']) == ['apple', 'banana', 'cherry', 'date', 'elderberry']\n", "\nassert decode_secret_list(0b00000... | ["pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass"] | 0.9 |
You are given two dictionaries, `dict_A` and `dict_B`, representing the preferences of two users for different types of fruits. Each dictionary contains fruit names as keys and their corresponding preference scores as values, ranging from 1 to 10, where 10 indicates the highest preference. The fruit names in both dicti... | ```python
def merge_preferences(dict_A, dict_B):
"""
Merges two dictionaries of fruit preferences, giving priority to the second dictionary.
Parameters:
dict_A (dict): The first dictionary of fruit preferences.
dict_B (dict): The second dictionary of fruit preferences with higher priority.
... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It normalizes the keys to lowercase and merges the dictionaries with preferences from dict_B taking priority."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optim... | ["\nassert merge_preferences({'Apple': 7, 'Banana': 3}, {'apple': 8, 'Orange': 5}) == {'apple': 8, 'banana': 3, 'orange': 5}\n", "\nassert merge_preferences({'Grape': 5, 'Kiwi': 6}, {'grape': 4, 'kiwi': 7}) == {'grape': 4, 'kiwi': 7}\n", "\nassert merge_preferences({'Mango': 10}, {'mango': 10}) == {'mango': 10}\n", "\n... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given two integers, `A` and `B`. Your task is to compute the integer division of `A` by `B` using only addition, subtraction, and bit manipulation. The result should be rounded down to the nearest integer. You are not allowed to use any built-in division operators or libraries that directly perform division. Im... | ```python
def divide(A, B):
"""
Computes the integer division of A by B using only addition, subtraction, and bit manipulation.
:param A: The dividend integer.
:param B: The divisor integer.
:return: The quotient of A divided by B, rounded down to the nearest integer.
"""
if B == 0:
... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It implements the division of big integers using only addition, subtraction, and bit manipulation without using any auxiliary functions or additional data structures. It also handles division by zero by raisi... | ["\nassert divide(10, 2) == 5\n", "\nassert divide(7, 3) == 2\n", "\nassert divide(15, 5) == 3\n", "\nassert divide(1, 1) == 1\n", "\nassert divide(0, 1) == 0\n", "\nassert divide(-10, 2) == -5\n", "\nassert divide(10, -2) == -5\n", "\nassert divide(-10, -2) == 5\n", "\nassert divide(100, 3) == 33\n", "\nassert divide(... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given the root of a binary tree. Your task is to return the postorder traversal of its nodes' values using an iterative approach. The postorder traversal sequence is defined as visiting the left subtree, then the right subtree, and finally the root node.
**Input:**
- The input is the root of a binary tree. Eac... | ```python
# Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def postorderTraversal(root: TreeNode) -> list:
"""
Returns the postorder traversal of a binary tree's nodes' values us... | {"requirement_conformance": {"score": 4, "justification": "The solution meets the basic requirements of implementing an iterative postorder traversal of a binary tree. However, it does not provide a function definition with type hints for the parameters and return type, which is a minor detail."}, "logical_correctness"... | ["\nassert postorderTraversal(None) == []\n", "\nassert postorderTraversal(TreeNode(1)) == [1]\n", "\nassert postorderTraversal(TreeNode(1, TreeNode(2))) == [2, 1]\n", "\nassert postorderTraversal(TreeNode(1, None, TreeNode(2))) == [2, 1]\n", "\nassert postorderTraversal(TreeNode(1, TreeNode(2, TreeNode(3)))) == [3, 2,... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 |
You are given a dictionary where each key is associated with a list of integers. Your task is to create a function that returns a new dictionary. In this new dictionary, each key should be mapped to the count of unique integers in the corresponding list from the input dictionary.
**Input:**
- A dictionary `input_dict`... | ```python
def count_unique_elements(input_dict):
"""
Returns a dictionary with each key mapped to the count of unique elements in the corresponding list.
:param input_dict: A dictionary where each key is a string and each value is a list of integers.
:return: A dictionary with each key mapped to the co... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the specified requirements by taking a dictionary of lists as input and returning a new dictionary with the count of unique elements for each key."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct ... | ["\nassert count_unique_elements({'a': [1, 2, 2, 3], 'b': [4, 4, 4, 5, 5]}) == {'a': 3, 'b': 2}\n", "\nassert count_unique_elements({'x': [10, 20, 30], 'y': [40, 50, 60, 70]}) == {'x': 3, 'y': 4}\n", "\nassert count_unique_elements({'m': [1, 1, 1, 1], 'n': [2, 2, 2, 2]}) == {'m': 1, 'n': 1}\n", "\nassert count_unique_e... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are participating in a machine learning competition where you need to optimize a model using multiple loss functions. Each loss function has a computed value and a weight that indicates its importance in the optimization process. Your task is to write a function that applies these weights to the loss values.
You a... | ```python
def apply_weights(loss_values: dict, loss_objects: dict) -> dict:
"""
Applies weights to the loss values based on the provided loss objects.
Parameters:
- loss_values (dict): A dictionary with loss function names as keys and computed loss values as values.
- loss_objects (dict): A dic... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It correctly applies weights to the loss values and handles cases where some loss objects may not have a `get_weight()` method by treating their weight as 1.0."}, "logical_correctness": {"score": 5, "justific... | ["\nassert apply_weights({\"loss1\": 2.0, \"loss2\": 3.0}, {\"loss1\": type(\"Loss\", (object,), {\"get_weight\": lambda self: 0.5})(), \"loss2\": type(\"Loss\", (object,), {\"get_weight\": lambda self: 2.0})()}) == {\"loss1\": 1.0, \"loss2\": 6.0}\n", "\nassert apply_weights({\"loss1\": 1.0, \"loss2\": 1.0}, {\"loss1\... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a dictionary `input_dict` where each key is unique. Your task is to create a function that returns a new dictionary with keys and values swapped. If any value in the original dictionary appears more than once, the function should return `None`.
**Input:**
- A dictionary `input_dict` with unique keys.
*... | ```python
def swap_keys_values(input_dict):
"""
Swaps the keys and values of the input dictionary.
Parameters:
input_dict (dict): A dictionary with unique keys.
Returns:
dict or None: A new dictionary with keys and values swapped if all values are unique; otherwise, None.
"""
s... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It correctly swaps keys and values and returns None if a value appears more than once."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It eff... | ["\nassert swap_keys_values({'a': 'b', 'c': 2}) == {'b': 'a', 2: 'c'}\n", "\nassert swap_keys_values({'x': 1, 'y': 2, 'z': 3}) == {1: 'x', 2: 'y', 3: 'z'}\n", "\nassert swap_keys_values({'key': 'value', 'another': 'value'}) == None\n", "\nassert swap_keys_values({}) == {}\n", "\nassert swap_keys_values({'single': 'entr... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass"] | 0.9 |
You are tasked with implementing a Python class `Employee` that manages employee details and salary transactions. The class should have the following attributes and methods:
- **Attributes:**
- `name`: A string representing the employee's name.
- `position`: A string representing the employee's position.
- `sala... | ```python
import threading
class Employee:
def __init__(self, name, position, salary):
"""
Initializes an Employee instance 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... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It implements the `give_raise` method to increase the salary by a given percentage and logs the transaction details to a file named `salary_transactions.log` in the specified format. The logging is also threa... | ["\nassert Employee(\"Alice\", \"Engineer\", 70000).give_raise(5) is None\n", "\nassert Employee(\"Bob\", \"Manager\", 80000).give_raise(15).salary == 92000.0\n", "\nemp = Employee(\"Charlie\", \"Designer\", 60000)\nemp.give_raise(20)\nassert emp.salary == 72000.0\n", "\nemp = Employee(\"David\", \"Analyst\", 55000)\ne... | ["pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 |
You are given a list of integers `numbers` and an integer `k`. Your task is to implement a function `calculate_moving_average` that computes the moving averages of the list using a sliding window of size `k`. The function should return a list of these averages. If the list has fewer than `k` elements, return an empty l... | ```python
def calculate_moving_average(numbers, k):
"""
Calculate the moving averages of a list using a sliding window of size k.
:param numbers: List of integers.
:param k: Integer representing the window size.
:return: List of floating-point numbers representing the moving averages.
"""
i... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements. It calculates the moving averages for the given list of numbers and window size, and returns an empty list if the input list has fewer than k elements."}, "logical_correctness": {"score": 5, "justification": ... | ["\nassert calculate_moving_average([1, 2, 3, 4, 5], 3) == [2.0, 3.0, 4.0]\n", "\nassert calculate_moving_average([10, 20, 30, 40, 50], 2) == [15.0, 25.0, 35.0, 45.0]\n", "\nassert calculate_moving_average([5, 5, 5, 5, 5], 5) == [5.0]\n", "\nassert calculate_moving_average([1, 2, 3], 4) == []\n", "\nassert calculate_mo... | ["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 `find_mode(numbers)` that determines and returns the mode of the list, which is defined as the number that appears most frequently. If there are multiple numbers with the same highest frequency, return any one of them.
**Input:**
- A list of intege... | ```python
def find_mode(numbers):
"""
Returns the mode of the list, which is the number that appears most frequently.
If there are multiple modes, returns any one of them.
:param numbers: List of integers
:return: Integer representing the mode of the list
"""
from collections import Counter... | {"requirement_conformance": {"score": 5, "justification": "The function correctly implements the requirement to find and return the mode of the list. It handles the case where there are multiple modes by returning any one of them."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct.... | ["\nassert find_mode([1, 2, 2, 3, 3, 4]) in [2, 3]\n", "\nassert find_mode([4, 4, 1, 2, 2, 3, 3]) in [2, 3, 4]\n", "\nassert find_mode([7, 7, 7, 1, 2, 2, 3]) == 7\n", "\nassert find_mode([1, 1, 2, 3, 4, 4, 5, 5]) in [1, 4, 5]\n", "\nassert find_mode([10]) == 10\n", "\nassert find_mode([1, 2, 3, 4, 5]) in [1, 2, 3, 4, 5... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 |
You are given a list of distinct items. Your task is to write a Python function that generates all possible non-empty combinations of these items, considering combinations of all possible lengths. The function should return a list of lists, where each inner list represents a unique combination of items.
**Input:**
- A... | ```python
from itertools import combinations
def generate_combinations(items):
"""
Generate all possible non-empty combinations of a given list of items.
Parameters:
items (list): A list of distinct strings.
Returns:
list: A list of lists, where each inner list is a unique combination of item... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by generating all possible combinations of a given list of items, including combinations of different lengths, and returns them as a list of lists."}, "logical_correctness": {"score": 5, "justification": "The logic is co... | ["\nassert generate_combinations([\"apple\", \"banana\", \"pear\"]) == [['apple'], ['banana'], ['pear'], ['apple', 'banana'], ['apple', 'pear'], ['banana', 'pear'], ['apple', 'banana', 'pear']]\n", "\nassert generate_combinations([\"a\", \"b\"]) == [['a'], ['b'], ['a', 'b']]\n", "\nassert generate_combinations([]) == [... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of tables, each containing a set of columns. Each column has a name, a boolean attribute indicating whether it is a primary column, and a complexity attribute which is a positive integer. Your task is to write a function that returns the name of the column that is most frequently marked as primary ... | ```python
def find_most_frequent_primary_or_highest_complexity_column(tables):
"""
Returns the name of the column that is most frequently marked as primary among all the tables
and has the highest complexity. If no column is marked as primary, returns the name of the first
column with the highest comple... | {"requirement_conformance": {"score": 3, "justification": "The solution addresses the requirement to find the most frequently marked primary column and considers the complexity attribute. However, it does not handle the tie-breaking rule correctly as per the original instruction. It should return the column that appear... | ["\nassert find_most_frequent_primary_or_highest_complexity_column([{'name': 'table1', 'columns': [{'name': 'col1', 'primary': True, 'complexity': 5}]}]) == 'col1'\n", "\nassert find_most_frequent_primary_or_highest_complexity_column([{'name': 'table1', 'columns': [{'name': 'col1', 'primary': False, 'complexity': 5}]}]... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass"] | 0.9 |
You are given a string `s` consisting of `n` characters. Your goal is to transform this string into a palindrome by deleting the minimum number of characters. Write a function `min_deletions_to_palindrome` that computes the minimum number of deletions required.
**Input:**
- A single string `s` (1 ≤ |s| ≤ 1000) consist... | ```python
def min_deletions_to_palindrome(s: str) -> int:
"""
Computes the minimum number of deletions required to transform the string s into a palindrome.
:param s: A string consisting of lowercase English letters.
:return: The minimum number of deletions needed.
"""
n = len(s)
dp = [... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by calculating the minimum number of deletions required to make the string a palindrome."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses dynamic ... | ["\nassert min_deletions_to_palindrome(\"abcda\") == 2\n", "\nassert min_deletions_to_palindrome(\"racecar\") == 0\n", "\nassert min_deletions_to_palindrome(\"abcdef\") == 5\n", "\nassert min_deletions_to_palindrome(\"a\") == 0\n", "\nassert min_deletions_to_palindrome(\"ab\") == 1\n", "\nassert min_deletions_to_palind... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of tuples, where each tuple consists of two strings. Your task is to write a function that concatenates the two strings in each tuple and returns a list of the concatenated results.
**Input:**
- A list of tuples, where each tuple contains two strings.
**Output:**
- A list of strings, where each s... | ```python
def concatenate_tuples(tuples_list):
"""
Concatenates the two strings in each tuple of the given list and returns a list of the concatenated results.
:param tuples_list: List of tuples, where each tuple contains two strings.
:return: List of concatenated strings.
"""
return [a + b for... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by correctly concatenating the two strings from each tuple in the list and returning the expected list of concatenated strings."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and... | ["\nassert concatenate_tuples([(\"Hello\", \"World\")]) == [\"HelloWorld\"]\n", "\nassert concatenate_tuples([(\"Foo\", \"Bar\"), (\"Baz\", \"Qux\")]) == [\"FooBar\", \"BazQux\"]\n", "\nassert concatenate_tuples([(\"a\", \"b\"), (\"c\", \"d\"), (\"e\", \"f\")]) == [\"ab\", \"cd\", \"ef\"]\n", "\nassert concatenate_tupl... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 |
You are given a list of integers representing device indices. Your task is to implement a function `get_device_key` that constructs a string key for querying a device cache. The key must be a concatenation of unique device indices, sorted in lexicographical order, and separated by hyphens.
**Input:**
- A list of integ... | ```python
def get_device_key(device_indices):
"""
Constructs a device key from a list of device indices.
Parameters:
device_indices (list of int): A list of device indices.
Returns:
str: A string representing the device key, with unique indices sorted in lexicographical order and separ... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by removing duplicates, sorting the indices, and joining them into a lexicographically ordered string."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. I... | ["\nassert get_device_key([3, 1, 2]) == \"1-2-3\"\n", "\nassert get_device_key([10, 20, 30, 20, 10]) == \"10-20-30\"\n", "\nassert get_device_key([5, 5, 5, 5, 5]) == \"5\"\n", "\nassert get_device_key([1]) == \"1\"\n", "\nassert get_device_key([]) == \"\"\n", "\nassert get_device_key([9, 7, 5, 3, 1]) == \"1-3-5-7-9\"\n... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of words `words` and a list of tuples `ranges`. Each tuple in `ranges` consists of two integers representing a start and end index for a slice of the `words` list. Your task is to implement the function `get_word_slices` that returns a list of word slices corresponding to the given ranges. Each sli... | ```python
from typing import List, Tuple
def get_word_slices(words: List[str], ranges: List[Tuple[int, int]]) -> List[List[str]]:
"""
Returns a list of word slices corresponding to the given ranges.
:param words: List of words to be sliced.
:param ranges: List of tuples, each representing a start ... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the specified requirements by implementing the function `get_word_slices` that takes a list of words and a list of tuples representing ranges, and returns the corresponding word slices."}, "logical_correctness": {"score": 5, "justificat... | ["\nassert get_word_slices([\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\"], [(0, 2)]) == [['apple', 'banana']]\n", "\nassert get_word_slices([\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\"], [(1, 4)]) == [['banana', 'cherry', 'date']]\n", "\nassert get_word_slices([\"apple\", \"banana\", \"ch... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of dictionaries. Your task is to implement a function `group_by_key(dict_list: list, key: str) -> dict` that groups these dictionaries based on the values associated with a specified key. The function should return a dictionary where each key is a unique value from the specified key in the input di... | ```python
def group_by_key(dict_list: list, key: str) -> dict:
"""
Groups a list of dictionaries by a specified key.
Parameters:
dict_list (list): A list of dictionaries to be grouped.
key (str): The key by which to group the dictionaries.
Returns:
dict: A dictionary where keys are unique ... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by grouping the dictionaries by the specified key and returning a dictionary with the correct structure."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally s... | ["\nassert group_by_key([{\"a\": 1, \"b\": 2}, {\"a\": 1, \"b\": 3}, {\"a\": 2, \"b\": 4}], \"a\") == {1: [{\"a\": 1, \"b\": 2}, {\"a\": 1, \"b\": 3}], 2: [{\"a\": 2, \"b\": 4}]}\n", "\nassert group_by_key([{\"x\": \"foo\", \"y\": \"bar\"}, {\"x\": \"foo\", \"y\": \"baz\"}, {\"x\": \"qux\", \"y\": \"quux\"}], \"x\") ==... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a string `s` consisting of uppercase and lowercase letters, digits, and special characters, including Unicode characters. Your task is to implement a function `convert_to_lowercase` that converts all the alphabetic characters in the string to their lowercase equivalents while leaving all other characters ... | ```python
def convert_to_lowercase(input_string):
"""
Convert all alphabetic characters in the input string to lowercase.
Parameters:
input_string (str): The string to be converted.
Returns:
str: A new string with all alphabetic characters in lowercase.
"""
return input_string.... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by converting all characters in the input string to lowercase and handles Unicode characters properly using the built-in lower() method."}, "logical_correctness": {"score": 5, "justification": "The logic is completely co... | ["\nassert convert_to_lowercase(\"HELLO\") == \"hello\"\n", "\nassert convert_to_lowercase(\"WORLD\") == \"world\"\n", "\nassert convert_to_lowercase(\"Python3.8\") == \"python3.8\"\n", "\nassert convert_to_lowercase(\"12345\") == \"12345\"\n", "\nassert convert_to_lowercase(\"!@#$%^&*()\") == \"!@#$%^&*()\"\n", "\nass... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a task to implement a function that creates a unique temporary directory for storing intermediate results of a long-running process. The function should accept two parameters: the path to the working directory and the desired name for the temporary directory. If the specified directory name already exists... | ```python
import os
import time
import threading
def create_unique_temp_dir(working_dir, temp_dir_name):
"""
Creates a unique temporary directory inside the specified working directory.
If the specified temp_dir_name already exists, it appends a timestamp to make it unique.
Parameters:
- working_d... | {"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements by creating a unique temporary directory and handling concurrent access. However, it does not explicitly manage the cleanup of the temporary directory, which might be an expected requirement."}, "logical_correctness": {... | ["\nassert os.path.isdir(create_unique_temp_dir(\"/tmp\", \"test_dir\"))\n", "\nassert create_unique_temp_dir(\"/tmp\", \"test_dir\") != create_unique_temp_dir(\"/tmp\", \"test_dir\")\n", "\nassert create_unique_temp_dir(\"/tmp\", \"test_dir\").endswith(\"_test_dir\")\n", "\nassert create_unique_temp_dir(\"/tmp\", \"te... | ["pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 |
You are tasked with implementing the `deep_flatten` function, which processes a nested dictionary and returns a flattened version of it. The input dictionary can contain other dictionaries, lists, tuples, or sets as values. Your function must handle recursive structures and avoid infinite loops when encountering self-r... | ```python
def deep_flatten(nested_dict):
"""
Flattens a nested dictionary into a single-level dictionary.
Args:
nested_dict (dict): A dictionary that may contain other dictionaries, lists, tuples, or sets as values.
Returns:
dict: A flattened dictionary with keys representing the path ... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by flattening nested dictionaries, lists, tuples, and sets into a single dictionary. It also handles self-referencing structures to avoid infinite loops."}, "logical_correctness": {"score": 5, "justification": "The logi... | ["\nassert deep_flatten({}) == {}\n", "\nassert deep_flatten({'a': 1}) == {'a': 1}\n", "\nassert deep_flatten({'a': {'b': 2}}) == {'a_b': 2}\n", "\nassert deep_flatten({'a': [1, 2, 3]}) == {'a_0': 1, 'a_1': 2, 'a_2': 3}\n", "\nassert deep_flatten({'a': (1, 2, 3)}) == {'a_0': 1, 'a_1': 2, 'a_2': 3}\n", "\nassert deep_fl... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass"] | 0.9 |
You are given a list of `n` intervals, where each interval is represented as a tuple `(start, end)`. Your task is to merge all overlapping intervals and return the merged list of intervals. Intervals `[a, b]` and `[c, d]` are considered overlapping if `b >= c`. The function should handle edge cases such as when the inp... | ```python
def merge_intervals(intervals):
"""
Merges overlapping intervals in the given list and returns the merged list.
:param intervals: List of tuples, where each tuple represents an interval (start, end).
:return: List of tuples representing the merged intervals.
"""
if len(intervals) ... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It handles the merging of overlapping intervals and correctly returns the input list as is when it is empty or contains only one interval."}, "logical_correctness": {"score": 5, "justification": "The logic is... | ["\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, 3), (2, 5), (4, 6)]) == [(1, 6)]\n", "\nassert merge_intervals... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of non-negative integers. Your task is to write a function that returns a list of their square roots. The function should handle an empty list as well, returning an empty list in that case.
**Sample Input:**
```
[4, 9, 16, 25]
```
**Sample Output:**
```
[2.0, 3.0, 4.0, 5.0]
``` | ```python
import math
def sqrt(numbers):
"""
Calculate the square roots of a list of non-negative integers.
:param numbers: List of non-negative integers.
:return: List of square roots of the input numbers.
"""
return [math.sqrt(num) for num in numbers]
``` | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by modifying the function to handle a list of numbers instead of a single number."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It correctly applies th... | ["\nassert sqrt([4, 9, 16]) == [2.0, 3.0, 4.0]\n", "\nassert sqrt([0, 1, 2]) == [0.0, 1.0, 1.4142135623730951]\n", "\nassert sqrt([1.0, 4.0, 9.0]) == [1.0, 2.0, 3.0]\n", "\nassert sqrt([25, 36, 49]) == [5.0, 6.0, 7.0]\n", "\nassert sqrt([0.25, 0.36, 0.49]) == [0.5, 0.6, 0.7]\n", "\nassert sqrt([100, 225, 400]) == [10.0... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are tasked with implementing a `Book` class for a library management system. The class should have the following attributes and methods:
- **Attributes:**
- `title` (str): The title of the book.
- `author` (str): The author of the book.
- `publisher` (str): The publisher of the book.
- `year_of_publication... | ```python
class Book:
"""
A class to represent a Book in a library system.
Attributes
----------
title : str
The title of the book.
author : str
The author of the book.
publisher : str
The publisher of the book.
year_of_publication : int
The year in w... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements, including the attributes and methods for the Book class, and ensures that borrow_book and return_book change the number of copies available accordingly."}, "logical_correctness": {"score": 5, "justificati... | ["\nassert Book(\"1984\", \"George Orwell\", \"Secker & Warburg\", 1949, \"9780451524935\", 3).check_availability() == True\n", "\nassert Book(\"To Kill a Mockingbird\", \"Harper Lee\", \"J.B. Lippincott & Co.\", 1960, \"9780060935467\", 0).check_availability() == False\n", "\nassert Book(\"The Great Gatsby\", \"F. Sco... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are tasked with implementing a `Rectangle` class in Python. The class should have two attributes, `width` and `height`, and should provide the following functionalities:
- A method to calculate the area of the rectangle.
- A method to calculate the perimeter of the rectangle.
- A method to determine if the rectangl... | ```python
class Rectangle:
def __init__(self, width, height):
"""
Initialize a new Rectangle instance with given width and height.
:param width: The width of the rectangle.
:param height: The height of the rectangle.
"""
self.width = width
self.height = heigh... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing the Rectangle class with width and height attributes, and methods to calculate area, perimeter, and check if it is a square."}, "logical_correctness": {"score": 5, "justification": "The logic i... | ["\nassert Rectangle(3, 4).area() == 12\n", "\nassert Rectangle(5, 5).area() == 25\n", "\nassert Rectangle(7, 2).perimeter() == 18\n", "\nassert Rectangle(10, 10).perimeter() == 40\n", "\nassert Rectangle(1, 1).is_square() == True\n", "\nassert Rectangle(2, 3).is_square() == False\n", "\nassert Rectangle(0, 0).area() =... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are tasked with creating a Python class named `Book` to represent a book with the following attributes: `title`, `author`, and `isbn`. Implement the following methods:
- `display_info`: Returns a string containing the book's title, author, and ISBN in the format: `"Title: {title}, Author: {author}, ISBN: {isbn}"`.
... | ```python
class Book:
def __init__(self, title, author, isbn):
"""
Initializes a new Book instance with the given title, author, and ISBN.
:param title: The title of the book.
:param author: The author of the book.
:param isbn: The ISBN of the book.
"""
... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing a Book class with title, author, and ISBN attributes, and methods to display book information and compare books based on ISBN."}, "logical_correctness": {"score": 5, "justification": "The logic... | ["\nassert Book(\"1984\", \"George Orwell\", \"978-0451524935\").display_info() == \"Title: 1984, Author: George Orwell, ISBN: 978-0451524935\"\n", "\nassert Book(\"To Kill a Mockingbird\", \"Harper Lee\", \"978-0060935467\").display_info() == \"Title: To Kill a Mockingbird, Author: Harper Lee, ISBN: 978-0060935467\"\n... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
Xenny is given two positive integers, A and B. He needs to determine the prime factorization of the integer \( A^B \), but only include prime factors that are less than or equal to \( 10^5 \). Additionally, the total number of prime factors (counting multiplicities) must not exceed 5000. Your task is to write an effici... | ```python
def prime_factors(n, limit=10**5):
"""
Returns a dictionary of prime factors of n that are less than or equal to limit.
Each key is a prime factor and its value is the corresponding power.
"""
factors = {}
# Check for number of 2s in n
while n % 2 == 0:
factors[2] = factors... | {"requirement_conformance": {"score": 3, "justification": "The solution meets the basic requirement of finding the prime factorization of A^B and excluding prime factors greater than 10^5. However, it does not address the constraint that the total number of prime factors should not exceed 5000."}, "logical_correctness"... | ["\nassert small_prime_factorization(2, 3) == {2: 3}\n", "\nassert small_prime_factorization(60, 2) == {2: 4, 3: 2, 5: 2}\n", "\nassert small_prime_factorization(100, 1) == {2: 2, 5: 2}\n", "\nassert small_prime_factorization(101, 1) == {101: 1}\n", "\nassert small_prime_factorization(101, 10000) == {}\n", "\nassert sm... | ["pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass"] | 0.9 |
You are given a list of integers. Your task is to implement a function `find_mode` that returns the mode of the list. The mode is defined as the integer that appears most frequently. If there are multiple integers with the same highest frequency, return the smallest one. If the list is empty, return `None`.
**Input:**... | ```python
def find_mode(numbers):
"""
Returns the mode of the list of integers. The mode is the integer that appears most frequently.
If there are multiple integers with the same highest frequency, returns the smallest one.
Returns None if the list is empty.
:param numbers: List of integers
... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements: it correctly identifies the mode, handles multiple values with the same highest frequency by returning the smallest one, and returns None for an empty list."}, "logical_correctness": {"score": 5, "justificati... | ["\nassert find_mode([1, 2, 2, 3, 3]) == 2\n", "\nassert find_mode([4, 4, 1, 2, 2, 3, 3]) == 2\n", "\nassert find_mode([7, 7, 7, 7, 7]) == 7\n", "\nassert find_mode([1, 1, 2, 2, 3, 3, 4, 4]) == 1\n", "\nassert find_mode([5, 5, 5, 1, 1, 1, 2, 2, 3]) == 1\n", "\nassert find_mode([]) == None\n", "\nassert find_mode([10]) ... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are tasked with implementing a sorting algorithm in Python. Write a function `custom_sort(arr)` that accepts a list `arr` of integers and sorts it in non-decreasing order using any sorting algorithm of your choice. The function should return the sorted list.
**Sample Input:**
```
[3, 6, 8, 10, 1, 2, 1]
```
**Samp... | ```python
def custom_sort(arr):
"""
Sorts a list of integers in non-decreasing order using the QuickSort algorithm.
Parameters:
arr (list): A list of integers to be sorted.
Returns:
list: The sorted list of integers.
"""
def quicksort(low, high):
if low < high:
pi =... | {"requirement_conformance": {"score": 5, "justification": "The function `custom_sort` fully meets the requirement by implementing a sorting algorithm (quicksort) that sorts an array of integers in ascending order and returns the sorted array."}, "logical_correctness": {"score": 5, "justification": "The logic of the qui... | ["\nassert custom_sort([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10]\n", "\nassert custom_sort([5, 3, 8, 4, 2]) == [2, 3, 4, 5, 8]\n", "\nassert custom_sort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", "\nassert custom_sort([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 1... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of integers. Your task is to find the maximum value in the list and then multiply each element of the list by this maximum value. Output the transformed list.
**Input:**
- A list of integers `input_list` (1 ≤ len(input_list) ≤ 10^3, -10^3 ≤ input_list[i] ≤ 10^3).
**Output:**
- A list of integers ... | ```python
def transform_list_by_max(input_list):
"""
Transforms the input list by multiplying each element by the maximum value in the list.
Parameters:
input_list (list of int): The list of integers to be transformed.
Returns:
list of int: The transformed list where each element is multiplied... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It takes a list of integers, finds the maximum value, multiplies each element by this maximum value, and outputs the transformed list."}, "logical_correctness": {"score": 5, "justification": "The logic is com... | ["\nassert transform_list_by_max([1, 2, 3, 4, 5]) == [5, 10, 15, 20, 25]\n", "\nassert transform_list_by_max([10, 20, 30]) == [300, 600, 900]\n", "\nassert transform_list_by_max([0, 0, 0]) == [0, 0, 0]\n", "\nassert transform_list_by_max([-1, -2, -3]) == [-3, -6, -9]\n", "\nassert transform_list_by_max([5]) == [25]\n",... | ["pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 |
You are given a dictionary `scores` representing the scores of students in a class. The keys in the dictionary are the names of the students, and the values are their respective scores. Your task is to write a function `convert_scores_to_grades` that converts these scores into letter grades based on the following crite... | ```python
def convert_scores_to_grades(scores):
"""
Convert a dictionary of student scores to a dictionary of letter grades.
Parameters:
scores (dict): A dictionary with student names as keys and scores as values.
Returns:
dict: A dictionary with student names as keys and letter grades... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by converting scores to grades based on the given criteria and returning a new dictionary with student names as keys and their corresponding grades as values."}, "logical_correctness": {"score": 5, "justificat... | ["\nassert convert_scores_to_grades({\"Alice\": 95}) == {\"Alice\": \"A\"}\n", "\nassert convert_scores_to_grades({\"Bob\": 82}) == {\"Bob\": \"B\"}\n", "\nassert convert_scores_to_grades({\"Charlie\": 67}) == {\"Charlie\": \"D\"}\n", "\nassert convert_scores_to_grades({\"David\": 58}) == {\"David\": \"F\"}\n", "\nasse... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given two words, `beginWord` and `endWord`, and a list of words `wordList`. Your task is to find the length of the shortest transformation sequence from `beginWord` to `endWord` such that:
1. Only one letter can be changed at a time.
2. Each intermediate word must exist in the `wordList`.
3. No word in the tra... | ```python
from collections import deque
def ladderLength(beginWord, endWord, wordList):
"""
Finds the length of the shortest transformation sequence from beginWord to endWord,
using words from wordList where only one letter can be changed at a time and each
intermediate word must exist in the wordList.... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It finds the shortest transformation sequence from beginWord to endWord using the given word list, ensuring no word is reused and only one letter is changed at a time."}, "logical_correctness": {"score": 5, "... | ["\nassert ladderLength(\"hit\", \"cog\", [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]) == 5\n", "\nassert ladderLength(\"hit\", \"cog\", [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]) == 0\n", "\nassert ladderLength(\"a\", \"c\", [\"a\",\"b\",\"c\"]) == 2\n", "\nassert ladderLength(\"hot\", \"dog\", [\"hot\",\"dog\"]... | ["pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass"] | 0.9 |
You are given a string `s`. Your task is to determine whether the string is a palindrome, considering only alphanumeric characters and ignoring cases. A palindrome is a string that reads the same forward and backward.
**Input:**
- A single line containing the string `s` (1 ≤ |s| ≤ 10^5).
**Output:**
- Print `True` if... | ```python
import re
def is_palindrome(s: str) -> bool:
"""
Determines if the given string is a palindrome, considering only alphanumeric characters and ignoring cases.
:param s: The input string.
:return: True if the string is a palindrome, False otherwise.
"""
cleaned_s = re.sub(r'[^a-z0-... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by ignoring case sensitivity and removing non-alphanumeric characters before checking if the string is a palindrome."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and... | ["\nassert is_palindrome(\"A man, a plan, a canal, Panama!\") == True\n", "\nassert is_palindrome(\"racecar\") == True\n", "\nassert is_palindrome(\"No lemon, no melon\") == True\n", "\nassert is_palindrome(\"Was it a car or a cat I saw?\") == True\n", "\nassert is_palindrome(\"Hello, World!\") == False\n", "\nassert i... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a rectangular pasture of size R × C, where each cell can be empty ('.'), contain a sheep ('S'), a wolf ('W'), or a dog ('D'). Initially, there are no dogs in the pasture. Each dog guards a 4-cell diamond-shaped area, including its own cell, and no wolf can enter any part of this guarded area. Your task is... | ```python
def can_protect_sheep(R, C, pasture):
"""
Determines if it is possible to place dogs in the pasture such that no wolf can reach any sheep.
:param R: Number of rows in the pasture.
:param C: Number of columns in the pasture.
:param pasture: List of strings representing the pasture.
... | {"requirement_conformance": {"score": 3, "justification": "The solution attempts to place dogs to guard sheep but does not fully implement the requirement that each dog guards a 4-cell diamond-shaped area. It only checks adjacent cells and does not correctly mark the diamond-shaped area."}, "logical_correctness": {"sco... | ["\nassert can_protect_sheep(3, 3, ['S..', '...', '..W']) == None\n", "\nassert can_protect_sheep(3, 3, ['S..', '...', 'W..']) == None\n", "\nassert can_protect_sheep(3, 3, ['S..', 'W..', '..W']) == None\n", "\nassert can_protect_sheep(3, 3, ['S..', '...', '...']) == None\n", "\nassert can_protect_sheep(3, 3, ['...', '... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are tasked with implementing a recursive function named `sum_of_squares(n)` that computes the sum of the squares of all integers from 1 to `n` (inclusive). Your solution must strictly adhere to recursion and must not utilize any iterative constructs or built-in summation functions.
**Constraints:**
- 1 ≤ n ≤ 100
... | ```python
def sum_of_squares(n):
"""
Recursively calculates the sum of squares of all numbers from 1 to n.
Parameters:
n (int): The upper limit of the range (inclusive).
Returns:
int: The sum of squares from 1 to n.
"""
if n == 1:
return 1
else:
return n * n + sum_o... | {"requirement_conformance": {"score": 5, "justification": "The function correctly implements the requirement to calculate the sum of squares from 1 to n using recursion without any iterative constructs or built-in summation functions."}, "logical_correctness": {"score": 5, "justification": "The logic of the function is... | ["\nassert sum_of_squares(1) == 1\n", "\nassert sum_of_squares(2) == 5\n", "\nassert sum_of_squares(3) == 14\n", "\nassert sum_of_squares(4) == 30\n", "\nassert sum_of_squares(5) == 55\n", "\nassert sum_of_squares(6) == 91\n", "\nassert sum_of_squares(10) == 385\n", "\nassert sum_of_squares(15) == 1240\n", "\nassert su... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 |
You are given a string containing English numbers from 0 to 9. Your task is to write a function `convert_numbers` that converts all English numbers in the string to their corresponding Persian/Farsi numbers. The conversion should apply to numbers within words as well, converting each digit individually.
**Input:**
- A... | ```python
def convert_numbers(input_string):
"""
Convert all English numbers in the input string to their corresponding Persian/Farsi numbers.
:param input_string: A string containing English letters, spaces, and numbers from 0 to 9.
:return: A string with all English numbers replaced by their Pers... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements, including converting English numbers to their Persian/Farsi equivalents and handling numbers within words."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimall... | ["\nassert convert_numbers(\"Today is 2023 and we have 123 apples.\") == \"Today is \u06f2\u06f0\u06f2\u06f3 and we have \u06f1\u06f2\u06f3 apples.\"\n", "\nassert convert_numbers(\"I have 1 apple, 2 bananas, and 3 oranges.\") == \"I have \u06f1 apple, \u06f2 bananas, and \u06f3 oranges.\"\n", "\nassert convert_numbers... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a list of integers. Your task is to find the smallest number in the list without using recursion, stacks, queues, or any other data structures. Implement the solution in a programming language that does not natively support recursion.
**Input:**
- A list of integers `numbers` (1 ≤ len(numbers) ≤ 1000, -1... | ```python
def find_smallest_number(numbers):
"""
Finds the smallest number in a list of integers without using recursion, stacks, or queues.
:param numbers: List of integers
:return: The smallest integer in the list
"""
smallest = numbers[0]
for number in numbers:
if number < smalle... | {"requirement_conformance": {"score": 2, "justification": "The solution does not address the sequence of operations mentioned in the question. It simply finds the smallest number in the list without performing any operations."}, "logical_correctness": {"score": 5, "justification": "The logic for finding the smallest nu... | ["\nassert find_smallest_number([5, 3, 8, 1, 4]) == 1\n", "\nassert find_smallest_number([10, 20, 30, 40, 50]) == 10\n", "\nassert find_smallest_number([100, 200, 3, 400, 500]) == 3\n", "\nassert find_smallest_number([-1, -2, -3, -4, -5]) == -5\n", "\nassert find_smallest_number([0, 0, 0, 0, 0]) == 0\n", "\nassert find... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given an array of integers. Your task is to group all elements with the same value into sub-arrays. The sub-arrays should appear in the order of their first occurrence in the input array. Each sub-array must be sorted in ascending order. Implement a function to achieve this.
**Input:**
- An array of integers, ... | ```python
def group_and_sort_elements(arr):
"""
Groups elements of the array into sub-arrays of the same value,
maintaining the order of their first appearance and sorting each sub-array.
:param arr: List[int] - The input array of integers.
:return: List[List[int]] - A list of sub-arrays with s... | {"requirement_conformance": {"score": 3, "justification": "The solution groups elements with the same value into sub-arrays and maintains the order of their first appearance. However, it does not sort the sub-arrays in ascending order as specified in the requirements."}, "logical_correctness": {"score": 3, "justificati... | ["\nassert group_and_sort_elements([4, 6, 4, 5, 6, 6, 4, 5]) == [[4, 4, 4], [6, 6, 6], [5, 5]]\n", "\nassert group_and_sort_elements([1, 2, 3, 4, 5]) == [[1], [2], [3], [4], [5]]\n", "\nassert group_and_sort_elements([5, 5, 5, 5, 5]) == [[5, 5, 5, 5, 5]]\n", "\nassert group_and_sort_elements([]) == []\n", "\nassert gro... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given two lists, `reference_list` and `generated_list`. The `reference_list` contains all elements from a reference dataset, and the `generated_list` contains elements that were automatically generated. Your task is to determine the fraction of elements in the `reference_list` that are also present in the `gene... | ```python
def calculate_fraction_captured(reference_list, generated_list):
"""
Calculate the fraction of elements in reference_list that are also present in generated_list.
:param reference_list: List of integers representing the reference dataset.
:param generated_list: List of integers representi... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing the function to calculate the fraction of elements in the reference_list that are also present in the generated_list. It operates in linear time with respect to the length of the longer list by using a s... | ["\nassert calculate_fraction_captured([1, 2, 3, 4, 5], [3, 4, 5]) == 0.6\n", "\nassert calculate_fraction_captured([1, 2, 3], [4, 5, 6]) == 0.0\n", "\nassert calculate_fraction_captured([], [1, 2, 3]) == 0.0\n", "\nassert calculate_fraction_captured([1, 2, 3], []) == 0.0\n", "\nassert calculate_fraction_captured([1, 2... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
In a distributed system, tasks are assigned to various services. Given a task and a service, determine whether the task should exist for the service. Implement the function `should_task_exist_for_service(task, service)` without using any conditional statements (`if`, `elif`, `else`). Use dictionaries or other data stru... | ```python
def should_task_exist_for_service(task, service):
"""
Determines if a given task should exist for a specified service without using conditional statements.
Parameters:
task (str): The name of the task.
service (str): The name of the service.
Returns:
bool: True if the tas... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by implementing the function without using any conditional statements and using dictionaries to handle the logic."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally str... | ["\nassert should_task_exist_for_service('task1', 'service1') == True\n", "\nassert should_task_exist_for_service('task2', 'service1') == True\n", "\nassert should_task_exist_for_service('task3', 'service1') == False\n", "\nassert should_task_exist_for_service('task3', 'service2') == True\n", "\nassert should_task_exis... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
In a role-playing game, you need to design a function to generate a monster's attributes. The monster should have the following properties:
- `name`: A string representing the monster's name.
- `health`: An integer representing the monster's health points.
- `experience_points`: An integer representing the experience ... | ```python
import random
def generate_monster():
"""
Generates a dictionary representing a monster with specific attributes including name, health, experience points,
maximum damage, and a randomly selected subset of elemental resistances.
Returns:
dict: A dictionary containing the monster'... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements, including the correct monster attributes and the random selection of resistance types."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The fu... | ["\nassert generate_monster()[\"name\"] == \"Beast\"\n", "\nassert generate_monster()[\"health\"] == 30\n", "\nassert generate_monster()[\"experience_points\"] == 75\n", "\nassert generate_monster()[\"maximum_damage\"] == 15\n", "\nassert len(generate_monster()[\"resistance_types\"]) >= 1 and len(generate_monster()[\"r... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are tasked with implementing a function `validate_input` that processes a given input `value`. The input can be an integer, float, string, list, or tuple. If the input is a string, it must be convertible to a float. If the input is a list or tuple, all elements must be convertible to floats. The function should ret... | ```python
def validate_input(value):
"""
Validates and converts the input value to a float or a list of floats.
Args:
value (int, float, str, list, tuple): The input value to be validated and converted.
Returns:
float or list of floats: The float representation of the input value or a ... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements, including handling integers, floats, strings, lists, and tuples, and raising appropriate ValueError messages."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consi... | ["\nassert validate_input(10) == 10.0\n", "\nassert validate_input(10.5) == 10.5\n", "\nassert validate_input(\"10.5\") == 10.5\n", "\nassert validate_input(\"10\") == 10.0\n", "\nassert validate_input([1, 2, 3]) == [1.0, 2.0, 3.0]\n", "\nassert validate_input((1.1, 2.2, 3.3)) == [1.1, 2.2, 3.3]\n", "\nassert validate_... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 |
You are given a string `s` consisting solely of the characters '(', ')', '{', '}', and '['. Your task is to determine if the string is valid. A string is considered valid if all brackets are closed in the correct order and each opening bracket is closed by a bracket of the same type. Implement a function `is_valid` tha... | ```python
def is_valid(s: str) -> bool:
"""
Determines if the input string s, consisting of '(', ')', '{', '}', and '[',
is a valid bracket sequence where all brackets are closed in the correct order.
:param s: A string containing only the characters '(', ')', '{', '}', and '['.
:return: True i... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by checking if all brackets are closed in the correct order and if all open brackets are closed by the same type of brackets."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and ... | ["\nassert is_valid(\"()\") == True\n", "\nassert is_valid(\"()[]{}\") == True\n", "\nassert is_valid(\"(]\") == False\n", "\nassert is_valid(\"([)]\") == False\n", "\nassert is_valid(\"{[]}\") == True\n", "\nassert is_valid(\"\") == True\n", "\nassert is_valid(\"((((()))))\") == True\n", "\nassert is_valid(\"((((())))... | ["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 `unique_elements` that returns a new list containing only the unique elements from the original list, while maintaining their original order of appearance.
**Input:**
- A list of integers `lst` (1 ≤ len(lst) ≤ 10^5), where each integer is in the ra... | ```python
def unique_elements(lst):
"""
Returns a list of unique elements from the given list, preserving the original order.
:param lst: List of integers
:return: List of unique integers in the order they first appeared
"""
seen = set()
unique_list = []
for item in lst:
if item... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by returning a list of unique elements while preserving the original order."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses a set to track seen e... | ["\nassert unique_elements([1, 2, 3, 2, 1]) == [1, 2, 3]\n", "\nassert unique_elements(['a', 'b', 'c', 'a', 'b']) == ['a', 'b', 'c']\n", "\nassert unique_elements([10, 20, 30, 40, 50]) == [10, 20, 30, 40, 50]\n", "\nassert unique_elements([]) == []\n", "\nassert unique_elements([1, 1, 1, 1, 1]) == [1]\n", "\nassert uni... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass"] | 0.9 |
You are given a string `input_string` and a character `char`. Your task is to implement a function `remove_char(input_string, char)` that returns a new string with all occurrences of `char` removed from `input_string`. The function should handle edge cases such as empty strings and special characters.
**Input:**
- The... | ```python
def remove_char(input_string, char):
"""
Removes all occurrences of the specified character from the input string.
Parameters:
input_string (str): The original string from which to remove characters.
char (str): The character to be removed from the input string.
Returns:
str: The... | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by removing all occurrences of the specified character from the input string and handles the example usage correctly."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally... | ["\nassert remove_char(\"Hello, World!\", \"o\") == \"Hell, Wrld!\"\n", "\nassert remove_char(\"Python Programming\", \"m\") == \"Python Prograing\"\n", "\nassert remove_char(\"1234567890\", \"5\") == \"123467890\"\n", "\nassert remove_char(\"!!!\", \"!\") == \"\"\n", "\nassert remove_char(\"abcabcabc\", \"a\") == \"bc... | ["pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass"] | 0.9 |
You are given a positive integer `num`. Your task is to write a function `sum_of_digits` that calculates and returns the sum of the digits of `num`.
**Input:**
- A single integer `num` (1 ≤ num ≤ 10^9).
**Output:**
- An integer representing the sum of the digits of `num`.
**Sample Input:**
```
9
123
```
**Sample O... | ```python
def sum_of_digits(num):
"""
Calculate the sum of the digits of a given positive integer.
Parameters:
num (int): A positive integer whose digits are to be summed.
Returns:
int: The sum of the digits of the input number.
"""
total = 0
while num > 0:
digit = num % 10... | {"requirement_conformance": {"score": 5, "justification": "The code fully meets the requirement of calculating the sum of the digits of a given number. It correctly implements the logic to extract each digit and sum them up."}, "logical_correctness": {"score": 5, "justification": "The logic of the code is completely co... | ["\nassert sum_of_digits(0) == 0\n", "\nassert sum_of_digits(9) == 9\n", "\nassert sum_of_digits(123) == 6\n", "\nassert sum_of_digits(456) == 15\n", "\nassert sum_of_digits(789) == 24\n", "\nassert sum_of_digits(1001) == 2\n", "\nassert sum_of_digits(9999) == 36\n", "\nassert sum_of_digits(1111) == 4\n", "\nassert sum... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 |
You are given a nested list of integers. Your task is to determine if the list contains at least one even number and at least one odd number. The list can be nested to any depth. Write a function `contains_even_and_odd` that takes such a list as input and returns `True` if both even and odd numbers are present, otherwi... | ```python
def contains_even_and_odd(lst):
"""
Determines if a nested list of integers contains at least one even and one odd number.
:param lst: List of integers, which can be nested.
:return: True if both even and odd numbers are present, False otherwise.
"""
def flatten(nested_list):
... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements, including handling nested lists of integers."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The function correctly identifies the presence of both eve... | ["\nassert contains_even_and_odd([1, 3, 5, 7]) == False\n", "\nassert contains_even_and_odd([2, 4, 6, 8]) == False\n", "\nassert contains_even_and_odd([1, 2, 3, 4]) == True\n", "\nassert contains_even_and_odd([1, 3, 5, 7, 9, 11, 12]) == True\n", "\nassert contains_even_and_odd([1, [2, [3, [4]]]]) == True\n", "\nassert ... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are given a sorted list of integers `nums` and an integer `target`. Implement a binary search algorithm to determine the index of the `target` within the list. If the `target` is not present, return -1. Your function should be efficient and have a time complexity of O(log n).
**Input:**
- A sorted list of integers... | ```python
def binarySearch(nums, target):
"""
Perform a binary search on a sorted list of integers to find the index of the target.
:param nums: List[int] - A sorted list of integers.
:param target: int - The integer to search for in the list.
:return: int - The index of the target if found, ot... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing a binary search algorithm that returns the index of the target if found, or -1 if not found."}, "logical_correctness": {"score": 5, "justification": "The logic of the binary search algorithm is completel... | ["\nassert binarySearch([1, 2, 3, 4, 5], 3) == 2\n", "\nassert binarySearch([1, 2, 3, 4, 5], 1) == 0\n", "\nassert binarySearch([1, 2, 3, 4, 5], 5) == 4\n", "\nassert binarySearch([1, 2, 3, 4, 5], 6) == -1\n", "\nassert binarySearch([], 1) == -1\n", "\nassert binarySearch([1], 1) == 0\n", "\nassert binarySearch([1], 2)... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are tasked with implementing a Python class named `Employee` that encapsulates the attributes `name`, `age`, and `salary`. The class should provide methods to get and set these attributes with the following constraints:
- The `age` attribute must not be negative.
- The `salary` attribute must not be less than zero.... | ```python
class Employee:
def __init__(self, name, age, salary):
self.name = name
self._age = age
self._salary = salary
def get_name(self):
"""Returns the name of the employee."""
return self.name
def set_name(self, name):
"""Sets the name of the employee.""... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by defining the Employee class with attributes for name, age, and salary, and includes getter and setter methods with validation for age and salary."}, "logical_correctness": {"score": 5, "justification": "The... | ["\nassert Employee(\"John\", 30, 50000).get_name() == \"John\"\n", "\nassert Employee(\"Jane\", 25, 60000).get_age() == 25\n", "\nassert Employee(\"Doe\", 40, 75000).get_salary() == 75000\n", "\nemployee = Employee(\"Alice\", 28, 55000)\nemployee.set_name(\"Bob\")\nassert employee.get_name() == \"Bob\"\n", "\nemployee... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 |
You are developing a secure link generator for a web application. The generator must produce a signed URL that includes an expiration time and a signature. The URL should expire after a specified duration and the signature should be generated using HMAC-SHA256 with a provided secret key. The expiration time must be a c... | ```python
import hmac
import hashlib
import base64
import time
import urllib.parse
def is_prime(n: int) -> bool:
"""Check if a number is a prime number."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
... | {"requirement_conformance": {"score": 5, "justification": "The function meets all specified requirements, including handling the URL, secret key, and expiration time, and ensuring the expiration time is not a prime number."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and cons... | ["\nassert generate_signed_url(\"http://example.com\", \"secret\", 10) != generate_signed_url(\"http://example.com\", \"secret\", 10)\n", "\nassert \"e=\" in generate_signed_url(\"http://example.com\", \"secret\", 10)\n", "\nassert \"s=\" in generate_signed_url(\"http://example.com\", \"secret\", 10)\n", "\nassert gene... | ["fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 |
You are given an unsorted array of integers `nums` and an integer `k`. Your task is to find the kth smallest element in the array. Implement a function that solves this problem with a time complexity better than O(n log n).
**Input:**
- The first line contains an integer `n` (1 ≤ n ≤ 10^5), the number of elements in t... | ```python
def partition(nums, left, right):
"""
Partitions the array around a pivot element such that elements less than 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 left: Starting index of the partition... | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of finding the kth smallest element in an unsorted array using a sorting algorithm with a time complexity better than O(n log n). The Quickselect algorithm is used, which has an average time complexity of O(n)."}, "logic... | ["\nassert findKthSmallest([3, 2, 1, 5, 6, 4], 2) == 2\n", "\nassert findKthSmallest([7, 10, 4, 3, 20, 15], 3) == 7\n", "\nassert findKthSmallest([7, 10, 4, 3, 20, 15], 4) == 10\n", "\nassert findKthSmallest([12, 3, 5, 7, 4, 19, 26], 3) == 5\n", "\nassert findKthSmallest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5) == 5\n", "\n... | ["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
- 18