id
stringlengths
32
32
input
stringlengths
181
3.45k
output
stringlengths
0
19.8k
domain
stringclasses
2 values
generation_algorithm
stringclasses
2 values
llm_judgement
stringlengths
446
1.62k
unit_tests
stringlengths
277
6.65k
tests_execution_status
stringclasses
708 values
average_test_score
stringclasses
11 values
reasoning
stringlengths
1.22k
147k
45ec4865601377389e9590693d52df71
You are tasked with implementing a custom sorting algorithm in Python to sort a list of integers in ascending order. Your function should be named `custom_sort`. The algorithm you choose to implement must be either bubble sort or selection sort. Your function should return the sorted list. **Input:** - A list of integ...
To solve the problem of sorting a list of integers in ascending order using a custom sorting algorithm, we will implement **Selection Sort**. This algorithm is chosen for its simplicity and clarity in implementation, as well as its efficiency for small to moderately sized lists. --- ### ✅ **Approach: Selection Sort**...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by implementing a custom sorting algorithm (selection sort) that sorts a list of integers in ascending order and is named `custom_sort`."}, "logical_correctness": {"score": 5, "justification": "The logic of the selection...
["\nassert custom_sort([64, 25, 12, 22, 11]) == [11, 12, 22, 25, 64]\n", "\nassert custom_sort([5, 2, 9, 1, 5, 6]) == [1, 2, 5, 5, 6, 9]\n", "\nassert custom_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert custom_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]\n", "\nassert custom_sort([]) == []\n", "\nassert custom_so...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a custom sorting function called custom_sort that uses either bubble sort or selection sort. Let me think about which one to choose. Both have similar time complexities, but maybe bubble sort is easier to implement? Or maybe selection sort? Let me recall how they work. Bubble sort works by repeat...
677939876b07542e01433f5406ed0a25
You are given a directed graph with `n` nodes and `m` edges. Each node `i` has an associated profit `p_i`, and each edge `j` connecting node `u_j` to node `v_j` has an associated cost `c_j`. Your task is to find a path starting from node 1 that maximizes the total profit minus the total cost. If multiple paths yield th...
To solve this problem, we need to find a path starting from node 1 that maximizes the total profit minus the total cost. Each node has an associated profit, and each edge has an associated cost. The goal is to determine the path that yields the highest net value (total profit minus total cost). ### Approach 1. **Graph...
algorithmic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirement of finding a path starting from node 1 that maximizes the total profit minus the total cost. However, it does not handle the case where no path exists from node 1 to any other node, which could result in an incorrect ...
["\nassert max_profit_minus_cost(1, 0, [10], []) == 10\n", "\nassert max_profit_minus_cost(2, 1, [10, 20], [(1, 2, 5)]) == 25\n", "\nassert max_profit_minus_cost(3, 2, [10, 20, 30], [(1, 2, 5), (2, 3, 10)]) == 45\n", "\nassert max_profit_minus_cost(3, 2, [10, 20, 30], [(1, 2, 25), (2, 3, 10)]) == 10\n", "\nassert max_p...
["pass", "pass", "pass", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0.3
Okay, let's tackle this problem. So, the task is to find a path starting from node 1 that maximizes the total profit minus the total cost. Hmm, right. Each node has a profit, and each edge has a cost. So the total profit would be the sum of the profits of the nodes visited, minus the sum of the costs of the edges taken...
59922d1e09a12101a8018344e6f34b44
You are tasked with implementing a function to display a tree structure in the console. The tree is represented as a dictionary where each key is a node name and each value is a list of its child node names. Your function should print the tree starting from the root node, with each level of the tree indented by two spa...
To display a tree structure in the console, we can use a recursive approach. The tree is represented as a dictionary where each key is a node and its value is a list of child nodes. The root node is provided, and we need to print the tree with proper indentation to indicate the hierarchy. --- ### ✅ **Approach** We d...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by correctly printing the tree structure with each level indented by two spaces."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The function uses recur...
["\nassert print_tree({\"root\": [\"child1\", \"child2\"]}, \"root\") == \"root\\n child1\\n child2\"\n", "\nassert print_tree({\"root\": [\"child1\"]}, \"root\") == \"root\\n child1\"\n", "\nassert print_tree({\"root\": []}, \"root\") == \"root\"\n", "\nassert print_tree({\"root\": [\"child1\", \"child2\"], \"child...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a function that takes a tree dictionary and a root node, then prints the tree structure with proper indentation. Let me think about how to approach this. First, the tree is represented as a dictionary where each key is a node, and the value is a list of its children. The root is given, so I need ...
fd546ced41c1bc61f2e0254a837b2484
You are given the task of simulating the placement of `n` stars in a spiral constellation centered at the origin (0,0) on a 2D plane. The first star should be positioned at the topmost point (0, radius). The stars must be distributed along a logarithmic spiral defined by the equation `r = a * e^(b * θ)`, where `a` and ...
To simulate the placement of `n` stars in a spiral constellation centered at the origin on a 2D plane, we must adhere to the following key requirements: - The **first star** is placed at the **topmost point** `(0, radius)` which corresponds to an angle `θ = π/2` and radius `r = radius`. - The **stars are distributed a...
generic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The function generates a spiral pattern of stars and returns a list of tuples representing the coordinates. It meets the basic requirements but could benefit from more detailed specifications for constants a and b, and the angle increment calculation could be m...
["\nassert len(generate_constellation(1)) == 1\n", "\nassert generate_constellation(1) == [(0.0, 1.0)]\n", "\nassert len(generate_constellation(5)) == 5\n", "\nassert generate_constellation(0) == []\n", "\nassert generate_constellation(2)[0][1] > generate_constellation(2)[1][1]\n", "\nassert generate_constellation(3)[0...
["pass", "fail", "pass", "fail", "fail", "fail", "pass", "fail", "fail", "pass"]
0.4
Okay, I need to simulate placing n stars in a spiral constellation. The spiral is defined by r = a * e^(bθ), and the stars should be evenly spaced along this spiral. The first star is at (0, radius), which is the topmost point. Let me think about how to approach this. First, the spiral starts at θ = π/2. Since the fir...
09904b654c87c0697844fcf03431e7d4
You are given a string `s`. Your task is to write a function `count_vowels_consonants` that processes the string and returns a dictionary with two keys: `'vowels'` and `'consonants'`. The values associated with these keys should represent the number of vowels and consonants in the string, respectively. The function sho...
To solve the problem of counting vowels and consonants in a given string, we need to process the string while ignoring non-alphabetic characters and treating uppercase and lowercase letters as equivalent. Here's a clear and efficient implementation of the required function. --- ### ✅ Problem Breakdown - **Input:** A...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all the specified requirements. It takes a string as input, returns a dictionary with counts of vowels and consonants, ignores non-alphabetic characters, and is case-insensitive."}, "logical_correctness": {"score": 5, "justification": "...
["\nassert count_vowels_consonants(\"Hello, World!\") == {'vowels': 3, 'consonants': 7}\n", "\nassert count_vowels_consonants(\"Python Programming\") == {'vowels': 4, 'consonants': 11}\n", "\nassert count_vowels_consonants(\"AEIOU\") == {'vowels': 5, 'consonants': 0}\n", "\nassert count_vowels_consonants(\"bcdfg\") == ...
["pass", "fail", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass"]
0.8
Okay, I need to write a function called count_vowels_consonants that takes a string and returns a dictionary with the counts of vowels and consonants. Let me think about how to approach this. First, the problem says to ignore non-alphabetic characters. So I need to process each character in the string and check if it'...
c9023f53e0045f9faf7d58cfc1a6a3a8
You are given a hypergraph `H` represented as a list of edges, where each edge is a set of nodes. Your task is to compute the s-centrality of nodes or edges in the hypergraph using a provided centrality measure function `func`. The s-centrality should be calculated without modifying or removing any edges from the hyper...
To compute the **s-centrality** of nodes in a hypergraph using a given centrality function, we need to first model the hypergraph as a **standard graph**. This is achieved by **representing each hyperedge as a complete subgraph (clique)** of its nodes. Once this transformation is complete, we can apply the provided cen...
generic
evol-instruct
{"requirement_conformance": {"score": 3, "justification": "The solution converts the hypergraph to a simple graph and computes centrality using the provided function. However, it does not explicitly handle the s-centrality measure, which is a specific type of centrality measure for hypergraphs. The solution also does n...
["\nassert compute_s_centrality([{'a', 'b'}, {'b', 'c'}], nx.degree_centrality) == {'a': 0.5, 'b': 1.0, 'c': 0.5}\n", "\nassert compute_s_centrality([{'x', 'y', 'z'}, {'x', 'w'}], nx.degree_centrality) == {'x': 1.0, 'y': 0.5, 'z': 0.5, 'w': 0.5}\n", "\nassert compute_s_centrality([{'a', 'b', 'c'}, {'b', 'c', 'd'}, {'d'...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to compute the s-centrality of nodes or edges in a hypergraph using a given centrality measure function. Let me think about how to approach this. First, the input is a hypergraph represented as a list of edges. Each edge is a set of nodes. The task is to calculate the s-centrality without modifying or rem...
fbbb0c0887a9a0c73bd3a8120ee916e6
You are given a sequence of integers. Your task is to implement a function `sum_of_even_elements` that computes the sum of all even numbers in the sequence. The sequence can be a list, tuple, or range of integers. If the sequence is a list or tuple and contains more than 5 even numbers, return the sum of these even num...
To solve the problem of computing the sum of even numbers in a sequence, we need to carefully handle the condition that arises when the sequence is a list or tuple and contains more than 5 even numbers. --- ### ✅ **Understanding the Problem** The function `sum_of_even_elements` must: 1. **Identify even numbers** in...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements, including handling different types of input sequences and the additional requirement of sorting and summing even numbers when the sequence is a list or tuple with more than 5 even numbers."}, "logical_correct...
["\nassert sum_of_even_elements([1, 2, 3, 4, 5]) == 6\n", "\nassert sum_of_even_elements(range(1, 11)) == 30\n", "\nassert sum_of_even_elements((1, 3, 5, 7, 9)) == 0\n", "\nassert sum_of_even_elements([10, 2, 8, 4, 6, 12, 14, 16]) == 60\n", "\nassert sum_of_even_elements([2, 4, 6, 8, 10]) == 30\n", "\nassert sum_of_eve...
["pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
Okay, let's see. I need to write a function called sum_of_even_elements that takes a sequence of integers and returns the sum of even numbers. But there's a condition: if the sequence is a list or tuple and has more than 5 even numbers, then I have to return the sum of those even numbers in ascending order. Otherwise, ...
a60116ba63b3ef08f472bde38f8f9633
You are given a list of distinct integers `elements` and an integer `n`. Your task is to write a function `generate_combinations` that returns all possible combinations of `n` elements from the `elements` list. The function should utilize Python's `itertools` module to generate these combinations. The original list sho...
To solve the problem of generating all possible combinations of `n` elements from a given list of distinct integers using Python's `itertools` module, we can follow a structured and efficient approach. --- ### ✅ **Problem Requirements Recap** - **Input:** - A list of distinct integers `elements` (with length betwe...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by using the itertools module to generate combinations and handling cases where n is greater than the length of the elements list."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct...
["\nassert generate_combinations([1, 2, 3, 4], 2) == [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]\n", "\nassert generate_combinations([1, 2, 3], 4) == []\n", "\nassert generate_combinations(['a', 'b', 'c'], 2) == [('a', 'b'), ('a', 'c'), ('b', 'c')]\n", "\nassert generate_combinations([], 1) == []\n", "\nassert gen...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a Python function called generate_combinations that takes a list of integers and an integer n. The goal is to return all possible combinations of n elements from the list using itertools. Also, the original list should stay unchanged. And if n is larger than the length of elements, return an empty...
3a0e0f6ee90a20df30951c09c29ada0d
You are tasked with implementing a `Matrix` class in Python that supports basic matrix operations. The class should be able to handle the following operations: 1. **Initialization**: Create a matrix from a given list of lists (rows). 2. **Addition**: Add two matrices of the same dimensions. 3. **Subtraction**: Subtrac...
To solve the problem, we implement a `Matrix` class in Python that supports basic matrix operations including addition, subtraction, multiplication, transposition, determinant calculation, and a string representation. The class is designed to ensure robustness by handling invalid operations and input validation. --- ...
generic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The class meets most of the specified requirements, including initialization, addition, subtraction, multiplication, transposition, determinant calculation, and string representation. However, it does not include a check for the size attribute in the constructo...
["\nassert str(Matrix([[1, 2], [3, 4]])) == \"1\\t2\\n3\\t4\"\n", "\nassert (Matrix([[1, 2], [3, 4]]) + Matrix([[5, 6], [7, 8]])).data == [[6, 8], [10, 12]]\n", "\nassert (Matrix([[1, 2], [3, 4]]) - Matrix([[1, 1], [1, 1]])).data == [[0, 1], [2, 3]]\n", "\nassert (Matrix([[1, 2], [3, 4]]) * Matrix([[2, 0], [1, 2]])).da...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a Matrix class in Python that can handle all these operations. Let me start by thinking about the structure. First, the initialization. The constructor should take a list of lists. I should store the matrix as a list of lists. But I need to make sure that all rows are of the same length. Wait, m...
07ef99918679cecd9602bbdee0ee65ee
You are given three integers `a`, `b`, and `c`. Your task is to implement a function `rotate_numbers(a, b, c)` that returns a tuple with the integers rotated in the following manner: the first integer should move to the second position, the second integer should move to the third position, and the third integer should ...
To solve the problem of rotating three integers `a`, `b`, and `c` such that the first moves to the second position, the second to the third, and the third to the first, we can take advantage of Python’s tuple syntax. --- ### 🧠 Problem Analysis Given three integers `a`, `b`, and `c`, the desired output is a tuple wh...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by correctly rotating the input integers and returning them in the specified order."}, "logical_correctness": {"score": 5, "justification": "The logic of the function is completely correct and directly implements the req...
["\nassert rotate_numbers(1, 2, 3) == (3, 1, 2)\n", "\nassert rotate_numbers(4, 5, 6) == (6, 4, 5)\n", "\nassert rotate_numbers(0, 0, 0) == (0, 0, 0)\n", "\nassert rotate_numbers(-1, -2, -3) == (-3, -1, -2)\n", "\nassert rotate_numbers(10, 20, 30) == (30, 10, 20)\n", "\nassert rotate_numbers(100, 200, 300) == (300, 100...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to solve this problem where I have to rotate three numbers a, b, c such that the first moves to the second position, the second to the third, and the third to the first. And I can't use any additional variables for swapping. Hmm, how to do that? Let me think. Let's see the sample input: 1, 2, 3 becomes (3...
b6dbfa73932fba72ffdad2685940342e
You are tasked with implementing a function `is_palindrome` that checks if a given string is a palindrome. A string is considered a palindrome if, after removing all non-alphanumeric characters and converting all uppercase letters to lowercase, it reads the same forwards and backwards. Your function should return `True...
To determine whether a given string is a **palindrome**, we must follow a specific transformation process: - **Remove all non-alphanumeric characters**. - **Convert all characters to lowercase**. - **Check if the resulting string reads the same forwards and backwards**. However, we are **not allowed** to use: - Regul...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by considering only alphanumeric characters, ignoring case, and returning the correct boolean value for palindrome checking."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The ...
["\nassert is_palindrome(\"A man, a plan, a canal: Panama\") == True\n", "\nassert is_palindrome(\"race a car\") == False\n", "\nassert is_palindrome(\"No 'x' in Nixon\") == True\n", "\nassert is_palindrome(\"Was it a car or a cat I saw?\") == True\n", "\nassert is_palindrome(\"12321\") == True\n", "\nassert is_palindr...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function called is_palindrome that checks if a string is a palindrome. The problem says that after removing all non-alphanumeric characters and converting to lowercase, the string should read the same forwards and backwards. And I can't use regular expressions or built-in methods that remove non...
2946f9b1e5009eb04a124cdfd9b7548b
You are given a text file named "data.txt". Your task is to write a program that reads this file and counts the frequency of each word, excluding common stop words. The stop words are: "the", "and", "is", "in", "at", "which", "on", "a", "an". The comparison for stop words should be case-insensitive. The output should l...
To solve the problem, we need to read a text file, count the frequency of each word, **excluding** a predefined list of stop words, and output the results in descending order of frequency. The comparison for stop words should be **case-insensitive**. --- ### ✅ **Key Steps in the Solution** 1. **Read the Input File**...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It reads a text file, counts the number of times each word appears, ignores common stop words in a case-insensitive manner, and outputs the count of each word in descending order of frequency."}, "logical_cor...
["\nassert word_count('empty.txt') == None\n", "\nassert word_count('single_word.txt') == None\n", "\nassert word_count('stop_words_only.txt') == None\n", "\nassert word_count('mixed_case.txt') == None\n", "\nassert word_count('punctuation.txt') == None\n", "\nassert word_count('multiple_lines.txt') == None\n", "\nasse...
["fail", "pass", "pass", "fail", "pass", "pass", "fail", "fail", "fail", "fail"]
0.4
Okay, I need to write a program that reads a text file called data.txt, counts the frequency of each word, but excludes some stop words. The stop words are given as a list, and the comparison should be case-insensitive. Then, output the words in descending order of their counts. First, I should think about how to proc...
ada5f48d6e408a6af5cb7bec05351a3d
You are tasked with implementing a Python class `Employee` to manage employee details in a company's database. The class should support the following functionalities: - Initialize an employee with a name, ID, department, and salary. - Provide a method to give a raise to the employee, which increases the salary by a sp...
Here's a well-structured implementation of the `Employee` class that fulfills the specified requirements. The class is designed to manage employee details, including initialization, salary adjustments, and department transfers, with appropriate validation to ensure correctness. --- ### ✅ **Class Implementation** ```...
generic
self-instruct
{"requirement_conformance": {"score": 3, "justification": "The class meets basic requirements by including the specified attributes and methods, but it does not include any additional methods or properties that might be expected in a more comprehensive Employee class."}, "logical_correctness": {"score": 4, "justificati...
["\nassert Employee(\"John Doe\", 1, \"HR\", 50000).name == \"John Doe\"\n", "\nassert Employee(\"Jane Smith\", 2, \"Engineering\", 75000).id == 2\n", "\nassert Employee(\"Alice Johnson\", 3, \"Marketing\", 60000).department == \"Marketing\"\n", "\nassert Employee(\"Bob Brown\", 4, \"Finance\", 80000).salary == 80000\n...
["pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass"]
0.9
Okay, I need to create a Python class called Employee that manages employee details. Let me think about the requirements. First, the __init__ method should take name, id, department, and salary. So in the constructor, I'll assign these attributes to the instance variables. Like self.name = name, self.id = id, etc. Th...
897396a94bdeb10a842a66c3cabf216f
You are given a list of `n` intervals, where each interval is represented by a pair of integers `(start, end)`. Your task is to calculate the total overlap between all pairs of intervals. The overlap between two intervals is defined as the length of their intersection. If two intervals do not intersect, their overlap i...
To solve the problem of calculating the total overlap between all pairs of intervals, we follow a structured approach that ensures correctness and efficiency. --- ### 🔍 **Understanding the Problem** Each interval is represented as a pair `(start, end)`, and we are required to compute the **total overlap** between *...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It sorts the intervals by their start points and calculates the total overlap between all pairs of intervals."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optim...
["\nassert total_overlap([(1, 5), (3, 7), (2, 4), (6, 8)]) == 6\n", "\nassert total_overlap([(1, 3), (4, 6), (7, 9)]) == 0\n", "\nassert total_overlap([(1, 10), (2, 5), (3, 7)]) == 8\n", "\nassert total_overlap([(5, 10), (10, 15), (15, 20)]) == 0\n", "\nassert total_overlap([(1, 2), (2, 3), (3, 4)]) == 0\n", "\nassert ...
["pass", "pass", "fail", "pass", "pass", "pass", "pass", "fail", "pass", "pass"]
0.8
Okay, I need to solve this problem where I have to calculate the total overlap between all pairs of intervals. Let's see. The input is a list of intervals, and I have to sort them by their start points first. Then, for every pair of intervals, compute their overlap and sum all those overlaps. First, let me think abou...
f1e5ef7044585a580153c15d6d06e0d7
Chef and Chefu are eagerly looking to purchase cakes of equal price from a cake shop. Chef has coins of denomination $N$ and Chefu has coins of denomination $M$. They wish to determine the minimum amount they must spend to buy cakes such that each of them pays an equal amount using only their respective coins. Implemen...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 3, "justification": "The solution attempts to find the minimum amount to be spent by calculating the LCM of the two denominations. However, it does not fully meet the requirement of not using multiplication or division operations, as it uses division in the calculation of the LCM."...
["\nassert minimum_amount(12, 18) == 36\n", "\nassert minimum_amount(5, 10) == 10\n", "\nassert minimum_amount(7, 3) == 21\n", "\nassert minimum_amount(21, 6) == 42\n", "\nassert minimum_amount(8, 12) == 24\n", "\nassert minimum_amount(1, 1) == 1\n", "\nassert minimum_amount(13, 17) == 221\n", "\nassert minimum_amount(...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to solve this problem where Chef and Chefu want to buy cakes of equal price, and each pays the same amount using their own coins. The goal is to find the minimum amount they must spend, which is essentially the LCM of their coin denominations. But the catch is that I can't use multiplication or division op...
6066118a6c1e9af805f3b37e8b7ed55d
You are tasked with writing a program that reads a JSON file and retrieves the value associated with a specified key. Your program should prompt the user to input the filename and the key. The program must handle the following scenarios: - If the file does not exist, output an error message: "Error: The file '{filename...
Here's a well-structured Python program that reads a JSON file and retrieves the value associated with a specified key, while handling all the specified error conditions. --- ### ✅ **Program Description** This program: 1. Prompts the user to enter a filename and a key. 2. Attempts to read and parse the JSON file. 3...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The program fully meets all specified requirements. It prompts the user for the file name and key, handles cases where the file does not exist, and handles cases where the key is not found in the JSON file."}, "logical_correctness": {"score": 5, "justification"...
["\nassert read_json_key(\"data.json\", \"name\") == \"John\"\n", "\nassert read_json_key(\"data.json\", \"age\") == 30\n", "\nassert read_json_key(\"data.json\", \"address\") == \"Key 'address' not found in the JSON data.\"\n", "\nassert read_json_key(\"non_existent_file.json\", \"name\") == \"Error: The file 'non_exi...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a Python program that reads a JSON file and retrieves a value based on a key. Let me think about how to approach this. First, the program should prompt the user for the filename and the key. So I'll need to get input from the user. Maybe using input() function twice. Wait, but how to handle the i...
d55496138ee703c02f2732b0ed19c799
You are tasked with developing a keyword extraction system for a document analysis project. Implement a function `extract_keywords(text: str, num_keywords: int) -> List[str]` that processes a given text and identifies the top `num_keywords` most frequently occurring words. The function should handle punctuation and be ...
To solve the problem of extracting the top `num_keywords` most frequently occurring words from a given text, we need to carefully process the text to ensure it is **case-insensitive**, **ignores punctuation**, and **counts only alphanumeric sequences** as valid words. --- ### ✅ Problem Breakdown Given: - A text stri...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by taking a string `text` and an integer `num_keywords` as input and returning a list of the top `num_keywords` most frequent words in the text. It also considers punctuation and case sensitivity."}, "logical_correctnes...
["\nassert extract_keywords(\"hello world hello\", 1) == [\"hello\"]\n", "\nassert extract_keywords(\"test test test test\", 2) == [\"test\"]\n", "\nassert extract_keywords(\"a b c d e f g\", 3) == [\"a\", \"b\", \"c\"]\n", "\nassert extract_keywords(\"Python is great, and python is fun.\", 2) == [\"python\", \"is\"]\n...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a Python function called extract_keywords that takes a text string and a number, then returns the top num_keywords most frequent words. Let's think about how to approach this. First, the function needs to process the text. The constraints say it's case-insensitive, so I should convert the entire ...
0fb19322cc1987058b2f94ebe9b56c82
You are given a function `f(x1, x2, ..., xn) = x1^2 + x2^2 + ... + xn^2` where each variable `xi` must be an integer between 1 and 10 inclusive. Your task is to find the set of integers `(x1, x2, ..., xn)` that minimizes the function `f`. Implement a genetic algorithm to solve this optimization problem. Your program sh...
To solve the optimization problem of minimizing the function $$ f(x_1, x_2, ..., x_n) = x_1^2 + x_2^2 + ... + x_n^2 $$ where each $ x_i \in [1, 10] $, we implement a **Genetic Algorithm (GA)**. The GA is a population-based search algorithm inspired by natural selection and genetics, designed to find near-optimal so...
algorithmic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirements of implementing a genetic algorithm to optimize the sum of squares function with constraints on variable values. However, it does not specify the exact number of variables or generations, which are part of the proble...
["\nassert genetic_algorithm(10, 1, 10)[1] >= 1 and genetic_algorithm(10, 1, 10)[1] <= 100\n", "\nassert genetic_algorithm(20, 2, 20)[1] >= 2 and genetic_algorithm(20, 2, 20)[1] <= 200\n", "\nassert genetic_algorithm(30, 3, 30)[1] >= 3 and genetic_algorithm(30, 3, 30)[1] <= 300\n", "\nassert all(1 <= x <= 10 for x in g...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to solve this problem where I have to find the minimum of the function f(x1, x2, ..., xn) = sum of squares of each variable. Each variable is an integer between 1 and 10 inclusive. And I have to use a genetic algorithm for this. Let me think about how to approach this. First, understanding the problem. Th...
31803e17ff08a171b7c1bceb2ae258b2
You are given a list of distinct words `W` and a list of tuples `T`. Each tuple in `T` contains a sequence of words. Your task is to construct a new list of tuples `T'` where each tuple is formed by removing the first word from the corresponding tuple in `T` and appending a new word from `W`. The new word must not alre...
To solve this problem, we are given a list of distinct words `W` and a list of tuples `T`. Our goal is to construct a new list of tuples `T'` where each tuple is formed by: 1. Removing the first word from the corresponding tuple in `T`. 2. Appending a new word from `W` that: - Is **not already present** in the modi...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It removes the first word from each tuple, appends a new word from the list of words, and ensures no word is repeated within a single tuple."}, "logical_correctness": {"score": 5, "justification": "The logic ...
["\nassert transform_tuples([\"apple\", \"banana\", \"cherry\"], [(\"orange\", \"banana\"), (\"cherry\", \"date\")]) == [(\"banana\", \"apple\"), (\"date\", \"banana\")]\n", "\nassert transform_tuples([\"apple\", \"banana\", \"cherry\"], [(\"apple\", \"banana\"), (\"banana\", \"cherry\")]) == [(\"banana\", \"cherry\"),...
["pass", "fail", "pass", "pass", "pass", "pass", "fail", "fail", "pass", "fail"]
0.6
Okay, let's tackle this problem. So, the task is to process each tuple in T by removing the first word and appending a new word from W. The new word has to be the next in the circular order of W, and it shouldn't already be in the tuple. Hmm, let me think about how to approach this. First, I need to understand the pro...
4968e29cd2aaded9b8613650a17f50c0
You are given two dictionaries, `dict1` and `dict2`. Your task is to update `dict1` in-place with values from `dict2` under the following conditions: - Only update the values of keys that are present in both `dict1` and `dict2`. - A value in `dict1` should only be updated if the corresponding value in `dict2` is strict...
To solve the problem of merging two dictionaries under specific conditions, we need to ensure that only common keys between `dict1` and `dict2` are considered for updates. Furthermore, the value from `dict2` must be strictly greater than the corresponding value in `dict1` for an update to occur. --- ### ✅ **Approach ...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It updates the values of `dict1` in-place only if the corresponding value in `dict2` is strictly greater, and it does not modify the keys of `dict1`."}, "logical_correctness": {"score": 5, "justification": "T...
["\nassert merge_dicts({'a': 1, 'b': 2}, {'b': 3, 'c': 4}) == {'a': 1, 'b': 3}\n", "\nassert merge_dicts({'x': 10, 'y': 20}, {'x': 5, 'y': 25}) == {'x': 10, 'y': 25}\n", "\nassert merge_dicts({'m': 100, 'n': 200}, {'m': 100, 'n': 200}) == {'m': 100, 'n': 200}\n", "\nassert merge_dicts({'p': 1, 'q': 2}, {'r': 3, 's': 4}...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a function called merge_dicts that takes two dictionaries, dict1 and dict2, and updates dict1 in-place based on certain conditions. Let me think about the requirements. First, the problem says that only keys present in both dictionaries should be updated. So I need to check for keys that are comm...
388dd359dc4decd2fc8b601ea4f6d9d9
You are given a list of convex polygons, each defined by the number of its sides. For each polygon, determine the number of ways to draw non-intersecting diagonals inside it. Output a list of these counts. **Input:** - The first line contains an integer `T` (1 ≤ T ≤ 100), the number of test cases. - Each of the next `...
To solve the problem of determining the number of ways to draw non-intersecting diagonals inside a convex polygon with `N` sides, we rely on a well-known mathematical structure: the **Catalan numbers**. --- ### 🔍 Understanding the Problem The key insight is that the number of **non-intersecting diagonal configurati...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by calculating the number of non-intersecting diagonals for each polygon in the list using the Catalan number formula."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The soluti...
["\nassert non_intersecting_diagonals([3]) == [1]\n", "\nassert non_intersecting_diagonals([4]) == [1]\n", "\nassert non_intersecting_diagonals([5]) == [2]\n", "\nassert non_intersecting_diagonals([6]) == [5]\n", "\nassert non_intersecting_diagonals([7]) == [14]\n", "\nassert non_intersecting_diagonals([8]) == [42]\n",...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to solve this problem where for each convex polygon with N sides, I have to find the number of ways to draw non-intersecting diagonals. Let me think about how to approach this. Hmm, I remember something about Catalan numbers. Oh right! The number of ways to triangulate a convex polygon with N sides is the...
a35b9faff916765db87cf32ed1fe1dbc
You are tasked with implementing a function `extract_emails` that identifies and extracts all valid email addresses from a provided text string. The function should utilize regular expressions to accurately match email addresses, accommodating various formats, including those with subdomains and special characters. You...
To solve the problem of extracting valid email addresses from a given text string, we can utilize **regular expressions (regex)** to efficiently identify and return all matching email patterns. --- ### ✅ Problem Summary We are given a string `text` and need to extract **all valid email addresses** that appear in it....
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by extracting email addresses from a given text using regular expressions and handling different email formats, including those with subdomains and special characters."}, "logical_correctness": {"score": 4, "justificatio...
["\nassert extract_emails(\"contact@example.com\") == [\"contact@example.com\"]\n", "\nassert extract_emails(\"support@my-subdomain.example.co.uk\") == [\"support@my-subdomain.example.co.uk\"]\n", "\nassert extract_emails(\"admin@company.org\") == [\"admin@company.org\"]\n", "\nassert extract_emails(\"user.name+tag+sor...
["pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass"]
0.9
Okay, I need to write a function called extract_emails that takes a text string and returns all valid email addresses found in it. The function should use regular expressions. Let me think about how to approach this. First, I remember that email addresses can have various parts. The basic structure is local-part@domai...
3befca9a6d9ae69d1f6c548bf6cac1f7
You are given a message encrypted using a modified Vigenere cipher. In this variant, the ASCII value of each character in the key is offset by a random integer between -5 and 5 before being used to shift the characters in the ciphertext. Your task is to decrypt the message. The key is repeated as necessary to match the...
To decrypt a message encrypted using a modified Vigenère cipher, we need to reverse the encryption process. The key is first adjusted by adding a random offset to each character's ASCII value, and then this adjusted value is used to shift the ciphertext characters back to the original plaintext. --- ### **Understandi...
generic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the core requirement of decrypting a message encrypted with a modified Vigenere cipher, considering an offset for each key character. However, it assumes the alphabet is based on ASCII values (0-255) rather than strictly alphabetic charac...
["\nassert decrypt_modified_vigenere(\"b\", \"a\", [1]) == \"a\"\n", "\nassert decrypt_modified_vigenere(\"a\", \"b\", [-1]) == \"a\"\n", "\nassert decrypt_modified_vigenere(\"f\", \"a\", [5]) == \"a\"\n", "\nassert decrypt_modified_vigenere(\"a\", \"f\", [-5]) == \"a\"\n", "\nassert decrypt_modified_vigenere(\"m\", \"...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to decrypt a message that was encrypted using a modified Vigenère cipher. Let me think about how this works. So, the standard Vigenère cipher uses a key where each character's position determines the shift. For example, if the key is 'hello', each letter is converted to a number (like a=0, b=1, etc.), an...
2ec799cdcce1ff1d9ceef1b7748fdce0
You are tasked with designing a RESTful API using Flask to manage a simple to-do list application. The API must support the following operations: 1. **GET /tasks**: Retrieve all tasks. 2. **POST /tasks**: Create a new task. The request body must be a JSON object with at least a 'title' field. 3. **GET /tasks/<task_id>...
To implement a RESTful API for managing a simple to-do list using Flask, we define a set of routes that support the following operations: - **GET /tasks**: Retrieve all tasks. - **POST /tasks**: Create a new task. - **GET /tasks/<task_id>**: Retrieve a specific task by ID. - **PUT /tasks/<task_id>**: Update a specific...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements by implementing all the required RESTful API endpoints for managing a to-do list."}, "logical_correctness": {"score": 4, "justification": "The logic is largely correct and consistent, handling tasks approp...
["\nassert get_tasks().json == {'tasks': [{'id': 1, 'title': 'Buy groceries', 'description': 'Milk, Cheese, Pizza, Fruit', 'done': False}, {'id': 2, 'title': 'Learn Python', 'description': 'Need to find a good Python tutorial on the web', 'done': False}]}\n", "\nassert get_task(1).json == {'task': {'id': 1, 'title': 'B...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to design a RESTful API using Flask for a to-do list app. Let me think about how to approach this. The requirements are to handle GET, POST, GET by ID, PUT by ID, and DELETE by ID. First, I should set up a Flask app. I'll need to import Flask and maybe some other modules like jsonify for handling JSON re...
5eb796d9734418c88a24c07bc1ac0a73
You are given a list of integers. Your task is to implement a function that computes the median of the list. The function should handle edge cases where the list is empty or contains only one element. **Input:** - A list of integers `lst` (0 ≤ len(lst) ≤ 10^5), where each integer `x` satisfies -10^9 ≤ x ≤ 10^9. **Ou...
To compute the **median** of a list of integers, we must follow a structured approach that handles both **odd** and **even** length lists, as well as **edge cases** such as an empty list. --- ### ✅ **Key Requirements** - **Input**: A list of integers `lst` (can be empty or have 1 element). - **Output**: - The **m...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by calculating the median and handling edge cases where the list is empty or contains only one element."}, "logical_correctness": {"score": 5, "justification": "The logic for finding the median is completely correct and...
["\nassert find_median([1, 3, 5]) == 3\n", "\nassert find_median([1, 3, 5, 7]) == 4.0\n", "\nassert find_median([1]) == 1\n", "\nassert find_median([7, 3, 1, 5]) == 4.0\n", "\nassert find_median([10, 20, 30, 40, 50]) == 30\n", "\nassert find_median([1, 2, 3, 4, 5, 6]) == 3.5\n", "\nassert find_median([5, 5, 5, 5, 5]) =...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function that computes the median of a list of integers. Let me think about how to approach this. First, the median is the middle value when the list is sorted. If the list has an odd number of elements, it's the middle one. If even, it's the average of the two middle numbers. But I have to ha...
827041a2e7bc57c884acc86d5e271e4f
You are given a list of distinct items. Your task is to write a function `generate_combinations` that generates all possible combinations of these items. The function should return a list of lists, where each inner list represents a unique combination of the items. The order of the combinations in the output does not m...
To solve the problem of generating all possible combinations (subsets) of a list of distinct items, we can leverage the **bitmasking** technique. This approach is both efficient and straightforward, especially given the constraint that the input list length is between 1 and 10, which ensures the total number of combina...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by generating all possible combinations of the input list and returning them as a list of lists."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses ...
["\nassert generate_combinations([]) == [[]]\n", "\nassert generate_combinations(['a']) == [[], ['a']]\n", "\nassert generate_combinations(['a', 'b']) == [[], ['a'], ['b'], ['a', 'b']]\n", "\nassert generate_combinations(['a', 'b', 'c']) == [[], ['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']]\...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function called generate_combinations that takes a list of distinct items and returns all possible combinations. The sample input is ['a', 'b'], and the output includes the empty list, each single item, and the pair. Wait, so combinations here include all subsets of the items, right? Because for...
99dbb44e76ad466dc936f7976fff75ff
You are given a task to develop a program that verifies the integrity of a file by comparing its SHA-1 hash with a provided hash value. The program should handle case sensitivity and special characters in filenames across different operating systems. Your program will receive two inputs: a filename and a SHA-1 hash val...
To solve the problem of verifying file integrity using SHA-1 hashing, we need a program that: 1. **Reads the filename and expected SHA-1 hash** from input. 2. **Opens the file in binary mode** to ensure that all data is read correctly, regardless of encoding. 3. **Computes the SHA-1 hash** of the file's contents. 4. *...
generic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirements of verifying file integrity using SHA-1 hash and handling filenames with case sensitivity and special characters. However, it does not explicitly handle cross-operating system differences in filename handling."}, "lo...
["\nassert verify_file_integrity(\"testfile.txt\", \"da39a3ee5e6b4b0d3255bfef95601890afd80709\") == False\n", "\nassert verify_file_integrity(\"testfile.txt\", \"2ef7bde608ce5404e97d5f042f95f89f1c232871\") == True\n", "\nassert verify_file_integrity(\"TestFile.txt\", \"2ef7bde608ce5404e97d5f042f95f89f1c232871\") == Fal...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a program that checks if a file's SHA-1 hash matches a given hash. Let me think about how to approach this. First, the inputs are a filename and a hash. The program needs to read the file, compute its SHA-1 hash, and compare it with the provided one. But wait, how do I handle different operating ...
34f8c8f01f1f5968c940ea7f26b7e7df
You are tasked with developing a Python function `extract_keywords` that processes a given text and returns a list of the most frequent keywords. The function should utilize the Natural Language Toolkit (NLTK) for text processing and keyword extraction. The keywords should be limited to nouns, adjectives, verbs, and ad...
To solve the problem of extracting the top `n` most frequent keywords from a given text, we need to perform several natural language processing (NLP) tasks using the **NLTK** library. The goal is to filter out **stopwords**, **punctuation**, and **non-relevant parts of speech (POS)**, then return the most frequent keyw...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by extracting the most frequent keywords from the input text using NLTK. It also allows specifying the number of top keywords to return."}, "logical_correctness": {"score": 5, "justification": "The logic is completely c...
["\nassert extract_keywords(\"The quick brown fox jumps over the lazy dog.\") == ['quick', 'brown', 'fox', 'jumps', 'lazy']\n", "\nassert extract_keywords(\"Python is great and Python is fun.\", top_n=2) == ['python', 'great']\n", "\nassert extract_keywords(\"NLTK is a leading platform for building Python programs to w...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to create a Python function called extract_keywords that processes a given text and returns the top n keywords. The keywords should be nouns, adjectives, verbs, and adverbs. Also, I have to use NLTK for this. Let me think about the steps I need to take. First, I remember that NLTK has tools for tokenizati...
9be1cf77ab32f990d408e770baaa4d7c
You are tasked with implementing a function `filter_even_numbers` that processes a list of integers. Your goal is to return a new list consisting solely of the even numbers from the provided list. The current implementation utilizes a `for` loop, but you must refactor it to use a list comprehension. **Input:** - A li...
To solve the problem of filtering even numbers from a list of integers, we can refactor the original implementation that uses a `for` loop into a more concise and Pythonic solution using **list comprehension**. --- ### ✅ Problem Summary - **Input:** A list of integers `numbers` where the length is between 0 and 1000...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by rewriting the function using a list comprehension to filter even numbers."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured, using a list comprehension t...
["\nassert filter_even_numbers([1, 2, 3, 4, 5, 6]) == [2, 4, 6]\n", "\nassert filter_even_numbers([10, 15, 20, 25, 30]) == [10, 20, 30]\n", "\nassert filter_even_numbers([11, 13, 17, 19]) == []\n", "\nassert filter_even_numbers([]) == []\n", "\nassert filter_even_numbers([0, -2, -4, -5]) == [0, -2, -4]\n", "\nassert fi...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to refactor the filter_even_numbers function to use a list comprehension instead of a for loop. Let me think about how to approach this. The original function probably loops through each number in the input list, checks if it's even, and if so, adds it to a new list. So the current code might look somethi...
04e293f6f763e88e5c21786341ec7c2b
You are given a positive integer \( n \). Your task is to implement a function that computes the \( n \)-th Fibonacci number using memoization. The Fibonacci sequence is defined as follows: \( F(1) = 1 \), \( F(2) = 1 \), and \( F(n) = F(n-1) + F(n-2) \) for \( n > 2 \). **Input:** - A single integer \( n \) (1 ≤ \( n...
To compute the **n-th Fibonacci number** efficiently using **memoization**, we can use a recursive approach with a dictionary to store previously computed values. This avoids redundant calculations and significantly improves performance, especially for larger values of `n` (up to 50 in this case). --- ### 📌 **Unders...
algorithmic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution meets the basic requirement of calculating the nth Fibonacci number using memoization. However, it does not handle the case when n is less than 1, which is not specified in the question but is an important edge case."}, "logical_correctness": {"sco...
["\nassert fibonacci(1) == 1\n", "\nassert fibonacci(2) == 1\n", "\nassert fibonacci(3) == 2\n", "\nassert fibonacci(4) == 3\n", "\nassert fibonacci(5) == 5\n", "\nassert fibonacci(6) == 8\n", "\nassert fibonacci(7) == 13\n", "\nassert fibonacci(8) == 21\n", "\nassert fibonacci(9) == 34\n", "\nassert fibonacci(10) == 5...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function that computes the nth Fibonacci number using memoization. Let me think about how to approach this. First, the Fibonacci sequence is defined with F(1) and F(2) both being 1, and each subsequent term is the sum of the two previous ones. So for n=10, the output is 55, which matches the s...
f4480f0cf22a893ec64202a8ea7443f2
You are tasked with implementing a function `parse_log_entry(entry)` that processes a log entry string and extracts specific components. The log entry is formatted as `"[timestamp] [log_level] message"`. Your function should return a dictionary with keys `timestamp`, `log_level`, and `message` corresponding to the extr...
To solve the problem of parsing a log entry string into its components — `timestamp`, `log_level`, and `message` — we need to accurately extract the parts based on a specific format. The format is: ``` "[timestamp] [log_level] message" ``` However, upon close inspection, the **sample input** does not match this forma...
generic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements by parsing the log entry into a dictionary with the correct keys. However, it does not handle the case where the timestamp and log level are not enclosed in square brackets as specified in the question."}, "logical_corr...
["\nassert parse_log_entry(\"2023-04-01 12:34:56 [INFO] Server started successfully\") == {\"timestamp\": \"2023-04-01 12:34:56\", \"log_level\": \"INFO\", \"message\": \"Server started successfully\"}\n", "\nassert parse_log_entry(\"[2023-04-01 12:34:56] [INFO] Server started successfully\") == {}\n", "\nassert parse_...
["fail", "fail", "pass", "pass", "fail", "fail", "fail", "fail", "pass", "pass"]
0.4
Okay, I need to write a Python function called parse_log_entry that takes a string entry and returns a dictionary with timestamp, log_level, and message. If the format is wrong, return an empty dict. Let me think about how to approach this. The log entry is supposed to be in the format "[timestamp] [log_level] message...
a97cf0c3abad742b13e37f737696cb61
You are tasked with implementing a `Car` class in Python to simulate a car's attributes and behaviors. The class should encapsulate the following properties: `make`, `model`, `year`, and `mileage`. Your implementation should include the following methods: - `drive(distance: int)`: This method should increase the car's...
To implement the `Car` class as specified, we need to encapsulate four key attributes: `make`, `model`, `year`, and `mileage`. Additionally, the class must support three operations: 1. **Drive** – Increase the car's mileage by a given distance. 2. **Update Year** – Change the car's year to a new value. 3. **Display In...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The class Car fully meets all the specified requirements by including the attributes make, model, year, and mileage, and the methods drive, update_year, and display_info."}, "logical_correctness": {"score": 5, "justification": "The logic of the class is complet...
["\nassert Car(\"Toyota\", \"Corolla\", 2020, 15000).make == \"Toyota\"\n", "\nassert Car(\"Toyota\", \"Corolla\", 2020, 15000).model == \"Corolla\"\n", "\nassert Car(\"Toyota\", \"Corolla\", 2020, 15000).year == 2020\n", "\nassert Car(\"Toyota\", \"Corolla\", 2020, 15000).mileage == 15000\n", "\ncar = Car(\"Honda\", \...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a Car class in Python based on the given requirements. Let me think about what needs to be done. First, the class should have attributes: make, model, year, and mileage. So in the __init__ method, I'll need to initialize these. The parameters for the constructor should be make, model, year, and ...
08fe2029a1043378709beee20b45f7b3
You are given a list of integers. Your task is to determine the length of the longest increasing subsequence within this list. An increasing subsequence is defined as a sequence where each element is strictly greater than the preceding one. For example, in the list `[10, 9, 2, 5, 3, 7, 101, 18]`, the longest increasing...
To solve the problem of finding the length of the **Longest Increasing Subsequence (LIS)** in a given list of integers, we can use an efficient algorithm that runs in **O(n log n)** time complexity. --- ### ✅ **Understanding the Problem** An **increasing subsequence** is a sequence of elements from the input list su...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function correctly implements the logic to find the length of the longest increasing subsequence as specified in the question."}, "logical_correctness": {"score": 5, "justification": "The logic used in the function is completely correct and consistently str...
["\nassert longest_increasing_subsequence([10, 9, 2, 5, 3, 7, 101, 18]) == 4\n", "\nassert longest_increasing_subsequence([0, 1, 0, 3, 2, 3]) == 4\n", "\nassert longest_increasing_subsequence([7, 7, 7, 7, 7, 7, 7]) == 1\n", "\nassert longest_increasing_subsequence([1, 2, 3, 4, 5]) == 5\n", "\nassert longest_increasing_...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to find the length of the longest increasing subsequence in a given list of integers. Let me think about how to approach this problem. First, what's an increasing subsequence? Oh right, it's a sequence where each element is strictly larger than the previous one. And the elements don't have to be consecut...
f9fcb503e66d124039403bcd09fadff1
You are given a text file named `input.txt` containing a body of text. Your task is to write a Python script that reads this file, counts the occurrences of each word (ignoring case and punctuation), and writes the results to another file named `output.txt`. Each line in the output file should contain a word followed b...
To solve the problem of counting word occurrences from a text file, while ignoring case and punctuation, and outputting the results in alphabetical order, we can follow a structured and robust approach using Python's `re` (regular expression) module and `collections.Counter`. --- ### ✅ **Approach Overview** 1. **Rea...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The script fully meets all specified requirements by reading from an input file, counting word occurrences while ignoring case and punctuation, and writing the results to an output file."}, "logical_correctness": {"score": 5, "justification": "The logic is comp...
["\nassert open('output.txt').read() == \"a 2\\nhello 1\\nworld 1\\n\" after count_words('input1.txt', 'output.txt') with 'input1.txt' containing \"Hello, world! a\\na\"\n", "\nassert open('output.txt').read() == \"test 2\\nthis 1\\n\" after count_words('input2.txt', 'output.txt') with 'input2.txt' containing \"Test th...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a Python script that reads from input.txt, processes the text to count word occurrences, and writes the results to output.txt. Let me think about how to approach this. First, I should read the input file. So, open input.txt and read all the lines. But maybe I can read it all at once using read() ...
da38a635d02525b50785630fbb94d678
You are tasked with writing a Python program to generate the first `N` prime numbers. Implement a function to check if a number is prime and use it to generate the required list of prime numbers. Your program should output the first `N` prime numbers in ascending order. **Input:** - An integer `N` (1 ≤ N ≤ 100), repre...
To generate the first `N` prime numbers, we can follow a structured approach using a helper function to check for primality and a loop to collect the primes. --- ### ✅ **Approach Overview** 1. **Prime Check Function (`is_prime`)**: - A number is prime if it is greater than 1 and not divisible by any number other ...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by generating a list of the first 20 prime numbers using a function to check if a number is prime."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The fu...
["\nassert generate_primes(0) == []\n", "\nassert generate_primes(1) == [2]\n", "\nassert generate_primes(2) == [2, 3]\n", "\nassert generate_primes(5) == [2, 3, 5, 7, 11]\n", "\nassert generate_primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]\n", "\nassert generate_primes(15) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, ...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a Python program that generates the first N prime numbers. Let's think about how to approach this. First, I need a function to check if a number is prime. Right, the prime checking function. How do I do that? Well, a prime number is a number greater than 1 that has no divisors other than 1 and i...
9db0281651185ed79c41a6c5a2d82538
You are given a binary tree. Your task is to find the node whose children have the maximum greatest common divisor (GCD) among all pairs of siblings in the tree, with the additional condition that the sum of the values of the siblings must be a prime number. Return the value of such a node. If no such siblings exist, r...
To solve the problem of finding the node whose children have the **maximum GCD** among all pairs of siblings in a binary tree, with the **additional condition that the sum of the siblings must be a prime number**, we follow a structured approach: --- ### ✅ **Key Steps in the Solution** 1. **Tree Traversal**: - We...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirements of finding the node with the maximum GCD of its siblings where the sum of the siblings is a prime number. However, it does not explicitly ensure a single pass through the binary tree, as it uses a depth-first search ...
["\nassert find_max_gcd_with_prime_siblings(TreeNode(10, TreeNode(2, TreeNode(3), TreeNode(7)), TreeNode(14, TreeNode(8), TreeNode(9)))) == 2\n", "\nassert find_max_gcd_with_prime_siblings(TreeNode(5, TreeNode(3, TreeNode(1), TreeNode(2)), TreeNode(7, TreeNode(4), TreeNode(6)))) == 1\n", "\nassert find_max_gcd_with_pri...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, let's see. I need to solve this problem where I have to find a node in a binary tree whose children have the maximum GCD. But there's a condition: the sum of the siblings (the two children of a node) must be a prime number. And then return the value of that node. If none, return 0. Hmm. Let me think about the st...
173227f52279d285bba17a592c052fc5
You are given a CSV file named `data.csv` with the first row containing column headers and subsequent rows containing numerical data. Your task is to write a Python program that reads this file, calculates the average of each numerical column, and prints the results in a formatted table. If a column contains non-numeri...
To solve the problem of calculating the average of each numerical column in a CSV file while handling non-numeric entries and formatting the output as specified, we can use the following structured and well-documented Python script. --- ### ✅ **Problem Summary** Given a CSV file `data.csv`, the task is to: 1. **Rea...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It reads a CSV file, calculates the average of each column, and displays the results in a formatted table."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimall...
["\nassert read_csv('data.csv')['Column1'] == [1.0, 2.0, 3.0]\n", "\nassert read_csv('data.csv')['Column2'] == [4.0, 5.0, 6.0]\n", "\nassert calculate_averages({'Column1': [1.0, 2.0, 3.0]}) == {'Column1': 2.0}\n", "\nassert calculate_averages({'Column2': [4.0, 5.0, 6.0]}) == {'Column2': 5.0}\n", "\nassert calculate_ave...
["fail", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass"]
0.7
Okay, I need to write a Python program that reads a CSV file, calculates the average of each numerical column, and prints the results in a formatted table. Let me think about how to approach this. First, I'll need to read the CSV file. The first row is the header, so I'll need to skip that. Then, for each subsequent r...
e4a614802d27bac0eb0654d19aa91f25
You are given a binary file named `data.bin` containing a sequence of big-endian encoded integers. Each integer is encoded using the minimum number of bytes necessary based on the following rule: if the first byte of the integer is `0x80` or higher, then the integer is encoded using 4 bytes; otherwise, it is encoded us...
To solve the problem of reading a binary file `data.bin` that contains a sequence of big-endian encoded integers, we need to carefully interpret the encoding rules: --- ### ✅ **Encoding Rules Recap** - Each integer is encoded using **the minimum number of bytes**. - **If the first byte of the integer is `0x80` or hi...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It correctly reads the binary file, infers the length of each integer based on the first byte, and returns a list of integers."}, "logical_correctness": {"score": 5, "justification": "The logic is completely ...
["\nassert read_big_endian_integers(\"test1.bin\") == [1, 2]\n", "\nassert read_big_endian_integers(\"test2.bin\") == [128, 255]\n", "\nassert read_big_endian_integers(\"test3.bin\") == [32767, 65535]\n", "\nassert read_big_endian_integers(\"test4.bin\") == [2147483647, 1]\n", "\nassert read_big_endian_integers(\"test5...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a function called read_big_endian_integers that reads a binary file and returns a list of integers based on the given encoding rules. Let me think about how to approach this. So the file is big-endian encoded. Each integer uses the minimum number of bytes. The rule is: if the first byte of the in...
a0f8a5727d450f06604ec92a5f58eb1c
You are tasked with implementing a function `fibonacci_series` that generates a Fibonacci sequence up to, but not including, a given integer `n`. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ones. Your function should return a list of Fibonacci numbers starting ...
To solve the problem of generating the Fibonacci sequence up to, but not including, a given integer `n`, we must carefully consider the sequence generation logic and the special cases outlined in the problem. --- ### ✅ Problem Requirements Recap - The Fibonacci sequence starts with `0` and `1`. - Each subsequent num...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements. It generates a Fibonacci series up to a given number `n` and returns a list containing the Fibonacci numbers from 0 up to, but not including, `n`. It also correctly returns an empty list if `n` is 0 or 1."}, ...
["\nassert fibonacci_series(0) == []\n", "\nassert fibonacci_series(1) == []\n", "\nassert fibonacci_series(2) == [0, 1]\n", "\nassert fibonacci_series(10) == [0, 1, 1, 2, 3, 5, 8]\n", "\nassert fibonacci_series(15) == [0, 1, 1, 2, 3, 5, 8, 13]\n", "\nassert fibonacci_series(21) == [0, 1, 1, 2, 3, 5, 8, 13]\n", "\nasse...
["pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
Okay, I need to write a function called fibonacci_series that generates the Fibonacci sequence up to but not including a given integer n. Let's think about how to approach this. First, the Fibonacci sequence starts with 0 and 1. Each subsequent number is the sum of the previous two. So for example, if n is 10, the out...
be107f507e0139285332a0c86a4f3749
You are tasked with implementing a function `get_constant` that retrieves the value of a specified mathematical constant. The function should accept two parameters: a string `constant_name` representing the name of the constant and a boolean `approx` indicating whether an approximate value is acceptable. The function s...
To implement the `get_constant` function as specified, we need to provide a way to retrieve either the exact symbolic representation or a numerical approximation of a mathematical constant based on the input parameters. --- ### ✅ **Approach Overview** We define a dictionary that maps each supported constant name to ...
generic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements by returning approximate and exact values for specified constants. However, it does not return None for non-exact values when approx is False, as it returns the sympy object instead."}, "logical_correctness": {"score": ...
["\nassert get_constant('pi', True) == 3.141592653589793\n", "\nassert get_constant('e', True) == 2.718281828459045\n", "\nassert get_constant('tau', True) == 6.283185307179586\n", "\nassert get_constant('sqrt2', True) == 1.4142135623730951\n", "\nassert get_constant('sqrt3', True) == 1.7320508075688772\n", "\nassert g...
["pass", "pass", "pass", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0.3
Okay, I need to implement the get_constant function as described. Let me think about how to approach this. First, the function needs to take two parameters: constant_name (a string) and approx (a boolean). The goal is to return the value of the specified mathematical constant. If approx is True, return up to 15 decima...
1ca80c0c530df2c1c7fc105ea42e6ec9
You are tasked with implementing a `Book` class that models a book with attributes for its title, author, and publication year. The class should have a constructor that initializes these attributes and a method `get_info` that returns a formatted string containing the book's details. **Input:** - The constructor will ...
To model a book with attributes such as title, author, and publication year, we can define a `Book` class in Python. This class will include an initializer method to set up these attributes and a method to return a formatted string representation of the book's details. --- ### ✅ Class Structure Overview - **Construc...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by defining a class `Book` with a constructor that takes `title`, `author`, and `year` as parameters and includes a method `get_info` that returns the required string format."}, "logical_correctness": {"score"...
["\nassert Book(\"1984\", \"George Orwell\", 1949).get_info() == \"Title: 1984, Author: George Orwell, Year: 1949\"\n", "\nassert Book(\"To Kill a Mockingbird\", \"Harper Lee\", 1960).get_info() == \"Title: To Kill a Mockingbird, Author: Harper Lee, Year: 1960\"\n", "\nassert Book(\"The Great Gatsby\", \"F. Scott Fitzg...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a Python class called Book. Let me think about what the problem says. The Book class should have attributes for title, author, and publication year. The constructor needs to take those three parameters. Oh right, the parameters are title (string), author (string), and year (integer). So the con...
106fbdf4a786d12b628b1581125f556a
In a game, you are given a grid with specified width and height. The grid is divided into segments, each with its own scaling factor. Each tile in the grid is square-shaped, and its dimensions are calculated based on the grid's dimensions, a fixed ratio (106.25/500), and the segment's scaling factor. Your task is to co...
To solve this problem, we need to compute the dimensions of square tiles for each segment of a grid, based on the grid's width and height, a fixed ratio, and a list of scaling factors. Each tile must be square-shaped, and its size is determined by the given formula involving the fixed ratio and the scaling factor. ---...
generic
evol-instruct
{"requirement_conformance": {"score": 3, "justification": "The function meets the basic requirements by calculating the tile dimensions for each segment. However, it does not specify which grid dimension (width or height) to use for the calculation, leading to potential confusion."}, "logical_correctness": {"score": 3,...
["\nassert calculate_tile_dimensions(1000, 500, [1.0]) == [(106, 213)]\n", "\nassert calculate_tile_dimensions(800, 400, [0.5]) == [(53, 106)]\n", "\nassert calculate_tile_dimensions(1200, 600, [1.5]) == [(159, 320)]\n", "\nassert calculate_tile_dimensions(500, 250, [2.0]) == [(213, 213)]\n", "\nassert calculate_tile_d...
["fail", "fail", "fail", "fail", "fail", "pass", "fail", "fail", "fail", "pass"]
0.2
Okay, let's see. I need to figure out the dimensions of each tile for each segment based on the given grid width and height, the scaling factors, and that fixed ratio of 106.25/500. Hmm, wait, what's the ratio for? Oh right, the problem says each tile's dimensions are calculated based on the grid's dimensions, that rat...
45bc227e11eb6cabd2a815fb84c9fb30
You are given a list of integers. Your task is to write a function that returns a new list with the elements in reverse order. You are not allowed to use any built-in functions that directly reverse the list. **Input:** - A list of integers `input_list` (1 ≤ len(input_list) ≤ 1000). **Output:** - A list of integers ...
To reverse a list of integers without using any built-in reverse functions, we can manually iterate through the list from the last element to the first and construct a new list by appending each element in reverse order. --- ### ✅ Approach 1. **Initialize an empty list** to store the reversed elements. 2. **Iterate ...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of reversing the list without using built-in functions."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently reverses the list as intended."}, "edge_case_consideration...
["\nassert reverse_list([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1]\n", "\nassert reverse_list(['a', 'b', 'c']) == ['c', 'b', 'a']\n", "\nassert reverse_list([]) == []\n", "\nassert reverse_list([10]) == [10]\n", "\nassert reverse_list([True, False, True]) == [True, False, True]\n", "\nassert reverse_list([None, 1, 'two', 3.0]...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function that reverses a list of integers without using any built-in reverse functions. Let's think about how to approach this. First, the input is a list, and I have to return a new list with elements in reverse order. So, for example, if the input is [1,2,3,4,5], the output should be [5,4,3,2...
5a7d4c418516ea9190bb42d387b529a3
You are given a non-negative integer `n`. Your task is to compute the nth Fibonacci number. The Fibonacci sequence is defined as follows: F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n > 1. **Input:** - The first line contains a single integer `n` (0 ≤ n ≤ 50). **Output:** - Print a single integer, the nth Fibo...
To compute the nth Fibonacci number, we can use an **iterative approach** that efficiently calculates the sequence up to the desired index. This method avoids the inefficiency of recursion and ensures that even for larger values of `n` (up to 50), the computation remains fast and straightforward. --- ### ✅ **Approach...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by calculating the nth Fibonacci number for non-negative integers and handling the base cases correctly."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and efficiently calculate...
["\nassert fibonacci(0) == 0\n", "\nassert fibonacci(1) == 1\n", "\nassert fibonacci(2) == 1\n", "\nassert fibonacci(3) == 2\n", "\nassert fibonacci(4) == 3\n", "\nassert fibonacci(5) == 5\n", "\nassert fibonacci(10) == 55\n", "\nassert fibonacci(15) == 610\n", "\nassert fibonacci(20) == 6765\n", "\nassert fibonacci(25...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a program that calculates the nth Fibonacci number. Let's think about how to approach this. The Fibonacci sequence starts with F(0) = 0, F(1) = 1, and each subsequent number is the sum of the two previous ones. So for n=5, the output is 5, right? Let me check that. Let's see: F(0) = 0 F(1) = 1 F(...
9ed1d6787703815e7d8bbe083b51e726
You are given the task of computing the factorial of a non-negative integer \( n \). Due to the limitations of recursion, your solution must use an iterative approach to efficiently calculate the factorial without causing stack overflow errors. Implement a function `factorial_iterative` that takes an integer \( n \) as...
To compute the factorial of a non-negative integer $ n $ using an **iterative approach**, we can avoid the risk of stack overflow that may occur with a recursive implementation. This is especially important when $ n $ is large, as the recursion depth could exceed Python’s default limit. --- ### ✅ Problem Requirements...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by rewriting the factorial calculation using an iterative approach, which avoids stack overflow errors for large numbers."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optim...
["\nassert factorial_iterative(0) == 1\n", "\nassert factorial_iterative(1) == 1\n", "\nassert factorial_iterative(5) == 120\n", "\nassert factorial_iterative(10) == 3628800\n", "\nassert factorial_iterative(12) == 479001600\n", "\nassert factorial_iterative(15) == 1307674368000\n", "\nassert factorial_iterative(20) ==...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write an iterative factorial function in Python. Let's think about how to approach this. The problem says to use an iterative method to avoid recursion stack overflow, which makes sense because for large n, recursion would hit the recursion limit and crash. First, the function is called factorial_itera...
adf829f3f7ac523351016a055842d974
You are given a nested list of integers. Your task is to write a function `flatten_list(nested_list)` that returns a single list containing all the integers from the nested list in the order they appear. The input list can contain integers and other nested lists of arbitrary depth. **Input:** - A nested list of intege...
To solve the problem of flattening a nested list of integers, we can use a **recursive approach**. This method allows us to traverse the list deeply, handling any level of nesting. --- ### ✅ **Approach Explanation** 1. **Base Case**: If the input is not a list (i.e., it's an integer), we simply return it. 2. **Recur...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by correctly flattening a nested list of integers into a single list."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The function uses recursion to hand...
["\nassert flatten_list([[1, 2, [3]], 4, [5, 6]]) == [1, 2, 3, 4, 5, 6]\n", "\nassert flatten_list([1, [2, [3, [4, [5]]]]]) == [1, 2, 3, 4, 5]\n", "\nassert flatten_list([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert flatten_list([]) == []\n", "\nassert flatten_list([[], [], []]) == []\n", "\nassert flatten_list([[[...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a function called flatten_list that takes a nested list and returns a flat list of all the integers in order. Let's think about how to approach this. So the input can have integers and other nested lists. For example, the sample input is [[1,2,[3]],4,[5,6]] and the output is [1,2,3,4,5,6]. So the...
f4175b057caf0df04057f163de700745
You are tasked with implementing a simple library management system. The system should support the following operations: - **Add Book**: Add a specified number of copies of a book to the library. - **Borrow Book**: Borrow a book if it is available. If the book is not available, print an appropriate message. - **Return ...
To implement a **Library Management System**, we define a `Library` class that supports the following operations: - **Add Book**: Adds a specified number of copies of a book to the library. - **Borrow Book**: Borrows a book if it's available. - **Return Book**: Returns a book to the library. - **Display Available Book...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements by implementing methods to add books, borrow books, return books, and display all available books."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally str...
["\nassert library.books == {}\n", "\nlibrary.add_book(\"Python Programming\", 3); assert library.books == {\"Python Programming\": 3}\n", "\nlibrary.add_book(\"Data Structures\", 2); assert library.books == {\"Python Programming\": 3, \"Data Structures\": 2}\n", "\nlibrary.borrow_book(\"Python Programming\"); assert l...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to create a Library class that can handle adding, borrowing, returning, and displaying books. Let me think about how to structure this. First, the library needs to keep track of books and their quantities. So maybe a dictionary where the keys are book titles and the values are the quantities. That makes s...
7ae127b9124c14482ee17ed80fe43487
You are given a list of monsters, each with a specific health value. In each turn, you must choose an attacking monster and a defending monster to engage in combat. The attacking monster's health must be a prime number that is one more than a multiple of 3 and also a Fibonacci number. The defending monster's health mus...
To solve this problem, we must simulate a sequence of battles between monsters based on specific rules for selecting attackers and defenders. The goal is to determine the **minimum possible final health** of the last monster alive. --- ### 🔍 **Understanding the Conditions** #### **Attacker Conditions:** - Must be a...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 2, "justification": "The solution does not fully meet the requirements. It does not consider the Fibonacci sequence for attackers and does not check if the composite number has divisors only from prime numbers congruent to 3 modulo 4."}, "logical_correctness": {"score": 3, "justifi...
["\nassert min_final_health([7, 10, 13, 15]) == 10\n", "\nassert min_final_health([4, 6, 8, 9]) == 4\n", "\nassert min_final_health([10, 15, 21, 25]) == 10\n", "\nassert min_final_health([13, 19, 25, 31]) == 25\n", "\nassert min_final_health([7, 13, 19, 25]) == 25\n", "\nassert min_final_health([4, 9, 16, 25]) == 4\n",...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, let's try to figure out this problem. So, the task is to determine the minimum possible final health of the last monster alive after all battles. The rules for choosing attackers and defenders are a bit complex, so I need to break them down step by step. First, let's understand the conditions for the attacking m...
169b1a54d26f3b51db1c25801ba1fd7c
You are tasked with implementing a function `create_spiral_matrix` that constructs a `num_rows` x `num_cols` matrix filled with integers in a spiral order starting from the top-left corner and moving clockwise. The integers should be unique and sequentially increasing from 1. If the matrix cannot be completely filled d...
To solve the problem of constructing a **spiral matrix** with dimensions `num_rows x num_cols` and filling it with integers from `1` to `num_rows * num_cols` in a **clockwise spiral order**, we can simulate the movement of a "pointer" across the matrix, changing direction whenever the next cell is out of bounds or alre...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It generates a spiral matrix of the given dimensions and fills it with integers in a spiral pattern starting from 1, ensuring no duplicates. If the matrix cannot be filled completely, the remaining positions ...
["\nassert create_spiral_matrix(1, 1) == [[1]]\n", "\nassert create_spiral_matrix(2, 2) == [[1, 2], [4, 3]]\n", "\nassert create_spiral_matrix(3, 3) == [[1, 2, 3], [8, 9, 4], [7, 6, 5]]\n", "\nassert create_spiral_matrix(3, 4) == [[1, 2, 3, 4], [10, 11, 12, 5], [9, 8, 7, 6]]\n", "\nassert create_spiral_matrix(4, 3) == ...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a function called create_spiral_matrix that takes num_rows and num_cols and returns a matrix filled in spiral order. Let me think about how to approach this. First, the spiral starts at the top-left corner and goes clockwise. So, the numbers go right, then down, then left, then up, and repeat. B...
a0cb85262fbba5856753a342a7318966
Given a string `s`, write a function to find the longest palindromic substring in `s`. A palindrome is a string that reads the same forward and backward. The function should handle edge cases such as an empty string or a string with a single character. Your solution should be efficient. **Examples:** - Input: `"babad...
To solve the problem of finding the **longest palindromic substring** in a given string `s`, we can use an **efficient and intuitive approach** based on **expanding around centers**. This method leverages the fact that a palindrome can be centered either at a single character (for odd-length palindromes) or between two...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by returning the longest palindromic substring, handling edge cases like an empty string or a single character string, and efficiently finding the longest palindrome."}, "logical_correctness": {"score": 5, "justificatio...
["\nassert longest_palindromic_substring(\"babad\") == \"bab\" or longest_palindromic_substring(\"babad\") == \"aba\"\n", "\nassert longest_palindromic_substring(\"cbbd\") == \"bb\"\n", "\nassert longest_palindromic_substring(\"a\") == \"a\"\n", "\nassert longest_palindromic_substring(\"\") == \"\"\n", "\nassert longes...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to find the longest palindromic substring in a given string. Let's think about how to approach this. Hmm, palindromes are strings that read the same forwards and backwards. So for example, "aba" or "abba" are palindromes. The problem is to find the longest such substring in the input string. First, I shou...
2f26755fa43b4836543d993bbd1b6b7f
You are given a string `s` consisting of lowercase English letters, digits, and special characters. Your task is to determine if the string, after removing all non-alphabetic characters, is in alphabetical order. Return `True` if it is, otherwise return `False`. **Examples:** - Input: `"abc123"` - Output: `True` - ...
To determine whether a given string, after removing all non-alphabetic characters, is in alphabetical order, we can follow a structured approach: --- ### ✅ **Problem Breakdown** 1. **Filter the string** to include only **alphabetic characters** (i.e., letters from `a` to `z`). 2. **Check if the filtered string** is ...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by removing all non-alphabetic characters and checking if the resulting string is in alphabetical order."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. It uses a generator expr...
["\nassert isAlphabetic(\"abc\") == True\n", "\nassert isAlphabetic(\"a1b2c3\") == True\n", "\nassert isAlphabetic(\"a!b@c#\") == True\n", "\nassert isAlphabetic(\"cba\") == False\n", "\nassert isAlphabetic(\"c3b2a1\") == False\n", "\nassert isAlphabetic(\"c!b@a#\") == False\n", "\nassert isAlphabetic(\"a\") == True\n"...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, let's see. I need to write a function that checks if a string, after removing all non-alphabetic characters, is in alphabetical order. Hmm. So first, I need to process the input string by removing any characters that are not letters. Then check if the resulting string is sorted in alphabetical order. Wait, what ...
05f9eb0a9d8d7155281ad503512a5754
You are given two integers, `K` and `M`. Your task is to determine the number of ways to form each sum from 2 to 2K using exactly `M` distinct positive integers, each not exceeding `K`. Implement a recursive solution with memoization to solve this problem. **Input:** - The first line contains two integers `K` and `M` ...
To solve the problem of determining the number of ways to form each sum from 2 to 2K using exactly M distinct positive integers, each not exceeding K, we can use a recursive approach with memoization. The key insight is to ensure that we count only combinations of distinct numbers, and we avoid counting permutations of...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by using a recursive approach with memoization to find the number of combinations for each sum from 2 to 2K using exactly M different numbers."}, "logical_correctness": {"score": 5, "justification": "The logic is comple...
["\nassert count_combinations(3, 2) == {2: 1, 3: 2, 4: 2, 5: 1, 6: 1}\n", "\nassert count_combinations(4, 2) == {2: 1, 3: 2, 4: 3, 5: 4, 6: 4, 7: 3, 8: 2, 9: 1}\n", "\nassert count_combinations(5, 2) == {2: 1, 3: 2, 4: 3, 5: 5, 6: 6, 7: 7, 8: 7, 9: 6, 10: 5, 11: 4, 12: 3, 13: 2, 14: 1}\n", "\nassert count_combinations(...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, let's tackle this problem. So, the task is to find the number of ways to form each sum from 2 to 2K using exactly M distinct positive integers, each not exceeding K. And we need to implement a recursive solution with memoization. Hmm. First, let me understand the problem. Let's take the sample input: K=5, M=2. T...
8208132022746493a9f470ac27f8f2d5
You are given a list of integers. Your task is to write a function `sort_numbers` that sorts the list in ascending order. The function should modify the list in place and not return anything. Note that the provided code snippet contains both syntax and logical errors. Correct the code to achieve the desired functionali...
To solve the problem of sorting a list of integers in ascending order **in place**, we need to ensure that the list is modified directly, without creating a new list or returning anything. The most efficient and idiomatic way to do this in Python is by using the built-in `list.sort()` method. --- ### ✅ Correct Implem...
algorithmic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the requirement to sort a list of numbers but does not handle potential errors or edge cases."}, "logical_correctness": {"score": 4, "justification": "The logic is correct for sorting the list in place, but it does not return the sorted l...
["\nassert sort_numbers([3, 1, 2]) == None\n", "\nassert sort_numbers([3, 1, 2]) == [1, 2, 3]\n", "\nassert sort_numbers([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]\n", "\nassert sort_numbers([]) == []\n", "\nassert sort_numbers([1]) == [1]\n", "\nassert sort_numbers([1, 1, 1, 1]) == [1, 1, 1, 1]\n", "\nassert sort_numbers([-1...
["pass", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0.1
Okay, I need to write a function called sort_numbers that sorts a list of integers in ascending order. The function has to modify the list in place and not return anything. The problem mentions that there are syntax and logical errors in the provided code snippet, but since I don't have the original code, I have to fig...
4e11513f0a9ef965ed15cde680583c4b
You are tasked with implementing a `Graph` class that supports storing and retrieving user data with compression. The `Graph` class should have the following methods: - `store_user_data(user_data)`: Accepts a dictionary `user_data` and stores it internally after compressing it using a chosen compression algorithm. - `...
To implement the `Graph` class as described, we need to support storing and retrieving user data with compression and decompression. The compression and serialization should be handled using the `zlib` and `pickle` libraries respectively. --- ### ✅ Key Requirements - **`store_user_data(user_data)`**: - Accepts a...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It implements the `Graph` class with `store_user_data` and `retrieve_user_data` methods that compress and decompress data respectively."}, "logical_correctness": {"score": 5, "justification": "The logic is co...
["\nassert Graph().retrieve_user_data() == {}\n", "\nassert Graph().retrieve_user_data() == {}\n", "\ng = Graph(); g.store_user_data({\"name\": \"Alice\", \"age\": 30}); assert g.retrieve_user_data() == {\"name\": \"Alice\", \"age\": 30}\n", "\ng = Graph(); g.store_user_data({\"key\": \"value\"}); assert g.retrieve_use...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to implement a Graph class that can store and retrieve user data with compression. The requirements say to use zlib for compression and pickle for serialization. Let me think about how to approach this. First, the store_user_data method needs to take a dictionary, compress it, and store it. Then retrieve_...
5271d6c5a95c8b69c1fa11c351641e73
You are given a nested dictionary. Your task is to write a function that recursively flattens this dictionary into a single-level dictionary. The keys in the new dictionary should be concatenated using a dot (`.`) to represent the hierarchy of keys from the original dictionary. **Input:** - A nested dictionary `d`. ...
To solve the problem of recursively flattening a nested dictionary, we need to transform a hierarchical structure into a flat dictionary where each key is a concatenation of the original keys separated by a dot (`.`). This is a classic use case for recursion, as the structure may have multiple levels of nesting. --- ...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of recursively flattening a nested dictionary into a single-level dictionary with keys concatenated using a dot (`.`) to represent the hierarchy."}, "logical_correctness": {"score": 5, "justification": "The logic is comp...
["\nassert flatten_dict({'a': 1, 'b': {'c': 2}}) == {'a': 1, 'b.c': 2}\n", "\nassert flatten_dict({'x': {'y': {'z': 3}}}) == {'x.y.z': 3}\n", "\nassert flatten_dict({'key': 'value'}) == {'key': 'value'}\n", "\nassert flatten_dict({}) == {}\n", "\nassert flatten_dict({'a': 1, 'b': 2, 'c': {'d': 3, 'e': {'f': 4}}}) == {'...
["pass", "pass", "pass", "pass", "pass", "pass", "fail", "fail", "pass", "fail"]
0.7
Okay, I need to write a function that takes a nested dictionary and flattens it into a single-level dictionary. The keys should be concatenated with dots to show the hierarchy. Let me think about how to approach this. So, the input is a dictionary that might have other dictionaries as values. For example, in the sampl...
c4f652fb4391578a9dcace58b1444376
You are given a list of strings. Your task is to implement a function that returns a new list containing only the unique strings from the input list, while preserving the order of their first appearance. The function should be optimized to handle large lists efficiently. **Sample Input:** ```python ["apple", "banana",...
To solve the problem of extracting unique strings from a list while preserving the order of their first appearance, we can utilize a combination of a `set` and a `list`. --- ### ✅ Problem Analysis We are given a list of strings and must return a new list that contains only the unique elements, maintaining the order ...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by returning a list of unique strings while preserving the original order of their first appearance. It also handles large lists efficiently using a set for tracking seen strings."}, "logical_correctness": {"score": 5, "...
["\nassert unique_strings([\"apple\", \"banana\", \"apple\", \"orange\"]) == [\"apple\", \"banana\", \"orange\"]\n", "\nassert unique_strings([\"hello\", \"world\", \"hello\", \"world\"]) == [\"hello\", \"world\"]\n", "\nassert unique_strings([\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"]) == [\"a\", \"b\", \"c\"]\n", "\na...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a Python function that takes a list of strings and returns a new list with only the unique strings, but keeping the order of their first appearance. Hmm. Let's think about how to approach this. So the key points are: uniqueness and preserving the order. So for each string in the input list, I nee...
ce602920e031f37eb41a87de0699abcc
Implement a stack using a list in Python. Your stack should support the following operations: - `is_empty()`: Returns `True` if the stack is empty, otherwise `False`. - `push(item)`: Adds an item to the top of the stack. - `pop()`: Removes and returns the top item of the stack. Raises an `IndexError` if the stack is em...
Here's a complete and well-documented implementation of a stack using a list in Python, along with a demonstration of its usage. The stack supports the required operations (`is_empty`, `push`, `pop`, `peek`) and includes error handling for empty stack scenarios. --- ### ✅ **Stack Implementation Using a List** ```pyt...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing the Stack class with push, pop, peek, and is_empty methods, and demonstrates their usage."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally ...
["\nassert Stack().is_empty() == True\n", "\nassert Stack().peek() == None\n", "\nassert Stack().pop() == None\n", "\ns = Stack(); s.push(5); assert s.peek() == 5\n", "\ns = Stack(); s.push(5); s.push(10); assert s.pop() == 10\n", "\ns = Stack(); s.push(5); s.push(10); s.pop(); assert s.is_empty() == False\n", "\ns = S...
["pass", "fail", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
0.8
Okay, I need to implement a stack using a list in Python. Let me think about how to approach this. So, a stack follows the LIFO (Last In, First Out) principle. That means the last element added is the first one to be removed. First, the operations required are is_empty(), push(), pop(), and peek(). Let me think about ...
02f20332c4356c08c0772176670d8b43
You are given two dates, `birth_date` and `current_date`, represented as instances of Python's `datetime.date` class. Your task is to implement a function `calculate_age` that computes the age of a person born on `birth_date` as of `current_date`. The age should be calculated in years, rounded down to the nearest whole...
To solve the problem of computing a person's age and the number of days since their last birthday, we need to consider both the chronological order of the dates and the specific rules for leap years, especially when the birth date falls on February 29. --- ### ✅ **Approach Overview** 1. **Age Calculation**: - The...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements. It calculates the age in years and the number of days past the most recent birthday, returning them as a tuple."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and con...
["\nassert calculate_age(date(1990, 1, 1), date(2022, 1, 1)) == (32, 0)\n", "\nassert calculate_age(date(1990, 1, 1), date(2022, 1, 2)) == (32, 1)\n", "\nassert calculate_age(date(1990, 12, 31), date(2023, 1, 1)) == (32, 1)\n", "\nassert calculate_age(date(1990, 12, 31), date(1991, 1, 1)) == (0, 1)\n", "\nassert calcul...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a Python function called calculate_age that takes two date objects, birth_date and current_date. The goal is to compute the age in years, rounded down, and also find out how many days have passed since the most recent birthday up to current_date. Let's think about how to approach this. First, cal...
27baf12f69ac98550b47342fb2a6edc5
You are tasked with implementing a `Deck` class that simulates a standard deck of 52 playing cards. The class should support the following operations: - `shuffle()`: Randomly shuffles the deck of cards. - `deal()`: Deals a single card from the deck and returns it. If the deck is empty, return `None`. Your implementat...
To simulate a standard 52-card deck of playing cards in Python, we can implement a `Deck` class that manages the cards, shuffles them, and deals them one at a time. The implementation will use the `random` module to ensure randomness in the shuffle and the `list` data structure to represent the deck. --- ### ✅ Key Fe...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The class Deck meets all the specified requirements. It includes the shuffle() method to shuffle the deck and the deal() method to deal a single card, returning None if the deck is empty."}, "logical_correctness": {"score": 5, "justification": "The logic is com...
["\nassert len(Deck().cards) == 52\n", "\nassert Deck().deal() == 'Ace of Spades'\n", "\ndeck = Deck()\ndeck.shuffle()\nassert len(deck.cards) == 52\n", "\ndeck = Deck()\ndeck.shuffle()\nfirst_card = deck.deal()\nassert first_card in ['2 of Hearts', '3 of Hearts', '4 of Hearts', '5 of Hearts', '6 of Hearts', '7 of Hear...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a Deck class in Python that can simulate a standard deck of 52 playing cards. Let me think about how to approach this. First, the deck should have all the standard cards. So, the cards are 4 suits (hearts, diamonds, clubs, spades) and 13 ranks (Ace through King). Wait, how to represent the cards...
81e1c1bc4c228277339fab339096c4fb
You are tasked with implementing a `Book` class and a `Library` class in Python. The `Book` class should store information about a book, including its title, author, and ISBN. The `Library` class should manage a collection of books and provide methods to add, remove, and list books. Your implementation should be tested...
To solve the problem, we implement two classes: `Book` and `Library`, each with specific responsibilities. The `Book` class manages individual book details, while the `Library` class handles a collection of books and supports operations such as adding, removing, and listing books. --- ### ✅ **Class Overview** #### *...
algorithmic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution meets the basic requirements by implementing a Book class and a Library class with methods to add, remove, and list books. However, it does not include additional features or functionalities that might be expected in a more comprehensive library sy...
["\nassert my_library.list_books() == [Book(title='1984', author='George Orwell', isbn='1234567890'), Book(title='To Kill a Mockingbird', author='Harper Lee', isbn='0123456789')]\n", "\nassert my_library.list_books() != [Book(title='1984', author='George Orwell', isbn='1234567890')]\n", "\nassert my_library.list_books(...
["fail", "pass", "fail", "pass", "fail", "pass", "pass", "fail", "pass", "fail"]
0.5
Okay, I need to create a Book class and a Library class in Python based on the given requirements. Let me start by thinking about what each class should do. First, the Book class. It needs to store title, author, and ISBN. So the __init__ method should take those three parameters and assign them as instance variables....
f8a0c400b0601e63424aa42104fd525a
You are given a string `s` consisting of alphanumeric characters, spaces, and punctuation. Your task is to determine if the string is a palindrome, ignoring spaces, punctuation, and capitalization. A string is considered a palindrome if it reads the same forwards and backwards. **Input:** - A single string `s` (1 ≤ |s...
To determine whether a given string is a **palindrome**, we must first **ignore** the following: - **Spaces** - **Punctuation** - **Capitalization** This means we need to preprocess the string by: 1. **Filtering** out all characters that are not alphanumeric. 2. **Converting** all remaining characters to the same ca...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements by ignoring spaces, punctuation, and capitalization, and correctly determining if the string is a palindrome."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and op...
["\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(\"Not a palindrome\") == False\n", "\nassert...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to determine if a given string is a palindrome, but I have to ignore spaces, punctuation, and capitalization. Hmm. Let's think about how to approach this. First, what's a palindrome? It's a string that reads the same forwards and backwards. But here, I have to process the string by removing all non-alphan...
9a307feb4ba6c3c6889793b242fb43b6
You are given an HTML document as a string. Your task is to write a Python function that parses the HTML and extracts all unique email addresses present in the document. The function should return a list of these unique email addresses. The HTML document may contain email addresses in plain text or within `mailto:` lin...
To solve the problem of extracting all unique email addresses from an HTML document, we need to consider two main sources of email addresses: 1. **Emails in plain text** within the document. 2. **Emails embedded in `mailto:` links** in anchor (`<a>`) tags. We'll use the `BeautifulSoup` library to parse the HTML docum...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by parsing an HTML document and extracting all unique email addresses from it, including those found in text and href attributes of anchor tags."}, "logical_correctness": {"score": 5, "justification": "The logic is comp...
["\nassert extract_unique_emails(\"<html><body><p>Email: test@example.com</p></body></html>\") == [\"test@example.com\"]\n", "\nassert extract_unique_emails(\"<html><body><a href='mailto:info@sample.org'>Contact us</a></body></html>\") == [\"info@sample.org\"]\n", "\nassert extract_unique_emails(\"<html><body><p>Reach ...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a Python function that parses an HTML document and extracts all unique email addresses. The emails can be in plain text or within mailto links. Let me think about how to approach this. First, I remember that parsing HTML can be done with libraries like BeautifulSoup. So maybe I should use that. B...
1f06f5a301c49a32a1dc83c1357aafde
You are given a list of integers. Your task is to find the longest increasing subsequence in this list. An increasing subsequence is defined as a sequence where each element is greater than the previous one. The subsequence does not need to be contiguous. If there are multiple subsequences of the same maximum length, r...
To solve the problem of finding the **Longest Increasing Subsequence (LIS)** in a list of integers, we can use a **Dynamic Programming (DP)** approach. This approach is efficient for the given constraints (with a maximum of 1000 elements), and it ensures that we not only find the **length** of the LIS but also **recons...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution correctly implements the logic to find the longest increasing subsequence and meets all the specified requirements."}, "logical_correctness": {"score": 4, "justification": "The logic is correct and the solution works as intended. However, the use o...
["\nassert longest_increasing_subsequence([10, 22, 9, 33, 21, 50, 41, 60, 80]) == [10, 22, 33, 50, 60, 80]\n", "\nassert longest_increasing_subsequence([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert longest_increasing_subsequence([5, 4, 3, 2, 1]) == [5]\n", "\nassert longest_increasing_subsequence([1, 3, 5, 4, 7]) =...
["pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass"]
0.9
Okay, I need to find the longest increasing subsequence in a given list of integers. Let me think about how to approach this problem. First, I remember that the Longest Increasing Subsequence (LIS) problem is a classic dynamic programming problem. The standard approach for finding the length of the LIS is O(n^2) time...
f199bfb5c1efeeb6741f6e9065455b4a
You are given an integer `n` in decimal form. Your task is to write a program that outputs the same integer `n` without using any built-in conversion functions or libraries. **Input:** - A single integer `n` (0 ≤ n ≤ 10^9). **Output:** - Print the integer `n` as it is. **Sample Input:** ``` 123 ``` **Sample Output...
To solve the problem of printing an integer `n` **without using any built-in conversion functions or libraries**, we can approach the task by **manually extracting each digit** of the number and **printing it as a character** using ASCII values. --- ### ✅ Problem Breakdown We are given an integer `n` in decimal form...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 3, "justification": "The solution meets the basic requirement of taking an integer input and outputting it. However, it does not perform any conversion as the task specifies, which is a key part of the requirement."}, "logical_correctness": {"score": 3, "justification": "The logic ...
["\nassert decimal_to_decimal(0) == 0\n", "\nassert decimal_to_decimal(123) == 123\n", "\nassert decimal_to_decimal(-456) == -456\n", "\nassert decimal_to_decimal(1000) == 1000\n", "\nassert decimal_to_decimal(-1) == -1\n", "\nassert decimal_to_decimal(9999) == 9999\n", "\nassert decimal_to_decimal(10) == 10\n", "\nass...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a program that takes an integer n and outputs it as is, but without using any built-in conversion functions or libraries. Hmm, the challenge here is to print the number directly without converting it to a string. Let me think about how to approach this. So, the input is an integer. For example, i...
b89862353edb8d21f7f08d7f841af77d
You are given a list of angles in degrees. Your task is to write a function `calculate_sine_sum` that computes the sum of the sine values of these angles after converting them to radians. The function should handle any potential errors gracefully, such as non-numeric inputs or math domain errors. **Input:** - A list ...
To solve the problem of computing the sum of the sine values of a list of angles in degrees, we must: 1. **Convert each angle from degrees to radians** — since Python's `math.sin()` function uses radians. 2. **Compute the sine of each converted angle**. 3. **Sum all the sine values**. 4. **Gracefully handle errors**, ...
generic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements by calculating the sum of sine values after converting degrees to radians. However, it does not fully meet the original instruction as it does not specify the conversion from degrees to radians in the question."}, "logi...
["\nassert calculate_sine_sum([0, 30, 45, 60, 90, 180, 360]) == 2.0\n", "\nassert calculate_sine_sum([0, 90, 180, 270, 360]) == 1.0\n", "\nassert calculate_sine_sum([45, 135, 225, 315]) == 0.0\n", "\nassert calculate_sine_sum([60, 120, 240, 300]) == 0.0\n", "\nassert calculate_sine_sum([180, 360, 540, 720]) == 0.0\n", ...
["fail", "fail", "fail", "fail", "fail", "pass", "pass", "pass", "fail", "fail"]
0.3
Okay, I need to write a Python function called calculate_sine_sum that takes a list of numbers representing angles in degrees and returns the sum of their sine values. But I have to handle errors like non-numeric inputs or math domain errors. Let me think about how to approach this. First, the main steps are: convert ...
4fece3a2ba04c4ba02353ccfbb20f746
You are given a task to write a Python function that processes a JSON file and extracts all unique keys from the JSON data. Your function should handle various error scenarios, such as the file not existing or the file containing invalid JSON. Your function should return a list of unique keys found in the JSON file. *...
To solve the problem of extracting all **unique keys** from a JSON file, we need to handle several key aspects: --- ### ✅ **Requirements Summary** - **Input**: A string representing the path to a JSON file. - **Output**: A list of **unique keys** from the JSON data. - **Error Handling**: - If the file does **not e...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by reading a JSON file, extracting unique keys, and handling errors such as invalid JSON files or missing files."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally str...
["\nassert get_unique_json_keys(\"non_existent_file.json\") == []\n", "\nassert get_unique_json_keys(\"invalid_json_file.json\") == []\n", "\nassert get_unique_json_keys(\"empty_file.json\") == []\n", "\nassert get_unique_json_keys(\"single_key.json\") == [\"name\"]\n", "\nassert get_unique_json_keys(\"nested_keys.json...
["pass", "pass", "pass", "fail", "fail", "fail", "fail", "fail", "fail", "pass"]
0.4
Okay, I need to write a Python function that reads a JSON file and extracts all unique keys. Let me think about how to approach this. First, the function needs to take a file path as input. Then, it should read the JSON data from that file. But wait, there are possible errors here. Like, the file might not exist, or t...
368f8d8b9cc574e9d1c463bbd45ba961
You are tasked with implementing a `BankAccount` class that simulates basic banking operations. The class should support the following functionalities: - Initialize the account with an optional initial balance. - Deposit a specified amount into the account, ensuring the deposit amount is positive. - Withdraw a specifie...
To implement the `BankAccount` class as specified, we need to provide the following functionalities: 1. **Initialization** with an optional initial balance. 2. **Deposit** a positive amount into the account. 3. **Withdraw** a positive amount from the account, ensuring it does not exceed the current balance. 4. Provide...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It includes a private attribute _balance, a read-only property balance, and methods deposit and withdraw that ensure the balance never goes negative."}, "logical_correctness": {"score": 5, "justification": "T...
["\nassert BankAccount().balance == 0\n", "\nassert BankAccount(100).balance == 100\n", "\naccount = BankAccount(100); account.deposit(50); assert account.balance == 150\n", "\naccount = BankAccount(100); account.withdraw(50); assert account.balance == 50\n", "\naccount = BankAccount(100); try: account.deposit(-50); as...
["pass", "pass", "pass", "pass", "fail", "fail", "fail", "pass", "pass", "pass"]
0.7
Okay, I need to create a BankAccount class in Python. Let me think about the requirements. The class should have an optional initial balance. So when initializing, maybe the constructor takes an initial_balance parameter, which defaults to zero if not provided. Then there's deposit functionality. The deposit amount m...
5c57f9c78d8a10476b2ccf7048160446
Design a simple REST API using Flask. The API should expose an endpoint `/api/data` that, when accessed, returns a JSON object. The JSON object must contain the following key-value pairs: - `id`: 1 - `name`: "Sample Data" - `description`: "This is a sample data object for testing." **Sample Input:** Accessing the endp...
To create a simple REST API using Flask that exposes an endpoint `/api/data` returning a specific JSON object, we can follow a straightforward approach using Flask's built-in capabilities. --- ### ✅ Step-by-Step Implementation 1. **Import Required Modules**: We'll need `Flask` for creating the web application a...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the specified requirements by creating a REST API with Flask that exposes the /api/data endpoint and returns the correct JSON object."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and the code ...
["\nassert get_data().json == {\"id\": 1, \"name\": \"Sample Data\", \"description\": \"This is a sample data object for testing.\"}\n", "\nassert get_data().status_code == 200\n", "\nassert get_data().content_type == 'application/json'\n", "\nassert get_data().json['id'] == 1\n", "\nassert get_data().json['name'] == \...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to design a simple REST API using Flask. The task is to create an endpoint at /api/data that returns a specific JSON object when accessed via a GET request. Let me think about how to approach this. First, I remember that Flask is a Python web framework, so I'll need to set up a Flask application. The basi...
c9b416a2d6cb7cf8c722a8839b8fcb76
You are tasked with implementing a `Rectangle` class in Python. The class should be initialized with a width and height. It must provide methods to compute the area, perimeter, and diagonal length of the rectangle. Additionally, it should include a method to scale the rectangle by a given factor, adjusting the width an...
To solve the problem, we need to implement a `Rectangle` class in Python that supports basic geometric operations such as calculating the area, perimeter, and diagonal length of a rectangle, and scaling the rectangle by a given factor. --- ### ✅ **Key Requirements** 1. **Initialization**: - The class should accep...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing the initializer, area, perimeter, diagonal, and scale methods as described in the question."}, "logical_correctness": {"score": 5, "justification": "The logic implemented in the methods is comp...
["\nassert Rectangle(3, 4).area() == 12\n", "\nassert Rectangle(5, 5).perimeter() == 20\n", "\nassert Rectangle(3, 4).diagonal() == 5.0\n", "\nassert Rectangle(1, 1).area() == 1\n", "\nassert Rectangle(0, 0).perimeter() == 0\n", "\nassert Rectangle(6, 8).diagonal() == 10.0\n", "\nrect = Rectangle(2, 3); rect.scale(3); ...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to create a Rectangle class in Python. Let me think about what's required. The class should be initialized with width and height. So the __init__ method will take those two parameters and assign them to instance variables. Maybe self.width and self.height. Then there are methods for area, perimeter, and d...
487b98f8f0537501173ed1f6aeb00593
You are tasked with implementing a simple banking system in Python. The system should support the following operations: 1. **Create Account**: Create a new bank account for a customer. Each account should have a unique account number, customer name, and initial balance. The initial balance must be non-negative. 2. **D...
To implement a simple banking system in Python, we need to support the following operations: 1. **Create Account** – Create a new account with a unique account number, customer name, and non-negative initial balance. 2. **Deposit** – Add a non-negative amount to an existing account. 3. **Withdraw** – Subtract a non-ne...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements, including creating bank accounts, depositing and withdrawing funds, displaying account information, and handling errors for invalid operations. It also provides a simple command-line interface for interacting...
["\nassert BankAccount(\"Alice\", 100).balance == 100\n", "\nassert BankAccount(\"Bob\", 0).balance == 0\n", "\nassert BankAccount(\"Charlie\", 50).account_number == 1001\n", "\naccount = BankAccount(\"David\", 200); account.deposit(50); assert account.balance == 250\n", "\naccount = BankAccount(\"Eve\", 300); account....
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to implement a simple banking system in Python based on the given requirements. Let me think about how to approach this. First, the system needs to handle creating accounts, depositing, withdrawing, and displaying account info. Also, handle invalid operations with error messages. The input is a series of ...
4920271a8514e3d7ba1dba23f24f69fe
You are given a string `s` consisting of characters `(`, `)`, `[`, `]`, `{`, and `}`. Your task is to determine if the string is valid. A string is considered valid if: - Every opening bracket has a corresponding closing bracket of the same type. - Opening brackets are closed in the correct order. For example, the str...
To determine whether a string consisting of brackets is valid, we need to ensure that: 1. **Every opening bracket has a corresponding closing bracket** of the same type. 2. **Opening brackets are closed in the correct order**, i.e., the most recent opening bracket must be closed first. This problem is a classic use c...
generic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirements of checking if the brackets are closed by the same type and in the correct order. However, it incorrectly returns False for any non-bracket characters, which is not specified in the requirements."}, "logical_correctn...
["\nassert is_valid(\"([{}])\") == True\n", "\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(\"([}\") ...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to solve this problem where I have to check if a string of brackets is valid. Let me think about how to approach this. So the problem says that a valid string must have every opening bracket closed in the correct order. Like, if there's a '(', it must be closed by a ')', and the order matters. For exampl...
e4da1dd91738ed7df85f13f2b0877170
You are given a list of integers. Your task is to find the longest subsequence in which the absolute difference between any two consecutive elements is exactly 1. If there are multiple subsequences of the same maximum length, return any one of them. **Input:** - A list of integers `nums` (1 ≤ len(nums) ≤ 10^3), where ...
To solve the problem of finding the **longest subsequence** in a list of integers such that the **absolute difference between any two consecutive elements is exactly 1**, we can use a **dynamic programming** approach that tracks the length of the longest valid subsequence ending at each index and keeps track of the **p...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function correctly implements the logic to find the longest subsequence where the difference between consecutive elements is exactly 1 and handles the case of multiple subsequences with the same maximum length by returning any one of them."}, "logical_corre...
["\nassert longest_subsequence_with_diff_1([1, 2, 3]) == [1, 2, 3]\n", "\nassert longest_subsequence_with_diff_1([1, 3, 5, 4, 3, 2, 1]) in [[5, 4, 3, 2, 1], [1, 2, 3]]\n", "\nassert longest_subsequence_with_diff_1([1, 4, 3, 2, 3, 4, 5]) in [[2, 3, 4, 5], [3, 4, 5]]\n", "\nassert longest_subsequence_with_diff_1([1, 1, 1...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to solve this problem where I have to find the longest subsequence in a list of integers such that the absolute difference between consecutive elements is exactly 1. And if there are multiple such subsequences with the same maximum length, return any one of them. Let me think about how to approach this. F...
fa3596d237bac3257d100e1ba6542fc7
You are tasked with implementing a `Book` class in Python to manage a library's inventory. The class should support the following functionalities: - Initialize a book with its title, author, ISBN, published year, and the number of available copies. - Check if the book is available for borrowing. - Borrow a book if ava...
To manage a library's inventory effectively, we implement a `Book` class in Python that supports the following core functionalities: - **Initialization** with title, author, ISBN, published year, and available copies. - **Availability check** to determine if the book can be borrowed. - **Borrowing** a book if availabl...
generic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The class Book meets the basic requirements by defining the necessary attributes and methods. However, it does not specify the types of the attributes or include any docstrings for the methods or class."}, "logical_correctness": {"score": 4, "justification": "T...
["\nassert Book(\"1984\", \"George Orwell\", \"1234567890\", 1949, 3).title == \"1984\"\n", "\nassert Book(\"1984\", \"George Orwell\", \"1234567890\", 1949, 3).author == \"George Orwell\"\n", "\nassert Book(\"1984\", \"George Orwell\", \"1234567890\", 1949, 3).isbn == \"1234567890\"\n", "\nassert Book(\"1984\", \"Geor...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a Book class in Python that manages a library's inventory. Let me think about the requirements. First, the class should initialize with title, author, ISBN, published year, and number of available copies. So the __init__ method will take those parameters and assign them as instance variables. Le...
18eaeed48742afbe9cf80b17c2442871
You are given two non-decreasing singly linked lists `l1` and `l2`. Your task is to merge these two lists into one sorted linked list. The new list should be constructed by splicing together the nodes of the first two lists in sorted order. Return the head of the merged linked list. **Input:** - Two non-decreasing sin...
To solve the problem of merging two non-decreasing singly linked lists into one sorted list, we can leverage a **two-pointer approach** similar to the merge step in the **merge sort algorithm**. This ensures that the resulting list remains sorted in non-decreasing order. --- ### ✅ **Approach** 1. **Initialize a dumm...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of merging two sorted linked lists into a single sorted linked list by splicing together the nodes."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It ef...
["\nassert mergeTwoLists(ListNode(1, ListNode(2, ListNode(4))), ListNode(1, ListNode(3, ListNode(4)))) == ListNode(1, ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(4))))))\n", "\nassert mergeTwoLists(ListNode(1, ListNode(3, ListNode(5))), ListNode(2, ListNode(4, ListNode(6)))) == ListNode(1, ListNode(2, List...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "pass", "fail", "fail"]
0.1
Okay, I need to merge two sorted linked lists into one sorted list. Let me think about how to approach this. So, the lists are non-decreasing, which means each node's value is less than or equal to the next node's value. The merged list should also be sorted. The key here is to combine them in a way that maintains th...
938fb01469396ee10a4dc1eeb88a2e13
You are given an array of integers `arr` and an integer `pivot_index`. Rearrange the elements in the array such that all elements less than the pivot value are moved to the left of the pivot position, and all elements greater than the pivot value are moved to the right of the pivot position. The pivot value itself shou...
To solve the problem of rearranging an array based on a given pivot index, we need to ensure that all elements less than the pivot value are moved to the left, all elements greater than the pivot value are moved to the right, and the pivot value itself is placed in its final sorted position. The relative order of eleme...
generic
evol-instruct
{"requirement_conformance": {"score": 3, "justification": "The solution attempts to rearrange the elements based on the pivot value but does not maintain the relative order of equal elements. It also incorrectly shifts elements smaller than the pivot to the beginning, which is not required."}, "logical_correctness": {"...
["\nassert three_way_partition([4, 5, 3, 2, 4, 8, 9, 4], 3) == [2, 3, 4, 4, 4, 8, 9, 5]\n", "\nassert three_way_partition([1, 2, 3, 4, 5], 2) == [1, 2, 3, 4, 5]\n", "\nassert three_way_partition([5, 4, 3, 2, 1], 2) == [2, 1, 3, 4, 5]\n", "\nassert three_way_partition([1, 1, 1, 1, 1], 2) == [1, 1, 1, 1, 1]\n", "\nassert...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to solve this problem where I have to rearrange an array based on a pivot index. Let me read the problem again carefully. The task is to rearrange the array such that all elements less than the pivot value are moved to the left of the pivot position, elements greater than the pivot are moved to the right,...
939ed97b821abd2b2ed86b975f041cb0
You are tasked with writing a Python program that computes the factorial of a non-negative integer using recursion. Your program should handle invalid inputs gracefully by raising a `ValueError` with an appropriate message if a negative integer is provided. **Input:** - A single integer `n` (0 ≤ n ≤ 20). **Output:**...
To compute the factorial of a non-negative integer using recursion in Python, we can implement a recursive function that follows the mathematical definition of factorial: - **Base Case:** `factorial(0) = 1` - **Recursive Case:** `factorial(n) = n * factorial(n - 1)` The program should also handle invalid inputs, spec...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by providing a recursive function to calculate the factorial and includes error handling for negative inputs."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct, with a proper base ...
["\nassert factorial(0) == 1\n", "\nassert factorial(1) == 1\n", "\nassert factorial(5) == 120\n", "\nassert factorial(7) == 5040\n", "\nassert factorial(10) == 3628800\n", "\nassert factorial(3) == 6\n", "\nassert factorial(15) == 1307674368000\n", "\ntry: factorial(-1); assert False except ValueError: assert True\n",...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to write a Python program that calculates the factorial of a non-negative integer using recursion. And handle invalid inputs by raising a ValueError if the input is negative. Let me think about how to approach this. First, the input is a single integer n. The constraints are 0 ≤ n ≤ 20. So, the program sh...
65ebf80ded38e6808f24a78bb84f43b1
You are given a string `s`. Your task is to implement a function `count_vowels` that returns the number of vowels (a, e, i, o, u) present in the string. The function should be case-insensitive. **Input:** - A single string `s` (1 ≤ |s| ≤ 10^5), consisting of alphabetic characters. **Output:** - An integer representi...
To solve the problem of counting the number of vowels in a given string, we can follow a clear and efficient approach. The key points to consider are: - The string may contain both uppercase and lowercase letters. - We need to count all vowels (`a`, `e`, `i`, `o`, `u`) regardless of their case. - The solution should b...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by counting vowels in a case-insensitive manner."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and efficiently counts the vowels in the input string."}, "edge_case_consideration...
["\nassert count_vowels(\"hello\") == 2\n", "\nassert count_vowels(\"HELLO\") == 2\n", "\nassert count_vowels(\"Python Programming\") == 4\n", "\nassert count_vowels(\"AEIOU\") == 5\n", "\nassert count_vowels(\"bcdfg\") == 0\n", "\nassert count_vowels(\"\") == 0\n", "\nassert count_vowels(\"abcdefghijklmnopqrstuvwxyz\"...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function called count_vowels that takes a string and returns the number of vowels in it. The vowels are a, e, i, o, u, and it should be case-insensitive. So both uppercase and lowercase letters count. Let me think about how to approach this. First, I should probably convert the entire string to...
5c3f7436f4504d98a010e77bc114fc7b
You are given a list of strings. Your task is to write a function that sorts the list first by the length of the strings in ascending order, and then alphabetically for strings of the same length. **Input:** - A list of strings, `strings`, where each string consists of lowercase English letters. **Output:** - A list...
To solve the problem of sorting a list of strings by their length in ascending order and, for strings of the same length, alphabetically, we can leverage Python's built-in `sorted()` function with a custom key. --- ### ✅ Problem Breakdown - **Input**: A list of strings, all consisting of lowercase English letters. -...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by sorting the list of strings first by their length and then by alphabetical order if the lengths are the same."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally stru...
["\nassert sort_strings_by_length_and_alphabet([\"banana\", \"apple\", \"cherry\", \"date\", \"fig\", \"grape\"]) == [\"fig\", \"date\", \"apple\", \"grape\", \"banana\", \"cherry\"]\n", "\nassert sort_strings_by_length_and_alphabet([\"a\", \"bb\", \"ccc\", \"dddd\"]) == [\"a\", \"bb\", \"ccc\", \"dddd\"]\n", "\nassert...
["pass", "pass", "pass", "pass", "pass", "fail", "fail", "pass", "pass", "pass"]
0.8
Okay, I need to write a Python function that sorts a list of strings first by their length and then alphabetically if they have the same length. Let me think about how to approach this. So the input is a list of strings, all lowercase. The output should be sorted first by length ascending. So shorter strings come firs...
1d8ef06967c8e03d59ec4e52533d84e8
You are given a list of dictionaries. Your task is to write a Python function that constructs a new list of dictionaries. Each dictionary in the new list should contain only the keys that are present in all dictionaries from the input list. The values associated with these keys in the new list should be the values from...
To solve the problem of extracting a list of dictionaries that only contain keys common across all input dictionaries, we can follow a structured approach that ensures we identify the intersection of keys and then filter each dictionary accordingly. --- ### ✅ Problem Summary Given a list of dictionaries, the goal is...
generic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements by returning a new list of dictionaries with only the keys present in all dictionaries. However, it does not handle the case where the input list contains only one dictionary, which should return the same dictionary."},...
["\nassert common_keys_dicts([{\"a\": 1, \"b\": 2}, {\"a\": 3, \"b\": 4}, {\"a\": 5, \"b\": 6}]) == [{\"a\": 1, \"b\": 2}, {\"a\": 3, \"b\": 4}, {\"a\": 5, \"b\": 6}]\n", "\nassert common_keys_dicts([{\"a\": 1, \"b\": 2}, {\"a\": 3, \"c\": 4}, {\"a\": 5, \"d\": 6}]) == [{\"a\": 1}, {\"a\": 3}, {\"a\": 5}]\n", "\nassert...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to solve this problem where I have to create a new list of dictionaries that only include the keys present in all the input dictionaries. Let me think about how to approach this. First, the input is a list of dictionaries. Each dictionary might have different keys. The output should be a list where each d...
1e5d10e1fb114c83e86456f27833e5ba
You are given a list of temperatures in Fahrenheit. Your task is to write a Python function `convert_to_celsius` that converts each temperature to Celsius and returns a new list with the converted values. The function should handle edge cases where the input list is empty or contains invalid data types (non-numeric val...
To solve the problem of converting a list of Fahrenheit temperatures to Celsius, we need to ensure that the input is valid and that each element is a numeric type (`int` or `float`). We also need to handle edge cases, such as empty lists or invalid inputs, by raising appropriate exceptions. Here is a well-structured a...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by converting a list of temperatures from Fahrenheit to Celsius and handling edge cases where the input list is empty or contains invalid data types."}, "logical_correctness": {"score": 5, "justification": "The logic fo...
["\nassert convert_to_celsius([32, 212, 98.6]) == [0.0, 100.0, 37.0]\n", "\nassert convert_to_celsius([0, 100]) == [-17.77777777777778, 37.77777777777778]\n", "\nassert convert_to_celsius([-40, 122]) == [-40.0, 50.0]\n", "\nassert convert_to_celsius([]) == []\n", "\nassert convert_to_celsius([32.0]) == [0.0]\n", "\nass...
["pass", "pass", "pass", "pass", "pass", "pass", "fail", "fail", "fail", "fail"]
0.6
Okay, I need to write a Python function called convert_to_celsius that takes a list of temperatures in Fahrenheit and converts them to Celsius. Let me think about the requirements. First, the function should return a new list with the converted values. So for each element in the input list, I need to apply the convers...
fd67b5acfb0801fedefe5bab3e29bcb7
You are given two lists, `x_values` and `y_values`, representing the x and y coordinates of a set of data points, respectively. Your task is to implement a function `calculate_polynomial_error` that takes a polynomial function `p` and these two lists as input. The function should compute and return the sum of the squar...
To solve the problem of computing the **sum of squared errors** between a polynomial function and a set of observed data points, we need to follow a clear and efficient approach. --- ### ✅ Problem Breakdown Given: - A polynomial function `p(x)` that maps an `x` value to a predicted `y` value. - Two lists: - `x_val...
generic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements by calculating the sum of squared differences between the predicted and actual y-values. However, it does not explicitly handle the efficiency requirement for up to 100,000 data points, although the current implementati...
["\nassert calculate_polynomial_error(lambda x: x, [0, 1, 2], [0, 1, 2]) == 0.0\n", "\nassert calculate_polynomial_error(lambda x: x + 1, [0, 1, 2], [0, 1, 2]) == 3.0\n", "\nassert calculate_polynomial_error(lambda x: 2 * x + 3, [1, 2, 3], [5, 7, 9]) == 0.0\n", "\nassert calculate_polynomial_error(lambda x: x**2, [1, 2...
["pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "fail"]
0.8
Okay, I need to write a function called calculate_polynomial_error. Let me think about what it needs to do. The function takes a polynomial p and two lists x_values and y_values. The goal is to compute the sum of squared differences between the predicted y-values (from p) and the actual y_values. So, for each x in x_v...
991788da824eb10eb67df18d14c86593
You are given a list of vaccine batches, each with a specific midichlorians count, and a list of infected patients, each with a specific midichlorians count. Each vaccine can only be used once and can only cure one patient. A patient is cured if the midichlorians count of the vaccine is strictly greater than the midich...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirements of sorting the vaccine strengths and patient midichlorians counts, and then comparing them to determine if all patients can be cured. However, it does not explicitly maximize the midichlorians count left in the vacci...
["\nassert can_cure_all_patients([5, 3, 4], [1, 2, 3]) == 3\n", "\nassert can_cure_all_patients([1, 2, 3], [3, 2, 1]) == -1\n", "\nassert can_cure_all_patients([10, 20, 30], [1, 2, 3]) == 54\n", "\nassert can_cure_all_patients([100, 200, 300], [50, 150, 250]) == 150\n", "\nassert can_cure_all_patients([10, 20, 30], [10...
["fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"]
0.8
Okay, I need to solve this problem. Let me read it carefully again. The problem says that we have a list of vaccines and a list of patients, each with their midichlorians counts. Each vaccine can be used once to cure exactly one patient. A patient is cured if the vaccine's midichlorians count is strictly greater than ...
47f952c00c6456e2945dba484c9df80d
You are given a string `s` consisting of words separated by spaces. Your task is to write a Python function that converts the string into a list of words and counts the frequency of each word. The function should return a dictionary where each key is a word and its corresponding value is the frequency of that word in t...
To solve the problem of counting the frequency of each word in a given string without using built-in functions like `split()` or `Counter()`, we can follow a manual approach that involves: 1. **Parsing the string into words** by iterating through each character and building words as we encounter non-space characters. ...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements. It converts a given string into a list of words and counts the frequency of each word without using built-in functions like split() or Counter()."}, "logical_correctness": {"score": 5, "justification": "T...
["\nassert word_frequency(\"hello world hello everyone\") == {'hello': 2, 'world': 1, 'everyone': 1}\n", "\nassert word_frequency(\"Python is great and python is fun\") == {'python': 2, 'is': 2, 'great': 1, 'and': 1, 'fun': 1}\n", "\nassert word_frequency(\"Test test TEST\") == {'test': 3}\n", "\nassert word_frequency(...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a Python function that takes a string and returns a dictionary with word frequencies. The constraints say I can't use split() or Counter(), so I have to do it manually. Let's think about how to approach this. First, I need to split the string into words. Since the words are separated by spaces, m...
f9b2f3ee63b8a6e567066b72334d42d6
You are given two integers, `numerator` and `denominator`, representing a fraction. Your task is to convert this fraction into its decimal representation as a string. If the decimal part is repeating, enclose the repeating part in parentheses. However, if the repeating part is longer than 5 digits, truncate it to the f...
To solve the problem of converting a fraction into its decimal representation with repeating parts enclosed in parentheses and truncated if necessary, we use a combination of division and remainder tracking to detect repeating decimals. --- ### ✅ **Approach Overview** 1. **Handle Special Cases**: - If the numerat...
algorithmic
evol-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirements of converting a fraction to a string format and handling repeating decimals. However, it does not limit the length of the repeating part to 5 digits correctly; it limits the entire repeating sequence to 5 characters ...
["\nassert fraction_to_decimal(1, 3) == \"0.(3)\"\n", "\nassert fraction_to_decimal(2, 1) == \"2\"\n", "\nassert fraction_to_decimal(4, 333) == \"0.(012)\"\n", "\nassert fraction_to_decimal(1, 2) == \"0.5\"\n", "\nassert fraction_to_decimal(22, 7) == \"3.(14285)\"\n", "\nassert fraction_to_decimal(0, 5) == \"0\"\n", "\...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function that converts a fraction into its decimal representation, handling repeating decimals by enclosing them in parentheses. Also, if the repeating part is longer than 5 digits, I have to truncate it to the first five. Let me think about how to approach this. First, I remember that when you...
901cc51ca9a56e6df800e90c09d6d9a7
You are given a positive integer `n`. Your task is to determine whether `n` is a perfect number. A perfect number is defined as a positive integer that is equal to the sum of its proper divisors, excluding the number itself. For example, 6 is a perfect number because its proper divisors are 1, 2, and 3, and 1 + 2 + 3 =...
To determine whether a given positive integer `n` is a **perfect number**, we need to check if the **sum of its proper divisors** (excluding the number itself) equals `n`. A **proper divisor** of a number `n` is a positive integer less than `n` that divides `n` exactly. --- ### ✅ **Approach** We can efficiently find...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing a function `is_perfect` that checks if a number is a perfect number and tests it with the number 28."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The function...
["\nassert is_perfect(6) == True\n", "\nassert is_perfect(28) == True\n", "\nassert is_perfect(496) == True\n", "\nassert is_perfect(8128) == True\n", "\nassert is_perfect(33550336) == True\n", "\nassert is_perfect(12) == False\n", "\nassert is_perfect(1) == False\n", "\nassert is_perfect(0) == False\n", "\nassert is_p...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a Python function to determine if a given integer n is a perfect number. Let me think about what a perfect number is. Oh right, a perfect number is equal to the sum of its proper divisors, excluding itself. So for example, 6's divisors are 1, 2, 3, and their sum is 6. So the function should return...
983188704dad1f05a49f3cacb3155c86
You are given a sorted array of integers and a target integer. Implement a function to find the index of the target in the array using the binary search algorithm. If the target is not present in the array, return -1. **Input:** - The first line contains an integer `n` (1 ≤ n ≤ 10^5), the number of elements in the ar...
To solve the problem of finding the index of a target integer in a sorted array using the binary search algorithm, we follow a structured approach that leverages the sorted nature of the array to efficiently narrow down the search space. --- ### ✅ **Approach Overview** Binary search is an efficient algorithm that wo...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing the binary search algorithm in Python and explaining its time complexity."}, "logical_correctness": {"score": 5, "justification": "The binary search algorithm is implemented correctly with no logical err...
["\nassert binary_search([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], 11) == 5\n", "\nassert binary_search([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], 1) == 0\n", "\nassert binary_search([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], 19) == 9\n", "\nassert binary_search([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], 20) == -1\n", "\nassert binary_search...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to implement a binary search algorithm to find the index of a target in a sorted array. Let's think about how binary search works. So, binary search works by repeatedly dividing the search interval in half. The array is sorted, so we can compare the target with the middle element. If the target is equal ...
63e854ca4ba41ad015035a042df01841
You are given an integer `n`. Your task is to write a function `prime_factors` that returns a list of its prime factors, with each factor appearing as many times as it divides `n`. **Input:** - An integer `n` (1 ≤ n ≤ 10^6) **Output:** - A list of integers representing the prime factors of `n`, in non-decreasing orde...
To solve the problem of finding the prime factors of a given integer `n` with each factor appearing as many times as it divides `n`, we can use a simple and efficient algorithm based on trial division. This method systematically checks for divisibility by increasing integers starting from the smallest prime, 2, and con...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by returning a list of prime factors with each factor appearing as many times as it divides the input integer."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally struct...
["\nassert prime_factors(84) == [2, 2, 3, 7]\n", "\nassert prime_factors(28) == [2, 2, 7]\n", "\nassert prime_factors(29) == [29]\n", "\nassert prime_factors(1) == []\n", "\nassert prime_factors(100) == [2, 2, 5, 5]\n", "\nassert prime_factors(49) == [7, 7]\n", "\nassert prime_factors(2) == [2]\n", "\nassert prime_fact...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function called prime_factors that takes an integer n and returns a list of its prime factors, with each factor appearing as many times as it divides n. The output should be in non-decreasing order. Let's think about how to approach this. First, I remember that prime factorization involves brea...
751656b4ae1a563d1e9674b76bfd4fb1
You are given a list of integers. Your task is to write a function that returns the second highest unique number in the list. If the list contains fewer than two unique numbers, the function should return `None`. **Input:** - A list of integers `numbers` (1 ≤ len(numbers) ≤ 10^5), where each integer is in the range [-...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by returning the second highest number or None if there are fewer than two unique numbers."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The function uses a set to remove dupl...
["\nassert find_second_highest([10, 20, 20, 30, 40, 50]) == 40\n", "\nassert find_second_highest([5, 5, 5, 5, 5]) == None\n", "\nassert find_second_highest([100]) == None\n", "\nassert find_second_highest([1, 2]) == 1\n", "\nassert find_second_highest([10, 10, 20]) == 10\n", "\nassert find_second_highest([3, 1, 4, 1, 5...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function that finds the second highest unique number in a list. Let's think about how to approach this. First, the problem says that if there are fewer than two unique numbers, return None. So, for example, if all elements are the same, or there's only one unique value, then return None. So th...
42d4c1f855f46a067c39e8c2bb2c7cff
You are tasked with implementing a `Rectangle` class in Python. The class should have the following functionalities: 1. An initializer method that takes two parameters: `width` and `height`. 2. A method `get_area` that returns the area of the rectangle. 3. A method `get_perimeter` that returns the perimeter of the rec...
Here's the implementation of the `Rectangle` class in Python, which satisfies all the specified requirements: --- ### ✅ **Implementation Overview** The `Rectangle` class is designed to encapsulate the properties and behaviors of a rectangle, including: - **Initialization** with `width` and `height`. - **Computing**...
generic
self-instruct
{"requirement_conformance": {"score": 3, "justification": "The solution meets basic requirements by defining a Rectangle class with methods to calculate area and perimeter, and a string representation. However, it does not include additional features or properties that might be expected, such as setters or validation f...
["\nassert Rectangle(3, 4).get_area() == 12\n", "\nassert Rectangle(5, 5).get_area() == 25\n", "\nassert Rectangle(0, 10).get_area() == 0\n", "\nassert Rectangle(7, 3).get_perimeter() == 20\n", "\nassert Rectangle(1, 1).get_perimeter() == 4\n", "\nassert Rectangle(10, 0).get_perimeter() == 20\n", "\nassert str(Rectangl...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a Rectangle class in Python based on the given requirements. Let me think through each part step by step. First, the initializer method. The class should take width and height as parameters. So the __init__ method will have self, width, and height as arguments. I'll assign those to instance vari...
f4b85c49f5f1a369628b20232279051e
You are developing a financial analysis module for a software application. Your task is to implement a function `calculate_compound_interest` that computes the total amount of money accumulated after a specified period, including interest, using the compound interest formula. The function should accept four parameters:...
To compute the total amount of money accumulated after a specified period using compound interest, we can implement the function `calculate_compound_interest` based on the well-known compound interest formula: $$ A = P \left(1 + \frac{r}{n}\right)^{nt} $$ Where: - $ A $ is the total amount after time $ t $, - $ P $ i...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function correctly implements all the specified requirements by taking in the four parameters (principal, rate, time, and compounded) and using them to calculate the total amount of money after the specified period of time using the compound interest formul...
["\nassert calculate_compound_interest(1000, 0.05, 1, 1) == 1050.0\n", "\nassert calculate_compound_interest(1500, 0.043, 6, 4) == 1938.842000777603\n", "\nassert calculate_compound_interest(2000, 0.06, 5, 12) == 2697.714735320319\n", "\nassert calculate_compound_interest(500, 0.03, 10, 2) == 674.4271247461903\n", "\na...
["pass", "fail", "fail", "fail", "fail", "fail", "fail", "pass", "pass", "pass"]
0.4
Okay, I need to write a Python function called calculate_compound_interest that takes four parameters: principal, rate, time, and compounded. The goal is to compute the total amount using the compound interest formula. Let me think about how to approach this. First, the formula is A = P * (1 + r/n) ** (n*t). So I need...
0040f96fddfef7e93ce6cc08a3ebb2f0
You are given a string `text`. Your task is to implement a function `count_words(text)` that returns a dictionary with the frequency of each unique word in the text, ignoring case and common English stop words. The function should handle punctuation and special characters appropriately. **Input:** - A single string `t...
To solve the problem of counting unique words in a given text while ignoring case, punctuation, and common English stop words, we can follow a structured and efficient approach using Python's built-in string and dictionary functionalities. --- ### ✅ **Step-by-Step Breakdown** 1. **Normalize Case**: Convert the entir...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements: it is case-insensitive, ignores common English stop words, and returns a dictionary with word counts. A simple test case is also provided."}, "logical_correctness": {"score": 5, "justification": "The logic is...
["\nassert count_words(\"The quick brown fox jumps over the lazy dog.\") == {'quick': 1, 'brown': 1, 'fox': 1, 'jumps': 1, 'over': 1, 'lazy': 1, 'dog': 1}\n", "\nassert count_words(\"Python is great and Python is fun.\") == {'python': 2, 'great': 1, 'fun': 1}\n", "\nassert count_words(\"Hello world! Hello everyone.\") ...
["fail", "pass", "pass", "fail", "pass", "fail", "pass", "fail", "pass", "pass"]
0.6
Okay, I need to write a Python function called count_words that takes a text string and returns a dictionary with word frequencies. But there are some conditions. Let me think about what needs to be done here. First, the function should ignore case. So words like "Python" and "python" should be considered the same. So...
7ccd5a38bfad17714ef7e40a565d579c
You are given a dataset of movie ratings represented as a 2D NumPy array, where each row corresponds to a user and each column corresponds to a movie. The value at each cell indicates the rating given by the user to the movie. Implement a function `svd_recommend_movies` that applies Singular Value Decomposition (SVD) t...
To solve the problem of recommending movies using **Singular Value Decomposition (SVD)**, we follow a structured approach to analyze the user's rating history, compute the SVD of the rating matrix, and predict the ratings for unrated movies. --- ### ✅ **Problem Breakdown** We are given a 2D NumPy array `ratings_matr...
algorithmic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing SVD on the input ratings matrix and recommending movies to a user by predicting their ratings for unseen movies."}, "logical_correctness": {"score": 4, "justification": "The logic is largely correct and ...
["\nassert svd_recommend_movies(0, np.array([[5, 3, 0, 1], [4, 0, 0, 1], [1, 1, 0, 5], [1, 0, 0, 4], [0, 1, 5, 4]])) == (2, 3.0)\n", "\nassert svd_recommend_movies(1, np.array([[5, 3, 0, 1], [4, 0, 0, 1], [1, 1, 0, 5], [1, 0, 0, 4], [0, 1, 5, 4]])) == (2, 3.0)\n", "\nassert svd_recommend_movies(2, np.array([[5, 3, 0, 1...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to implement the svd_recommend_movies function. Let me think about how to approach this. First, the problem says to use Singular Value Decomposition (SVD) on the ratings matrix. Then, predict the ratings for movies not rated by the specified user, and find the movie with the highest predicted rating that...
766b79a9f0a6ddc649248ea79ca2b02a
You are tasked with implementing a function `calculate_discount(price, discount_rate)` for a shopping application. The function should compute the final price of a product after applying a discount. The discount rate is provided as a percentage. If the discount rate exceeds 100%, the function should return the string "...
To implement the `calculate_discount` function as specified, we need to ensure that the inputs are valid, handle edge cases such as invalid types and negative values, and compute the final price correctly based on the given discount rate. Below is a well-structured and tested implementation of the function: --- ### ✅...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements, including handling invalid discount rates, negative discount rates, and invalid input types."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently handles a...
["\nassert calculate_discount(100, 20) == 80.0\n", "\nassert calculate_discount(100, -10) == 110.0\n", "\nassert calculate_discount(100, 101) == \"Invalid discount rate\"\n", "\nassert calculate_discount(-100, 20) == \"Invalid price: Price cannot be negative.\"\n", "\nassert calculate_discount(\"100\", 20) == \"Invalid...
["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0
Okay, I need to implement the calculate_discount function according to the given requirements. Let me think through all the conditions step by step. First, the function takes two parameters: price and discount_rate. Both should be numeric. But the input could be invalid, like strings or other types. So the first thing...
94b3e95b8f0d5fc8e9b13a3fcc0de139
You are given a list of integers. Your task is to implement a function `remove_duplicates` that returns a new list containing only the unique elements from the original list, preserving the order of their first appearance. **Input:** - A list of integers `input_list` (1 ≤ len(input_list) ≤ 10^5), where each integer i...
To solve the problem of removing duplicates from a list of integers while preserving the order of the first occurrences, we can use a combination of a **set** and a **list**. --- ### ✅ **Approach** The key idea is to: 1. **Track seen elements** using a set for O(1) average time complexity membership checks. 2. **Pr...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by removing duplicates and maintaining the original order of the first occurrence of each element."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It use...
["\nassert remove_duplicates([1, 2, 3, 2, 1]) == [1, 2, 3]\n", "\nassert remove_duplicates([10, 20, 20, 10, 30]) == [10, 20, 30]\n", "\nassert remove_duplicates([5, 5, 5, 5, 5]) == [5]\n", "\nassert remove_duplicates([]) == []\n", "\nassert remove_duplicates([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert remove_dupl...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a function called remove_duplicates that takes a list of integers and returns a new list with only the unique elements, preserving the order of their first appearance. Let me think about how to approach this. So the problem is similar to removing duplicates but keeping the first occurrence. For e...
33e3724c731081d3dca9121c285db0a5
You are given a nested list of integers with arbitrary depth. Your task is to flatten this list and then form `n`-length tuples from the resulting list. Write a function `process_nested_list` that takes a nested list and an integer `n` as input and returns a list of `n`-length tuples. **Input:** - A nested list of int...
To solve the problem of flattening a nested list of integers and grouping the result into `n`-length tuples, we can break the task into two main steps: 1. **Flatten the nested list**: This involves recursively traversing the input list and extracting all integers, regardless of their depth in the nesting structure. 2....
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by handling nested lists of arbitrary depth and forming n-length tuples from the flattened list."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The `fl...
["\nassert process_nested_list([1, [2, 3], 4, [5, 6]], 2) == [(1, 2), (3, 4), (5, 6)]\n", "\nassert process_nested_list([1, [2, [3, [4, 5]]]], 2) == [(1, 2), (3, 4), (5,)]\n", "\nassert process_nested_list([1, 2, 3, 4, 5, 6, 7], 3) == [(1, 2, 3), (4, 5, 6), (7,)]\n", "\nassert process_nested_list([[1, 2, [3, 4]], [5, 6...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to write a Python function called process_nested_list that takes a nested list and an integer n, then returns a list of n-length tuples from the flattened list. Let me think about how to approach this. First, the problem says the nested list can have arbitrary depth. So I need to flatten it completely. Ho...
98289beeb6fb16983381060e84fc4100
You are given a string `s`. Your task is to implement a function `find_unique_characters` that returns a set of lowercase alphabetic characters that appear exactly once in the string, ignoring case sensitivity. **Input:** - A single string `s` (1 ≤ |s| ≤ 10^5), which may contain alphabetic characters, digits, and spe...
To solve the problem of identifying all lowercase alphabetic characters that appear **exactly once** in a given string (ignoring case sensitivity), we need to follow a structured approach that ensures we correctly process and count the characters. --- ### ✅ **Approach** 1. **Convert the string to lowercase**: - T...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements: it takes a string as input, returns a set of unique characters, ignores case sensitivity, and returns only lowercase characters."}, "logical_correctness": {"score": 5, "justification": "The logic is completel...
["\nassert find_unique_characters(\"Python Programming\") == {'h', 't', 'r', 'g', 'm'}\n", "\nassert find_unique_characters(\"Hello World\") == {'h', 'e', 'w', 'r', 'd'}\n", "\nassert find_unique_characters(\"AaBbCc\") == set()\n", "\nassert find_unique_characters(\"12345\") == set()\n", "\nassert find_unique_character...
["fail", "pass", "pass", "pass", "fail", "fail", "pass", "fail", "pass", "pass"]
0.6
Okay, I need to solve this problem where I have to find all the lowercase letters that appear exactly once in a given string, ignoring case. Let me think about how to approach this. First, the input string can have various characters: letters (both cases), digits, and symbols. But the output is only lowercase alphabet...
e64846fca45771b976cdeb5c12ea8040
You are tasked with implementing a class `Employee` that manages employee details and department transfers. The class should support the following operations: 1. **Initialization**: Create an `Employee` object with a name, ID, and department. 2. **Transfer**: Change the department of an employee. 3. **Display Informat...
Here's a well-structured implementation of the `Employee` class that meets all the specified requirements: --- ### ✅ **Class Overview** The `Employee` class is designed to manage an employee's details, including their name, ID, and department. It supports the following operations: 1. **Initialization**: Sets up the...
generic
self-instruct
{"requirement_conformance": {"score": 3, "justification": "The solution meets basic requirements by defining the Employee class with the specified attributes and methods. However, it does not include additional functionalities or details that might be expected, such as validation or more complex operations."}, "logical...
["\nassert Employee(\"John Doe\", 123, \"HR\").display_info() == \"Employee Name: John Doe, ID: 123, Department: HR\"\n", "\nassert Employee(\"Jane Smith\", 456, \"Engineering\").display_info() == \"Employee Name: Jane Smith, ID: 456, Department: Engineering\"\n", "\nassert Employee(\"Alice Johnson\", 789, \"Marketing\...
["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
1
Okay, I need to create a Python class called Employee that can manage employee details and department transfers. Let me think about what the requirements are. First, the class needs to be initialized with a name, ID, and department. So the __init__ method should take those three parameters. I'll assign them as instanc...
0ee1a639d459e50c1b41132fe91de0dc
Implement a Python class named `BankAccount` with the following functionalities: - **Constructor (`__init__`)**: Initialize the bank account with an optional `initial_deposit` parameter. If no initial deposit is provided, the balance should start at 0. If an initial deposit is provided, it should be added to the balan...
Here's a well-structured implementation of the `BankAccount` class in Python, as per the specified requirements. The class includes the constructor, deposit, withdrawal, and balance retrieval methods, all with appropriate validation to ensure correctness and robustness. --- ### ✅ **Class Overview** The `BankAccount`...
algorithmic
self-instruct
{"requirement_conformance": {"score": 4, "justification": "The solution meets the basic requirements of creating a BankAccount class with deposit, withdraw, and get_balance methods. However, it does not explicitly state that the balance should be initialized to the value of initial_deposit if provided, which is a minor...
["\nassert BankAccount().get_balance() == 0\n", "\nassert BankAccount(100).get_balance() == 100\n", "\nassert BankAccount(50).deposit(50) == None and BankAccount(50).get_balance() == 100\n", "\nassert BankAccount(100).withdraw(50) == None and BankAccount(100).get_balance() == 50\n", "\nassert BankAccount(100).withdraw(...
["pass", "pass", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"]
0.2
Okay, I need to create a Python class called BankAccount with the specified functionalities. Let me think about each part step by step. First, the constructor. The __init__ method should take an optional initial_deposit. If it's provided, add it to the balance, else start at 0. So in Python, I can set a parameter with...
51cefcbba357262acd731bd0c30cc844
You are tasked with implementing an efficient caching mechanism using a dictionary to store key-value pairs. The cache has a fixed capacity, and when it reaches its maximum size, the least recently used (LRU) item should be evicted to make space for new items. Your implementation should support two operations: `get` an...
To solve the problem of implementing an efficient LRU (Least Recently Used) cache with a fixed capacity, we need to manage a dictionary that stores key-value pairs and ensures that when the cache is full, the least recently used item is evicted. --- ### ✅ **Approach** We use the `OrderedDict` from Python's `collecti...
generic
self-instruct
{"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by implementing a caching mechanism with a fixed size and LRU eviction policy using OrderedDict."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The use...
["\nassert Cache(2).get(1) == None\n", "\nassert Cache(2).get(2) == None\n", "\ncache = Cache(2)\ncache.put(1, 1)\ncache.put(2, 2)\nassert cache.get(1) == 1\n", "\ncache = Cache(2)\ncache.put(1, 1)\ncache.put(2, 2)\ncache.put(3, 3)\nassert cache.get(2) == None\n", "\ncache = Cache(2)\ncache.put(1, 1)\ncache.put(2, 2)\n...
["fail", "fail", "pass", "fail", "fail", "fail", "pass", "fail", "fail", "pass"]
0.3
Okay, I need to implement an LRU cache using a dictionary. Let me think about how to approach this. The problem says that the cache has a fixed capacity, and when it's full, the least recently used item is evicted. So for each get and put operation, I have to manage the order of usage. First, I remember that LRU can b...
3fd7a16c71ea522d033da11dd1a59d49
You are given two integers, `settings` and `constants`, each representing a set of bits. Your task is to determine if every bit that is set to 1 in `constants` is also set to 1 in `settings`. Implement a function `check_bits(settings, constants)` that returns `True` if this condition is met, and `False` otherwise. You ...
To solve the problem of determining whether **every bit that is set to 1 in `constants` is also set to 1 in `settings`**, we must avoid using bitwise operators such as `&`, `|`, `^`, `<<`, or `>>`. Instead, we can use arithmetic operations to simulate the behavior of bitwise operations. --- ### 🔍 Problem Analysis T...
generic
evol-instruct
{"requirement_conformance": {"score": 5, "justification": "The function correctly implements the logic to check if all bits set to 1 in `constants` are also set to 1 in `settings` without using bitwise operators or converting numbers to binary strings."}, "logical_correctness": {"score": 5, "justification": "The logic ...
["\nassert check_bits(13, 9) == False\n", "\nassert check_bits(15, 9) == True\n", "\nassert check_bits(0, 0) == True\n", "\nassert check_bits(1, 1) == True\n", "\nassert check_bits(2, 1) == False\n", "\nassert check_bits(3, 3) == True\n", "\nassert check_bits(8, 8) == True\n", "\nassert check_bits(8, 12) == False\n", "...
["fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]
0.9
Okay, I need to solve this problem where I have to check if all the bits set to 1 in the constants are also set in the settings. Let me think about how to approach this without using bitwise operators or converting to binary strings. So the problem is essentially checking if the constants is a subset of the settings ...