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 |
|---|---|---|---|---|---|---|---|---|---|
f72f9ef44ab20ada9b74a9df53363704 | You are given a list of integers representing daily stock prices. Your task is to determine the maximum profit that can be achieved by buying and selling the stock once, where you must buy before you sell. If no profit can be made, return 0.
**Input:**
- A list of integers `nums` (1 ≤ len(nums) ≤ 10^5), where each int... | To solve the problem of finding the **maximum profit** from buying and selling a stock **once**, with the condition that you must **buy before you sell**, we need to find the optimal day to buy and the optimal day to sell such that the difference (profit) is maximized.
---
### 🔍 Problem Analysis
- You are given a l... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by finding the maximum difference between any two elements where the larger element comes after the smaller one and returns 0 if no such pair exists."}, "logical_correctness": {"score": 5, "justification": "The logic is... | ["\nassert max_difference([7, 1, 5, 3, 6, 4]) == 5\n", "\nassert max_difference([7, 6, 4, 3, 1]) == 0\n", "\nassert max_difference([1, 2, 3, 4, 5]) == 4\n", "\nassert max_difference([1, 2]) == 1\n", "\nassert max_difference([2, 1]) == 0\n", "\nassert max_difference([1]) == 0\n", "\nassert max_difference([]) == 0\n", "\... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass"] | 0.9 | Okay, I need to solve this problem where I have to find the maximum profit from buying and selling a stock once. The key is to buy before selling, so the sell day has to be after the buy day. And if there's no possible profit, return 0. Let me think about how to approach this.
So the input is a list of integers, each ... |
0c50b4ae466ce2212f2e7822091c3f51 | You are given a list of dictionaries and a key. Your task is to sort the list of dictionaries in ascending order based on the values associated with the given key. You must implement the sorting algorithm yourself without using any external libraries.
**Input:**
- A list of dictionaries, where each dictionary contain... | To solve the problem of sorting a list of dictionaries by a specified key without using built-in sorting functions, we can implement a **selection sort** algorithm. This approach is both straightforward and effective for this scenario.
---
### ✅ Problem Summary
- **Input:** A list of dictionaries where each dictiona... | algorithmic | self-instruct | {"requirement_conformance": {"score": 4, "justification": "The function sorts a list of dictionaries by a specified key and returns a new sorted list. It does not use any external libraries for sorting, which meets the requirements. However, the function modifies the original list instead of returning a new one."}, "lo... | ["\nassert sort_list_of_dicts([{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 20}, {'name': 'Charlie', 'age': 30}], 'age') == [{'name': 'Bob', 'age': 20}, {'name': 'Alice', 'age': 25}, {'name': 'Charlie', 'age': 30}]\n", "\nassert sort_list_of_dicts([{'name': 'Charlie', 'age': 30}, {'name': 'Bob', 'age': 20}, {'n... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to sort a list of dictionaries based on a specific key. The user wants me to implement the sorting algorithm myself, not using any external libraries. So I can't just use the built-in sort function. Hmm, right, so I have to think about how to do this manually.
First, I remember that sorting algorithms lik... |
c4ecc3a4559c2a24032bcd3af9872468 | Harry is searching a building with `N` floors, numbered from 1 to `N`. He starts his search on the first floor and must return to the first floor to finish his search. During his search, Harry can visit any floor at most twice, and the sequence of floors he visits (excluding the starting floor) must be strictly increas... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 3, "justification": "The solution addresses the requirement that Harry must finish his search on the floor from which he started, which is floor 1, and must not visit any floor more than twice. However, it does not ensure that the sequence of floors he visits (excluding the startin... | ["\nassert find_harry_sequences(1) is None\n", "\nassert find_harry_sequences(2) is None\n", "\nassert find_harry_sequences(3) is None\n", "\nassert find_harry_sequences(4) is None\n", "\nassert find_harry_sequences(5) is None\n", "\nassert find_harry_sequences(0) is None\n", "\nassert find_harry_sequences(-1) is None\... | ["pass", "pass", "pass", "pass", "pass", "fail", "fail", "pass", "pass", "pass"] | 0.8 | Okay, I need to figure out all possible sequences Harry can visit given the constraints. Let me start by understanding the problem thoroughly.
Harry starts at floor 1 and must end there. The sequence of floors he visits (excluding the starting floor) must be strictly increasing. Also, each floor can be visited at most... | |
423cf20d94d5c6cbc95bc0d5ef7bd995 | You are to implement a simple text-based role-playing game using Python classes. The game involves two characters, a player and an enemy. Each character has a name, health points (HP), and an attack power. The player can choose to attack the enemy or use a potion to restore HP. The enemy attacks the player automaticall... | To implement the described text-based role-playing game using Python classes, we define two main classes: `Player` and `Enemy`. Each character has a name, health points (HP), and attack power. The game loop alternates between the player's turn and the enemy's turn, allowing the player to either attack or use a potion t... | generic | self-instruct | {"requirement_conformance": {"score": 4, "justification": "The solution meets most of the requirements, including character attributes, attack functionality, potion usage, and game loop. However, it does not explicitly handle the scenario where the player chooses an invalid action multiple times in a row."}, "logical_c... | ["\nassert Character(\"Hero\", 100, 20).name == \"Hero\"\n", "\nassert Character(\"Hero\", 100, 20).hp == 100\n", "\nassert Character(\"Hero\", 100, 20).attack_power == 20\n", "\nassert Character(\"Hero\", 100, 20).is_alive() == True\n", "\nassert Character(\"Hero\", 0, 20).is_alive() == False\n", "\nassert str(Charact... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to create a text-based RPG game in Python using classes. Let me think about how to approach this. The game has a player and an enemy. Each has name, HP, attack power. The player can attack or use a potion. The enemy attacks automatically. The game ends when one's HP is zero.
First, I should define classes... |
98eea8af8b848183f569aa265b0cc1ba | You are tasked with implementing a function to simulate a dice game. In this game, a player rolls two six-sided dice. The player wins immediately if the sum of the dice is 7 or 11. The player loses immediately if the sum is 2, 3, or 12. For any other sum, the player continues to roll the dice until either the sum match... | To simulate the dice game as described, we need to model the game logic based on the rules provided:
- **Initial Roll**: The player rolls two six-sided dice.
- If the **sum is 7 or 11**, the player **wins immediately**.
- If the **sum is 2, 3, or 12**, the player **loses immediately**.
- For any **other sum**, t... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all the specified requirements of the dice game, including the initial roll conditions and the subsequent rolls until a win or loss condition is met."}, "logical_correctness": {"score": 5, "justification": "The logic of the function is ... | ["\nassert dice_game() in [\"Win\", \"Lose\"]\n", "\nassert dice_game() in [\"Win\", \"Lose\"]\n", "\nassert dice_game() in [\"Win\", \"Lose\"]\n", "\nassert dice_game() in [\"Win\", \"Lose\"]\n", "\nassert dice_game() in [\"Win\", \"Lose\"]\n", "\nassert dice_game() in [\"Win\", \"Lose\"]\n", "\nassert dice_game() in ... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function that simulates this dice game. Let me think about the rules again. So, the player rolls two six-sided dice. The sum determines the outcome immediately if it's 7 or 11, they win. If it's 2, 3, or 12, they lose. Otherwise, they keep rolling until they either match the initial sum (win) or... |
02bc25ea7ff682ef0182c5b0022be8ff | You are tasked with implementing a stack data structure in Python. Your stack should support the following operations:
- `push(item)`: Adds an item to the top of the stack.
- `pop()`: Removes and returns the item from the top of the stack. If the stack is empty, raise an `IndexError` with the message "pop from empty s... | To implement a stack data structure in Python, we can leverage the built-in `list` type, which naturally supports the operations required for a stack (Last-In-First-Out). The stack will support the following operations:
- `push(item)`: Adds an item to the top of the stack.
- `pop()`: Removes and returns the item from ... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing the `push`, `pop`, `peek`, and `is_empty` methods with appropriate error handling for invalid operations."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correc... | ["\nassert Stack().is_empty() == True\n", "\nassert Stack().peek() == None\n", "\ns = Stack(); s.push(1); assert s.peek() == 1\n", "\ns = Stack(); s.push(1); s.push(2); assert s.pop() == 2\n", "\ns = Stack(); s.push(1); s.push(2); s.pop(); assert s.peek() == 1\n", "\ns = Stack(); s.push(1); s.push(2); s.pop(); s.pop();... | ["pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.8 | Okay, I need to implement a stack in Python. Let me think about how to approach this. The stack should support push, pop, peek, and is_empty operations.
First, I remember that a stack is a LIFO structure. So the last item added is the first one to be removed. The easiest way to implement this in Python is using a lis... |
ae3d836f4dca5ec67729ae57eda2705a | You are given a list of lists, `data_list`, where each sublist represents a dataset. It is guaranteed that the length of `data_list` is a multiple of 3. Your task is to implement a function `find_indices(data_list)` that returns a list of indices corresponding to every third sublist in `data_list` (i.e., sublists at in... | To solve the problem, we need to identify the indices of every third sublist in a list of lists (`data_list`) that contains an **odd number of elements**. The key insight is that the indices of every third sublist in a list (starting from index 0) are those that satisfy the condition:
```
index % 3 == 2
```
This is b... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function correctly identifies every third sublist starting from index 2 and checks if it has an odd number of elements, fully meeting the requirements."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently... | ["\nassert find_indices([[1, 2], [3, 4], [5, 6, 7], [8, 9], [10, 11, 12], [13, 14, 15]]) == [2, 5]\n", "\nassert find_indices([[1], [2, 3], [4, 5, 6], [7, 8, 9], [10], [11, 12, 13, 14], [15, 16, 17]]) == [0, 3, 6]\n", "\nassert find_indices([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]) ==... | ["pass", "fail", "fail", "fail", "pass", "fail", "pass", "fail", "fail", "fail"] | 0.3 | Okay, let's see. I need to write a function called find_indices that takes a data_list, which is a list of lists. The problem says that the length of data_list is a multiple of 3. So, the total number of sublists is divisible by 3. My task is to find the indices of every third sublist that has an odd number of elements... |
05c9c7ccea234cf72be53ebd4e3bc649 | You are tasked with developing a function to extract unique email addresses from a provided text block. The function should return a list of unique email addresses found in the text. Assume that email addresses conform to the standard format (e.g., "user@example.com"). The input text may contain special characters and ... | To solve the problem of extracting **unique email addresses** from a given text block, we can use **regular expressions** to identify all valid email patterns and then ensure uniqueness by using a set to track which emails have already been added.
---
### ✅ **Approach Overview**
1. **Identify Email Patterns**:
- ... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by extracting and returning a list of unique email addresses from the given text."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct, using a regular expression to find email addres... | ["\nassert extract_unique_emails(\"user@example.com user@example.com\") == [\"user@example.com\"]\n", "\nassert extract_unique_emails(\"user1@example.com user2@example.com\") == [\"user1@example.com\", \"user2@example.com\"]\n", "\nassert extract_unique_emails(\"user.name+tag+sorting@example.com\") == [\"user.name+tag+... | ["pass", "fail", "pass", "pass", "fail", "pass", "fail", "pass", "pass", "pass"] | 0.7 | Okay, I need to write a function that extracts unique email addresses from a given text. Let me think about how to approach this.
First, I remember that email addresses usually follow a certain pattern. The standard format is something like user@domain.com. So maybe I can use a regular expression to find all occurrenc... |
823c707ef7e22ed0a381b088efe9c035 | You are tasked with implementing a function to determine the minimum number of delivery trips required for a delivery person to deliver all items specified in a 2D array. Each row in the array represents a delivery location, and each element in the row represents the quantity of items to be delivered to that location. ... | To determine the **minimum number of delivery trips** required for a delivery person to deliver all items in a 2D array, we need to understand the following key points from the problem:
- **Each row** in the `delivery_matrix` represents a set of **delivery locations**.
- **Each element** in a row represents the **quan... | algorithmic | self-instruct | {"requirement_conformance": {"score": 2, "justification": "The solution does not meet the requirement that each location requires a separate delivery, regardless of the quantity. It incorrectly calculates trips based on the sum of items for each location rather than treating each location as a separate delivery."}, "lo... | ["\nassert calculate_minimum_delivery_trips([[10]]) == 1\n", "\nassert calculate_minimum_delivery_trips([[11]]) == 2\n", "\nassert calculate_minimum_delivery_trips([[5, 5]]) == 1\n", "\nassert calculate_minimum_delivery_trips([[10, 10]]) == 2\n", "\nassert calculate_minimum_delivery_trips([[3, 4, 3]]) == 1\n", "\nasser... | ["pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "fail", "pass"] | 0.8 | Okay, let's see. I need to find the minimum number of trips required for a delivery person to deliver all items. The delivery_matrix is a 2D array where each row represents a delivery request, and each element in the row is the quantity for a location. The delivery person can carry up to 10 items per trip. And each loc... |
b78314fce01281b3b6e67ac87de579b3 | You are given a linear regression model with coefficients stored in a list `coefficients`, which contains the intercept and slope in that order. Implement a function `predict` that takes a list of input values `x_values` and the `coefficients` list as input and returns a list of predicted values. The function should ha... | To solve the problem of making predictions using a linear regression model, we implement a function `predict` that takes a list of input values `x_values` and a list of coefficients `[intercept, slope]` as inputs. The goal is to return a list of predicted values based on the linear model:
$$
\text{prediction} = \text{... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by taking a list of input values and coefficients, and returning a list of predicted values. It also handles the edge case where the input list is empty by returning an empty list."}, "logical_correctness": {"score": 5,... | ["\nassert predict([1, 2, 3, 4], [0, 1]) == [1, 2, 3, 4]\n", "\nassert predict([0, 0, 0], [5, 0]) == [5, 5, 5]\n", "\nassert predict([1, 2, 3], [0, 0]) == [0, 0, 0]\n", "\nassert predict([], [0, 1]) == []\n", "\nassert predict([1, 2, 3], [1, 1]) == [2, 3, 4]\n", "\nassert predict([-1, -2, -3], [0, 1]) == [-1, -2, -3]\n... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a Python function called predict that takes x_values and coefficients and returns the predicted values. Let me think about how linear regression works here. The model is y = intercept + slope * x. So for each x in x_values, the prediction is coefficients[0] + coefficients[1] * x.
First, I need t... |
48edb49d33ba4424b1cc95dd74c2f7af | You are given a sequence of $n$ matrices $M_1, M_2, \ldots, M_n$ to be multiplied together. Each matrix $M_i$ has dimensions $r_i \times c_i$. The matrices are defined over a finite field $\mathbb{F}_q$, where $q$ is a prime number. Your task is to determine the minimum number of scalar multiplications required to comp... | To solve the problem of determining the minimum number of scalar multiplications required to compute the product of a sequence of matrices over a finite field $\mathbb{F}_q$, we utilize a dynamic programming approach. This approach is based on the classic matrix chain multiplication problem, which is optimized using dy... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by correctly implementing the matrix chain multiplication algorithm and handling the input/output as specified."}, "logical_correctness": {"score": 5, "justification": "The logic for matrix chain multiplication is compl... | ["\nassert matrix_chain_multiplication(2, 5, [(2, 3), (3, 4)]) == 24\n", "\nassert matrix_chain_multiplication(3, 7, [(10, 30), (30, 5), (5, 60)]) == 4500\n", "\nassert matrix_chain_multiplication(4, 11, [(1, 2), (2, 3), (3, 4), (4, 5)]) == 38\n", "\nassert matrix_chain_multiplication(5, 13, [(5, 10), (10, 3), (3, 12),... | ["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 number of scalar multiplications required to multiply a sequence of matrices over a finite field. Let me think about how to approach this.
First, I remember that the matrix chain multiplication problem is a classic dynamic programming problem. The goa... |
2d2c799f52e48852037935086646e569 | In the upcoming Equestria Games, the stadium is arranged as a circular ring divided into $N$ sectors. Each sector exclusively hosts fans of a particular team, with the $i^\text{th}$ sector clockwise from the northernmost sector accommodating fans of team $A_i$. Each team is represented by a unique color. Media companie... | To solve this problem, we need to determine the maximum number of non-overlapping ranges in a circular stadium that meet specific criteria: each range must include a specific sector, have a minimum length, and contain a minimum number of distinct colors. Given the constraints of the problem, we can simplify the solutio... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 3, "justification": "The solution attempts to address the problem requirements but has some issues. It correctly handles the circular nature of the stadium and the need for consecutive ranges of at least K sectors with at least C distinct colors. However, it does not ensure that th... | ["\nassert max_broadcasting_rights(5, [1, 2, 3, 4, 5], 3, 2, 2) == 1\n", "\nassert max_broadcasting_rights(6, [1, 2, 3, 1, 2, 3], 1, 3, 3) == 2\n", "\nassert max_broadcasting_rights(7, [1, 1, 1, 1, 1, 1, 1], 4, 3, 1) == 2\n", "\nassert max_broadcasting_rights(8, [1, 2, 3, 4, 5, 6, 7, 8], 5, 4, 4) == 1\n", "\nassert max... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, let's try to figure out how to solve this problem. So, the problem is about finding the maximum number of non-overlapping ranges in a circular stadium that meet certain conditions. Let me break down the problem step by step.
First, the stadium is circular with N sectors. Each sector has a unique color (though th... |
b636667360aa192191ef90d9501fbe0f | You are given a list of tuples, where each tuple consists of a word and its frequency of occurrence. Your task is to construct two mappings: one that maps each word to a unique integer ID, and another that maps each ID back to the corresponding word. The words should be ordered by their frequency in descending order. I... | To solve the problem of mapping words to unique integer IDs and vice versa based on their frequency and original order, we can follow a structured approach that ensures efficiency and correctness, even for large input sizes.
---
### ✅ **Problem Breakdown**
- **Input**: A list of tuples, where each tuple is of the fo... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It creates two mappings as required, orders the words by decreasing frequency, and resolves ties by the order of appearance in the list."}, "logical_correctness": {"score": 4, "justification": "The logic is l... | ["\nassert create_mappings([('apple', 10), ('banana', 5), ('cherry', 10), ('date', 3)]) == ({'apple': 0, 'cherry': 1, 'banana': 2, 'date': 3}, {0: 'apple', 1: 'cherry', 2: 'banana', 3: 'date'})\n", "\nassert create_mappings([('apple', 10), ('banana', 10), ('cherry', 10), ('date', 10)]) == ({'apple': 0, 'banana': 1, 'ch... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to solve this problem where I have to create two mappings: one from words to unique IDs and another from IDs back to words. The words should be ordered by their frequency in descending order. And if two words have the same frequency, the one that comes first in the original list gets the lower ID. Let me t... |
a5b0cd3ed231c1ca0a6872177ad597e3 | You are given a nested list structure, which may contain integers and other nested lists. Your task is to write a function `unlistify` that recursively flattens this nested list into a single-level list while preserving the order of elements.
**Input:**
- A nested list `nested_list` where each element is either an in... | To solve the problem of flattening a nested list structure into a single-level list while preserving the order of elements, we can use **recursion**. The nested list may contain integers and further nested lists at any level of depth, and our goal is to recursively process each element, expanding lists as needed and co... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by using recursion to flatten a nested list and preserving the order of elements."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The function correctly... | ["\nassert unlistify([1, [2, [3, 4], 5], 6]) == [1, 2, 3, 4, 5, 6]\n", "\nassert unlistify([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert unlistify([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", "\nassert unlistify([[[[1]]]]) == [1]\n", "\nassert unlistify([]) == []\n", "\nassert unlistify([[]... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 | Okay, I need to write a function called unlistify that takes a nested list and returns a flattened version. Let me think about how to approach this.
So the input can be a list that contains integers or other lists. The output should be a single-level list with all the integers in order. For example, the sample input [... |
02fb3e193915d021ab8f2535374ead67 | You are given a positive integer `n`. Your task is to write a Python program that calculates the sum of all prime numbers less than `n` using the Sieve of Eratosthenes algorithm.
**Input:**
- A single integer `n` (2 ≤ n ≤ 10^6)
**Output:**
- A single integer representing the sum of all prime numbers less than `n`.
... | To solve the problem of finding the **sum of all prime numbers less than a given integer `n`**, we use the **Sieve of Eratosthenes** algorithm. This is an efficient method for generating all prime numbers up to a given limit, and it is particularly suitable for large values of `n` (up to $10^6$).
---
### ✅ **Approach... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by implementing the Sieve of Eratosthenes algorithm to calculate the sum of all prime numbers below a given number `n`."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimal... | ["\nassert sum_of_primes_below(10) == 17\n", "\nassert sum_of_primes_below(2) == 0\n", "\nassert sum_of_primes_below(1) == 0\n", "\nassert sum_of_primes_below(0) == 0\n", "\nassert sum_of_primes_below(20) == 77\n", "\nassert sum_of_primes_below(30) == 129\n", "\nassert sum_of_primes_below(50) == 328\n", "\nassert sum_o... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python program that calculates the sum of all prime numbers less than a given integer n using the Sieve of Eratosthenes algorithm. Let me think about how to approach this.
First, I remember that the Sieve of Eratosthenes is an efficient way to find all primes up to a certain limit. The basic id... |
6ba34097947fd7942a93bdeee3d2843c | You are tasked with implementing a function `calculate_discount` that computes the final price of a product after applying a given discount percentage. The function should accept two parameters: `price`, a floating-point number representing the original price of the product, and `discount_percentage`, a floating-point ... | To accurately compute the final price of a product after applying a given discount percentage and ensure proper rounding to two decimal places, we must account for the limitations of floating-point arithmetic. Python’s built-in `round()` function can sometimes lead to incorrect rounding due to how floating-point number... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements by taking two arguments, calculating the discounted price, and returning the result rounded to two decimal places."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and c... | ["\nassert calculate_discount(100, 20) == 80.00\n", "\nassert calculate_discount(123.45, 30) == 86.42\n", "\nassert calculate_discount(50, 0) == 50.00\n", "\nassert calculate_discount(200, 50) == 100.00\n", "\nassert calculate_discount(0, 20) == 0.00\n", "\nassert calculate_discount(99.99, 100) == 0.00\n", "\nassert ca... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function called calculate_discount that takes price and discount_percentage as parameters. The goal is to compute the final price after applying the discount and round it to two decimal places. Let me think about how to approach this.
First, the discount percentage is applied to the original pr... |
a7ce342076d16909fe00e2d729cf9716 | Implement an optimized version of the Bubble Sort algorithm to sort an array of integers in ascending order. Your implementation should be efficient and maintainable, without altering the original functionality. The function should return the sorted array.
**Sample Input:**
```python
[64, 34, 25, 12, 22, 11, 90]
```
... | To implement an **optimized version of the Bubble Sort** algorithm, we must focus on two key improvements:
1. **Early termination** using a `swapped` flag to detect if a pass through the array resulted in any swaps. If no swaps occur, the array is already sorted, and we can exit early.
2. **Reduced inner loop iteratio... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution refactors the original code without changing its functionality and meets all specified requirements."}, "logical_correctness": {"score": 5, "justification": "The solution is logically correct and optimally structured. It introduces an optimization ... | ["\nassert bubble_sort([64, 34, 25, 12, 22, 11, 90]) == [11, 12, 22, 25, 34, 64, 90]\n", "\nassert bubble_sort([5, 1, 4, 2, 8]) == [1, 2, 4, 5, 8]\n", "\nassert bubble_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert bubble_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]\n", "\nassert bubble_sort([]) == []\n", "\nassert... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to implement an optimized version of Bubble Sort. Let me think about how Bubble Sort works. The basic idea is that in each pass, we compare adjacent elements and swap them if they're in the wrong order. This process repeats until the array is sorted. But the standard Bubble Sort has a time complexity of O(... |
fda418921ed58b4641eb7287d8879454 | You are given a list of lowercase words. Your task is to write a function `find_palindromes(words)` that identifies and returns a list of palindromes from the input list. A palindrome is defined as a word that reads the same forwards and backwards.
**Input:**
- A list of strings `words` (1 ≤ len(words) ≤ 100), where e... | To solve the problem of identifying palindromes from a list of words, we can utilize a simple and efficient approach based on string reversal.
---
### ✅ **Problem Analysis**
A **palindrome** is a word that reads the same forwards and backwards. For example:
- `'radar'` is a palindrome because reversing it yields `'r... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by correctly identifying and returning a list of palindromes from the input list of words."}, "logical_correctness": {"score": 5, "justification": "The logic used to check if a word is a palindrome is correct and consist... | ["\nassert find_palindromes(['radar', 'hello', 'world', 'level', 'python', 'madam']) == ['radar', 'level', 'madam']\n", "\nassert find_palindromes(['abc', 'def', 'ghi']) == []\n", "\nassert find_palindromes(['racecar', 'noon', 'civic']) == ['racecar', 'noon', 'civic']\n", "\nassert find_palindromes(['a', 'b', 'c', 'd']... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function called find_palindromes that takes a list of words and returns the palindromes in order. Let me think about how to approach this.
So, a palindrome is a word that reads the same forwards and backwards. Like 'radar' or 'madam'. So for each word in the input list, I need to check if it's ... |
6a9dee622549fc0fd393218e9bcec3c6 | You are tasked with analyzing a dataset from an e-commerce platform that includes product information. The dataset is represented as a pandas DataFrame with a column named 'price' that holds the selling price of each product. Some entries in the 'price' column may be missing or contain non-numeric values. Your goal is ... | To compute the **price disparity score** for the given dataset, we follow a structured approach that ensures all non-numeric and missing values are appropriately handled. The disparity score is defined as the ratio of the **maximum price** to the **minimum price** after replacing missing values with the **median price*... | generic | evol-instruct | {"requirement_conformance": {"score": 4, "justification": "The function addresses the main requirement of calculating the price disparity score and handles missing values by imputing them with the median price. However, it does not explicitly handle non-numeric values other than converting them to NaN, which is part of... | ["\nassert price_disparity_score(pd.DataFrame({'price': [100, 200, 300]})) == 3.0\n", "\nassert price_disparity_score(pd.DataFrame({'price': [100, 100, 100]})) == 1.0\n", "\nassert price_disparity_score(pd.DataFrame({'price': [100, 200, np.nan]})) == 2.0\n", "\nassert price_disparity_score(pd.DataFrame({'price': [100, ... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to compute the price disparity score for the given dataset. Let me think about the steps required here.
First, the problem says that the 'price' column might have missing values (NaN) or non-numeric values. My task is to handle those missing values by replacing them with the median price of the dataset. ... |
0598e7aa053d4bc18bcc3957ffcd28f4 | You are tasked with implementing a Python class `Employee` to manage employee records. The class should support the following functionalities:
- **Initialization**: Create an `Employee` object with attributes `name`, `id`, `position`, and `salary`.
- **Salary Adjustment**: Provide a method to raise the employee's sala... | To implement the `Employee` class as described, we need to define a class that supports the following features:
1. **Initialization** with `name`, `id`, `position`, and `salary`.
2. **Salary Adjustment** via a method that adds a specified amount to the employee's salary.
3. **String Representation** that returns a for... | generic | self-instruct | {"requirement_conformance": {"score": 3, "justification": "The solution meets basic requirements by defining an Employee class with properties and methods as specified. However, it does not include additional methods or properties that might be expected, such as setting a new position or getting the current salary."}, ... | ["\nassert str(Employee(\"John Doe\", 1, \"Developer\", 50000)) == \"Employee(id=1, name=John Doe, position=Developer, salary=50000)\"\n", "\nassert str(Employee(\"Jane Smith\", 2, \"Manager\", 75000)) == \"Employee(id=2, name=Jane Smith, position=Manager, salary=75000)\"\n", "\nassert str(Employee(\"Alice Johnson\", 3... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to create a Python class called Employee. Let me think about the requirements. The class should have an initialization method that takes name, id, position, and salary. Then, there's a method to raise the salary by a certain amount. Also, a string representation method that returns a specific format.
Firs... |
ba969678b112d9ca3c26ad0e6af0fcd3 | You are tasked with implementing a Minesweeper game simulator. The game is played on a 2D grid where each cell can either contain a mine or a number indicating the number of adjacent mines. The objective is to reveal all cells that do not contain mines without revealing any mines.
The game board is represented as a 2D... | To implement a Minesweeper game simulator, we need to manage the game board in a way that supports revealing cells, flagging cells, and checking for win conditions. The board is represented using a 2D list of integers, where:
- `0` through `8` indicate the number of adjacent mines.
- `-1` indicates a mine.
- We also n... | generic | evol-instruct | {"requirement_conformance": {"score": 4, "justification": "The solution meets most of the requirements, including revealing cells, handling mines, toggling flags, and checking for a win condition. However, it does not explicitly handle edge cases like invalid coordinates or non-integer inputs."}, "logical_correctness":... | ["\nassert Minesweeper([[0, 0, 0], [0, 0, 0], [0, 0, 0]]).reveal(0, 0) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n", "\nassert Minesweeper([[-1, 0, 0], [0, 0, 0], [0, 0, 0]]).reveal(0, 0) == [[-1, 0, 0], [0, 0, 0], [0, 0, 0]]\n", "\nassert Minesweeper([[0, 0, 0], [0, -1, 0], [0, 0, 0]]).reveal(0, 0) == [[0, 0, 0], [0, -1, 0... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass"] | 0.9 | Okay, I need to implement a Minesweeper simulator based on the given problem description. Let me think through the requirements step by step.
First, the board is a 2D list where each cell can be 0-8, -1 (mine), or maybe some other state like flagged or revealed. Wait, the problem says that the board is represented as ... |
60fbfa453166b17c48efbbf97d2cae64 | You are given a list of integers. Your task is to implement a function that sorts this list in ascending order using the bubble sort algorithm. You are not allowed to use any built-in sorting functions such as `sorted()` or `list.sort()`.
**Input:**
- A list of integers `arr` where `1 <= len(arr) <= 1000` and `-1000 ... | To solve the problem of sorting a list of integers using the **Bubble Sort** algorithm, we follow the standard approach of repeatedly swapping adjacent elements if they are in the wrong order. Each pass through the list ensures that the largest unsorted element "bubbles" to the end of the list. This process continues u... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by implementing the bubble sort algorithm without using any built-in sorting functions."}, "logical_correctness": {"score": 5, "justification": "The logic of the bubble sort algorithm is correctly implemented. The code c... | ["\nassert bubble_sort([34, 10, -42, 0, 15, 23, -10]) == [-42, -10, 0, 10, 15, 23, 34]\n", "\nassert bubble_sort([5, 1, 4, 2, 8]) == [1, 2, 4, 5, 8]\n", "\nassert bubble_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]\n", "\nassert bubble_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]\n", "\nassert bubble_sort([]) == []\n", "\nasse... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to implement a bubble sort algorithm to sort a list of integers in ascending order. Let me think about how bubble sort works.
So, bubble sort works by repeatedly swapping adjacent elements if they are in the wrong order. Each pass through the list places the next largest element in its correct position. ... |
c4671d225fb7fd3d9deee0edf8ad40d4 | You are given two integers, `a` and `b`. Your task is to write a function that returns the sum of these two integers.
**Input:**
- Two integers `a` and `b` (where -10^9 ≤ a, b ≤ 10^9).
**Output:**
- An integer representing the sum of `a` and `b`.
**Sample Input:**
```
3 5
```
**Sample Output:**
```
8
``` | To solve the problem of summing two integers `a` and `b`, we can take advantage of Python's inherent support for arbitrary-precision integers, which ensures that even values as large as $10^9$ or as small as $-10^9$ will be handled without any overflow issues.
---
### ✅ Problem Breakdown
- **Input:** Two integers `a... | algorithmic | self-instruct | {"requirement_conformance": {"score": 3, "justification": "The solution meets the basic requirement of converting a JavaScript function to Python, but it does not specify which JavaScript function to convert. The provided Python function is a simple addition function, which might not be the intended one."}, "logical_co... | ["\nassert add_numbers(2, 3) == 5\n", "\nassert add_numbers(-1, 1) == 0\n", "\nassert add_numbers(0, 0) == 0\n", "\nassert add_numbers(100, 200) == 300\n", "\nassert add_numbers(-50, -50) == -100\n", "\nassert add_numbers(1.5, 2.5) == 4.0\n", "\nassert add_numbers(-1.5, 1.5) == 0.0\n", "\nassert add_numbers(0.0, 0.0) =... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function that adds two integers a and b. Hmm, let's think. The problem seems straightforward, but I should make sure I cover all possible cases.
Wait, the input constraints are from -1e9 to 1e9. Oh right, but adding two integers within that range should not cause any overflow issues in Python b... |
f6bcd24edde8ab5e9913b4a2e8eb4e88 | Implement a stack data structure in Python with the following operations: `push`, `pop`, `peek`, and `size`. The stack should be implemented using a list and should support all operations in O(1) time complexity. Your implementation should handle edge cases such as popping or peeking from an empty stack gracefully.
**... | To implement a stack in Python using a list, we can take advantage of the built-in list operations, which are efficient and support O(1) time complexity for the required operations. The stack will support the following operations:
- `push(item)`: Adds an item to the top of the stack.
- `pop()`: Removes and returns the... | 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 size methods using a list. The is_empty method is also correctly implemented to support these operations."}, "logical_correctness": {"score": 5, "justi... | ["\nassert Stack().size() == 0\n", "\nassert Stack().is_empty() == True\n", "\ns = Stack(); s.push(1); assert s.peek() == 1\n", "\ns = Stack(); s.push(1); s.push(2); assert s.pop() == 2\n", "\ns = Stack(); s.push(1); s.push(2); s.pop(); assert s.size() == 1\n", "\ns = Stack(); s.push(1); s.push(2); s.pop(); assert s.pe... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to implement a stack in Python using a list. The operations required are push, pop, peek, and size. All of them should be O(1) time. Let me think about how to do this.
First, the stack is basically a list. For push, appending to the end of the list is O(1), right? So that's straightforward. For pop, I nee... |
db2d3fe6b5d249fbf3ec930453a11c59 | You are tasked with implementing a function `generate_acronym` that processes a given string `expression` to generate an acronym. The acronym is formed by taking the first letter of each word outside of nested parentheses, ignoring any alphanumeric characters following an asterisk (*) within these parentheses, and reve... | To solve the problem of generating an acronym from a given string, we must carefully follow the rules:
1. **Identify words outside of nested parentheses**.
2. **For each such word**, **ignore any alphanumeric characters that follow an asterisk (`*`)**.
3. **Reverse the entire word**.
4. **Take the first letter of the ... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 4, "justification": "The function handles nested parentheses and ignores alphanumeric characters following an asterisk within these parentheses. However, it does not reverse the order of characters in each word before including it in the acronym as specified in the updated requirem... | ["\nassert generate_acronym(\"In (t*he (Qu*ick (Br*brown) fox) jumps) over (the (lazy) dog)\") == \"nIzejD\"\n", "\nassert generate_acronym(\"(a*b) (cd) e(f*g) (h*x) y\") == \"dcey\"\n", "\nassert generate_acronym(\"Hello (World)\") == \"olleH\"\n", "\nassert generate_acronym(\"a(b*c)d\") == \"d\"\n", "\nassert generat... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a function called generate_acronym that takes a string and returns an acronym based on certain rules. Let me think about the problem step by step.
First, the rules: the acronym is formed by taking the first letter of each word outside of nested parentheses. But wait, there are some conditions. Al... |
1cf057969ce46701a191c802337c0125 | You are given a task to implement a function `parse_json(data)` that processes a JSON string. Your function should parse the JSON string and return the corresponding dictionary. If the input string is not a valid JSON, your function should return the string "Invalid JSON data".
**Input:**
- A single string `data` whic... | To solve the problem, we need to implement a function `parse_json(data)` that takes a string input and returns:
- A Python dictionary if the input is a **valid JSON object**.
- The string `"Invalid JSON data"` if the input is **not a valid JSON**.
---
### ✅ Key Considerations
- Python's built-in `json` module provi... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by parsing a JSON string and handling invalid JSON input by returning an appropriate error message."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally struct... | ["\nassert parse_json('{\"name\": \"John\", \"age\": 30}') == {\"name\": \"John\", \"age\": 30}\n", "\nassert parse_json('{\"key\": \"value\", \"number\": 123}') == {\"key\": \"value\", \"number\": 123}\n", "\nassert parse_json('{\"nested\": {\"key\": \"value\"}}') == {\"nested\": {\"key\": \"value\"}}\n", "\nassert pa... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function called parse_json that takes a string data and returns either a dictionary or "Invalid JSON data". Let me think about how to approach this.
First, the function needs to parse the JSON string. In Python, there's the json module which has a loads function to parse a JSON string in... |
f64fbe6ea4b2be6af658a1e8f99875fc | You are tasked with implementing a `Rectangle` class in Python. The class should have an initializer that accepts the width and height of the rectangle. It should also include methods to compute the area and perimeter of the rectangle. Your implementation should pass the following test cases:
**Sample Input:**
```
rec... | To implement the `Rectangle` class in Python as described, we need to define a class that accepts width and height in its constructor, and provides methods to calculate the area and perimeter of the rectangle.
---
### ✅ Class Design Overview
- **Constructor (`__init__`)**: Initializes the rectangle with given `width... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing a Rectangle class with methods to calculate area and perimeter."}, "logical_correctness": {"score": 5, "justification": "The logic for calculating the area and perimeter is completely correct a... | ["\nassert Rectangle(3, 4).area() == 12\n", "\nassert Rectangle(5, 5).perimeter() == 20\n", "\nassert Rectangle(0, 0).area() == 0\n", "\nassert Rectangle(0, 0).perimeter() == 0\n", "\nassert Rectangle(10, 2).area() == 20\n", "\nassert Rectangle(7, 3).perimeter() == 20\n", "\nassert Rectangle(1, 1).area() == 1\n", "\nas... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to create a Rectangle class in Python. Let me think about what's required. The initializer should take width and height. Then methods for area and perimeter.
So, the __init__ method will set the width and height as instance variables. Then the area is width multiplied by height. The perimeter is 2 times (... |
341525a61cbffa28f63cb241beb1ac3e | You are given a list of strings. Your task is to write a function that returns a new list containing the length of each string in the original list. The function should handle any list of strings, including an empty list.
**Sample Input:**
```
["hello", "world", "python"]
```
**Sample Output:**
```
[5, 5, 6]
```
**C... | To solve the problem, we need to write a function that takes a list of strings and returns a new list where each element is the length of the corresponding string in the input list. The function should be robust enough to handle edge cases such as an empty list or strings of zero length.
---
### ✅ Problem Analysis
-... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by returning a new list containing the length of each string in the original list."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses a list compreh... | ["\nassert lengths_of_strings([\"hello\", \"world\", \"python\"]) == [5, 5, 6]\n", "\nassert lengths_of_strings([\"a\", \"ab\", \"abc\"]) == [1, 2, 3]\n", "\nassert lengths_of_strings([\"\", \" \", \" \"]) == [0, 1, 2]\n", "\nassert lengths_of_strings([\"123\", \"4567\", \"89\"]) == [3, 4, 2]\n", "\nassert lengths_of_... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function that takes a list of strings and returns a new list with the lengths of each string. Let me think about how to approach this.
So, the input is a list like ["hello", "world", "python"], and the output should be [5,5,6]. Right. So for each string in the input list, I have to calculate it... |
a3fcee42235d3a91c1281d0c73d1735d | You are given two integers, `a` and `b`. Your task is to write a function that returns the sum of these two integers.
**Input:**
- Two integers `a` and `b` (where -10^9 ≤ a, b ≤ 10^9).
**Output:**
- An integer representing the sum of `a` and `b`.
**Sample Input:**
```
3 5
```
**Sample Output:**
```
8
``` | To solve the problem of summing two integers `a` and `b`, we can take advantage of the straightforward nature of integer addition in most programming languages, including Python.
---
### ✅ Problem Summary
- **Input:** Two integers `a` and `b` such that `-10^9 ≤ a, b ≤ 10^9`.
- **Output:** The sum of `a` and `b`.
- *... | algorithmic | self-instruct | {"requirement_conformance": {"score": 3, "justification": "The solution meets the basic requirement of converting a JavaScript function to Python, but it does not specify which JavaScript function to convert. The provided Python function is a simple addition function, which might not be the intended one."}, "logical_co... | ["\nassert add(2, 3) == 5\n", "\nassert add(-1, 1) == 0\n", "\nassert add(0, 0) == 0\n", "\nassert add(-5, -5) == -10\n", "\nassert add(100, 200) == 300\n", "\nassert add(1.5, 2.5) == 4.0\n", "\nassert add(-1.5, 1.5) == 0.0\n", "\nassert add(0.1, 0.2) == 0.3\n", "\nassert add(1000000, 1) == 1000001\n", "\nassert add(-1... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass"] | 0.9 | Okay, I need to write a function that adds two integers a and b. Let me think. Oh right, the problem says the input is two integers, and the output is their sum. So the function should take a and b as parameters and return a + b.
Wait, but how to structure this in code? The user didn't specify a programming language, ... |
043440e56e22a27688bf5409693aa2c7 | You are given a list of integers. Your task is to implement a function `sort_by_frequency` that sorts the integers based on their frequency of occurrence in descending order. If two integers have the same frequency, they should be sorted by their value in ascending order.
**Input:**
- A list of integers `arr` (1 ≤ le... | To solve the problem of sorting a list of integers based on their frequency of occurrence, we can use a combination of frequency counting and custom sorting.
---
### ✅ **Approach Overview**
1. **Frequency Counting**:
First, we count how many times each integer appears in the input list. This can be efficiently ... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by sorting the list of integers by their frequency of occurrence in descending order and by their value in ascending order when frequencies are the same."}, "logical_correctness": {"score": 5, "justification":... | ["\nassert sort_by_frequency([4, 6, 2, 6, 4, 4, 6]) == [4, 6, 2]\n", "\nassert sort_by_frequency([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == [4, 3, 2, 1]\n", "\nassert sort_by_frequency([5, 5, 5, 5, 5]) == [5]\n", "\nassert sort_by_frequency([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", "\nassert sort_... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a function called sort_by_frequency that takes a list of integers and returns them sorted by their frequency in descending order. And if two numbers have the same frequency, then they should be sorted by their value in ascending order. Let me think about how to approach this.
First, I need to cou... |
b8466d3a0535b55766bf643822a32ef2 | You are tasked with implementing a currency conversion function. Given an amount in a specific currency, convert it to another currency using predefined exchange rates. The exchange rates are provided in a dictionary where each currency's value is its exchange rate to USD. If either of the specified currencies is not f... | To implement the `convert_currency` function as specified, we need to:
1. **Understand the exchange rates**:
- The exchange rates are provided in a dictionary where the keys are currency codes, and the values represent the exchange rate **to USD**.
- For example, if `exchange_rates['EUR'] = 1.1764705882352942`, ... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements, including handling the conversion using a predefined exchange rate dictionary and raising a ValueError if a currency is not found."}, "logical_correctness": {"score": 5, "justification": "The logic is complet... | ["\nassert convert_currency(100, \"USD\", \"EUR\") == 85.0\n", "\nassert convert_currency(100, \"EUR\", \"USD\") == 117.64705882352942\n", "\nassert convert_currency(100, \"GBP\", \"JPY\") == 14666.666666666666\n", "\nassert convert_currency(11000, \"JPY\", \"USD\") == 100.0\n", "\nassert convert_currency(50, \"USD\", ... | ["pass", "pass", "fail", "pass", "pass", "fail", "fail", "pass", "fail", "fail"] | 0.5 | Okay, I need to write a Python function called convert_currency that takes an amount, from_currency, and to_currency. The goal is to convert the amount from one currency to another using predefined exchange rates. The exchange rates are given as a dictionary where each key is a currency code, and the value is the excha... |
d2a7ee6cfff397a3889ca48045dd68aa | You are given a list of integers. Your task is to modify the provided Python function to utilize a set for storing unique elements. This modification should enhance the performance of membership checks and automatically remove any duplicate values from the list. Implement the function `find_unique_elements` to achieve ... | To solve the problem efficiently, we need to modify the function `find_unique_elements` to utilize a **set** for storing unique elements. This change will not only automatically remove duplicates from the input list but also improve the performance of membership checks, which are typically O(1) in a set.
---
### ✅ **... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by modifying the code to use a set instead of a list to store unique elements, which improves performance for membership checks and eliminates duplicates."}, "logical_correctness": {"score": 5, "justification": "The logi... | ["\nassert find_unique_elements([1, 2, 2, 3, 4, 4, 5]) == {1, 2, 3, 4, 5}\n", "\nassert find_unique_elements([]) == set()\n", "\nassert find_unique_elements([10, 10, 10]) == {10}\n", "\nassert find_unique_elements([1, 2, 3, 4, 5]) == {1, 2, 3, 4, 5}\n", "\nassert find_unique_elements(['a', 'b', 'a', 'c', 'b']) == {'a',... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to modify the given Python function to use a set for storing unique elements. The goal is to enhance performance for membership checks and automatically remove duplicates. Let me think about how to approach this.
First, the original function probably processes a list of integers. The sample input has dupl... |
b164d9715be14cee1fadb37720ec867b | You are tasked with implementing a class `Employee` that models the attributes and behavior of an employee in a company. The class should have the following attributes: `name`, `position`, `salary`, and `years_of_experience`. The constructor should initialize these attributes. Additionally, the class should include a m... | To model an employee in a company, we can define a class called `Employee` that encapsulates the essential attributes and behavior related to an employee. The class includes the following features:
### ✅ **Class Features**
- **Attributes:**
- `name`: The name of the employee.
- `position`: The role or title of the... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The class Employee meets all the specified requirements including the initializer method and the calculate_bonus method with the correct rules."}, "logical_correctness": {"score": 5, "justification": "The logic for calculating the bonus is completely correct an... | ["\nassert Employee(\"John Doe\", \"Developer\", 50000, 3).calculate_bonus() == 5000.0\n", "\nassert Employee(\"Jane Smith\", \"Manager\", 75000, 5).calculate_bonus() == 11250.0\n", "\nassert Employee(\"Alice Johnson\", \"Director\", 100000, 10).calculate_bonus() == 15000.0\n", "\nassert Employee(\"Bob Brown\", \"CEO\"... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to create a Python class called Employee. Let me think about the requirements. The class should have attributes name, position, salary, and years_of_experience. The constructor should initialize these. Then there's a method called calculate_bonus that computes the bonus based on years of experience.
So fi... |
79cd0572dd261c862dabf46f0cc34453 | You are tasked with implementing a `Book` class to manage book details. The class should have the following attributes: `title`, `author`, `year_of_publication`, `genre`, and `isbn`. Implement the `update_genre` method to update the genre of the book with the following constraints:
- The genre must be one of the follow... | To implement the `Book` class as specified, we need to define a class with five attributes: `title`, `author`, `year_of_publication`, `genre`, and `isbn`. Additionally, we must implement two methods:
1. **`update_genre(new_genre)`**: This method will update the book's genre. It must validate that the new genre is one ... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements, including the attributes and methods for the Book class, the update_genre method with validation, and the __str__ method for string representation."}, "logical_correctness": {"score": 5, "justification": "The... | ["\nassert str(Book(\"1984\", \"George Orwell\", 1949, \"Fiction\", \"978-0451524935\")) == \"1984 by George Orwell (1949), Genre: Fiction, ISBN: 978-0451524935\"\n", "\nassert str(Book(\"To Kill a Mockingbird\", \"Harper Lee\", 1960, \"Fiction\", \"978-0060935467\")) == \"To Kill a Mockingbird by Harper Lee (1960), Ge... | ["pass", "pass", "pass", "pass", "pass", "pass", "fail", "fail", "pass", "pass"] | 0.8 | Okay, I need to create a Book class in Python with specific attributes and methods. Let me think about what's required here.
First, the attributes are title, author, year_of_publication, genre, and isbn. So the __init__ method should take these as parameters and assign them to instance variables. Wait, but the problem... |
5af4ccb47fdd73653cf6bbf4815ddb8d | You are given a CSV file containing numerical data. Your task is to write a Python script that reads this file, computes the average of a specified column, and writes the result to another CSV file. The output file should contain a single row with the column name prefixed by "average_" and the computed average.
**Inpu... | To solve the problem of computing the average of a specific column from a CSV file and writing the result to another CSV file, we can follow a structured approach using Python's built-in `csv` module. The script reads from `input.csv`, calculates the average of the `salary` column, and writes the result to `output.csv`... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by reading a CSV file, calculating the average of a specified column, and writing the result to another CSV file."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and op... | ["\nassert calculate_average_and_write('test_input1.csv', 'test_output1.csv', 'age') is None\n", "\nassert calculate_average_and_write('test_input2.csv', 'test_output2.csv', 'salary') is None\n", "\nassert calculate_average_and_write('test_input3.csv', 'test_output3.csv', 'height') is None\n", "\nassert calculate_avera... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a Python script that reads a CSV file, calculates the average of a specific column, and writes the result to another CSV file. Let's think about how to approach this.
First, I remember that Python has the csv module which can help read and write CSV files. So I'll probably use that. Also, since t... |
0aaf6b9755e2c1b81f5b39fbbac8091d | You are tasked with implementing a `Matrix` class in Python that supports basic matrix operations: addition, subtraction, and multiplication. The class should be able to handle matrices of arbitrary dimensions, provided that the operations are mathematically valid.
Your `Matrix` class should have the following methods... | Here's a well-structured and complete implementation of the `Matrix` class in Python that supports basic matrix operations: **addition**, **subtraction**, and **multiplication**, along with a string representation method. The class adheres to the problem constraints and handles edge cases such as dimension mismatches d... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing the Matrix class with methods for addition, subtraction, and multiplication, as well as a string representation method."}, "logical_correctness": {"score": 5, "justification": "The logic for ma... | ["\nassert str(Matrix([[1, 2], [3, 4]]).add(Matrix([[2, 0], [1, 2]]))) == \"3 2\\n4 6\"\n", "\nassert str(Matrix([[1, 2], [3, 4]]).subtract(Matrix([[2, 0], [1, 2]]))) == \"-1 2\\n2 2\"\n", "\nassert str(Matrix([[1, 2], [3, 4]]).multiply(Matrix([[2, 0], [1, 2]]))) == \"4 4\\n10 8\"\n", "\nassert str(Matrix([[1, 2, 3], [... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to create a Matrix class in Python that can handle addition, subtraction, and multiplication. Let me think about how to approach this.
First, the __init__ method. It takes a 2D list called data. So I'll store that as an instance variable, maybe self.data. But maybe I should also check if the data is valid... |
7ab949dd4f7253070c659aeb11563c60 | In a binary classification challenge, you are provided with two lists, `y_true` and `y_pred`, each of length `n`, containing binary labels `1` or `-1`. The list `y_true` represents the actual labels, while `y_pred` contains the predicted labels. Your objective is to calculate the F1 score, which is the harmonic mean of... | To calculate the **F1 score** in a binary classification problem, we need to determine the **True Positives (TP)**, **False Positives (FP)**, and **False Negatives (FN)**. The F1 score is the **harmonic mean of precision and recall**, defined as:
$$
\text{F1} = \frac{2 \cdot \text{precision} \cdot \text{recall}}{\text... | generic | evol-instruct | {"requirement_conformance": {"score": 4, "justification": "The solution computes the F1 score using the true labels and predicted labels without using loops or list comprehensions, as required. However, it does not explicitly handle the case where both precision and recall are zero, which is an edge case."}, "logical_c... | ["\nassert compute_f1([1, 1, -1, -1], [1, -1, 1, -1]) == 0.5\n", "\nassert compute_f1([1, 1, 1, 1], [1, 1, 1, 1]) == 1.0\n", "\nassert compute_f1([-1, -1, -1, -1], [-1, -1, -1, -1]) == 1.0\n", "\nassert compute_f1([1, 1, 1, 1], [-1, -1, -1, -1]) == 0.0\n", "\nassert compute_f1([-1, -1, -1, -1], [1, 1, 1, 1]) == 0.0\n",... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to calculate the F1 score for a binary classification problem. The input is two lists, y_true and y_pred, each with binary labels 1 or -1. The F1 score is the harmonic mean of precision and recall. Let me think about how to approach this without using loops or list comprehensions.
First, I remember that p... |
bcb493c1c5207dea4d3978776b948020 | You are given an integer `n`. Determine if `n` can be expressed as the sum of three consecutive integers. You are **not** allowed to use any arithmetic operations (+, -, *, /, %) in your implementation.
**Input:**
- An integer `n` (-10^9 ≤ n ≤ 10^9)
**Output:**
- Return `True` if `n` can be expressed as the sum of th... | To determine whether a given integer `n` can be expressed as the sum of three consecutive integers, we begin by analyzing the mathematical structure of such sums.
---
### **Mathematical Insight**
Let the three consecutive integers be:
- $ x - 1 $
- $ x $
- $ x + 1 $
Their sum is:
$$
(x - 1) + x + (x + 1) = 3x
$$
... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 4, "justification": "The solution addresses the main requirement of determining if a number can be written as the sum of three consecutive integers without using arithmetic operations. However, it uses recursion to simulate division, which is not explicitly prohibited but could be ... | ["\nassert can_be_sum_of_three_consecutive_integers(9) == True\n", "\nassert can_be_sum_of_three_consecutive_integers(10) == False\n", "\nassert can_be_sum_of_three_consecutive_integers(15) == True\n", "\nassert can_be_sum_of_three_consecutive_integers(1) == False\n", "\nassert can_be_sum_of_three_consecutive_integers(... | ["fail", "fail", "fail", "pass", "pass", "fail", "pass", "pass", "fail", "pass"] | 0.5 | Okay, let's see. The problem is to determine if a given integer n can be expressed as the sum of three consecutive integers. And I can't use any arithmetic operations. Hmm, that's a bit tricky. Let me think about how to approach this.
First, let's understand what three consecutive integers look like. Let's say the thr... |
6a24a81ab6674af279bc43a177163bb7 | You are given a string `s`. Your task is to write a function that counts the number of vowels in the string. The vowels are 'a', 'e', 'i', 'o', 'u' (both lowercase and uppercase).
**Input:**
- A single string `s` (1 ≤ |s| ≤ 1000), where |s| denotes the length of the string.
**Output:**
- An integer representing the ... | To solve the problem of counting the number of vowels in a given string, we need to identify all characters that are vowels, regardless of their case (i.e., both lowercase and uppercase). The vowels are defined as `'a'`, `'e'`, `'i'`, `'o'`, and `'u'`.
---
### ✅ Approach
1. **Define the set of vowels**: We use a set... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by counting both upper and lower case vowels in the input string."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses a generator expression within t... | ["\nassert count_vowels(\"Hello, World!\") == 3\n", "\nassert count_vowels(\"Python Programming\") == 4\n", "\nassert count_vowels(\"AEIOUaeiou\") == 10\n", "\nassert count_vowels(\"\") == 0\n", "\nassert count_vowels(\"bcdfg\") == 0\n", "\nassert count_vowels(\"abcdefghijklmnopqrstuvwxyz\") == 5\n", "\nassert count_vo... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function that counts the number of vowels in a given string. Let me think about how to approach this.
First, what's a vowel? The problem says vowels are 'a', 'e', 'i', 'o', 'u' and both lowercase and uppercase. So I need to check each character in the string and see if it's one of those. Oh rig... |
4f8f309c31e3a8120e89148c336900b6 | You are given a list of tuples. Your task is to write a function `remove_duplicates` that processes this list and returns a new list with all duplicate tuples removed. Two tuples are considered duplicates if they contain the same elements in the same order. The order of the tuples in the output list should be the same ... | To solve the problem of removing duplicate tuples from a list while preserving the order of their first occurrence, we can use a combination of a list and a set.
---
### ✅ Problem Breakdown
- **Input**: A list of tuples, where each tuple contains integers.
- **Output**: A new list of tuples with duplicates removed.
... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by removing duplicate tuples while considering the order of elements in the tuples."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses a ... | ["\nassert remove_duplicates([(1, 2), (3, 4), (1, 2), (5, 6), (7, 8), (3, 4)]) == [(1, 2), (3, 4), (5, 6), (7, 8)]\n", "\nassert remove_duplicates([(1, 2), (2, 1), (3, 4)]) == [(1, 2), (2, 1), (3, 4)]\n", "\nassert remove_duplicates([(1, 1), (1, 1), (1, 1)]) == [(1, 1)]\n", "\nassert remove_duplicates([]) == []\n", "\n... | ["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 tuples and returns a new list with duplicates removed. The key is that two tuples are duplicates if they have the same elements in the same order. And the order in the output should be the same as their first occurrence in the input.
Hmm, s... |
77376c4221bcb43fda9265362262313b | You are given a string `url`. Your task is to determine whether it is a valid URL or not. A valid URL must conform to the following pattern:
- It starts with `http://`, `https://`, or `ftp://`.
- It can be followed by a domain name, `localhost`, an IPv4 address, or an IPv6 address.
- It may optionally include a port nu... | To determine whether a given string is a **valid URL**, we need to ensure it conforms to a specific pattern. The URL must:
1. **Start with one of the following protocols**: `http://`, `https://`, or `ftp://`.
2. **Contain a valid domain name**, which can be:
- `localhost`
- An **IPv4 address** (e.g., `192.168.1.... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of checking if a given string is a valid URL using a regular expression."}, "logical_correctness": {"score": 4, "justification": "The logic is largely correct and consistent, using a comprehensive regex pattern to valida... | ["\nassert is_valid_url(\"https://www.google.com\") == True\n", "\nassert is_valid_url(\"http://example.com\") == True\n", "\nassert is_valid_url(\"ftp://files.example.com\") == True\n", "\nassert is_valid_url(\"https://localhost\") == True\n", "\nassert is_valid_url(\"https://192.168.1.1\") == True\n", "\nassert is_va... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function called is_valid_url that checks if a given string is a valid URL based on specific rules. Let me think about how to approach this.
First, the URL must start with http://, https://, or ftp://. So the first thing I should check is whether the string starts with one of these three protoco... |
4ef7e6af4fe449cbd3e7906bf247428b | You are given a list of strings and a threshold value. Your task is to write a program that sorts the strings in ascending order based on their length, excluding any strings whose length exceeds the threshold.
**Input:**
- The first line contains an integer `n` (1 ≤ n ≤ 100), the number of strings.
- The next `n` lin... | To solve the given problem, we need to filter and sort a list of strings based on their length, excluding any strings that exceed a specified threshold. The sorted list should be ordered by the length of the strings in ascending order, and for strings of the same length, they should be sorted lexicographically (in alph... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It sorts the list of strings based on their length in ascending order and excludes strings longer than the specified threshold."}, "logical_correctness": {"score": 5, "justification": "The logic is completely... | ["\nassert sort_strings_by_length([\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\", \"fig\", \"grape\"], 5) == ['fig', 'date', 'apple', 'grape']\n", "\nassert sort_strings_by_length([\"hello\", \"world\", \"python\", \"is\", \"awesome\"], 4) == ['is']\n", "\nassert sort_strings_by_length([\"short\", \"longe... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass"] | 0.9 | Okay, let's see. I need to write a program that takes a list of strings and a threshold, then sorts the strings by their length in ascending order, but only includes those that don't exceed the threshold. Hmm.
So the input starts with an integer n, which is the number of strings. Then there are n lines of strings, eac... |
cdd6e9cfe10e9be92611964469ce7e5d | You are given a list of distinct integers. Your task is to generate all possible subsets (the power set) of the given list. The subsets should be returned as a list of lists, where each inner list represents a subset of the input list. The order of subsets in the output does not matter.
**Input:**
- A list of integers... | To solve the problem of generating all possible subsets (the **power set**) of a given list of distinct integers, we can use a **bitmasking** approach. This method is efficient, easy to implement, and well-suited for the given constraints (input list length ≤ 10).
---
### ✅ **Problem Summary**
Given a list of **dist... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of generating all possible subsets (power set) of a given set. It takes a list of elements as input and outputs a list of lists, where each inner list represents a subset of the input set."}, "logical_correctness": {"sco... | ["\nassert generate_power_set([]) == [[]]\n", "\nassert generate_power_set([1]) == [[], [1]]\n", "\nassert generate_power_set([1, 2]) == [[], [1], [2], [1, 2]]\n", "\nassert generate_power_set([1, 2, 3]) == [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]\n", "\nassert generate_power_set([4, 5, 6]) == [[], [4], [... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to generate all possible subsets of a given list of distinct integers. The output should be the power set, which is all subsets. Let me think about how to approach this.
First, I remember that for a set with n elements, the power set has 2^n elements. So for the sample input [1,2,3], there are 8 subsets. ... |
8f2eecedba6b08014d35adca76d90621 | You are given a list of integers `nums` and an integer `k`. Your task is to find the maximum product of any `k` distinct elements from the list. It is guaranteed that `1 <= k <= len(nums)`.
**Input:**
- The first line contains an integer `n` (the length of the list `nums`).
- The second line contains `n` space-separa... | To solve the problem of finding the **maximum product of any `k` distinct elements** from a list of integers, we must carefully consider both **positive and negative numbers**. The key insight is that **negative numbers can contribute to a larger product when paired appropriately** (e.g., two negatives multiply to a po... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by correctly implementing the logic to find the maximum product of any k distinct elements from the list. It handles the edge cases where k is 1 or k is equal to the length of the list."}, "logical_correctness": {"score... | ["\nassert max_product([3, 1, 5, 4, 6], 3) == 90\n", "\nassert max_product([1, 2, 3, 4, 5], 2) == 20\n", "\nassert max_product([10, 20, 30, 40, 50], 5) == 12000000\n", "\nassert max_product([1, 1, 1, 1, 1], 3) == 1\n", "\nassert max_product([5, 5, 5, 5, 5], 1) == 5\n", "\nassert max_product([-1, -2, -3, -4], 2) == -1\n... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to find the maximum product of any k distinct elements from the given list of integers. Let's think about how to approach this.
First, the problem says that the elements have to be distinct, so I can't use the same element more than once. The goal is to select k elements such that their product is as larg... |
29eaf15cb9ac71e304c623f7949e0713 | You are given a list of integers. Your task is to implement a function `remove_duplicates(input_list)` that processes this list and returns a new list with all duplicate elements removed while maintaining the original order of the first occurrence of each element.
**Input:**
- A list of integers `input_list` (1 ≤ len(... | To solve the problem of removing duplicates from a list while preserving the order of the first occurrence of each element, we can use a combination of a set and a list.
---
### ✅ Problem Summary
We are given a list of integers and need to return a new list that contains all the elements from the original list, but ... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by removing duplicates and maintaining the order of elements."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and efficiently removes duplicates while preserving the order of elem... | ["\nassert remove_duplicates([1, 2, 3, 2, 1]) == [1, 2, 3]\n", "\nassert remove_duplicates(['a', 'b', 'c', 'a', 'b']) == ['a', 'b', 'c']\n", "\nassert remove_duplicates([10, 20, 20, 10, 30]) == [10, 20, 30]\n", "\nassert remove_duplicates([]) == []\n", "\nassert remove_duplicates([1, 1, 1, 1, 1]) == [1]\n", "\nassert r... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function called remove_duplicates that takes a list of integers and returns a new list with duplicates removed, but keeping the order of the first occurrence. Let me think about how to approach this.
So, the key here is to maintain the order of elements as they first appear. So for each ... |
b3c56172227d56e1082af6ffe31fed7e | You are given a list of events, each represented as a tuple containing a time (float) and an actor (string). Your task is to determine the minimum sequence of events that conclusively identifies the culprit. The sequence must be consistent with both prosecution and defense narratives, meaning there should be no contrad... | To solve the problem of identifying the minimum sequence of events that conclusively identifies the culprit, we follow a structured approach based on the constraints and the provided function `is_culprit`.
---
### **Key Observations and Assumptions**
1. **Culprit Identification**:
- The function `is_culprit(actor... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 4, "justification": "The solution addresses the core requirements of sorting events, checking for contradictions, and identifying the culprit. However, it does not fully handle the cyclic renumbering of events up to twice independently for prosecution and defense narratives."}, "lo... | ["\nassert find_min_sequence([(1.5, 'Alice'), (2.1, 'Bob'), (1.8, 'Alice'), (0.5, 'Charlie'), (2.5, 'Alice')], is_culprit) == ([(0.0, 'Alice'), (0.3, 'Alice'), (1.0, 'Alice')], 'Alice')\n", "\nassert find_min_sequence([(1.0, 'Bob'), (2.0, 'Alice'), (3.0, 'Bob'), (4.0, 'Alice')], is_culprit) == ([(0.0, 'Alice'), (2.0, '... | ["fail", "fail", "pass", "fail", "fail", "pass", "fail", "fail", "fail", "pass"] | 0.3 | Okay, let's see. I need to figure out the minimum sequence of events that conclusively identifies the culprit. The sequence has to be consistent with both prosecution and defense narratives, which probably means that there are no contradictions in the events. Also, events can be cyclically renumbered up to twice indepe... |
deb6d68837c160eb11032a22c9d6ea32 | You are given a positive integer `n`. Your task is to determine the number of ways to express `n` as the sum of consecutive positive integers. For instance, if `n = 15`, there are three ways to express it: `1 + 2 + 3 + 4 + 5`, `4 + 5 + 6`, and `7 + 8`.
**Input:**
- A single integer `n` (1 ≤ n ≤ 10^9).
**Output:**
- P... | To solve the problem of determining the number of ways to express a given positive integer `n` as the sum of consecutive positive integers, we can leverage a mathematical insight rooted in the properties of divisors and arithmetic sequences.
---
### **Key Insight**
The sum of `k` consecutive positive integers starti... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by correctly calculating the number of ways to express n as the sum of consecutive positive integers and handles the provided examples correctly."}, "logical_correctness": {"score": 5, "justification": "The logic is com... | ["\nassert count_consecutive_sum_ways(15) == 3\n", "\nassert count_consecutive_sum_ways(10) == 2\n", "\nassert count_consecutive_sum_ways(1) == 1\n", "\nassert count_consecutive_sum_ways(5) == 2\n", "\nassert count_consecutive_sum_ways(9) == 2\n", "\nassert count_consecutive_sum_ways(25) == 3\n", "\nassert count_consec... | ["fail", "pass", "pass", "pass", "fail", "pass", "pass", "fail", "fail", "fail"] | 0.5 | Okay, I need to find the number of ways to express a given integer n as the sum of consecutive positive integers. Let me think about how to approach this problem.
First, I remember that there's a mathematical approach to this problem. Let me recall. Oh right! The number of ways is related to the number of odd divisors... |
596436eac482167b65f5bcfe913da666 | You are given a list of URLs. Your task is to determine the reachability of each URL by checking if the server responds with a 200 OK status. Implement a function `check_urls_reachability` that takes a list of URLs as input and returns a list of tuples. Each tuple should contain the URL and a boolean indicating whether... | To determine the reachability of a list of URLs based on whether they return a `200 OK` HTTP status code, we can use Python's `requests` library. This library provides a simple and intuitive way to make HTTP requests and inspect the response.
Below is the implementation of the `check_urls_reachability` function. It:
... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by taking a list of URLs, checking their reachability, and returning a list of tuples with the URL and a boolean indicating reachability."}, "logical_correctness": {"score": 4, "justification": "The logic is largely cor... | ["\nassert check_urls_reachability([\"http://example.com\"]) == [(\"http://example.com\", True)]\n", "\nassert check_urls_reachability([\"http://nonexistentwebsite123456789.com\"]) == [(\"http://nonexistentwebsite123456789.com\", False)]\n", "\nassert check_urls_reachability([\"https://www.google.com\", \"http://nonexi... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a Python function called check_urls_reachability that takes a list of URLs and returns a list of tuples. Each tuple has the URL and a boolean indicating if it's reachable. Reachable means the server responds with a 200 OK status.
First, I need to figure out how to check the HTTP status code for ... |
5fbd663a498d311ebbc5b54987cd273f | You are tasked with implementing a `Car` class that simulates basic functionalities of a car. The class should support the following operations:
- Initialize a car with attributes: make, model, year, speed, and color.
- Accelerate the car by a given speed increase.
- Decelerate the car by a given speed decrease.
- Cha... | Here's a well-structured implementation of the `Car` class that meets all the specified requirements. The class supports initializing a car with specific attributes, accelerating and decelerating, changing color, updating make and model, and returning a string representation of the car's current state.
---
### ✅ **Cl... | generic | self-instruct | {"requirement_conformance": {"score": 4, "justification": "The solution meets most of the specified requirements, including the attributes and methods for the Car class. However, it does not explicitly state the requirements that need to be met, and the additional method `update_make_and_model` is not part of the origi... | ["\nassert my_car.make == 'Honda'\n", "\nassert my_car.model == 'Civic'\n", "\nassert my_car.year == 2020\n", "\nassert my_car.speed == 60\n", "\nassert my_car.color == 'blue'\n", "\nmy_car.accelerate(20); assert my_car.speed == 80\n", "\nmy_car.brake(10); assert my_car.speed == 70\n", "\nmy_car.paint('red'); assert my... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to create a Car class in Python based on the given requirements. Let me think about what each part requires.
First, the class should initialize with make, model, year, speed, and color. Wait, the sample input shows that the first line is "Toyota Corolla 2020 60 blue" which probably corresponds to make, mo... |
51a86a9e97ed74cf7e4a855688469deb | You are given a string representing geographic coordinates in the format "Lat: <latitude>, Lon: <longitude>". Your task is to implement a function `extract_coordinates` that parses this string and returns a dictionary with keys 'latitude' and 'longitude', where the values are the corresponding float numbers.
**Input:... | To solve the problem of parsing a string representing geographic coordinates into a dictionary with float values for latitude and longitude, we can use a straightforward string splitting approach. This method is effective and efficient given the consistent format of the input string.
---
### ✅ **Approach Overview**
... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by correctly parsing the input string and returning the latitude and longitude in a dictionary format."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently ... | ["\nassert extract_coordinates(\"Lat: 40.7128, Lon: -74.0060\") == {'latitude': 40.7128, 'longitude': -74.0060}\n", "\nassert extract_coordinates(\"Lat: 34.0522, Lon: -118.2437\") == {'latitude': 34.0522, 'longitude': -118.2437}\n", "\nassert extract_coordinates(\"Lat: 0.0, Lon: 0.0\") == {'latitude': 0.0, 'longitude':... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function called extract_coordinates that takes a string input in the format "Lat: <latitude>, Lon: <longitude>" and returns a dictionary with the latitude and longitude as floats. Let me think about how to approach this.
First, the input string is something like "Lat: 40.7128, Lon: -74.0... |
e546040da06203cf2ac397fa303a26e1 | You are tasked with implementing a function to convert an integer to its Roman numeral representation. Your function should be able to handle any integer input from 1 to 3999, inclusive. The Roman numeral system uses combinations of the following symbols: `I` (1), `V` (5), `X` (10), `L` (50), `C` (100), `D` (500), and ... | To convert an integer into its Roman numeral representation, we can use a systematic approach that leverages the known patterns and combinations in the Roman numeral system. Roman numerals are constructed using a set of symbols that represent specific values, with some special cases for subtractive notation (like IV fo... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by converting integers from 1 to 3999 into their Roman numeral representations."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently converts integers to Roman numeral... | ["\nassert convert_to_roman(1) == \"I\"\n", "\nassert convert_to_roman(4) == \"IV\"\n", "\nassert convert_to_roman(9) == \"IX\"\n", "\nassert convert_to_roman(58) == \"LVIII\"\n", "\nassert convert_to_roman(1994) == \"MCMXCIV\"\n", "\nassert convert_to_roman(3999) == \"MMMCMXCIX\"\n", "\nassert convert_to_roman(500) ==... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a function that converts an integer to a Roman numeral. Let's think about how Roman numerals work. The basic symbols are I, V, X, L, C, D, M for 1, 5, 10, 50, 100, 500, 1000. But there are also combinations for numbers like 4 (IV), 9 (IX), 40 (XL), etc. So maybe I should create a list that include... |
a526d7baf8153c56b894b28f4bd1925e | You are given a sequence of numbers that may include negative values and duplicates. Your task is to implement a function `find_range(data)` that returns a tuple containing the smallest and largest numbers in the sequence. The function should ignore `None` values and raise a `ValueError` if there are fewer than two dis... | To solve the problem of finding the smallest and largest numbers in a list that may contain `None` values and duplicates, we need to follow a structured approach that ensures correctness, adheres to constraints, and avoids using built-in `min()` and `max()` functions.
---
### ✅ **Problem Summary**
We are given a lis... | generic | evol-instruct | {"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirements by finding the smallest and largest numbers in the sequence, ignoring None values, and handling sequences with fewer than two distinct numbers by raising a ValueError. However, it does not explicitly handle sequences wi... | ["\nassert find_range([3, 1, 4, None, 1, 5]) == (1, 5)\n", "\nassert find_range([-10, 0, 10, -10, None, None]) == (-10, 10)\n", "\nassert find_range([5, 5, 5, 5]) == (5, 5)\n", "\nassert find_range([None, None, 7, 7, None]) == (7, 7)\n", "\nassert find_range([100]) == (100, 100)\n", "\nassert find_range([0, -1, -2, -3,... | ["pass", "pass", "fail", "fail", "fail", "pass", "pass", "pass", "fail", "pass"] | 0.6 | Okay, I need to write a Python function called find_range that takes a list of numbers and None values. The goal is to find the smallest and largest numbers, ignoring the None values. But I can't use the built-in min and max functions. Also, if there are fewer than two distinct numbers, I have to raise a ValueError. Le... |
50b8c5188b36b9b8f94e2f9a18d2bdd4 | You are tasked with implementing a simple library management system using a Python class. The system should support the following operations:
1. **Add a Book**: Given an ISBN, title, and author, add the book to the library.
2. **Remove a Book**: Given an ISBN, remove the book from the library if it exists.
3. **List A... | To implement a simple library management system, we define a class named `Library` that supports three primary operations: adding a book, removing a book, and listing all books. Each book is represented as a dictionary with keys `"ISBN"`, `"title"`, and `"author"`.
Here's the implementation:
---
### ✅ **Library Clas... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all the specified requirements by implementing methods to add a book, remove a book, and list all books. Each book is stored with an ISBN, title, and author."}, "logical_correctness": {"score": 4, "justification": "The logic is largely ... | ["\nassert Library().list_all_books() == []\n", "\nassert Library().add_book(\"978-3-16-148410-0\", \"Python Programming\", \"John Doe\") is None\n", "\nlib = Library()\nlib.add_book(\"978-3-16-148410-0\", \"Python Programming\", \"John Doe\")\nassert lib.list_all_books() == [{\"ISBN\": \"978-3-16-148410-0\", \"title\"... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to create a Python class called Library that can manage books. Let me think about what each method needs to do.
First, the add_book method. It should take ISBN, title, and author. The library's internal storage is a list, so I'll need to append a dictionary with those keys. Wait, the problem says each boo... |
12205fa2ab08f1de94b1b08d95c977ae | You are tasked with implementing a function `pack_key` that processes a given input `key`. The function should verify if `key` is a string consisting solely of alphabetic characters (a-z, A-Z). If `key` satisfies this condition, it should be encapsulated within a 1-tuple and returned. Otherwise, the original `key` shou... | To solve the problem, we need to implement a function `pack_key` that behaves as follows:
- If the input `key` is a **string** that **consists solely of alphabetic characters (a-z, A-Z)**, then it should be **encapsulated in a 1-tuple** and returned.
- Otherwise, the original `key` should be returned **unchanged**, re... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by checking if the key is a string containing only alphabetic characters and returning it as a 1-tuple if true, otherwise returning the key as is."}, "logical_correctness": {"score": 5, "justification": "The l... | ["\nassert pack_key(\"abc\") == (\"abc\",)\n", "\nassert pack_key(\"XYZ\") == (\"XYZ\",)\n", "\nassert pack_key(\"aBcDeFgHiJkLmNoPqRsTuVwXyZ\") == (\"aBcDeFgHiJkLmNoPqRsTuVwXyZ\",)\n", "\nassert pack_key(\"123\") == \"123\"\n", "\nassert pack_key(\"abc123\") == \"abc123\"\n", "\nassert pack_key(\"!@#\") == \"!@#\"\n", ... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function called pack_key that processes a given input key. The function has to check if the key is a string made up only of alphabetic characters (a-z, A-Z). If it is, then wrap it in a 1-tuple and return that. Otherwise, return the original key as it is.
First, I need to think about ho... |
ecb104864e6592051a4cddd1c90401cc | You are given a string `s`. Your task is to write a function that counts the number of vowels in the string. The function should be case-insensitive, meaning it should count both uppercase and lowercase vowels.
**Input:**
- A single string `s` (1 ≤ |s| ≤ 1000), consisting of English letters and spaces.
**Output:**
-... | To solve the problem of counting the number of vowels in a given string, we need to consider the following:
- **Vowels** are defined as the characters `'a'`, `'e'`, `'i'`, `'o'`, and `'u'`, and their uppercase counterparts.
- The function should be **case-insensitive**, meaning both uppercase and lowercase vowels shou... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by implementing a function that counts all vowels in the given input string."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It correctly identifies vowe... | ["\nassert count_vowels(\"A quick brown fox jumps over the lazy dog\") == 11\n", "\nassert count_vowels(\"\") == 0\n", "\nassert count_vowels(\"AEIOUaeiou\") == 10\n", "\nassert count_vowels(\"bcdfghjklmnpqrstvwxyz\") == 0\n", "\nassert count_vowels(\"abcdefghijklmnopqrstuvwxyz\") == 5\n", "\nassert count_vowels(\"The ... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function that counts the number of vowels in a given string. The vowels are a, e, i, o, u, and their uppercase counterparts. Oh right, and the function should be case-insensitive. So whether the character is uppercase or lowercase, if it's a vowel, it should be counted.
First, I should think ab... |
61de0a700c45ef3f08d805e038634e6e | You are tasked with implementing a function `generate_md5_hash(text)` that computes the MD5 hash of a given string `text`. Your function should utilize the `hashlib` library to generate the hash and return it as a hexadecimal string.
**Input:**
- A single string `text` (1 ≤ len(text) ≤ 1000).
**Output:**
- A string ... | To compute the MD5 hash of a given string in Python, we can use the built-in `hashlib` library. This library provides a convenient way to generate cryptographic hashes, and the `md5()` function from it is suitable for our task.
Here's a breakdown of the process:
1. **Import the `hashlib` module**: This is required to... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by using the hashlib library to generate an MD5 hash and returning it as a hexadecimal string."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured.... | ["\nassert generate_md5_hash(\"hello world\") == \"5eb63bbbe01eeed093cb22bb8f5acdc3\"\n", "\nassert generate_md5_hash(\"\") == \"d41d8cd98f00b204e9800998ecf8427e\"\n", "\nassert generate_md5_hash(\"OpenAI\") == \"d0a29130f8b0d7d4699cf4b8e8b3c094\"\n", "\nassert generate_md5_hash(\"123456\") == \"e10adc3949ba59abbe56e05... | ["pass", "pass", "fail", "pass", "pass", "pass", "fail", "fail", "fail", "fail"] | 0.5 | Okay, I need to write a Python function called generate_md5_hash that takes a string and returns its MD5 hash as a hexadecimal string. Let me think about how to do this.
First, I remember that Python has a library called hashlib which can be used to generate hashes. So I'll need to import that. Right, so the steps wou... |
832a795d0c63fb0c9f5c5b500238643e | You are given a dataset of signal strengths and corresponding timestamps. The dataset is represented as a list of tuples, where each tuple contains two elements: the signal strength (a float) and the timestamp (a float representing the number of seconds since the start of the experiment).
Your task is to write a funct... | To solve the problem, we are given a list of signal strength and timestamp pairs, along with a decay factor `tau`. Our goal is to compute the optimal signal strength using the provided formula:
$$
\text{optimal signal strength} = \frac{n - \frac{m}{\tau}}{s}
$$
Where:
- $ n $: the number of data points.
- $ m $: the... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function correctly implements the formula provided in the question and handles the input as specified."}, "logical_correctness": {"score": 5, "justification": "The logic of the function is correct and consistently follows the formula given in the question t... | ["\nassert find_optimal_signal([(1.0, 0.0), (2.0, 1.0), (3.0, 2.0)], 1.0) == (3 - (0 + 2 * math.exp(-1) + 3 * math.exp(-2)) / 1) / 6\n", "\nassert find_optimal_signal([(1.0, 0.0), (1.0, 1.0), (1.0, 2.0)], 1.0) == (3 - (0 + 1 * math.exp(-1) + 2 * math.exp(-2)) / 1) / 3\n", "\nassert find_optimal_signal([(2.0, 0.0), (2.0... | ["fail", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass"] | 0.8 | Okay, I need to write a function called find_optimal_signal that takes data and tau as inputs and returns the optimal signal strength based on the given formula. Let me think about how to approach this.
First, let me understand the formula. The optimal signal strength is (n - m / tau) divided by s. So I need to comput... |
870921661e54a4b67d1e2f2b094b0d3c | You are tasked with implementing a function to compute the Goods and Services Tax (GST) for a given product price and tax rate. The GST is determined by multiplying the product price by the tax rate and dividing by 100. Your function should accept two floating-point numbers as input: `price` and `tax_rate`. It should r... | To compute the Goods and Services Tax (GST) for a given product price and tax rate, we follow a clear and structured approach:
---
### ✅ **Function Requirements**
- **Input**: Two floating-point numbers: `price` and `tax_rate`.
- **Output**: The GST amount, calculated as:
$$
\text{GST} = \frac{\text{price} \time... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements: it calculates the GST based on the price and tax rate, returns the result rounded to two decimal places, and raises a ValueError for invalid inputs."}, "logical_correctness": {"score": 5, "justification": "Th... | ["\nassert calculate_gst(100.0, 10.0) == 10.0\n", "\nassert calculate_gst(200.0, 5.0) == 10.0\n", "\nassert calculate_gst(0.0, 10.0) == 0.0\n", "\nassert calculate_gst(100.0, 0.0) == 0.0\n", "\nassert calculate_gst(150.75, 15.0) == 22.61\n", "\nassert calculate_gst(1234.56, 7.89) == 97.65\n", "\nassert calculate_gst(10... | ["pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass", "pass", "fail"] | 0.8 | Okay, I need to write a Python function called calculate_gst that takes two floating-point numbers, price and tax_rate. The function should compute the GST by multiplying price by tax_rate and dividing by 100. Then round it to two decimal places. But first, I have to check if either price or tax_rate is negative. If so... |
02797eddd344fe9a791f0cbf07325212 | You are given a string `s` consisting of `n` characters. Your task is to determine the length of the longest substring of `s` that contains only unique characters.
**Input:**
- A single string `s` (1 ≤ |s| ≤ 10^5), where |s| denotes the length of the string.
**Output:**
- An integer representing the length of the lo... | To solve the problem of finding the length of the longest substring with all unique characters, we can efficiently use the **sliding window technique** combined with a hash map (dictionary) to track the last seen positions of characters.
---
### ✅ **Approach Overview**
We maintain a **sliding window** defined by two... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by finding the longest substring with unique characters and returning its length."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and efficiently finds the longest substring with ... | ["\nassert longest_unique_substring(\"abcabcbb\") == 3\n", "\nassert longest_unique_substring(\"bbbbb\") == 1\n", "\nassert longest_unique_substring(\"pwwkew\") == 3\n", "\nassert longest_unique_substring(\"dvdf\") == 3\n", "\nassert longest_unique_substring(\"anviaj\") == 5\n", "\nassert longest_unique_substring(\"abc... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to find the length of the longest substring with all unique characters. Let me think about how to approach this.
Hmm, I remember there's a sliding window technique for this kind of problem. Oh right, the problem is similar to the classic "longest substring without repeating characters" problem. So the ap... |
c0b83c604a52e2058756b0307044a045 | You are tasked with implementing a simple ticket booking system for a movie theater. The theater has a total of 100 seats. Your program should allow users to book a specified number of tickets. If the requested number of tickets is greater than the available seats, the system should return an appropriate message. Other... | To solve the problem of implementing a simple ticket booking system for a movie theater, we need to manage seat availability and process multiple booking requests sequentially. Each request is for a specific number of tickets, and we must ensure that the number of requested tickets does not exceed the available seats. ... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It simulates a simple ticket booking system with a total of 100 seats and allows users to book a specified number of tickets."}, "logical_correctness": {"score": 5, "justification": "The logic is completely c... | ["\nassert theater.book_tickets(0) == \"Invalid number of tickets. Please enter a positive number.\"\n", "\nassert theater.book_tickets(-5) == \"Invalid number of tickets. Please enter a positive number.\"\n", "\nassert theater.book_tickets(100) == \"Successfully booked 100 tickets.\"\n", "\nassert theater.available_se... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to solve this ticket booking system problem. Let me think about how to approach it.
The problem says there's a theater with 100 seats. Users make multiple booking requests. For each request, I have to check if the number of tickets they want is available. If yes, subtract it from the available seats and ... |
ba5e336c7179cbb6528b07909de3d745 | You are given a text file containing a list of integers, one per line. Your task is to write a function `process_file` that reads the file in a single pass without storing all integers in memory and returns two values:
1. The sum of all integers in the file.
2. The product of all integers in the file that are multiple... | To solve the problem, we need a function `process_file` that reads a text file containing integers, one per line, and returns two values: the **sum** of all integers and the **product** of all integers that are multiples of 3. The function should handle the file in a memory-efficient manner, processing each line as it ... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements. It reads the file in a single pass, calculates the sum of all integers, and computes the product of integers that are multiples of 3. It also handles the default file name correctly."}, "logical_correctness":... | ["\nassert process_file(\"test1.txt\") == (15, 9) # File contains: 1, 2, 3, 4, 5\n", "\nassert process_file(\"test2.txt\") == (0, 0) # File is empty\n", "\nassert process_file(\"test3.txt\") == (3, 3) # File contains: 3\n", "\nassert process_file(\"test4.txt\") == (6, 0) # File contains: 1, 2\n", "\nassert proce... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a Python function called process_file that reads a text file with integers, one per line. The function has to return two values: the sum of all integers and the product of those that are multiples of 3. And it should take an optional file path, defaulting to "input.txt" if none is given.
First, I... |
c34062536c319c5da5532e33ff6a80d3 | You are given a list of unique identifiers for a set of subjects. You are also provided with a function `similarity_fn` that computes the similarity score between any two subjects based on their identifiers. Your task is to construct an adjacency list for an undirected graph representing the relationships between these... | To solve the problem of constructing an undirected graph adjacency list based on a similarity threshold, we need to carefully process the given inputs and ensure the final output adheres to the specified requirements.
---
### ✅ **Problem Summary**
Given:
- A list of **unique identifiers** for subjects.
- A **similar... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It constructs an adjacency list for a graph representing relationships between subjects based on a similarity score threshold, and returns the adjacency list in the required coordinate format with edges sorte... | ["\nassert construct_adjacency_list([\"A\", \"B\", \"C\"], lambda x, y: 1 if x != y else 0, 0.5) == [[\"A\", \"A\", \"B\", \"B\", \"C\", \"C\"], [\"B\", \"C\", \"A\", \"C\", \"A\", \"B\"]]\n", "\nassert construct_adjacency_list([\"X\", \"Y\", \"Z\"], lambda x, y: 0, 0.1) == [[], []]\n", "\nassert construct_adjacency_li... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "fail"] | 0.8 | Okay, I need to write a function called construct_adjacency_list. Let's see what the requirements are. The input is subject_ids, a similarity function, and a threshold. The output should be an adjacency list as two lists: sources and destinations. Each edge is bidirectional, so each (v, w) pair needs to appear twice, o... |
f5040f175cb230f96034378656b4a2a5 | You are given a list of integers. Your task is to implement a function `find_max_in_list` that returns the maximum value in the list. The function should handle edge cases such as an empty list or a list with a single element.
**Input:**
- A list of integers `numbers` (0 ≤ len(numbers) ≤ 10^3), where each integer `x`... | To solve the problem of finding the maximum value in a list of integers, we need to consider both the core functionality and the edge cases.
---
### ✅ **Problem Summary**
We are given a list of integers `numbers` where the length can vary from 0 to 1000. Each integer lies in the range [-10^6, 10^6]. The function `fi... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements, including handling an empty list and a list with a single element."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It correctly identifies th... | ["\nassert find_max_in_list([3, 5, 1, 2, 4]) == 5\n", "\nassert find_max_in_list([10]) == 10\n", "\nassert find_max_in_list([]) == None\n", "\nassert find_max_in_list([-1, -2, -3, -4]) == -1\n", "\nassert find_max_in_list([0, 0, 0, 0]) == 0\n", "\nassert find_max_in_list([100, 200, 300, 400, 500]) == 500\n", "\nassert ... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function called find_max_in_list that returns the maximum value in a list of integers. Let's think about how to approach this.
First, the function has to handle edge cases. Like, if the list is empty, return None. Oh right, the input can be an empty list. And if there's only one element, then t... |
4a5f436fe5d294bb0e4a6059c8afabe2 | You are given a list of complex numbers, `zliste`, and a complex number `v`. Your task is to implement a function `complex_shift` that returns a new list of complex numbers. The new list should be such that no two consecutive elements have the same imaginary part. The function should handle an empty list by returning a... | To solve the problem of ensuring that no two consecutive elements in a list of complex numbers have the same imaginary part, we can follow a structured approach that involves:
1. **Initialization**: Begin by adding the given complex number `v` to each element in the input list `zliste`. This creates an intermediate li... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by taking a list of complex numbers and another complex number, and returns a new list where no two consecutive elements have the same imaginary part."}, "logical_correctness": {"score": 5, "justification": "The logic i... | ["\nassert complex_shift([], 1+1j) == []\n", "\nassert complex_shift([1+1j], 1+1j) == [2+2j]\n", "\nassert complex_shift([1+1j, 2+1j], 1+1j) == [2+2j, 3+3j]\n", "\nassert complex_shift([1+1j, 2+2j], 1+1j) == [2+2j, 3+3j]\n", "\nassert complex_shift([1+1j, 2+1j, 3+1j], 1+1j) == [2+2j, 3+3j, 4+4j]\n", "\nassert complex_s... | ["pass", "pass", "fail", "pass", "fail", "pass", "fail", "fail", "fail", "fail"] | 0.4 | Okay, I need to solve this problem where I have to create a function called complex_shift. Let me read the problem statement again carefully.
The task is to take a list of complex numbers, zliste, and a complex number v. The function should return a new list where no two consecutive elements have the same imaginary p... |
bcfbf33bddf5a5a6691101d20a4f0d2e | Implement a Python class `BankAccount` that simulates a simple bank account with the following functionalities:
- Initialize the account with a balance of zero and a transaction count of zero.
- Provide a method `deposit` to add a specified amount to the account balance. The method should raise a `ValueError` if the de... | Here's a well-structured implementation of the `BankAccount` class in Python that fulfills all the specified requirements. The class simulates a simple bank account with support for deposits, withdrawals, balance checks, and transaction tracking.
---
### ✅ **Implementation Details**
- **Initialization**: The account... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by implementing methods for depositing money, withdrawing money, checking the account balance, and keeping track of the number of transactions. The account balance starts at zero as required."}, "logical_corre... | ["\nassert BankAccount().get_balance() == 0\n", "\nassert BankAccount().get_transaction_count() == 0\n", "\naccount = BankAccount(); account.deposit(100); assert account.get_balance() == 100\n", "\naccount = BankAccount(); account.deposit(100); account.deposit(50); assert account.get_balance() == 150\n", "\naccount = B... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "fail", "fail"] | 0.7 | Okay, I need to create a Python class called BankAccount. Let me think about the requirements. The account starts with a balance of zero and a transaction count of zero. So in the __init__ method, I should initialize balance and transaction_count.
Wait, the deposit method adds an amount to the balance. But it should r... |
3fb883a911ee33dc747e91e47340c8c0 | You are given a list of non-negative integers `numbers`. Your task is to implement a function `compute_factorials(numbers)` that calculates the factorial of each integer in the list and returns a dictionary. The keys of the dictionary should be the integers from the list, and the values should be their corresponding fa... | To solve the problem of computing factorials for a list of non-negative integers and returning a dictionary mapping each number to its factorial, we can proceed with a clear and efficient approach.
---
### ✅ Problem Summary
Given a list of non-negative integers `numbers`, the task is to compute the **factorial** of ... | generic | self-instruct | {"requirement_conformance": {"score": 3, "justification": "The function computes the factorial of each number in the list and returns a dictionary with the correct structure. However, the example output in the comment is incorrect (3! should be 6, 5! should be 120, and 2! should be 2, which is correct in the code but i... | ["\nassert compute_factorials([0]) == {0: 1}\n", "\nassert compute_factorials([1]) == {1: 1}\n", "\nassert compute_factorials([2, 3]) == {2: 2, 3: 6}\n", "\nassert compute_factorials([4, 5, 6]) == {4: 24, 5: 120, 6: 720}\n", "\nassert compute_factorials([7, 8, 9]) == {7: 5040, 8: 40320, 9: 362880}\n", "\nassert compute... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function called compute_factorials that takes a list of non-negative integers and returns a dictionary with each number as a key and its factorial as the value. Let me think about how to approach this.
First, I remember that the factorial of a number n is the product of all positive inte... |
705c096eebcbe2665563b594dea2d11d | Given two strings `s1` and `s2`, your task is to find the longest common substring between them. If no common substring exists, return an empty string.
**Input:**
- Two strings `s1` and `s2` (1 ≤ |s1|, |s2| ≤ 1000), consisting of lowercase English letters.
**Output:**
- A single string representing the longest commo... | To solve the problem of finding the **longest common substring** between two strings `s1` and `s2`, we can use **dynamic programming (DP)**. This approach is efficient and leverages the structure of the problem to find the solution in a reasonable time frame for the given constraints (strings of length up to 1000).
--... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function correctly implements the logic to find the longest common substring between two input strings and handles the case where there is no common substring by returning an empty string."}, "logical_correctness": {"score": 5, "justification": "The logic u... | ["\nassert longest_common_substring(\"abcdef\", \"zabcf\") == \"abc\"\n", "\nassert longest_common_substring(\"hello\", \"yellow\") == \"ello\"\n", "\nassert longest_common_substring(\"abc\", \"def\") == \"\"\n", "\nassert longest_common_substring(\"abcde\", \"edcba\") == \"e\"\n", "\nassert longest_common_substring(\"... | ["pass", "pass", "pass", "fail", "pass", "pass", "fail", "pass", "pass", "pass"] | 0.8 | Okay, I need to find the longest common substring between two given strings. Let's think about how to approach this problem.
First, I remember that a substring is a contiguous sequence of characters within a string. So, unlike subsequences which don't need to be contiguous, here the characters must be consecutive.
... |
e9bfdbd37687600a93a2e830c4393793 | You are given a dataset of user-product interactions stored in a text file. Each line in the file represents a single interaction and contains four comma-separated values: user ID, product ID, rating, and date in the format `YYYY-MM-DD`. Your task is to implement a function `filter_products` that processes this dataset... | To solve the problem, we need to process a dataset of user-product interactions and filter out the entries that meet two specific conditions:
1. The user has rated the product with a score **of 4.5 or higher**.
2. The rating was given on a **weekend** (Saturday or Sunday).
---
### ✅ **Approach Overview**
1. **Readi... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all the specified requirements. It reads the dataset from a file, filters interactions based on the rating and the day of the week, and returns the correct dictionary format."}, "logical_correctness": {"score": 5, "justification": "The ... | ["\nassert filter_products(\"test_data.txt\") == {'user1': ['productA', 'productB'], 'user2': ['productC']}\n", "\nassert filter_products(\"empty_data.txt\") == {}\n", "\nassert filter_products(\"no_weekend_data.txt\") == {}\n", "\nassert filter_products(\"only_weekend_data.txt\") == {'user1': ['productA'], 'user2': ['... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a Python function called filter_products that takes a data_file path and returns a dictionary mapping users to their products rated 4.5 or higher on weekends. Let's think about how to approach this.
First, I need to read the data from the text file. Each line has user ID, product ID, rating, and ... |
763e1aa76ecd9f3c4493902068845030 | You are given a list of words. Your task is to determine whether each word is a palindrome. A word is considered a palindrome if it reads the same backward as forward. Implement a function `classify_palindromes(words)` that accepts a list of words and returns a list of tuples. Each tuple should consist of the original ... | To solve the problem of identifying palindromes from a list of words, we can leverage Python's string slicing feature, which allows us to reverse a string with minimal syntax.
---
### ✅ Problem Breakdown
A **palindrome** is a word that reads the same forward and backward. For example:
- "level" is a palindrome becau... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by defining a function `classify_palindromes` that takes a list of words and returns a list of tuples with each word and a boolean indicating whether it is a palindrome."}, "logical_correctness": {"score": 5, "justifica... | ["\nassert classify_palindromes([\"level\", \"world\", \"madam\", \"python\"]) == [(\"level\", True), (\"world\", False), (\"madam\", True), (\"python\", False)]\n", "\nassert classify_palindromes([\"racecar\", \"noon\", \"palindrome\", \"radar\"]) == [(\"racecar\", True), (\"noon\", True), (\"palindrome\", False), (\"... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function called classify_palindromes that takes a list of words and returns a list of tuples. Each tuple has the original word and a boolean indicating if it's a palindrome.
First, I should remember what a palindrome is. Oh right, a word that reads the same backward as forward. So like ... |
a0114f2275c27de9c686a8704f3b20d9 | You are given a list of integers representing scores from a game. Your task is to implement a function `calculate_statistics` that computes and returns the mean, median, and standard deviation of the scores. The function should return a dictionary with keys `mean`, `median`, and `std_dev`. You are allowed to use the `s... | To solve the problem of computing the **mean**, **median**, and **standard deviation** of a list of integers representing game scores, we can leverage Python's built-in `statistics` module. This module provides convenient and efficient functions for these statistical computations.
---
### ✅ **Function Implementation*... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements by calculating the mean, median, and standard deviation of the scores and returning them in a dictionary with the correct keys."}, "logical_correctness": {"score": 5, "justification": "The logic is completely ... | ["\nassert calculate_statistics([100, 100, 100]) == {'mean': 100.0, 'median': 100.0, 'std_dev': 0.0}\n", "\nassert calculate_statistics([50, 60, 70, 80, 90]) == {'mean': 70.0, 'median': 70.0, 'std_dev': 14.142135623730951}\n", "\nassert calculate_statistics([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == {'mean': 5.5, 'median': 5.... | ["pass", "fail", "pass", "fail", "pass", "fail", "fail", "pass", "fail", "fail"] | 0.4 | Okay, I need to write a Python function called calculate_statistics that takes a list of integers and returns the mean, median, and standard deviation as a dictionary. The user mentioned that I can use the statistics module, so I should check what functions are available there.
First, let me recall how to compute thes... |
c9977db3ff61796346c41efee269073e | You are tasked with implementing a function `create_html_table(data)` in Python. The function should accept a list of dictionaries `data` as input, where each dictionary represents a row in an HTML table and the keys of the dictionary are the column headers. Your function should generate and return a string that repres... | To solve the problem of generating an HTML table from a list of dictionaries, we need to construct a well-formed HTML table with a header row and data rows corresponding to each dictionary in the input list. The keys of the dictionaries represent the column headers, and the values represent the row data.
---
### ✅ **... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by generating an HTML table from a list of dictionaries, using the keys as column headers and the dictionary values as row data."}, "logical_correctness": {"score": 4, "justification": "The logic is correct and consiste... | ["\nassert create_html_table([{\"name\": \"Alice\", \"age\": 30}, {\"name\": \"Bob\", \"age\": 25}]) == \"<table>\\n <tr>\\n\\t<th>name</th>\\n\\t<th>age</th>\\n </tr>\\n <tr>\\n\\t<td>Alice</td>\\n\\t<td>30</td>\\n </tr>\\n <tr>\\n\\t<td>Bob</td>\\n\\t<td>25</td>\\n </tr>\\n</table>\"\n", "\nassert create_html_t... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a Python function called create_html_table that takes a list of dictionaries and returns an HTML table as a string. Let me think about how to approach this.
First, the input data is a list of dictionaries. Each dictionary represents a row. The keys of the dictionaries are the column headers. So t... |
fc23dde3449053c4afb17fe964770345 | You are given a list of integers. Your task is to write a function that removes all duplicate elements from the list while maintaining the original order of the remaining elements.
**Input:**
- A list of integers `lst` (1 ≤ len(lst) ≤ 10^5), where each integer is in the range [-10^9, 10^9].
**Output:**
- A list of i... | To solve the problem of removing duplicates from a list of integers while preserving the original order of the elements, we can use a combination of a set and a list to track which elements have already been added.
---
### ✅ **Approach**
- **Key Insight**: Since the order of the first occurrence of each element must... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by removing duplicates while preserving the order of the remaining elements."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses a set to track seen ... | ["\nassert remove_duplicates_preserve_order([1, 2, 3, 2, 1]) == [1, 2, 3]\n", "\nassert remove_duplicates_preserve_order([10, 20, 20, 10, 30]) == [10, 20, 30]\n", "\nassert remove_duplicates_preserve_order([5, 5, 5, 5, 5]) == [5]\n", "\nassert remove_duplicates_preserve_order([]) == []\n", "\nassert remove_duplicates_p... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a function that removes duplicates from a list of integers while keeping the original order. Let me think about how to approach this.
So, the problem says that duplicates should be removed, but the order of the remaining elements must be the same as their first occurrence. For example, in the sam... |
06576b5f85d7e75e9cbb2454b690d6c8 | You are developing a compiler for a simple virtual machine (VM) that supports calling functions from different classes. Each function can accept a variable number of arguments. Your task is to implement the `generate_vm_command` function, which generates a command string for the VM.
The function should adhere to the f... | To implement the `generate_vm_command` function, we need to ensure that both the `class_name` and `func_name` are valid according to the specified constraints. These constraints are:
- Both names must start with a letter (`a-z` or `A-Z`).
- The rest of the characters must be alphanumeric (`a-z`, `A-Z`, `0-9`) or under... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets all specified requirements, including input validation and command string formatting."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It uses regular expressions to vali... | ["\nassert generate_vm_command(\"MyClass\", \"myFunction\", 3) == \"call MyClass.myFunction 3\"\n", "\nassert generate_vm_command(\"AnotherClass\", \"another_function\", 0) == \"call AnotherClass.another_function 0\"\n", "\nassert generate_vm_command(\"Class123\", \"func_456\", 10) == \"call Class123.func_456 10\"\n", ... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to implement the generate_vm_command function. Let me think about the requirements.
First, the function needs to check if the class_name and func_name are valid. The constraints say they must start with a letter and can only contain alphanumeric characters and underscores. So, I need to validate both name... |
4cb7499277a8bb541bcfda8306780833 | You are tasked with writing a program that generates the Fibonacci sequence up to the nth number, where n is a positive integer provided by the user. The program should output the sequence as a space-separated string.
**Input:**
- A single integer n (1 ≤ n ≤ 50), representing the number of terms in the Fibonacci seque... | To generate the Fibonacci sequence up to the `n`th number, we can follow a straightforward approach that builds the sequence iteratively, starting from the first two terms, `0` and `1`. For each subsequent term, we calculate the sum of the last two numbers in the sequence.
Here's a well-structured and efficient implem... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by generating a Fibonacci sequence up to the nth number provided by the user and printing it to the console."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently gener... | ["\nassert generate_fibonacci(0) == None\n", "\nassert generate_fibonacci(-5) == None\n", "\nassert generate_fibonacci(1) == None # This will print \"Fibonacci sequence up to 1: 0\"\n", "\nassert generate_fibonacci(2) == None # This will print \"Fibonacci sequence up to 2: 0 1\"\n", "\nassert generate_fibonacci(5) ==... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a program that generates the Fibonacci sequence up to the nth number. Let's think about how to approach this.
First, the Fibonacci sequence starts with 0 and 1, right? Each subsequent number is the sum of the previous two. So for n=5, the output is 0 1 1 2 3. That makes sense.
Wait, what if n ... |
275f78b2a55d54bee86a5208c736faaf | You are tasked with implementing a simple recommendation system using collaborative filtering. Given a user-item interaction matrix where rows represent users and columns represent items, and the matrix contains ratings given by users to items, your goal is to recommend the top-N items for a specified user based on the... | To solve the problem of recommending items to a user using collaborative filtering, we follow the **user-based collaborative filtering** approach, where we compute **cosine similarity** between users and use that to predict ratings for items that the target user hasn't rated yet.
---
### 🔍 **Problem Breakdown**
Giv... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It takes a user-item interaction matrix, computes cosine similarity between users, and recommends the top-N items for a given user based on the ratings of similar users."}, "logical_correctness": {"score": 5,... | ["\nassert recommend_items(np.array([[5, 3, 0, 1], [4, 0, 0, 1], [1, 1, 0, 5], [1, 0, 0, 4], [0, 1, 5, 4]]), 0, 2).tolist() == [2, 3]\n", "\nassert recommend_items(np.array([[5, 3, 0, 1], [4, 0, 0, 1], [1, 1, 0, 5], [1, 0, 0, 4], [0, 1, 5, 4]]), 1, 2).tolist() == [2, 3]\n", "\nassert recommend_items(np.array([[5, 3, 0,... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to implement a collaborative filtering recommendation system using cosine similarity. Let's see. The input is a user-item matrix where each entry is a rating or 0. The task is to recommend top N items for a specific user based on similar users' ratings.
First, I need to understand how collaborative filter... |
4db8eb48476cdd7561edfbd85de6a590 | You are given an array of integers `arr` and a positive integer `k`. Your task is to find the maximum sum of any contiguous subarray of size `k` using the sliding window technique. If `k` is greater than the length of the array, return `None`.
**Input:**
- The first line contains an integer `n` (1 ≤ n ≤ 10^5), the len... | To solve the problem of finding the maximum sum of any contiguous subarray of size `k` using the **sliding window technique**, we can follow an efficient and linear approach that avoids recalculating the sum from scratch for each subarray. This ensures an optimal time complexity of **O(n)**, which is crucial for handli... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by implementing the sliding window technique to find the maximum sum of a subarray of size k."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It efficien... | ["\nassert max_sum_subarray_of_size_k([2, 1, 5, 1, 3, 2], 3) == 9\n", "\nassert max_sum_subarray_of_size_k([1, 4, 2, 10, 23, 3, 1, 0, 20], 4) == 39\n", "\nassert max_sum_subarray_of_size_k([2, 3, 4, 1, 5], 2) == 7\n", "\nassert max_sum_subarray_of_size_k([100, 200, 300, 400], 2) == 700\n", "\nassert max_sum_subarray_of... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to solve this problem where I have to find the maximum sum of a contiguous subarray of size k using the sliding window technique. Let me think about how to approach this.
First, the problem says that if k is greater than the array's length, return None. So I should check that first. But according to the i... |
079f81daddae12baf72a6c819d7a99f2 | The Swedish Military Intelligence and Security Service (Militära underrättelse- och säkerhetstjänsten, MUST) is tasked with locating a submarine in the Stockholm archipelago using intercepted encrypted messages that may contain location and route information. Given an encrypted message and a decrypted message fragment,... | To solve the problem of determining whether a decrypted message fragment can be uniquely mapped to a position in an encrypted message using a simple substitution cipher (considering both direct and reverse mappings), we need to follow a systematic approach.
---
### 🔍 **Understanding the Problem**
We are given:
- An... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 3, "justification": "The solution addresses the basic requirement of determining if a fragment can be uniquely mapped to a position in the encrypted message using a simple substitution cipher, considering both direct and reverse mappings. However, it does not consider the frequency... | ["\nassert can_uniquely_map(\"HELLO\", \"GXFODFZC\") == False\n", "\nassert can_uniquely_map(\"HELLO\", \"HELLO\") == True\n", "\nassert can_uniquely_map(\"HELLO\", \"OLLEH\") == True\n", "\nassert can_uniquely_map(\"HELLO\", \"HOLLE\") == False\n", "\nassert can_uniquely_map(\"HELLO\", \"HELLOHELLO\") == False\n", "\n... | ["pass", "fail", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.8 | Okay, I need to solve this problem where I have to determine if a decrypted message fragment can be uniquely mapped to a position in an encrypted message using a substitution cipher. The substitution cipher can have both direct and reverse mappings. Let me think about how to approach this.
First, let me understand the... |
b09ecc433852fdacce15121c7aa30932 | You are given an undirected graph represented as an adjacency list. Your task is to determine whether the graph is bipartite. A graph is bipartite if its vertices can be divided into two disjoint sets such that no two graph vertices within the same set are adjacent.
**Input:**
- The first line contains an integer `n` ... | To determine whether an undirected graph is **bipartite**, we can use a **Breadth-First Search (BFS)** approach. A graph is bipartite if its vertices can be divided into two disjoint sets such that no two adjacent vertices belong to the same set. This is equivalent to saying that the graph must not contain any **odd-le... | algorithmic | self-instruct | {"requirement_conformance": {"score": 4, "justification": "The function correctly implements the logic to check if a graph is bipartite. It uses a depth-first search (DFS) approach to color the graph and checks for conflicts. However, it assumes the graph is represented as an adjacency list with nodes indexed from 0 to... | ["\nassert is_bipartite([[1, 3], [0, 2], [1, 3], [0, 2]]) == True\n", "\nassert is_bipartite([[1, 2, 3], [0, 2], [0, 1, 3], [0, 2]]) == False\n", "\nassert is_bipartite([[1], [0]]) == True\n", "\nassert is_bipartite([[1, 2], [0, 2], [0, 1]]) == False\n", "\nassert is_bipartite([[], []]) == True\n", "\nassert is_biparti... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "pass"] | 0.9 | Okay, I need to determine if a given undirected graph is bipartite. Let me think about what a bipartite graph is. Oh right, a graph is bipartite if we can divide its vertices into two sets such that no two adjacent vertices are in the same set. So, basically, there should be no odd-length cycles.
How do I check that?... |
9998531c72a752141ec3ea5eb798f25c | You are given a list of `n` sentences. Your task is to compute the similarity between each pair of sentences and return a similarity matrix. The similarity between two sentences is defined as the cosine similarity of their word frequency vectors. Each sentence should be preprocessed by converting it to lowercase and re... | To solve the problem of computing a similarity matrix between a list of sentences based on cosine similarity of their word frequency vectors, we follow a structured approach that ensures the preprocessing, vectorization, and similarity calculation are handled correctly.
---
### ✅ **Step-by-Step Breakdown**
#### 1. *... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements by computing the similarity between each pair of sentences using the cosine similarity formula and returning a similarity matrix."}, "logical_correctness": {"score": 5, "justification": "The logic is completel... | ["\nassert sentence_similarity([\"hello world\", \"hello world\"]) == [[1.0, 1.0], [1.0, 1.0]]\n", "\nassert sentence_similarity([\"hello world\", \"world hello\"]) == [[1.0, 1.0], [1.0, 1.0]]\n", "\nassert sentence_similarity([\"hello world\", \"goodbye world\"]) == [[1.0, 0.5773502691896257], [0.5773502691896257, 1.0... | ["pass", "pass", "fail", "fail", "fail", "pass", "pass", "pass", "pass", "pass"] | 0.7 | Okay, let's see. I need to compute the similarity matrix for a list of sentences using cosine similarity of their word frequency vectors. Hmm. Let me break this down step by step.
First, the preprocessing. Each sentence has to be converted to lowercase and punctuation removed. Oh right, so for each sentence, I need to... |
82d7b83239cef783a53df2e0e14fc0f6 | You are given a singly-linked list. Your task is to reverse the linked list in-place. The function should modify the original list and return the new head of the reversed list.
**Input:**
- The first line contains an integer `n`, the number of nodes in the linked list.
- The second line contains `n` space-separated in... | To solve the problem of reversing a singly-linked list **in-place** and returning the new head, we follow a standard iterative approach that modifies the `next` pointers of each node to point to the previous node. This ensures that the reversal is done in-place with a time complexity of **O(n)** and a space complexity ... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of reversing the linked list in-place and returning the new head of the reversed list."}, "logical_correctness": {"score": 5, "justification": "The logic for reversing the linked list is completely correct and optimally ... | ["\nassert reverse_linked_list(ListNode(1)).val == 1\n", "\nassert reverse_linked_list(ListNode(1, ListNode(2))).val == 2\n", "\nassert reverse_linked_list(ListNode(1, ListNode(2))).next.val == 1\n", "\nassert reverse_linked_list(ListNode(1, ListNode(2, ListNode(3)))).val == 3\n", "\nassert reverse_linked_list(ListNode... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to reverse a singly-linked list in-place. Let me think about how to approach this. So the problem says that the function should modify the original list and return the new head. The input is given as a number of nodes followed by their values. The output should be the reversed list's values.
First, I reme... |
c5654beb01330dd806563d5d4806d1cf | You are given a list of integers. Your task is to write a function that counts the number of negative integers in the list. The function should be efficient and easy to read. Avoid using global variables and choose meaningful variable names.
**Sample Input:**
```python
numbers = [3, -1, -4, 2, 0, -5]
```
**Sample Out... | To solve the problem of counting the number of negative integers in a list, we can take advantage of Python's concise and efficient list comprehension features. The key idea is to iterate through the list and count how many elements are less than zero.
Here's a clean and efficient implementation of the function:
```p... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by refactoring the code to improve readability and efficiency, avoiding global variables, and using better variable names."}, "logical_correctness": {"score": 5, "justification": "The logic of the solution is completely... | ["\nassert count_negative_numbers([1, -2, 3, -4, 5]) == 2\n", "\nassert count_negative_numbers([-1, -2, -3, -4, -5]) == 5\n", "\nassert count_negative_numbers([1, 2, 3, 4, 5]) == 0\n", "\nassert count_negative_numbers([]) == 0\n", "\nassert count_negative_numbers([0, 0, 0, 0]) == 0\n", "\nassert count_negative_numbers(... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function that counts the number of negative integers in a list. Let's see. The sample input is [3, -1, -4, 2, 0, -5], and the output is 3. So the negatives are -1, -4, -5. Right.
First, the function should take a list of integers as input. Wait, the problem says the function is given a l... |
bfccae9910411a753470381bbc4ba02e | You are given a list of words. Implement a function `generate_palindrome_dictionary` that constructs a dictionary. The keys of the dictionary should be the words from the input list, and the values should be palindromes formed by concatenating each word with its reverse. If a word is already a palindrome, it should be ... | To solve the problem of generating a dictionary where each key is a word from the input list and the corresponding value is a palindrome formed by concatenating the word with its reverse, we can follow a straightforward and efficient approach.
---
### ✅ **Approach Overview**
For each word in the input list:
1. **Che... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the specified requirements by creating a dictionary with words as keys and their corresponding palindromes as values."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently handles the ... | ["\nassert generate_palindrome_dictionary([\"radar\"]) == {\"radar\": \"radar\"}\n", "\nassert generate_palindrome_dictionary([\"level\"]) == {\"level\": \"level\"}\n", "\nassert generate_palindrome_dictionary([\"hello\"]) == {\"hello\": \"helloolleh\"}\n", "\nassert generate_palindrome_dictionary([\"world\"]) == {\"wo... | ["pass", "pass", "pass", "pass", "fail", "pass", "fail", "pass", "pass", "pass"] | 0.8 | Okay, I need to write a Python function called generate_palindrome_dictionary that takes a list of words and returns a dictionary. The keys are the words from the input list, and the values are palindromes formed by concatenating each word with its reverse. But if the word is already a palindrome, then the value is the... |
370df51e95ec49141604f09c8d237366 | You are given two lists of integers. Your task is to implement a function `find_common_elements` that identifies and returns a list of unique integers that are present in both input lists. The order of elements in the output list is irrelevant.
**Input:**
- Two lists of integers, `list1` and `list2`.
**Output:**
- A ... | To solve the problem of identifying unique common elements between two integer lists, we can take advantage of Python's built-in `set` data structure. Sets are ideal for this task because:
- They automatically eliminate duplicates.
- They support efficient membership checking and intersection operations.
---
### ✅ A... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by taking two lists of integers as input and returning a list of unique common elements."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The function uses set operations to find... | ["\nassert find_common_elements([1, 2, 3], [2, 3, 4]) == [2, 3]\n", "\nassert find_common_elements([5, 6, 7], [8, 9, 10]) == []\n", "\nassert find_common_elements([1, 1, 2, 2], [2, 2, 3, 3]) == [2]\n", "\nassert find_common_elements([], [1, 2, 3]) == []\n", "\nassert find_common_elements([1, 2, 3], []) == []\n", "\nass... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a function called find_common_elements that takes two lists and returns a list of unique integers present in both. Let me think about how to approach this.
So the problem says that the output should have unique elements, so duplicates in the input lists shouldn't matter. For example, in the sampl... |
6ac1fef30dc42f57cb7c486e60ea8483 | You are given a hexadecimal color code as a string. Your task is to write a function `convert_hex_to_rgb` that converts this hexadecimal color code into its corresponding RGB representation. The hexadecimal color code is valid if it starts with a '#' followed by either 3 or 6 hexadecimal digits (0-9, a-f, A-F). If the ... | To solve the problem of converting a hexadecimal color code to its corresponding RGB representation, we need to carefully validate the input and then perform the conversion using Python's built-in capabilities.
---
### ✅ **Approach Overview**
1. **Input Validation**:
- The input must start with a `#` character.
... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by converting a hexadecimal color code to its RGB representation and handling invalid hex codes."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. It chec... | ["\nassert convert_hex_to_rgb('#123') == (17, 34, 51)\n", "\nassert convert_hex_to_rgb('#abc') == (170, 187, 204)\n", "\nassert convert_hex_to_rgb('#123456') == (18, 34, 54)\n", "\nassert convert_hex_to_rgb('#abcdef') == (171, 205, 239)\n", "\nassert convert_hex_to_rgb('123') == \"Invalid hex code.\"\n", "\nassert conv... | ["pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 | Okay, I need to write a function called convert_hex_to_rgb that takes a hex code and converts it to RGB. Let me think about how to approach this.
First, the input is a string. The valid hex codes start with a '#' followed by either 3 or 6 hexadecimal digits. So the first thing I should check is whether the string star... |
da14b1b2b55766ecf8877b88f9b98b37 | You are given a string `s`. Your task is to implement a function `extract_last_digit_sequence` that identifies and returns the last sequence of digits in `s` that is at least 3 characters long. If no such sequence exists, the function should return `None`.
**Input:**
- A single string `s` (1 ≤ |s| ≤ 1000), which may c... | To solve the problem of extracting the last sequence of digits from a string that is at least 3 characters long, we can leverage **regular expressions** to efficiently identify all sequences of digits. Once we have these sequences, we can filter them based on their length and then return the last valid one.
---
### ✅... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by extracting the last sequence of digits that is at least 3 characters long and returning None if no such sequence exists."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. It us... | ["\nassert extract_last_digit_sequence(\"abc123def4567\") == \"4567\"\n", "\nassert extract_last_digit_sequence(\"no digits here\") == None\n", "\nassert extract_last_digit_sequence(\"123\") == \"123\"\n", "\nassert extract_last_digit_sequence(\"12 345 6789\") == \"6789\"\n", "\nassert extract_last_digit_sequence(\"a1b... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail", "pass", "fail"] | 0.8 | Okay, I need to write a Python function called extract_last_digit_sequence that takes a string s and returns the last sequence of digits that's at least 3 characters long. If there's none, return None. Let me think about how to approach this.
First, I need to find all sequences of digits in the string. Then, among tho... |
6cbe1b4782fdf9f02f7f159095d3370b | You are given a dictionary `performance` where each key is a subject and the corresponding value is a list of integers representing the marks obtained by a student in various assessments for that subject. Your task is to compute the average marks for each subject, rounded to two decimal places, and return a new diction... | To solve this problem, we need to compute the average marks for each subject in a dictionary, rounding the result to **two decimal places**, and return a new dictionary that includes only those subjects with **at least three assessments**.
---
### ✅ **Approach Overview**
1. **Iterate through the dictionary**: For ea... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirements by calculating the average marks for each subject with three or more assessments and rounding them to two decimal places."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and cons... | ["\nassert calculate_average_marks({'Math': [88, 92, 85, 91], 'Science': [78, 84], 'English': [90, 88, 85, 92], 'History': [80, 78, 85]}) == {'Math': 91.5, 'English': 91.25, 'History': 81.0}\n", "\nassert calculate_average_marks({'Math': [100, 100, 100], 'Science': [50, 50, 50], 'English': [75, 75, 75]}) == {'Math': 10... | ["fail", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 | Okay, let's see. I need to write a Python function that takes a dictionary called performance. Each key is a subject, and the value is a list of integers representing marks. The task is to compute the average for each subject, round it to two decimal places, and return a new dictionary that includes only those subjects... |
fadf4a1860d7bb77454e805e64a12254 | You are given a rectangular image with dimensions `height` and `width`. Your task is to partition this image into a grid consisting of `nbr_col` columns and `nbr_col` rows, resulting in `nbr_col^2` equal-sized square boxes. If the image cannot be perfectly divided, the remaining pixels should be distributed evenly acro... | To solve the problem of partitioning a rectangular image into a grid of equal-sized rectangles, we need to carefully compute the dimensions of each rectangle based on the given number of columns (`nbr_col`) and the image's dimensions (`height`, `width`). The goal is to divide the image into `nbr_col^2` equal-sized rect... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirements by dividing the image into a grid of equal-sized square boxes and distributing the remaining pixels evenly across the squares."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and... | ["\nassert get_grid_boxes(2, 4, 4) == [(0, 0, 2, 2), (2, 0, 4, 2), (0, 2, 2, 4), (2, 2, 4, 4)]\n", "\nassert get_grid_boxes(3, 6, 6) == [(0, 0, 2, 2), (2, 0, 4, 2), (4, 0, 6, 2), (0, 2, 2, 4), (2, 2, 4, 4), (4, 2, 6, 4), (0, 4, 2, 6), (2, 4, 4, 6), (4, 4, 6, 6)]\n", "\nassert get_grid_boxes(2, 5, 5) == [(0, 0, 2, 2), (... | ["pass", "pass", "fail", "fail", "pass", "pass", "fail", "fail", "fail", "pass"] | 0.5 | Okay, let's tackle this problem. So, the task is to divide an image into a grid of square boxes. The number of columns and rows is given by nbr_col, so there are nbr_col squared boxes. The image's height and width might not divide evenly into the grid, so we need to distribute the remaining pixels evenly, rounding down... |
d1b730902687037858453a5aa97d8cb5 | You are given a dictionary `counts` where each key is a string representing a fruit and each value is an integer representing the quantity of that fruit. Your task is to implement a function `sort_by_value(counts)` that sorts the dictionary by its values in descending order and returns a list of tuples. Each tuple shou... | To solve the problem of sorting a dictionary of fruit counts by their values in descending order, we can leverage Python’s built-in `sorted()` function, which allows for custom sorting via the `key` parameter.
---
### ✅ Problem Breakdown
- **Input:** A dictionary `counts` where keys are strings (fruit names) and val... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by sorting the dictionary by its values in descending order and returning a list of tuples."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and optimally structured. The use of th... | ["\nassert sort_by_value({\"apple\": 10, \"banana\": 5, \"cherry\": 20, \"date\": 15}) == [(\"cherry\", 20), (\"date\", 15), (\"apple\", 10), (\"banana\", 5)]\n", "\nassert sort_by_value({\"a\": 1, \"b\": 2, \"c\": 3}) == [(\"c\", 3), (\"b\", 2), (\"a\", 1)]\n", "\nassert sort_by_value({\"x\": 100, \"y\": 100, \"z\": 1... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python function called sort_by_value that takes a dictionary called counts and returns a list of tuples sorted by the values in descending order. Let me think about how to approach this.
So, the input is a dictionary where the keys are fruit names and the values are quantities. The output shoul... |
8ed02f8624c197ef87f70a75adf27f1b | You are tasked with implementing a function to validate email addresses. Your function should determine if a given string adheres to the general format of an email address, which consists of a local part, an "@" symbol, and a domain part. The local part may include letters, digits, dots, underscores, percent signs, plu... | To solve the problem of validating email addresses, we need to ensure that the input string adheres to the standard format of an email address. The email consists of three main components:
1. **Local part** – the part before the `@` symbol.
2. **@ symbol** – the separator between the local and domain parts.
3. **Domai... | generic | self-instruct | {"requirement_conformance": {"score": 4, "justification": "The function addresses the basic requirement of checking if a string is a valid email address using a regular expression. However, it does not handle all possible valid email formats as per the official specifications (RFC 5322)."}, "logical_correctness": {"sco... | ["\nassert is_valid_email(\"test@example.com\") == True\n", "\nassert is_valid_email(\"user.name+tag+sorting@example.com\") == True\n", "\nassert is_valid_email(\"user@sub.example.com\") == True\n", "\nassert is_valid_email(\"user@123.123.123.123\") == True\n", "\nassert is_valid_email(\"user@[IPv6:2001:db8::1]\") == F... | ["pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.8 | Okay, I need to write a function to validate email addresses based on the given criteria. Let me think about the requirements.
First, the email must have a local part, an @ symbol, and a domain part. So the first thing is to check that the string contains exactly one @, and that it's not at the start or end. Like, if ... |
a521c6d7cfbe1423338da96df3c19cad | You are tasked with implementing a function `extract_emails(text)` that identifies and extracts all email addresses from a given string `text`. The function should utilize regular expressions to match email addresses in the format `local-part@domain`. The local part may consist of letters (both uppercase and lowercase)... | To solve the problem of extracting email addresses from a given text, we use **regular expressions** to match the specific pattern of valid email addresses as defined in the problem statement.
---
### ✅ **Email Format Rules Recap**
The email format is defined as:
- **Local Part**: Consists of letters (uppercase/low... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The function fully meets the requirement by using a regular expression to extract email addresses from the input string and returns a list of all found email addresses."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and... | ["\nassert extract_emails(\"Please contact us at support@example.com\") == [\"support@example.com\"]\n", "\nassert extract_emails(\"Reach out to sales@example.co.uk for sales inquiries.\") == [\"sales@example.co.uk\"]\n", "\nassert extract_emails(\"No emails here!\") == []\n", "\nassert extract_emails(\"Multiple emails... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "fail"] | 0.9 | Okay, I need to write a Python function called extract_emails that uses regular expressions to find all email addresses in a given text. Let me think about how to approach this.
First, I remember that email addresses have a specific format. The problem says the local part can include letters, digits, dots, hyphens, an... |
8d0200d0dcb5660431d33a8e6e60af50 | You are given a function `get_max` that is supposed to return the maximum value from a list of numbers. However, the function does not handle the case when the input list is empty. Modify the function to return `None` if the input list is empty.
**Sample Input:**
- `get_max([3, 1, 4, 1, 5, 9])`
- `get_max([])`
**Sam... | To address the issue of handling an empty list in the `get_max` function, we need to ensure that the function gracefully returns `None` when the input list is empty. This prevents a potential `ValueError` that would occur if the built-in `max()` function is called on an empty list.
---
### ✅ Solution Overview
The fu... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by handling an empty list input gracefully and returning None as specified in the question."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. It checks if the list is empty and ret... | ["\nassert get_max([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == 9\n", "\nassert get_max([-10, -20, -30, -40]) == -10\n", "\nassert get_max([0, 0, 0, 0]) == 0\n", "\nassert get_max([100]) == 100\n", "\nassert get_max([]) == None\n", "\nassert get_max([1.5, 2.5, 0.5, 3.5]) == 3.5\n", "\nassert get_max([1000, 2000, 3000, 4000, 5... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to modify the get_max function so that it returns None when the input list is empty. Let me think about how to approach this.
First, the original function probably just finds the maximum value in the list. But if the list is empty, trying to find the max would cause an error, right? Like, if you call max ... |
5adb790b310b800c5cd9413d2bf63df4 | Nikita is performing a series of operations on an initially empty stack. Each operation is either a `push(x)` or a `pop()`. However, there is a constraint: every `push(x)` operation must be preceded by a `pop()` operation unless the stack is empty. Given a sequence of `m` operations, determine the integer at the top of... | To solve this problem, we simulate a stack using a list in Python. The key point is to process the given sequence of operations as they are, assuming that the input is always valid according to the stated constraint. That is, every `push(x)` operation is either preceded by a `pop()` or is the first operation (when the ... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the specified requirements. It correctly implements the stack operations with the constraint that every push(x) must be preceded by a pop() unless the stack is empty."}, "logical_correctness": {"score": 5, "justification": "The logic is... | ["\nassert determine_stack_top([\"push(10)\"]) == 10\n", "\nassert determine_stack_top([\"push(10)\", \"pop\"]) == None\n", "\nassert determine_stack_top([\"push(10)\", \"pop\", \"push(20)\"]) == 20\n", "\nassert determine_stack_top([\"push(10)\", \"push(20)\"]) == 20\n", "\nassert determine_stack_top([\"push(10)\", \"... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, let's see. I need to solve this problem where Nikita is performing operations on a stack with a specific constraint. The problem says that every push operation must be preceded by a pop unless the stack is empty. Hmm, so I need to make sure that whenever a push is done, there was a previous pop before it, unless ... |
d9f6d8275ed4d9e4dfd52255fa90ced6 | You are tasked with implementing a function that determines the reachability of a given URL. Your function should utilize the `requests` library to send an HTTP GET request to the URL and check if the response status code is 200, indicating that the URL is reachable. If the request fails due to any exception, or if the... | To determine the reachability of a given URL, we can utilize the `requests` library in Python to send an HTTP GET request. The core logic revolves around checking whether the response status code is `200 OK`, which indicates the URL is reachable. If the request fails due to any exception (e.g., network issues, invalid ... | algorithmic | self-instruct | {"requirement_conformance": {"score": 4, "justification": "The function uses the `requests` library to check if a URL is reachable and handles exceptions. It meets the basic requirements but could improve by returning more detailed status codes or messages."}, "logical_correctness": {"score": 4, "justification": "The l... | ["\nassert is_url_reachable(\"https://www.google.com\") == True\n", "\nassert is_url_reachable(\"https://www.nonexistentwebsite123456789.com\") == False\n", "\nassert is_url_reachable(\"http://example.com\") == True\n", "\nassert is_url_reachable(\"https://github.com\") == True\n", "\nassert is_url_reachable(\"ftp://ex... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a Python function that checks if a URL is reachable using the requests library. Let me think about how to approach this.
First, the function will take a URL as input. Then, I need to send an HTTP GET request to that URL. The requests library is going to handle the HTTP requests, so I'll import th... |
a93d5545172d04b31db82a8304985071 | You are tasked with writing a Python program that generates all prime numbers up to a given integer \( n \). Your solution should be efficient enough to handle large values of \( n \).
**Input:**
- A single integer \( n \) (where \( 2 \leq n \leq 10^6 \)).
**Output:**
- A list of all prime numbers less than or equal ... | To efficiently generate all prime numbers up to a given integer $ n $, we utilize the **Sieve of Eratosthenes** algorithm. This algorithm is well-suited for large values of $ n $ (up to $ 10^6 $) due to its time complexity of $ O(n \log \log n) $, which is significantly faster than checking each number individually for... | algorithmic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement of generating a list of prime numbers up to a given number $n$ using the Sieve of Eratosthenes algorithm, which is optimized for handling large values of $n$."}, "logical_correctness": {"score": 5, "justification": "The ... | ["\nassert sieve_of_eratosthenes(10) == [2, 3, 5, 7]\n", "\nassert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]\n", "\nassert sieve_of_eratosthenes(1) == []\n", "\nassert sieve_of_eratosthenes(2) == [2]\n", "\nassert sieve_of_eratosthenes(0) == []\n", "\nassert sieve_of_eratosthenes(30) == [2, 3, 5, 7, 11,... | ["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"] | 1 | Okay, I need to write a Python program that generates all prime numbers up to a given integer n. The user mentioned that the solution should be efficient enough for large n, like up to 10^6. Hmm, so the Sieve of Eratosthenes is probably the way to go here. Let me think about how that works.
The Sieve of Eratosthenes w... |
64d001e3ce11a8387bb70fde2e3d72f3 | You are given three points \( p1 \), \( p2 \), and \( p \) in a 3D space. Your task is to find the reflection point \( x \) of point \( p \) onto the line segment defined by points \( p1 \) and \( p2 \). The calculations must be performed using only integer arithmetic. Additionally, determine the minimum integer scalin... | To solve the problem of finding the **reflection point** of a point `p` onto the line segment defined by `p1` and `p2`, and then determining the **minimum integer scaling factor** `k` such that the scaled coordinates of the reflection point are all non-negative integers, we proceed with the following logical approach:
... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 3, "justification": "The solution addresses the reflection of a point onto a line in 3D space using integer arithmetic. However, it does not correctly compute the reflection point and the scaling factor as specified. The reflection point calculation is incorrect, and the scaling fa... | ["\nassert reflect_point((0, 0), (1, 1), (2, 2)) == ((0, 0), 1)\n", "\nassert reflect_point((1, 1), (2, 2), (3, 3)) == ((1, 1), 1)\n", "\nassert reflect_point((0, 0), (1, 0), (2, 0)) == ((0, 0), 1)\n", "\nassert reflect_point((0, 0), (0, 1), (0, 2)) == ((0, 0), 1)\n", "\nassert reflect_point((1, 1), (1, 1), (2, 2)) == ... | ["fail", "fail", "fail", "fail", "pass", "fail", "fail", "fail", "fail", "fail"] | 0.1 | Okay, I need to find the reflection of a point p over the line segment defined by p1 and p2. And then find the minimum integer scaling factor k such that when I multiply the reflection point by k, all coordinates are non-negative integers. All calculations must be done with integer arithmetic. Let me think about how to... |
38c8ab75c6291604232990b4f842313b | You are given an array of integers `numbers` and an integer `target`. Your task is to determine if there are two distinct elements in `numbers` that add up to `target`. If such a pair exists, return a tuple containing the two numbers in any order. If no such pair exists, return an empty tuple. Your solution should have... | To solve the problem of finding two distinct elements in an array that add up to a given target, we can use an efficient approach with a time complexity of **O(n)**. This is achieved by leveraging a **hash map (dictionary)** to store the elements we have seen so far as we iterate through the array.
---
### ✅ **Approa... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It defines a function `find_pair` that takes a list of integers and a target sum, and returns a tuple of two numbers that add up to the target sum or an empty tuple if no such pair exists. The solution also e... | ["\nassert find_pair([2, 7, 11, 15], 9) == (2, 7)\n", "\nassert find_pair([3, 2, 4], 6) == (2, 4)\n", "\nassert find_pair([3, 3], 6) == (3, 3)\n", "\nassert find_pair([1, 2, 3, 4, 5], 10) == (5, 5)\n", "\nassert find_pair([1, 2, 3, 4, 5], 8) == (3, 5)\n", "\nassert find_pair([1, 2, 3, 4, 5], 11) == (5, 6)\n", "\nassert... | ["pass", "pass", "pass", "fail", "pass", "fail", "pass", "pass", "pass", "pass"] | 0.8 | Okay, I need to solve this problem where I have to find two distinct elements in an array that add up to a target. The solution must run in O(n) time. Let me think about how to approach this.
Hmm, the brute force way would be to check every pair, but that's O(n²), which is definitely not acceptable for n up to 1e5. So... |
8558b7a01f88e1842217d57bce27df91 | You are developing a web application using Flask, a Python web framework. Your application has a single endpoint `/calculate` that accepts a POST request with a JSON payload containing two integers, `num1` and `num2`. The endpoint should return a JSON response with the sum of these two integers. Your task is to write a... | To validate the correctness of the `/calculate` endpoint in a Flask web application, we can create a test suite using the `unittest` framework. The test suite will cover three main scenarios:
1. **Valid input** with two integers.
2. **Invalid input** where one or both of the values are not integers.
3. **Missing input... | generic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements. It includes a Flask endpoint that correctly handles valid and invalid inputs, and a test suite that validates the response for both valid and invalid inputs."}, "logical_correctness": {"score": 5, "justificat... | ["\nassert app.test_client().post('/calculate', json={\"num1\": 1, \"num2\": 2}).status_code == 200\n", "\nassert app.test_client().post('/calculate', json={\"num1\": 1, \"num2\": 2}).json == {'sum': 3}\n", "\nassert app.test_client().post('/calculate', json={\"num1\": -1, \"num2\": -2}).status_code == 200\n", "\nasser... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a test suite for the Flask endpoint /calculate using unittest. Let me think about how to approach this.
First, the endpoint accepts a POST request with JSON containing num1 and num2 as integers. The response should be their sum. But there are cases where inputs are invalid, like non-integer value... |
16be12ed93d18c3a5ed297c6ff3956d5 | You are given a string `s` consisting of words separated by spaces. Your task is to write a function `reverse_words` that returns a new string with the words in the original string in reverse order. The input string will not contain leading or trailing spaces, and words are guaranteed to be separated by a single space.... | To solve the problem of reversing the order of words in a given string, we can follow a clear and efficient approach using Python's built-in string and list operations.
---
### ✅ **Approach**
1. **Split the Input String**:
Use the `split()` method to break the string into a list of words. This method handles sp... | generic | self-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets the requirement by reversing the order of words in the input string and returning the new string."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct. The function splits the string into words, rever... | ["\nassert reverse_words(\"hello world\") == \"world hello\"\n", "\nassert reverse_words(\"a b c d e\") == \"e d c b a\"\n", "\nassert reverse_words(\"Python is fun\") == \"fun is Python\"\n", "\nassert reverse_words(\"OpenAI GPT-4\") == \"GPT-4 OpenAI\"\n", "\nassert reverse_words(\" leading and trailing spaces \") ... | ["fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail", "fail"] | 0 | Okay, I need to write a function called reverse_words that takes a string s and returns a new string with the words in reverse order. Let's think about how to approach this.
So the input is a string with words separated by single spaces. The output should have the same words but in reverse order. For example, "hello w... |
16f3e0bbec3ed03d856823fad2a8c670 | You are tasked with implementing a function `process_value` that processes numeric inputs according to specific rules. The function should handle integers, floats, complex numbers, strings, and nested collections (lists, tuples, sets). The rules are as follows:
- For integers and floats, if the value is non-negative, ... | To solve the problem, we need to implement a function `process_value` that processes various types of inputs according to specific rules. The function must handle integers, floats, complex numbers, strings, and nested collections (lists, tuples, sets) recursively. The processing rules are as follows:
---
### **Rules ... | algorithmic | evol-instruct | {"requirement_conformance": {"score": 5, "justification": "The solution fully meets all specified requirements, including handling strings, complex numbers, and nested lists, tuples, and sets."}, "logical_correctness": {"score": 5, "justification": "The logic is completely correct and consistently applies the required ... | ["\nassert process_value(10) == 506\n", "\nassert process_value(-10) == -10\n", "\nassert process_value(\"abc\") == \"Error\"\n", "\nassert process_value(3+4j) == complex(150, 10)\n", "\nassert process_value(-3+4j) == complex(-3, 4)\n", "\nassert process_value([1, -2, \"a\", 3+4j]) == [506, -2, \"Error\", complex(150, ... | ["pass", "pass", "pass", "pass", "pass", "fail", "fail", "fail", "pass", "pass"] | 0.7 | Okay, I need to implement this process_value function. Let me think about the requirements step by step.
First, the function has to handle different types: integers, floats, complex numbers, strings, and nested collections like lists, tuples, sets. Each type has specific processing rules.
Let me start by breaking do... |
4df04f2c8b27a8e585552134ddd125cd | You are tasked with implementing a function `validate_email` that determines whether a given string is a valid email address based on a simplified format. The email format must adhere to the pattern `username@domain.com`, where:
- `username` consists of lowercase letters, digits, and optionally a single period (`.`) or... | To determine whether a given string is a valid email address based on a simplified format, we must ensure it adheres to the following structure:
```
username@domain.tld
```
Where:
- **Username**:
- Consists of lowercase letters, digits, and optionally a single period (`.`) or underscore (`_`) between two alphanume... | generic | self-instruct | {"requirement_conformance": {"score": 4, "justification": "The function meets the basic requirement of validating the email format. However, it does not handle all possible valid email formats as per the general specification (e.g., it does not allow for uppercase letters, numbers, or special characters in the username... | ["\nassert validate_email(\"example@domain.com\") == True\n", "\nassert validate_email(\"user.name@domain.co\") == True\n", "\nassert validate_email(\"user_name@domain.com\") == True\n", "\nassert validate_email(\"user-name@domain.com\") == True\n", "\nassert validate_email(\"user@sub.domain.com\") == False\n", "\nasse... | ["pass", "pass", "pass", "fail", "pass", "pass", "pass", "pass", "pass", "pass"] | 0.9 | Okay, I need to write a function called validate_email that checks if a given string is a valid email based on specific rules. Let me think about the requirements.
First, the email must be in the format username@domain.com. So the structure is username followed by @, then domain, and the domain must end with .com, but... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.