version stringclasses 1
value | style stringclasses 2
values | subset stringclasses 12
values | question_id stringlengths 9 23 | question stringlengths 27 8.13k | solution stringlengths 99 5.97k | test stringlengths 105 4.45k | test_info listlengths 0 13 | gpt_pass_sequence listlengths 1 10 | gpt_pass_trial_num int64 1 10 | gpt_difficulty stringclasses 3
values | gpt_pass_percentage float64 0.1 1 | trials dict | chosen_trial stringclasses 10
values | metadata dict | benchmark_similarity float64 0.16 0.93 | benchmark_instruction stringclasses 1
value | benchmark_task_id stringclasses 1
value | filter_reason stringclasses 1
value | base_id stringlengths 7 21 | variant stringclasses 2
values | top_function_names listlengths 2 13 | n_top_functions int64 2 13 | helper_call_edges listlengths 1 16 | n_helper_call_edges int64 1 16 | harness_functions listlengths 0 3 | structural_wrapper bool 1
class | class_names listlengths 0 5 | has_class bool 2
classes | test_kind stringclasses 1
value | test_has_solution_import bool 2
classes | third_party_imports listlengths 0 5 | stdlib_only bool 2
classes | question_norm_sha1 stringlengths 40 40 | solution_ast_sha1 stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
v1.0 | instruct | Filter | Filter_41887_I | Propose an efficient algorithm for sorting a large array of integers in ascending order using the Merge Sort technique, but with an additional requirement of using a fixed amount of auxiliary space. Additionally, ensure that the algorithm is able to handle arrays containing duplicate integers efficiently. | def merge_sort(arr):
"""
Sorts the array using merge sort technique.
Parameters:
arr (List[int]): The list of integers to be sorted.
Returns:
List[int]: The sorted list of integers.
"""
if len(arr) <= 1:
return arr
middle = len(arr) // 2
left = merge_sort(arr[:midd... | from solution import merge_sort
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_array():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_sorted_array():
assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_merge_s... | [
{
"docstring": "Sorts the array using merge sort technique.\n\nParameters:\narr (List[int]): The list of integers to be sorted.\n\nReturns:\nList[int]: The sorted list of integers.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr, temp=None, start=0, end=None):\n if end is None:\n end = len(arr) - 1\n if start < end:\n mid = (start + end) // 2\n merge_sort(arr, temp, start,... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00041887",
"row_id": 41887,
"seed_ids": "['Qwen2-72B-Instruct_91060']"
} | 0.653648 | Filter_41887 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d053b1bf10e59d02a19b863406f688f839fb0021 | 66e2222e2ebf20d842b0242b5c8df6adb8fb31f4 | |||
v1.0 | instruct | Filter | Filter_41890_I | Write a Python code to search for a given keyword in a dictionary and return the key-value pairs that contain the keyword. Additionally, the code should only consider matches if the keyword appears at the beginning of a word within the value. Partial matches should not be considered as matches. Furthermore, the code sh... | def is_valid_word(word, valid_words):
"""
Returns True if the word is a valid English word according to the predefined list of valid words.
"""
return word in valid_words
def search_keyword_in_dict(dictionary, keyword, valid_words):
"""
Searches for a given keyword in the dictionary and returns... | from solution import search_keyword_in_dict
valid_words = {"happy", "go", "yes", "no", "word"}
def test_search_keyword_found():
dictionary = {
"1": "happy day",
"2": "yes indeed",
"3": "no way",
"4": "just a word"
}
keyword = "happy"
assert search_keyword_in_dict(dictio... | [
{
"docstring": "Returns True if the word is a valid English word according to the predefined list of valid words.",
"function_declaration": "def is_valid_word(word, valid_words):",
"function_name": "is_valid_word",
"parameter_list": "(word, valid_words)"
},
{
"docstring": "Searches for a giv... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_word(word, valid_words):\n \"\"\"\n Returns True if the word is a valid English word according to the predefined list of valid words.\n \"\"\"\n return word in valid_w... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00041890",
"row_id": 41890,
"seed_ids": "['Qwen2-72B-Instruct_91066']"
} | 0.569335 | Filter_41890 | I | [
"is_valid_word",
"search_keyword_in_dict"
] | 2 | [
[
"search_keyword_in_dict",
"is_valid_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 807b488ab5a5b7eddbd058175c49644fdda3e82a | 387c08a39820b7a964256cb50486fd8cf41a2623 | |||
v1.0 | instruct | Filter | Filter_41902_I | Develop a recursive method to generate and display the Fibonacci sequence. The method should be able to handle and correct a given erroneous input case while maintaining the ability to calculate the first 10 numbers in the series. | def fibonacci(n: int) -> int:
"""
Returns the nth Fibonacci number using recursion.
If the input n is invalid (negative or non-integer), it returns -1.
"""
if not isinstance(n, int) or n < 0:
return -1
if n == 0:
return 0
elif n == 1:
return 1
else:
return... | from solution import fibonacci, fibonacci_sequence
def test_fibonacci_base_cases():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
def test_fibonacci_recursive_cases():
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
assert fibonacci(6... | [
{
"docstring": "Returns the nth Fibonacci number using recursion.\nIf the input n is invalid (negative or non-integer), it returns -1.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Returns the first 'length' numbers in... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n, memo=None):\n \"\"\"\n Recursive function to generate the nth Fibonacci number.\n If n is not suitable, it calculates the first 10 Fibonacci numbers by default.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00041902",
"row_id": 41902,
"seed_ids": "['Qwen2-72B-Instruct_91086']"
} | 0.705709 | Filter_41902 | I | [
"fibonacci",
"fibonacci_sequence"
] | 2 | [
[
"fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f1fd18ebdbb40645526eed5b43caa9cd88a174fd | 3cb4b394b426a169a982e5e62987f2ba2e78b0cb | |||
v1.0 | instruct | Filter | Filter_41907_I | Write a program that calculates the square root of the sum of the first n natural numbers using Python. Additionally, your solution should only use recursion and not use any built-in Python functions or libraries for calculating the square root or sum of natural numbers. Your program should be able to handle large valu... | def sum_natural_numbers(n):
"""
Recursively calculates the sum of the first n natural numbers.
"""
if n == 0:
return 0
return n + sum_natural_numbers(n - 1)
def sqrt(number, approx=1.0):
"""
Recursively calculates the square root of a number using the Newton-Raphson method.
"""
... | from solution import sum_natural_numbers, sqrt, square_root_of_sum
def test_sum_natural_numbers():
assert sum_natural_numbers(0) == 0
assert sum_natural_numbers(1) == 1
assert sum_natural_numbers(5) == 15
assert sum_natural_numbers(10) == 55
def test_sqrt():
assert abs(sqrt(4) - 2) < 1e-10
ass... | [
{
"docstring": "Recursively calculates the sum of the first n natural numbers.",
"function_declaration": "def sum_natural_numbers(n):",
"function_name": "sum_natural_numbers",
"parameter_list": "(n)"
},
{
"docstring": "Recursively calculates the square root of a number using the Newton-Raphs... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_natural_numbers(n):\n \"\"\"\n Returns the sum of the first n natural numbers using recursion.\n \"\"\"\n if n <= 1:\n return n\n else:\n return n + sum_na... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00041907",
"row_id": 41907,
"seed_ids": "['Qwen2-72B-Instruct_91094']"
} | 0.6393 | Filter_41907 | I | [
"sum_natural_numbers",
"sqrt",
"square_root_of_sum"
] | 3 | [
[
"square_root_of_sum",
"sqrt"
],
[
"square_root_of_sum",
"sum_natural_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 77a49cd54536c772ba3985ea1dc69dd3f441619f | 289075a8f7d64060406727ee7729a7e25a7a3846 | |||
v1.0 | instruct | Filter | Filter_41910_I | Develop a Python program to categorize 1D array elements into prime and composite numbers. In addition to this, the program should also throw an exception if there are any string or negative values in the array as it can only process positive integers. Further, you must implement an efficient way to obtain the prime nu... | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def categorize_numbers(arr):
if any(type(x... | from solution import categorize_numbers
def test_categorize_numbers_all_primes():
assert categorize_numbers([2, 3, 5, 7, 11, 13, 17]) == ([2, 3, 5, 7, 11, 13, 17], [])
def test_categorize_numbers_all_composites():
assert categorize_numbers([4, 6, 8, 9, 10, 12, 14]) == ([], [4, 6, 8, 9, 10, 12, 14])
def test_... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def categorize_numbers(arr):",
"function_name": "categorize_numbers",
"parameter_list": "(arr)"
}
] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00041910",
"row_id": 41910,
"seed_ids": "['Qwen2-72B-Instruct_91097']"
} | 0.587903 | Filter_41910 | I | [
"is_prime",
"categorize_numbers"
] | 2 | [
[
"categorize_numbers",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 93fb6539329fa3688f3fd26934d12b5e46658674 | 0cd6665b27fe32781c0753fbdf31be7533ad236a | |||
v1.0 | instruct | Filter | Filter_41930_I | Please write a python function that takes in a string representing a mathematical expression and returns a boolean value indicating whether the expression is valid or not. The expression should strictly follow the BODMAS rule, which means the expression must have brackets (parentheses), and the operations inside the br... | def is_valid_expression(expression):
"""
Validates whether the given mathematical expression is valid according to BODMAS rules and does not have
division by zero.
Parameters:
- expression (str): The mathematical expression in string format.
Returns:
- bool: True if the expression is valid... | from solution import is_valid_expression
def test_balanced_brackets():
assert is_valid_expression("(1 + 2)") == True
assert is_valid_expression("((1 + 2) * (3 / 4))") == True
assert is_valid_expression("(1 + (2 * 3))") == True
assert is_valid_expression("(1 + 2") == False
assert is_valid_expression... | [
{
"docstring": "Validates whether the given mathematical expression is valid according to BODMAS rules and does not have\ndivision by zero.\n\nParameters:\n- expression (str): The mathematical expression in string format.\n\nReturns:\n- bool: True if the expression is valid, False otherwise.",
"function_dec... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_expression(expression):\n \"\"\"\n Validates a mathematical expression according to the BODMAS rule by ensuring:\n - It contains brackets.\n - Operations ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00041930",
"row_id": 41930,
"seed_ids": "['Qwen2-72B-Instruct_91130']"
} | 0.628387 | Filter_41930 | I | [
"is_valid_expression",
"_are_brackets_balanced"
] | 2 | [
[
"is_valid_expression",
"_are_brackets_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c9844ca8bb98b043607327847da2ea00a522cfbd | 730e0bee056e99c347d5c89586550b496ec2b5ef | |||
v1.0 | instruct | Filter | Filter_41944_I | You have found a set of numbers (from a lottery ticket) these numbers are 5 random numbers from a pool of 69 and a final number from a pool of 26. If you have one of the combinations how would we write a python code that takes these numbers (as an input) from a user as their selected ticket and compares it to 10,000 ra... | import random
def generate_random_ticket():
"""
Generates a random ticket with 5 unique numbers from 1 to 69
and a final number from 1 to 26.
"""
main_numbers = sorted(random.sample(range(1, 70), 5))
powerball_number = random.randint(1, 26)
return main_numbers + [powerball_number]
def che... | from solution import generate_random_ticket, check_for_duplicate, check_lottery
def test_generate_random_ticket():
ticket = generate_random_ticket()
assert len(ticket) == 6
assert all(1 <= num <= 69 for num in ticket[:5])
assert 1 <= ticket[5] <= 26
def test_check_for_duplicate_no_match():
user_ti... | [
{
"docstring": "Generates a random ticket with 5 unique numbers from 1 to 69 \nand a final number from 1 to 26.",
"function_declaration": "def generate_random_ticket():",
"function_name": "generate_random_ticket",
"parameter_list": "()"
},
{
"docstring": "Checks if user_ticket is a duplicate... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_lottery_ticket():\n main_numbers = sorted(random.sample(range(1, 70), 5))\n final_number = random.randint(1, 26)\n return main_numbers, final_number\n\nd... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00041944",
"row_id": 41944,
"seed_ids": "['Qwen2-72B-Instruct_91154']"
} | 0.549553 | Filter_41944 | I | [
"generate_random_ticket",
"check_for_duplicate",
"check_lottery"
] | 3 | [
[
"check_lottery",
"check_for_duplicate"
],
[
"check_lottery",
"generate_random_ticket"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2c9a0b13bc31fbf12352faf524b4add5a7193f6d | ec87d3bd1787c43e29a81b1293e870f4cf939efc | |||
v1.0 | instruct | Filter | Filter_41954_I | Please create some programming code that can facilitate the function of registering a new user in a manner that is analogous to how sign-up systems work in real life. The code you write should be detailed and include validation checks to make sure that the password chosen by the user is strong enough to protect their i... | import re
import sqlite3
def validate_password(password):
"""
Validates that the password is strong enough.
A strong password should have at least:
- 8 characters
- 1 uppercase letter
- 1 lowercase letter
- 1 digit
- 1 special character
"""
if len(password) < 8:
return F... | from solution import validate_password, register_user
import sqlite3
def test_validate_password():
# Test valid password
assert validate_password('Valid123@') == True
# Test too short password
assert validate_password('Val1@') == False
# Test no uppercase letter
assert validate_password('valid1... | [
{
"docstring": "Validates that the password is strong enough.\nA strong password should have at least:\n- 8 characters\n- 1 uppercase letter\n- 1 lowercase letter\n- 1 digit\n- 1 special character",
"function_declaration": "def validate_password(password):",
"function_name": "validate_password",
"pa... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\n# Database simulation\ndatabase = {\n 'users': []\n}\n\ndef is_strong_password(password):\n \"\"\"\n Validates that the password is strong.\n A strong password should ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00041954",
"row_id": 41954,
"seed_ids": "['Qwen2-72B-Instruct_91173']"
} | 0.319854 | Filter_41954 | I | [
"validate_password",
"register_user"
] | 2 | [
[
"register_user",
"validate_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04d3c9b59eb7ae472e3e541684c80c147c76d764 | 2fada1b5907a2ce97bb96047732785b7696516dc | |||
v1.0 | instruct | Filter | Filter_41975_I | Please write a python function to detect cycles in a directed graph using depth-first search (DFS). However, you cannot use any built-in Python data structures such as dictionaries, lists, or sets for your implementation. Instead, you must use a linked list and a stack implemented from scratch. In addition to this, you... | class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def append(self, data):
new_node = Node(data)
if not self.head:
self.head = new_node
return
last = self.hea... | from solution import LinkedList, Stack, detect_cycle
def test_simple_acyclic_graph():
graph = [LinkedList() for _ in range(5)]
graph[0].append(1)
graph[1].append(2)
graph[2].append(3)
graph[3].append(4)
assert detect_cycle(graph, 5) == False
def test_simple_cyclic_graph():
graph = [Linked... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, value):\n self.value = value\n self.next = None\n\nclass LinkedList:\n def __init__(self):\n self.head = None\n \n def append(... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00041975",
"row_id": 41975,
"seed_ids": "['Qwen2-72B-Instruct_91213']"
} | 0.522468 | Filter_41975 | I | [
"dfs",
"detect_cycle"
] | 2 | [
[
"detect_cycle",
"dfs"
]
] | 1 | [] | false | [
"Node",
"LinkedList",
"Stack"
] | true | pytest | true | [] | true | 0c6f2a72243e72a94c0ec7a661040f72c376abae | 97097bdc556feba89047e28c660ced0cd0babc0e | |||
v1.0 | instruct | Filter | Filter_41988_I | How can we design a C API python extension that will check if a binary tree is a binary search tree in pypy and cpython? Implement a new function that considers the height of the tree while checking if it is a binary search tree. In addition, ensure that the new function efficiently handles large datasets by optimizing... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def is_bst_util(node, left, right):
"""
Helper function to check if binary tree is a binary search tree
"""
if node is None:
return True
if node.val < left or node.val > r... | from solution import TreeNode, is_bst_and_height
def test_is_bst_and_height_empty():
bst, h = is_bst_and_height(None)
assert bst == True
assert h == 0
def test_is_bst_and_height_single_node():
root = TreeNode(10)
bst, h = is_bst_and_height(root)
assert bst == True
assert h == 1
def test_i... | [] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef is_bst_and_height(node, min_key=float('-inf'), max_key=float('... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00041988",
"row_id": 41988,
"seed_ids": "['Qwen2-72B-Instruct_91240']"
} | 0.484789 | Filter_41988 | I | [
"is_bst_util",
"is_bst",
"height",
"is_bst_and_height"
] | 4 | [
[
"is_bst",
"is_bst_util"
],
[
"is_bst_and_height",
"height"
],
[
"is_bst_and_height",
"is_bst"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 0fe566b0505d46b081fa42f62644cb26125cb12e | 39443f866436cbdb099a9f08f72b274bb2ba05c2 | |||
v1.0 | instruct | Filter | Filter_41990_I | Utilize Python's Scipy library to find the area under the curve of the equation y=2x^3+x, between x values of 0 and 4. Implement this through numerical integration using both the quadrature method and the trapezoidal rule, then compare the accuracy of both methods by assessing the difference between their results and t... | import numpy as np
from scipy.integrate import quad, trapezoid
def f(x):
return 2 * x**3 + x
def exact_integral(a, b):
"""
Calculates the exact integral of the function 2x^3 + x from a to b.
"""
F = lambda x: (1/2)*x**2 + (1/2)*x**4
return F(b) - F(a)
def quadrature_integration(a, b, func):
... | from solution import f, exact_integral, quadrature_integration, trapezoidal_integration, compare_methods
def test_exact_integral():
result = exact_integral(0, 4)
expected = (0.5 * 4**2 + 0.5 * 4**4) - (0.5 * 0**2 + 0.5 * 0**4)
assert result == expected
def test_quadrature_integration():
result = quadr... | [
{
"docstring": null,
"function_declaration": "def f(x):",
"function_name": "f",
"parameter_list": "(x)"
},
{
"docstring": "Calculates the exact integral of the function 2x^3 + x from a to b.",
"function_declaration": "def exact_integral(a, b):",
"function_name": "exact_integral",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from scipy.integrate import quad, trapezoid\nimport numpy as np\n\ndef integrand(x):\n return 2 * x**3 + x\n\ndef exact_integral():\n \"\"\"\n Compute the exact integral of y = 2x^3 +... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00041990",
"row_id": 41990,
"seed_ids": "['Qwen2-72B-Instruct_91247']"
} | 0.448622 | Filter_41990 | I | [
"f",
"exact_integral",
"quadrature_integration",
"trapezoidal_integration",
"compare_methods"
] | 5 | [
[
"compare_methods",
"exact_integral"
],
[
"compare_methods",
"f"
],
[
"compare_methods",
"quadrature_integration"
],
[
"compare_methods",
"trapezoidal_integration"
]
] | 4 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | d5381f7ee971011b9d8aac6e968d27414b462f1a | 0f17edf77a6cf657d03c8e39c0835bf5de26bc95 | |||
v1.0 | instruct | Filter | Filter_42001_I | Design a Python function that can identify prime numbers from a collection of integers, including negative integers and zero. This function should be capable of distinguishing prime numbers from non-prime numbers, even in scenarios where the collection includes repeat numbers. The output should be arranged as a tuple: ... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def process_primes(numbers):
primes = [n for n in set(numbers) if is_prime(n... | from solution import is_prime, process_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(0) == False
assert is_prime(-1) == False
assert is_prime(11) == True
assert is_prime(15) == Fal... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def process_primes(numbers):",
"function_name": "process_primes",
"parameter_list": "(numbers)"
}
] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Determines if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042001",
"row_id": 42001,
"seed_ids": "['Qwen2-72B-Instruct_91277']"
} | 0.70796 | Filter_42001 | I | [
"is_prime",
"process_primes"
] | 2 | [
[
"process_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2302d9759c53f767643966dd01387e97241ccaa1 | d40d7e41245d1815b07aeacf3d2e27a9255caa97 | |||
v1.0 | instruct | Filter | Filter_42019_I | Write a Python program to iterate through the given list and print the square root of each element, but only if the element is a prime number between 2 and 100, inclusive. If the element is not a prime number or falls outside the range, print "Invalid number: {element}". If the list is empty, print "Empty list." | import math
def is_prime(n):
"""Returns True if n is a prime number, False otherwise."""
if n <= 1:
return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
def process_list(elements):
"""Processes the elements to print the square r... | from solution import process_list
def test_process_list_with_valid_primes(capsys):
process_list([2, 3, 5, 7, 11, 101])
captured = capsys.readouterr()
assert "1.4142135623730951\n1.7320508075688772\n2.23606797749979\n2.6457513110645907\n3.3166247903554\nInvalid number: 101\n" in captured.out
def test_proce... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Processes the elements to print the square root if it's a prime number between 2 and 100, otherwise prin... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042019",
"row_id": 42019,
"seed_ids": "['Qwen2-72B-Instruct_91309']"
} | 0.610016 | Filter_42019 | I | [
"is_prime",
"process_list"
] | 2 | [
[
"process_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a503498bb5a13e9c2eced98c54f372d6a1496a99 | b899f99a17f03eeba207965db635067b1739c2fc | |||
v1.0 | instruct | Filter | Filter_42036_I | Develop a code snippet to create a dictionary with keys as the elements of a list and corresponding values, and then sort this dictionary based on the values. The resulting dictionary should only include keys that are prime numbers. | def is_prime(num):
"""
Check if a number is prime.
"""
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def create_and_sort_dict(elements, values):
"""
Creates a dictionary with keys as the elements an... | from solution import create_and_sort_dict
def test_create_and_sort_dict_positive_prime():
elements = [2, 3, 5, 4, 7]
values = [10, 20, 30, 40, 50]
result = create_and_sort_dict(elements, values)
assert result == {2: 10, 3: 20, 5: 30, 7: 50}
def test_create_and_sort_dict_mix():
elements = [10, 11, ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Creates a dictionary with keys as the elements and values as corresponding values,\nthen sorts the dictionary based on values ... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042036",
"row_id": 42036,
"seed_ids": "['Qwen2-72B-Instruct_91338']"
} | 0.529327 | Filter_42036 | I | [
"is_prime",
"create_and_sort_dict"
] | 2 | [
[
"create_and_sort_dict",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 33bb10ecb9290255343d03c38fb7fc061e67e66e | 481b5738190549ecb88ec8cdbbbc25cd754f1dc8 | |||
v1.0 | instruct | Filter | Filter_42042_I | Develop a code script that, when supplied with two binary tree data structures, verifies if they have similar elements and returns the total number of occurrences of each similar element in both trees. Additionally, integrate functionality to construct these trees from the array input yourself. The implementation shoul... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree_from_list(arr):
"""
Build a binary tree from the input list.
"""
if not arr:
return None
root = TreeNode(arr[0])
nodes = [root]... | from solution import build_tree_from_list, find_similar_elements
def test_find_similar_elements():
tree1 = build_tree_from_list([1, 3, 2, 4, 5])
tree2 = build_tree_from_list([2, 1, 4, 3, 5])
result = find_similar_elements(tree1, tree2)
assert result == {1: 1, 2: 1, 3: 1, 4: 1, 5: 1}
def test_find... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042042",
"row_id": 42042,
"seed_ids": "['Qwen2-72B-Instruct_91349']"
} | 0.452562 | Filter_42042 | I | [
"build_tree_from_list",
"in_order_traversal",
"find_similar_elements"
] | 3 | [
[
"find_similar_elements",
"in_order_traversal"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | e86503c38b716fbe4fb7c3818458915c291041d1 | 2f0613b1a8268e4f0e2b8f4d77dcf5eae648dc82 | |||
v1.0 | instruct | Filter | Filter_42083_I | Create a program to calculate the Fibonacci sequence up to the nth element, but with the additional requirement that each number in the sequence must be checked for primality before being included in the sequence. Additionally, implement a time complexity of O(n) for the program. | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def fibonacci_with_primes(n):
if n <= 0:
... | from solution import fibonacci_with_primes, is_prime
def test_is_prime():
assert not is_prime(1), "Test as False for 1"
assert is_prime(2), "Test as True for 2"
assert is_prime(3), "Test as True for 3"
assert not is_prime(4), "Test as False for 4"
assert is_prime(29), "Test as True for 29"
def tes... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def fibonacci_with_primes(n):",
"function_name": "fibonacci_with_primes",
"parameter_list": "(n)"
}
] | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if the number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042083",
"row_id": 42083,
"seed_ids": "['Qwen2-72B-Instruct_91431']"
} | 0.696269 | Filter_42083 | I | [
"is_prime",
"fibonacci_with_primes"
] | 2 | [
[
"fibonacci_with_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 23aa568d40243d1c0683f09dc67b1f574db44494 | 379b2bf950765d5f78d2e6ae735ac3807b5989b9 | |||
v1.0 | instruct | Filter | Filter_42088_I | Create a nested for loop that iterates from 10 to 25 by 4's, but only prints the numbers that are divisible by both 3 and 5. Additionally, you need to implement a counter that keeps track of the total number of divisible numbers. Finally, instead of using the modulus operator to check divisibility, you need to implemen... | def is_divisible_by(a, b):
"""
Custom function to check if a is divisible by b without using the modulus operator.
"""
return a / b == a // b
def print_divisible():
"""
Iterates from 10 to 25 by 4's and prints numbers that are divisible by both
3 and 5. Returns the total count of such numbe... | from solution import is_divisible_by, print_divisible
def test_is_divisible_by():
assert is_divisible_by(15, 3) == True
assert is_divisible_by(15, 5) == True
assert is_divisible_by(15, 4) == False
assert is_divisible_by(20, 5) == True
assert is_divisible_by(21, 3) == True
assert is_divisible_by... | [
{
"docstring": "Custom function to check if a is divisible by b without using the modulus operator.",
"function_declaration": "def is_divisible_by(a, b):",
"function_name": "is_divisible_by",
"parameter_list": "(a, b)"
},
{
"docstring": "Iterates from 10 to 25 by 4's and prints numbers that ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_divisible(n, divisor):\n \"\"\"\n Checks if n is divisible by divisor without using the modulus operator.\n \"\"\"\n return (n / divisor) == (n // divisor)\n\ndef print_divi... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042088",
"row_id": 42088,
"seed_ids": "['Qwen2-72B-Instruct_91440']"
} | 0.53652 | Filter_42088 | I | [
"is_divisible_by",
"print_divisible"
] | 2 | [
[
"print_divisible",
"is_divisible_by"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 965906fe25afdf1c3bfdc868995662bae5dd523c | 4331765e4b12b50c1562b5be6c286364a377ec0d | |||
v1.0 | instruct | Filter | Filter_42100_I | Create a python for-loop to print out the following list, but only print out the squares of the odd integers in the list that are also prime numbers. The solution should have a time complexity of O(n^2) where n is the length of the list, and should not use any external libraries for checking prime numbers. | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def print_prime_square_odd(numbers):
"""
Prints the squares of odd integers in the list that are also p... | from solution import is_prime, print_prime_square_odd
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(9) == False
assert is_prime(11) == True
def test_print_prime_square_odd(capfd):
numbers = ... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Prints the squares of odd integers in the list that are also prime numbers.",
"function_declaration": "def print_prime_square... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042100",
"row_id": 42100,
"seed_ids": "['Qwen2-72B-Instruct_91461']"
} | 0.568653 | Filter_42100 | I | [
"is_prime",
"print_prime_square_odd"
] | 2 | [
[
"print_prime_square_odd",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 64c01ecef5bae20f7201cdc8e5348b58e1160147 | 7d17f851f3d9d1067d1099a0b81e345a8f094286 | |||
v1.0 | instruct | Filter | Filter_42113_I | As an mlp-pytorch model prediction engineer, you need to implement a model on a device. However, there is a new constraint where you're given a custom function that determines the device based on certain conditions. Your task is to write an algorithm that will run the prediction process on the determined device using t... | class Device:
CPU = "cpu"
GPU = "gpu"
def determine_device(custom_function):
"""
Determines the device based on the custom function provided.
"""
return custom_function()
def model_prediction(model, input_data, custom_function):
"""
Runs the prediction process on the determined device ... | from solution import Device, determine_device, model_prediction, MockModel, MockInputData
def test_determine_device_cpu():
assert determine_device(lambda: Device.CPU) == Device.CPU
def test_determine_device_gpu():
assert determine_device(lambda: Device.GPU) == Device.GPU
def test_prediction_on_cpu():
mod... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class CustomDevice:\n def __init__(self, device_type):\n self.device_type = device_type\n\n def __str__(self):\n return self.device_type\n\ndef determine_device(condition):... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042113",
"row_id": 42113,
"seed_ids": "['Qwen2-72B-Instruct_91488']"
} | 0.339598 | Filter_42113 | I | [
"determine_device",
"model_prediction"
] | 2 | [
[
"model_prediction",
"determine_device"
]
] | 1 | [] | false | [
"Device",
"MockModel",
"MockInputData"
] | true | pytest | true | [] | true | 750f4c8b67e84e664a4ea37c7a2ac61944b35351 | 824fbeafcac33f919a54fe6eee60c3f3284cbe37 | |||
v1.0 | instruct | Filter | Filter_42115_I | Modify the following Python code to check if a given string is a palindrome using a recursive function. Your solution should have a time complexity of O(n) and should not use any built-in string manipulation functions (e.g. reverse(), slicing, etc.). | def is_palindrome_recursive(s, left, right):
"""
Checks if the string is a palindrome recursively.
:param s: The string to check
:param left: Pointer to the left character
:param right: Pointer to the right character
:return: True if the string is a palindrome, False otherwise
"""
if lef... | from solution import is_palindrome
def test_is_palindrome_empty_string():
assert is_palindrome("") == True
def test_is_palindrome_single_character():
assert is_palindrome("a") == True
def test_is_palindrome_odd_length():
assert is_palindrome("racecar") == True
def test_is_palindrome_even_length():
a... | [
{
"docstring": "Checks if the string is a palindrome recursively.\n:param s: The string to check\n:param left: Pointer to the left character\n:param right: Pointer to the right character\n:return: True if the string is a palindrome, False otherwise",
"function_declaration": "def is_palindrome_recursive(s, l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome_recursive(s, start, end):\n \"\"\"\n Check if the string `s` is a palindrome using a recursive approach.\n \n Args:\n s (str): The string to check.\n start ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042115",
"row_id": 42115,
"seed_ids": "['Qwen2-72B-Instruct_91491']"
} | 0.786936 | Filter_42115 | I | [
"is_palindrome_recursive",
"is_palindrome"
] | 2 | [
[
"is_palindrome",
"is_palindrome_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 817c63fa96d06c3f1f0a56939c7980d03c3ad1ef | 65dea3cbd9719c9676e6d2e4706183c21acdadaa | |||
v1.0 | instruct | Filter | Filter_42123_I | Architect a Python subroutine which accepts an array of n textual elements and two numeric parameters k and m. Return an array of the longest k words from the initial array, but only include those with a consonant count greater than or equal to m. | def consonant_count(word):
"""
Returns the number of consonants in a word.
"""
vowels = 'aeiouAEIOU'
return sum(1 for char in word if char.isalpha() and char not in vowels)
def longest_words_with_consonants(words, k, m):
"""
Returns the longest k words from the given list that have a conson... | from solution import longest_words_with_consonants, consonant_count
def test_consonant_count():
assert consonant_count("hello") == 3
assert consonant_count("world") == 4
assert consonant_count("aeiou") == 0
assert consonant_count("bcdfghjklmnpqrstvwxyz") == 21
def test_longest_words_with_consonants():... | [
{
"docstring": "Returns the number of consonants in a word.",
"function_declaration": "def consonant_count(word):",
"function_name": "consonant_count",
"parameter_list": "(word)"
},
{
"docstring": "Returns the longest k words from the given list that have a consonant count of at least m.",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_consonants(word):\n \"\"\"\n Returns the number of consonants in the given word.\n \"\"\"\n consonants = \"bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ\"\n return sum(1 ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042123",
"row_id": 42123,
"seed_ids": "['Qwen2-72B-Instruct_91508']"
} | 0.675004 | Filter_42123 | I | [
"consonant_count",
"longest_words_with_consonants"
] | 2 | [
[
"longest_words_with_consonants",
"consonant_count"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f3815d3a5072fb8e23e070ca824ccabbff0e48fc | aaea10ea751481ebeec760471f50af79be371c9d | |||
v1.0 | instruct | Filter | Filter_42132_I | Refine the script to accurately determine the longest identical substrings amidst a couple of text inputs disregarding case-sensitivity. Moreover, identify substrings that signify prime numbers. Your solution should still manage to maintain overall comprehendability and brevity as best as possible. | def is_prime(n):
"""
Checks if a number is a prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def longest_common_substring(s1, s2):
"""
Finds the longest common substring between s1 and s2 ignoring... | from solution import longest_common_substring, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(17) == True
assert is_prime(1... | [
{
"docstring": "Checks if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Finds the longest common substring between s1 and s2 ignoring case, \nand identifies if the substring represents a prime number... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042132",
"row_id": 42132,
"seed_ids": "['Qwen2-72B-Instruct_91523']"
} | 0.575716 | Filter_42132 | I | [
"is_prime",
"longest_common_substring"
] | 2 | [
[
"longest_common_substring",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 80039507ba9706316a0d81842604150332a6b7bc | 1654b67385a96133e960641e7d07d4092ba20db9 | |||
v1.0 | instruct | Filter | Filter_42144_I | Write a python function that takes in a directory path and deletes all the files that have a ".txt" extension. It should prompt the user for confirmation before deleting any files. If the user confirms, the function should proceed with the deletion; if not, it should exit without deleting any files. Moreover, the funct... | import os
import csv
from datetime import datetime
def get_confirmation(prompt):
response = input(prompt).lower()
if response in ['yes', 'y']:
return True
return False
def delete_txt_files(directory_path):
deleted_files_count = 0
log_file_path = 'deleted_files_log.csv'
error_log_file_p... | import os
import tempfile
import pytest
from unittest import mock
from solution import delete_txt_files
@mock.patch('builtins.input', lambda *args: 'yes')
def test_delete_txt_files_success():
with tempfile.TemporaryDirectory() as tmpdirname:
# Create mock .txt files
for i in range(5):
w... | [
{
"docstring": null,
"function_declaration": "def get_confirmation(prompt):",
"function_name": "get_confirmation",
"parameter_list": "(prompt)"
},
{
"docstring": null,
"function_declaration": "def delete_txt_files(directory_path):",
"function_name": "delete_txt_files",
"parameter... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport csv\nfrom datetime import datetime\n\ndef get_confirmation(prompt):\n response = input(prompt).lower()\n if response in ['yes', 'y']:\n return True\n return F... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042144",
"row_id": 42144,
"seed_ids": "['Qwen2-72B-Instruct_91539']"
} | 0.613384 | Filter_42144 | I | [
"get_confirmation",
"delete_txt_files"
] | 2 | [
[
"delete_txt_files",
"get_confirmation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eb23b8b7d2c0635e6c4ccca896bf78da579d9ca9 | e9b5de7fc5d965b1206780f43173e9b75ce529c5 | |||
v1.0 | instruct | Filter | Filter_42151_I | Implement the Affine cipher encryption and decryption algorithms in Python. The Affine cipher is a monoalphabetic substitution cipher, where each letter in the plaintext is mapped to its numeric equivalent, encrypted using a simple mathematical function, and then converted back to a letter. The encryption function for ... | def affine_encrypt(plaintext, a, b):
"""
Encrypts the plaintext using the affine cipher with keys a and b.
"""
m = 26
if gcd(a, m) != 1:
raise ValueError("Key 'a' must be coprime with 26")
ciphertext = ''
for char in plaintext:
if char.isalpha():
x = ord(char... | from solution import affine_encrypt, affine_decrypt, mod_inverse, gcd
def test_affine_encrypt_decrypt():
a, b = 5, 8
plaintext = "HelloWorld"
ciphertext = affine_encrypt(plaintext, a, b)
decrypted_text = affine_decrypt(ciphertext, a, b)
assert decrypted_text == plaintext
def test_affine_encrypt_wi... | [
{
"docstring": "Encrypts the plaintext using the affine cipher with keys a and b.",
"function_declaration": "def affine_encrypt(plaintext, a, b):",
"function_name": "affine_encrypt",
"parameter_list": "(plaintext, a, b)"
},
{
"docstring": "Decrypts the ciphertext using the affine cipher with... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def affine_encrypt(plaintext, a, b):\n \"\"\"\n Encrypts the plaintext using the affine cipher with keys a and b.\n \"\"\"\n m = 26\n if gcd(a, m) != 1:\n raise ValueErro... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042151",
"row_id": 42151,
"seed_ids": "['Qwen2-72B-Instruct_91552']"
} | 0.586208 | Filter_42151 | I | [
"affine_encrypt",
"affine_decrypt",
"mod_inverse",
"gcd"
] | 4 | [
[
"affine_decrypt",
"mod_inverse"
],
[
"affine_encrypt",
"gcd"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 52760406d70b96830e959a8f1169d68549d0bdc6 | d0d071de7210f6ce53febb55e555cda27b1740c1 | |||
v1.0 | instruct | Filter | Filter_42153_I | Note the provided erroneous Python code for reference, it contains several inconsistencies that need to be rectified. Your principal task is to execute an interpolation search on a predefined sorted list where the probe value is a randomly selected element from a separate given list. Expected results are the index of t... | import random
def interpolation_search(sorted_list, item):
"""
Perform an interpolation search on a sorted list to find the index of the given item.
Parameters:
sorted_list (list): A list of sorted elements.
item (int): The element to search for.
Returns:
int: The index of the ite... | from solution import interpolation_search, find_index_of_random_element_from_another_list
import random
def test_interpolation_search_found():
sorted_list = [10, 22, 35, 47, 53, 68, 72, 88, 92, 105]
assert interpolation_search(sorted_list, 35) == 2
assert interpolation_search(sorted_list, 47) == 3
asse... | [
{
"docstring": "Perform an interpolation search on a sorted list to find the index of the given item.\n\nParameters:\nsorted_list (list): A list of sorted elements.\nitem (int): The element to search for.\n\nReturns:\nint: The index of the item if found, otherwise -1.",
"function_declaration": "def interpol... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef interpolation_search(sorted_list, item):\n \"\"\"\n Perform an interpolation search on a sorted list to find the index of the given item.\n \n Parameters:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042153",
"row_id": 42153,
"seed_ids": "['Qwen2-72B-Instruct_91558']"
} | 0.479376 | Filter_42153 | I | [
"interpolation_search",
"find_index_of_random_element_from_another_list"
] | 2 | [
[
"find_index_of_random_element_from_another_list",
"interpolation_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 333245eb7b218e4221b2cb6b70c065503d592bcd | 2d932df476ac7a0fa923691fd448126ff533add3 | |||
v1.0 | instruct | Filter | Filter_42157_I | Given a function that calculates the dynamic Lotka-Volterra equations of a predator-prey system, where for a given initial value for the number of prey (x1) and predators (x2), the functions dx1dt and dx2dt represents the change in populations of predator and prey respectively in an ecosystem, add funcional capacity fo... | import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def lotka_volterra(X, t, a, b, c, d):
x1, x2 = X
dx1dt = a * x1 - b * x1 * x2
dx2dt = -c * x2 + d * x1 * x2
return [dx1dt, dx2dt]
def solve_lotka_volterra(x1_0, x2_0, params, t):
"""
Solves the Lotka-Volterra... | from solution import solve_lotka_volterra, plot_vector_field
import numpy as np
import matplotlib.pyplot as plt
def test_solve_lotka_volterra():
# Define parameters for test
a = 1.0 # Prey birth rate
b = 0.1 # Predation rate
c = 1.5 # Predator death rate
d = 0.075 # Predator reproduction rate
... | [
{
"docstring": null,
"function_declaration": "def lotka_volterra(X, t, a, b, c, d):",
"function_name": "lotka_volterra",
"parameter_list": "(X, t, a, b, c, d)"
},
{
"docstring": "Solves the Lotka-Volterra equations for the given initial values and parameters\nover the specified time range.\n... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.integrate import solve_ivp\n\ndef lotka_volterra(t, z, alpha, beta, delta, gamma):\n \"\"\"\n Returns the derivatives for ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042157",
"row_id": 42157,
"seed_ids": "['Qwen2-72B-Instruct_91565']"
} | 0.304019 | Filter_42157 | I | [
"lotka_volterra",
"solve_lotka_volterra",
"plot_vector_field"
] | 3 | [
[
"solve_lotka_volterra",
"lotka_volterra"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy",
"scipy"
] | false | 279e1fa34d5f8bc1734dc4b76d376ecf76479c0d | 002f81652ebc6bf505ae13b79773ab7aba06bfdc | |||
v1.0 | instruct | Filter | Filter_42160_I | Debug and modify the following program to meet the new requirements. The function should generate a list of n random integers (with no duplicates) between 0 and 100. After this, the function should find all the *prime* numbers in the list. The prime numbers should then be sorted in descending order and replaced in the ... | import random
def generate_random_list(n):
"""
Generates a list of n random integers between 0 and 100 with no duplicates.
"""
if n > 101:
raise ValueError("Cannot generate more than 101 unique integers between 0 and 100")
random_list = random.sample(range(101), n)
return random_list
... | from solution import generate_random_list, is_prime, replace_and_sort_primes, generate_and_sort_primes
def test_generate_random_list():
assert len(generate_random_list(5)) == 5
random_list = generate_random_list(101)
assert sorted(random_list) == list(range(101))
try:
generate_random_list(102)
... | [
{
"docstring": "Generates a list of n random integers between 0 and 100 with no duplicates.",
"function_declaration": "def generate_random_list(n):",
"function_name": "generate_random_list",
"parameter_list": "(n)"
},
{
"docstring": "Checks if a number is a prime number.",
"function_decl... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef is_prime(num):\n \"\"\"Helper function to determine if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042160",
"row_id": 42160,
"seed_ids": "['Qwen2-72B-Instruct_91568']"
} | 0.588564 | Filter_42160 | I | [
"generate_random_list",
"is_prime",
"replace_and_sort_primes",
"generate_and_sort_primes"
] | 4 | [
[
"generate_and_sort_primes",
"generate_random_list"
],
[
"generate_and_sort_primes",
"replace_and_sort_primes"
],
[
"replace_and_sort_primes",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 924b142fee387c4ce0956dc9efaa0f301f126f59 | 6cc36b457ba1c04460c2e7414fffda02db4b160f | |||
v1.0 | instruct | Filter | Filter_42166_I | Refine the pseudo-code for a custom function that segregates irregular and regular strings using finite state automata (FSA). The function should have the signature `is_irregular_string(s: str) -> bool`. Furthermore, add an auxiliary function that tests for regular strings, `is_regular_string(s: str) -> bool`. You shou... | import re
def is_regular_string(s):
"""
Returns True if the string s is regular, defined by the regex pattern.
"""
pattern = r'^[a-zA-Z0-9]+$' # Alphanumeric (Regular)
return bool(re.match(pattern, s))
def is_irregular_string(s):
"""
Returns True if the string s is irregular, defined by t... | from solution import is_regular_string, is_irregular_string
def test_is_regular_string_with_alphanumeric():
assert is_regular_string("abc123") == True
assert is_regular_string("ABC") == True
assert is_regular_string("1234567890") == True
def test_is_regular_string_with_non_alphanumeric():
assert is_re... | [
{
"docstring": "Returns True if the string s is regular, defined by the regex pattern.",
"function_declaration": "def is_regular_string(s):",
"function_name": "is_regular_string",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the string s is irregular, defined by the lack of reg... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_irregular_string(s: str) -> bool:\n \"\"\"\n Returns True if the string is an irregular string based on complex FSA patterns,\n returns False otherwise.\n For t... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042166",
"row_id": 42166,
"seed_ids": "['Qwen2-72B-Instruct_91575']"
} | 0.47033 | Filter_42166 | I | [
"is_regular_string",
"is_irregular_string"
] | 2 | [
[
"is_irregular_string",
"is_regular_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aeb6c08d30bebdf062d75214004857393e39a874 | ee48e45e0e7eb41f336e9d37e7d2f5bfa97a528d | |||
v1.0 | instruct | Filter | Filter_42199_I | Create a Python program that reverses the order of the given list of integers using a recursive function, without using any built-in functions or auxiliary data structures. The program should handle edge cases, such as an empty list, and it should also include a function to check the correctness of the recursive functi... | def reverse_list_recursive(lst):
"""
Reverses the order of a given list of integers recursively.
Parameters:
lst (list): The list of integers to be reversed
Returns:
list: The reversed list
"""
if len(lst) == 0:
return []
return [lst[-1]] + reverse_list_recursive(ls... | from solution import reverse_list_recursive, check_reverse_correctness
def test_reverse_list_recursive_empty():
assert reverse_list_recursive([]) == []
def test_reverse_list_recursive_single_element():
assert reverse_list_recursive([1]) == [1]
def test_reverse_list_recursive_two_elements():
assert revers... | [
{
"docstring": "Reverses the order of a given list of integers recursively.\n\nParameters:\nlst (list): The list of integers to be reversed\n\nReturns:\nlist: The reversed list",
"function_declaration": "def reverse_list_recursive(lst):",
"function_name": "reverse_list_recursive",
"parameter_list": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_list(lst):\n \"\"\"\n Reverses the order of the given list of integers using a recursive function.\n \n :param lst: List of integers\n :return: Reversed list of inte... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042199",
"row_id": 42199,
"seed_ids": "['Qwen2-72B-Instruct_91626']"
} | 0.650923 | Filter_42199 | I | [
"reverse_list_recursive",
"check_reverse_correctness"
] | 2 | [
[
"check_reverse_correctness",
"reverse_list_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f49b7b64e4d0136e610286138621c9354f2f1bc6 | 63194a8023747fd3f1c620ad9e3336ac1b048a44 | |||
v1.0 | instruct | Filter | Filter_42203_I | Create a Python dictionary that stores square roots of prime numbers from 1 to 15. Additionally, implement functionality for checking if the input number is prime. Then, if the given number is prime, append its square root to the dictionary. | import math
def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
retur... | from solution import is_prime, generate_prime_sqrt_dict
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
def test_generate_prime_sqrt_dict():
result = generate_prime_sqrt_dict(15)
... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates a dictionary containing square roots of prime numbers up to n.",
"function_declaration": "def generate_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042203",
"row_id": 42203,
"seed_ids": "['Qwen2-72B-Instruct_91631']"
} | 0.609936 | Filter_42203 | I | [
"is_prime",
"generate_prime_sqrt_dict"
] | 2 | [
[
"generate_prime_sqrt_dict",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8a28da3e1ca955f5a2f03a6ecacb3dcb79e524f2 | effb7e3dc15f2a3222c1c505703d075d7efc390e | |||
v1.0 | instruct | Filter | Filter_42214_I | Devise a computational procedure which utilizes the principles of the quick sort methodology to marshal alphanumeric elements contained in a string based on their lexicographical order. | def quicksort_helper(arr):
"""
Helper function to perform quicksort on a list.
"""
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort_helpe... | from solution import quicksort_string
def test_quicksort_string_empty():
assert quicksort_string('') == ''
def test_quicksort_string_single_character():
assert quicksort_string('a') == 'a'
assert quicksort_string('1') == '1'
def test_quicksort_string_sorted_input():
assert quicksort_string('abc') == ... | [
{
"docstring": "Helper function to perform quicksort on a list.",
"function_declaration": "def quicksort_helper(arr):",
"function_name": "quicksort_helper",
"parameter_list": "(arr)"
},
{
"docstring": "Sorts the alphanumeric elements of a string in lexicographical order using quicksort.",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort_helper(arr):\n \"\"\"\n Helper function to perform quicksort on a list.\n \"\"\"\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042214",
"row_id": 42214,
"seed_ids": "['Qwen2-72B-Instruct_91647']"
} | 0.585707 | Filter_42214 | I | [
"quicksort_helper",
"quicksort_string"
] | 2 | [
[
"quicksort_string",
"quicksort_helper"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3d20ae46b9582b2f8dd1fc777e3f0c0a1594c60a | 48262bc60ff085010e45d592e7c1ef3377db7d60 | |||
v1.0 | instruct | Filter | Filter_42237_I | Write a code which calculates the least common multiple (LCM) for more than two integers using Python. It should handle inputs of up to 10^4 integers, each ranging from 1 to 10^5. Implement this without using any built-in LCM functions. | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Helper function that returns the least common multiple of a and b.
"""
return a * b // gcd(a, b)
def lcm_multiple(numbers):
"""
Returns the LCM of a list of numbers.
"""
return reduce(lcm, numbers) | from solution import lcm_multiple
def test_lcm_multiple_basic():
assert lcm_multiple([1, 2, 3]) == 6
assert lcm_multiple([4, 5, 10]) == 20
assert lcm_multiple([6, 8, 12]) == 24
def test_lcm_multiple_large_set():
assert lcm_multiple([3, 5, 9, 15, 30]) == 90
assert lcm_multiple([7, 14, 21, 35]) == 2... | [
{
"docstring": "Helper function that returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the LCM of a list of numbers.",
"function_declaration": "def lcm_multiple(numbers):... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Calculate the least common multiple of two integers.\n \"\"\"\n return a * b // gcd(a, b)\n\ndef lcm... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042237",
"row_id": 42237,
"seed_ids": "['Qwen2-72B-Instruct_91691']"
} | 0.68757 | Filter_42237 | I | [
"lcm",
"lcm_multiple"
] | 2 | [
[
"lcm_multiple",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bc5c72d4a1f480de10a1af342609ca63a6d05140 | c70cb6b493e5cee48f3e4e6172171f9aca69424e | |||
v1.0 | instruct | Filter | Filter_42239_I | Devise two sophisticated methods for identifying palindromic numbers within the range from 1 to a specified value n, utilizing Python programming language. You should not refer to, import, or use any external libraries or modules. Make sure that at least one of your methods employs a recursive function. Furthermore, co... | def is_palindrome_iterative(number):
"""
Returns True if the given number is a palindrome using an iterative approach.
"""
str_number = str(number)
return str_number == str_number[::-1]
def is_palindrome_recursive(number, original_str=None, reversed_str=''):
"""
Returns True if the given nu... | from solution import is_palindrome_iterative, is_palindrome_recursive, find_palindromic_numbers
def test_is_palindrome_iterative():
assert is_palindrome_iterative(121) == True
assert is_palindrome_iterative(12321) == True
assert is_palindrome_iterative(123) == False
assert is_palindrome_iterative(1) ==... | [
{
"docstring": "Returns True if the given number is a palindrome using an iterative approach.",
"function_declaration": "def is_palindrome_iterative(number):",
"function_name": "is_palindrome_iterative",
"parameter_list": "(number)"
},
{
"docstring": "Returns True if the given number is a pa... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome_recursive(number):\n \"\"\"\n Check if a number is a palindrome using recursion.\n \"\"\"\n def recurse_check(s, start, end):\n if start >= end:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042239",
"row_id": 42239,
"seed_ids": "['Qwen2-72B-Instruct_91693']"
} | 0.660714 | Filter_42239 | I | [
"is_palindrome_iterative",
"is_palindrome_recursive",
"find_palindromic_numbers"
] | 3 | [
[
"find_palindromic_numbers",
"is_palindrome_iterative"
],
[
"find_palindromic_numbers",
"is_palindrome_recursive"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cbb8bf1a613f1c47a3e24ed7beaf737798162eb8 | 10771072908a908827ebd874f6341ae49ca3d136 | |||
v1.0 | instruct | Filter | Filter_42240_I | Create a concise Python script to output the Fibonacci sequence up to the 10th term. Then modify the script to recursively compute the Fibonacci number for any user-provided position in the sequence (e.g., 15th, 20th term). Make sure to provide commentary to explain your function. Start writing your script below this l... | def fibonacci_recursive(n):
"""
Returns the n-th Fibonacci number using a recursive approach.
"""
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
def fibonacci_sequence(n):
"""
Generates and returns a lis... | from solution import fibonacci_recursive, fibonacci_sequence
def test_fibonacci_recursive_base_cases():
assert fibonacci_recursive(0) == 0
assert fibonacci_recursive(1) == 1
def test_fibonacci_recursive():
assert fibonacci_recursive(2) == 1
assert fibonacci_recursive(3) == 2
assert fibonacci_recur... | [
{
"docstring": "Returns the n-th Fibonacci number using a recursive approach.",
"function_declaration": "def fibonacci_recursive(n):",
"function_name": "fibonacci_recursive",
"parameter_list": "(n)"
},
{
"docstring": "Generates and returns a list containing the Fibonacci sequence up to the n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Returns the Fibonacci sequence up to the nth term.\n \"\"\"\n sequence = []\n a, b = 0, 1\n for _ in range(n):\n sequence.append(... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042240",
"row_id": 42240,
"seed_ids": "['Qwen2-72B-Instruct_91695']"
} | 0.727085 | Filter_42240 | I | [
"fibonacci_recursive",
"fibonacci_sequence"
] | 2 | [
[
"fibonacci_sequence",
"fibonacci_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d8b97ea7ca0a509ff043ff5c0ab8ded495e0a8f | 88e7a83f345ad43ced7ccfd7af22354395a5334a | |||
v1.0 | instruct | Filter | Filter_42258_I | Write a Python program that converts decimal numbers to ternary (base 3) representation for all numbers in a given range and also efficiently handles negative inputs by converting them into their two's complement in ternary before conversion. | def decimal_to_ternary(n):
"""
Converts a given decimal number to its ternary (base 3) representation.
Handles both positive and negative numbers.
"""
if n == 0:
return '0'
result = ''
is_negative = n < 0
n = abs(n)
while n > 0:
result = str(n % 3) + result
... | from solution import decimal_to_ternary, decimal_range_to_ternary
def test_decimal_to_ternary_positive():
assert decimal_to_ternary(5) == '12'
assert decimal_to_ternary(10) == '101'
assert decimal_to_ternary(27) == '1000'
def test_decimal_to_ternary_negative():
assert decimal_to_ternary(-5) == '-12'
... | [
{
"docstring": "Converts a given decimal number to its ternary (base 3) representation.\nHandles both positive and negative numbers.",
"function_declaration": "def decimal_to_ternary(n):",
"function_name": "decimal_to_ternary",
"parameter_list": "(n)"
},
{
"docstring": "Converts all decimal ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decimal_to_ternary(n):\n \"\"\"\n Convert a decimal number to its ternary (base 3) representation. Handles both positive\n and negative numbers using two's complement representati... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042258",
"row_id": 42258,
"seed_ids": "['Qwen2-72B-Instruct_91725']"
} | 0.617543 | Filter_42258 | I | [
"decimal_to_ternary",
"decimal_range_to_ternary"
] | 2 | [
[
"decimal_range_to_ternary",
"decimal_to_ternary"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ccc8e3309dccda1f00aa34bfa2f2aec7e0613084 | e5566b6796dcd7acca9177c42359841b6184df3a | |||
v1.0 | instruct | Filter | Filter_42264_I | Develop a program in Python that takes a series of chemical compound names as an input, and returns the molecular formula and the total number of atoms in each molecule. For instance, for the input 'Water', 'Ethanol', your program should output the respective molecular formulas and total atoms. | def get_molecular_info(compound_name):
"""
Returns the molecular formula and total number of atoms for a given
chemical compound name.
"""
compound_data = {
'Water': ('H2O', 3),
'Ethanol': ('C2H6O', 9),
'Carbon Dioxide': ('CO2', 3),
'Glucose': ('C6H12O6', 24)
}
... | from solution import get_compounds_info
def test_known_compounds():
input_data = ['Water', 'Ethanol', 'Carbon Dioxide', 'Glucose']
expected_output = [
('Water', 'H2O', 3),
('Ethanol', 'C2H6O', 9),
('Carbon Dioxide', 'CO2', 3),
('Glucose', 'C6H12O6', 24)
]
assert get_comp... | [
{
"docstring": "Returns the molecular formula and total number of atoms for a given \nchemical compound name.",
"function_declaration": "def get_molecular_info(compound_name):",
"function_name": "get_molecular_info",
"parameter_list": "(compound_name)"
},
{
"docstring": "Takes a list of chem... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef get_molecular_formula_and_atom_count(compound_name):\n \"\"\"\n Returns the molecular formula and total number of atoms for a given compound.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042264",
"row_id": 42264,
"seed_ids": "['Qwen2-72B-Instruct_91737']"
} | 0.426889 | Filter_42264 | I | [
"get_molecular_info",
"get_compounds_info"
] | 2 | [
[
"get_compounds_info",
"get_molecular_info"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af63dc6c5f9fd2f7cb2870c1beebb299c1d87092 | 18f443d0df7152fbaa9363a6ccdc6f48ea3418b6 | |||
v1.0 | instruct | Filter | Filter_42316_I | Compose a Python code that determines the Greatest Common Divisor (GCD) for two given integers. Then, extend the program to take in multiple pairs of integers from a CSV file, calculate their GCD, and write the results into another CSV file. The program should also validate the input to ensure only positive integers ar... | import csv
from math import gcd
from typing import List, Tuple
def calculate_gcd(a: int, b: int) -> int:
"""
Calculates the Greatest Common Divisor (GCD) of two positive integers a and b.
If the numbers are not positive integers, it raises a ValueError.
"""
if a <= 0 or b <= 0:
raise ValueE... | from solution import calculate_gcd, read_csv, write_csv, process_gcds
import pytest
import os
def test_calculate_gcd():
assert calculate_gcd(48, 18) == 6
assert calculate_gcd(101, 103) == 1
assert calculate_gcd(36, 60) == 12
assert calculate_gcd(1, 1) == 1
def test_calculate_gcd_invalid_input():
w... | [
{
"docstring": "Calculates the Greatest Common Divisor (GCD) of two positive integers a and b.\nIf the numbers are not positive integers, it raises a ValueError.",
"function_declaration": "def calculate_gcd(a, b):",
"function_name": "calculate_gcd",
"parameter_list": "(a, b)"
},
{
"docstring... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nfrom math import gcd\nfrom typing import List, Tuple\n\ndef calculate_gcd(a: int, b: int) -> int:\n \"\"\"\n Calculates the Greatest Common Divisor (GCD) of two positive inte... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042316",
"row_id": 42316,
"seed_ids": "['Qwen2-72B-Instruct_91854']"
} | 0.679319 | Filter_42316 | I | [
"calculate_gcd",
"read_csv",
"write_csv",
"process_gcds"
] | 4 | [
[
"process_gcds",
"calculate_gcd"
],
[
"process_gcds",
"read_csv"
],
[
"process_gcds",
"write_csv"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 87a7adaf62533c117867443dc34fd118725cc92b | d44298fc18dde14cae2ce1ec0ca84adfeea61aed | |||
v1.0 | instruct | Filter | Filter_42318_I | You face a 3x3 square grid of light bulbs - all initially turned off. In each turn you may randomly select any one light bulb and change its state, along with its horizontally and vertically adjacent neighbors (if there are any). Design a concise executable code snippet using the Python language that solves the light s... | import random
def toggle(grid, x, y):
"""
Toggles the state of the bulb at (x, y) and its horizontal
and vertical neighbors in the grid.
"""
def in_bounds(x, y):
return 0 <= x < len(grid) and 0 <= y < len(grid[0])
for dx, dy in [(0, 0), (1, 0), (-1, 0), (0, 1), (0, -1)]:
nx, ny... | from solution import toggle, all_on, solve_light_switch_puzzle
def test_toggle():
grid = [[False, False, False],
[False, False, False],
[False, False, False]]
toggle(grid, 1, 1)
expected_grid = [[False, True, False],
[True, True, True],
... | [
{
"docstring": "Toggles the state of the bulb at (x, y) and its horizontal\nand vertical neighbors in the grid.",
"function_declaration": "def toggle(grid, x, y):",
"function_name": "toggle",
"parameter_list": "(grid, x, y)"
},
{
"docstring": "Checks if all bulbs in the grid are on.",
"f... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef flip(matrix, x, y):\n matrix[x][y] = not matrix[x][y]\n if x > 0:\n matrix[x-1][y] = not matrix[x-1][y]\n if x < 2:\n matrix[x+1][y] = not matrix[x+... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042318",
"row_id": 42318,
"seed_ids": "['Qwen2-72B-Instruct_91856']"
} | 0.417292 | Filter_42318 | I | [
"toggle",
"all_on",
"solve_light_switch_puzzle"
] | 3 | [
[
"solve_light_switch_puzzle",
"all_on"
],
[
"solve_light_switch_puzzle",
"toggle"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6b473a3444510c9861482b684315d10e96ddf9ae | 17ed13ed8cd0083e9ebd2966b04752849807e2c1 | |||
v1.0 | instruct | Filter | Filter_42325_I | Implement the quicksort algorithm in Python, but with a twist. Instead of always choosing the last element as the pivot, choose a pivot using the "median-of-three" rule. This rule suggests picking the median element among the first, middle, and last elements of the array to better handle sorted or nearly sorted input d... | def median_of_three(arr, low, mid, high):
""" Helper function to find the median of three elements."""
elements = [arr[low], arr[mid], arr[high]]
elements.sort()
return elements[1]
def partition(arr, low, high):
mid = (low + high) // 2
pivot = median_of_three(arr, low, mid, high)
while Tru... | from solution import quicksort_wrapper
def test_quicksort_wrapper_single_element():
assert quicksort_wrapper([1]) == [1]
def test_quicksort_wrapper_sorted_array():
assert quicksort_wrapper([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_quicksort_wrapper_reverse_array():
assert quicksort_wrapper([5, 4, 3, 2... | [
{
"docstring": "Helper function to find the median of three elements.",
"function_declaration": "def median_of_three(arr, low, mid, high):",
"function_name": "median_of_three",
"parameter_list": "(arr, low, mid, high)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, l... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def median_of_three(arr, low, mid, high):\n \"\"\"\n Find the median of the first, middle, and last elements.\n \"\"\"\n a = arr[low]\n b = arr[mid]\n c = arr[high]\n if (... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042325",
"row_id": 42325,
"seed_ids": "['Qwen2-72B-Instruct_91871']"
} | 0.573208 | Filter_42325 | I | [
"median_of_three",
"partition",
"quicksort",
"quicksort_wrapper"
] | 4 | [
[
"partition",
"median_of_three"
],
[
"quicksort",
"partition"
],
[
"quicksort_wrapper",
"quicksort"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 93cfc91bf7add390af8b6ec4107ddc5d447fdd96 | fedcac41c49a9b80c069eb94da5a9a05295333eb | |||
v1.0 | instruct | Filter | Filter_42336_I | Construct a for-loop for calculating the factorial of a given positive integer number greater than 10. Additionally, perform an error check to ensure the entered number is valid, meaning it's not a negative number, zero, or a floating point number. After confirming the validity of the number, calculate the factorial us... | def is_valid_number(num):
"""
Check if the number is a valid positive integer greater than 10.
"""
return isinstance(num, int) and num > 10
def factorial_recursive(n):
"""
Calculate the factorial of a number using a recursive approach.
"""
if n == 1:
return 1
else:
r... | from solution import is_valid_number, factorial_recursive, factorial_iterative, calculate_factorial
def test_is_valid_number():
assert is_valid_number(11) == True
assert is_valid_number(10) == False
assert is_valid_number(-5) == False
assert is_valid_number(0) == False
assert is_valid_number(10.5) ... | [
{
"docstring": "Check if the number is a valid positive integer greater than 10.",
"function_declaration": "def is_valid_number(num):",
"function_name": "is_valid_number",
"parameter_list": "(num)"
},
{
"docstring": "Calculate the factorial of a number using a recursive approach.",
"func... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def factorial_iterative(n):\n if not isinstance(n, int) or n <= 10:\n raise ValueError(\"Input must be a positive integer greater than 10\")\n \n result = 1\n for i in range... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042336",
"row_id": 42336,
"seed_ids": "['Qwen2-72B-Instruct_91894']"
} | 0.599643 | Filter_42336 | I | [
"is_valid_number",
"factorial_recursive",
"factorial_iterative",
"calculate_factorial"
] | 4 | [
[
"calculate_factorial",
"factorial_iterative"
],
[
"calculate_factorial",
"factorial_recursive"
],
[
"calculate_factorial",
"is_valid_number"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 93d9e33b34fba67643bc5228fa26ff97b8b60df0 | a82133cf9bc042c0fd54abd7418d5600d4288997 | |||
v1.0 | instruct | Filter | Filter_42369_I | Write a program that accurately calculates the Manhattan distance - the total absolute difference in the x-coordinates and y-coordinates - between two points in a 2D plane. Points are represented as objects or tuples with x and y coordinate values. Your implementation should also take into account that both the x and y... | def manhattan_distance(point1, point2):
"""
Calculate the Manhattan distance between two points in a 2D plane.
Each point is represented as a tuple (x, y) with x, y being integers or floating point numbers.
:param point1: Tuple (x1, y1) representing the first point.
:param point2: Tuple (x2, y2... | from solution import manhattan_distance, multiple_manhattan_distances
def test_manhattan_distance_integers():
assert manhattan_distance((1, 2), (4, 6)) == 7
def test_manhattan_distance_floats():
assert manhattan_distance((1.5, 2.5), (4.5, 6.5)) == 7.0
def test_manhattan_distance_negative_coordinates():
a... | [
{
"docstring": "Calculate the Manhattan distance between two points in a 2D plane.\nEach point is represented as a tuple (x, y) with x, y being integers or floating point numbers.\n\n:param point1: Tuple (x1, y1) representing the first point.\n:param point2: Tuple (x2, y2) representing the second point.\n:retur... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def manhattan_distance(point1, point2):\n \"\"\"\n Calculate the Manhattan distance between two points in a 2D plane.\n \n Parameters:\n - point1: tuple or list with two numbers... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042369",
"row_id": 42369,
"seed_ids": "['Qwen2-72B-Instruct_91965']"
} | 0.687859 | Filter_42369 | I | [
"manhattan_distance",
"multiple_manhattan_distances"
] | 2 | [
[
"multiple_manhattan_distances",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d8f75c0b514e178f7b1605bf9bfbe5e62f3687fd | 5b311848f3aaff0e9c6897f84c899d272cc7fe24 | |||
v1.0 | instruct | Filter | Filter_42370_I | Create a Python list comprehension that generates a list of all even numbers between 10 and 30 (inclusive). Then create a function to filter this list, returning only prime numbers. Please classify numbers under 20 and above 20 separately. | def generate_even_numbers(start=10, end=30):
"""
Generates a list of all even numbers between start and end (inclusive).
"""
return [x for x in range(start, end + 1) if x % 2 == 0]
def is_prime(n):
"""
Checks if the number n is prime.
"""
if n <= 1:
return False
for i in ran... | from solution import generate_even_numbers, is_prime, filter_prime_numbers, classify_numbers, classify_and_filter_primes
def test_generate_even_numbers():
assert generate_even_numbers(10, 30) == [10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3)... | [
{
"docstring": "Generates a list of all even numbers between start and end (inclusive).",
"function_declaration": "def generate_even_numbers(start=10, end=30):",
"function_name": "generate_even_numbers",
"parameter_list": "(start=10, end=30)"
},
{
"docstring": "Checks if the number n is prim... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_even_numbers():\n \"\"\"\n Generates a list of all even numbers between 10 and 30 (inclusive).\n \"\"\"\n return [x for x in range(10, 31) if x % 2 == 0]\n\ndef is_pri... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042370",
"row_id": 42370,
"seed_ids": "['Qwen2-72B-Instruct_91966']"
} | 0.582791 | Filter_42370 | I | [
"generate_even_numbers",
"is_prime",
"filter_prime_numbers",
"classify_numbers",
"classify_and_filter_primes"
] | 5 | [
[
"classify_and_filter_primes",
"classify_numbers"
],
[
"classify_and_filter_primes",
"filter_prime_numbers"
],
[
"classify_and_filter_primes",
"generate_even_numbers"
],
[
"filter_prime_numbers",
"is_prime"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | e5aa0c1242881c35bdee77c9d25f7127518345c6 | 9e569ad355647ac2bae72a0ba9da284d3f53a39a | |||
v1.0 | instruct | Filter | Filter_42383_I | Create a Python script that takes an integer as input and prints the first n prime numbers, separated by commas. The script should include error handling for non-integer inputs and negative numbers. Additionally, the solution should have a time complexity of O(n log(log(n))) or better. | def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def first_n_primes(n):
"""Generate the fir... | from solution import is_prime, first_n_primes
import pytest
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
def test_first_n_primes():
assert first_n_primes(0) == []
assert first_... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"function_name": "first_n_primes",
"parameter_list": "(... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042383",
"row_id": 42383,
"seed_ids": "['Qwen2-72B-Instruct_91988']"
} | 0.651111 | Filter_42383 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 67a4c243f44c977e45d3edccdaaa0ea9d8aaa77d | e2500441882d248034e00c7da0502e82db0e958f | |||
v1.0 | instruct | Filter | Filter_42402_I | Create a Python code that takes in two strings and finds all common characters from the strings. The code should handle cases where there are multiple occurrences of a character in a string and should return a dictionary where the keys are the common characters and the values are the minimum occurrences of that charact... | def common_characters(str1, str2):
"""
Returns a dictionary of common characters and their minimum occurrences.
Parameters:
str1 (str): The first input string
str2 (str): The second input string
Returns:
dict: A dictionary where keys are common characters and values are the minimum... | from solution import common_characters, print_common_characters_report
def test_common_characters_basic():
result = common_characters("apple", "plea")
assert result == {'p': 1, 'l': 1, 'e': 1, 'a': 1}
def test_common_characters_case_sensitivity():
result = common_characters("Apple", "plea")
assert res... | [
{
"docstring": "Returns a dictionary of common characters and their minimum occurrences.\n\nParameters:\nstr1 (str): The first input string\nstr2 (str): The second input string\n\nReturns:\ndict: A dictionary where keys are common characters and values are the minimum occurrences of that character",
"functi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef find_common_characters(str1, str2):\n \"\"\"\n Finds all common characters from the two strings. \n Returns a dictionary where the keys are the ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042402",
"row_id": 42402,
"seed_ids": "['Qwen2-72B-Instruct_92024']"
} | 0.727003 | Filter_42402 | I | [
"common_characters",
"print_common_characters_report"
] | 2 | [
[
"print_common_characters_report",
"common_characters"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 64fbb703220dc4e166e40fa590d2c3925f2f13aa | 2f604da6298e4bdaccd82707006b72710f2eedb7 | |||
v1.0 | instruct | Filter | Filter_42404_I | Create a Python circuit for a classical 1-bit full adder using only logical operators (AND, OR, NOT, XOR). | def xor(a, b):
"""
Returns the XOR of a and b.
"""
return (a or b) and not (a and b)
def and_op(a, b):
"""
Returns the AND of a and b.
"""
return a and b
def or_op(a, b):
"""
Returns the OR of a and b.
"""
return a or b
def not_op(a):
"""
Returns the NOT of a.
... | from solution import xor, and_op, or_op, not_op, full_adder
def test_xor():
assert xor(0, 0) == 0
assert xor(0, 1) == 1
assert xor(1, 0) == 1
assert xor(1, 1) == 0
def test_and_op():
assert and_op(0, 0) == 0
assert and_op(0, 1) == 0
assert and_op(1, 0) == 0
assert and_op(1, 1) == 1
de... | [
{
"docstring": "Returns the XOR of a and b.",
"function_declaration": "def xor(a, b):",
"function_name": "xor",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the AND of a and b.",
"function_declaration": "def and_op(a, b):",
"function_name": "and_op",
"parameter_list": "(... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def xor(a, b):\n \"\"\"\n Returns the XOR of a and b.\n \"\"\"\n return (a or b) and not (a and b)\n\ndef and_(a, b):\n \"\"\"\n Returns the AND of a and b.\n \"\"\"\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042404",
"row_id": 42404,
"seed_ids": "['Qwen2-72B-Instruct_92028']"
} | 0.542353 | Filter_42404 | I | [
"xor",
"and_op",
"or_op",
"not_op",
"full_adder"
] | 5 | [
[
"full_adder",
"and_op"
],
[
"full_adder",
"or_op"
],
[
"full_adder",
"xor"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5657ac6d874454427c3af2289984360aaafcce24 | 32d9efedab26a26ebd7edb76e061679b0bbab8f8 | |||
v1.0 | instruct | Filter | Filter_42411_I | Write a recursive function to implement the quicksort algorithm to sort an array of integers. Additionally, implement a check function which generates a random array of n integers and uses the function to sort them. Remember to handle possible edge cases, like having an empty array or an array already sorted. | import random
def quicksort(arr):
"""
Sorts an array of integers using the quicksort algorithm.
"""
if len(arr) <= 1:
return arr
else:
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in ... | from solution import quicksort
def test_quicksort_empty_array():
assert quicksort([]) == []
def test_quicksort_single_element():
assert quicksort([1]) == [1]
def test_quicksort_sorted_array():
assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_quicksort_reverse_sorted_array():
assert quic... | [
{
"docstring": "Sorts an array of integers using the quicksort algorithm.",
"function_declaration": "def quicksort(arr):",
"function_name": "quicksort",
"parameter_list": "(arr)"
},
{
"docstring": "Generates a random array of n integers and sorts it using quicksort.",
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef quicksort(arr):\n \"\"\"\n Recursively sorts an array of integers using the quicksort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n pi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042411",
"row_id": 42411,
"seed_ids": "['Qwen2-72B-Instruct_92040']"
} | 0.629223 | Filter_42411 | I | [
"quicksort",
"check"
] | 2 | [
[
"check",
"quicksort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c635b424f90d4063f23bb19974dcc4ae302375c5 | 14af1ac4a2644833f549ef4af16bee8eb9470514 | |||
v1.0 | instruct | Filter | Filter_42417_I | Write a python code to generate a list with first 20 prime numbers | def is_prime(n):
"""
Check if a number n is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def first_n_primes(n):
... | from solution import is_prime, first_n_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(20) == False
def test_first_n_primes():
expected_primes = [2, 3, 5, 7... | [
{
"docstring": "Check if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a list of the first n prime numbers.",
"function_declaration": "def first_n_primes(n):",
"function_nam... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i ==... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042417",
"row_id": 42417,
"seed_ids": "['Qwen2-72B-Instruct_92052']"
} | 0.56386 | Filter_42417 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d728282fe863b714cae044e2ba430dd0291fe358 | 1313acd75ad396927ebb45d5dbad310db0289b23 | |||
v1.0 | instruct | Filter | Filter_42470_I | Enhance the complexity of the problem presented in the code below. The function 'sequenceFormat' expects two arguments: a positive integer value 'n', and a sequence type, which could be one of these: ["odd", "even", "prime"]. It should generate a string sequence up to 'n' digits considering the particular pattern dicta... | def is_prime(num):
"""Return True if the number is a prime, else False"""
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def sequenceFormat(n, sequence_type):
"""
Generates a sequence up to 'n' considering ... | from solution import sequenceFormat
def test_sequence_odd():
assert sequenceFormat(10, "odd") == "1 3 5 7 9"
assert sequenceFormat(1, "odd") == "1"
def test_sequence_even():
assert sequenceFormat(10, "even") == "2 4 6 8 10"
assert sequenceFormat(1, "even") == ""
def test_sequence_prime():
assert ... | [
{
"docstring": "Return True if the number is a prime, else False",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generates a sequence up to 'n' considering the particular pattern dictated by the sequence type.\nsequenc... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"Check if a number is prime.\"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042470",
"row_id": 42470,
"seed_ids": "['Qwen2-72B-Instruct_92140']"
} | 0.615071 | Filter_42470 | I | [
"is_prime",
"sequenceFormat"
] | 2 | [
[
"sequenceFormat",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c142b6016e9bf15aca1239463b33d5824bbed1ff | b769528c5d9cb86708fd2a67d388113d01942eb6 | |||
v1.0 | instruct | Filter | Filter_42498_I | Modify the given physical model of pendulum motion to simulate variations in the pendulum's acceleration due to gravity by including a user-defined function that allows for the calculation of the acceleration due to gravity based on the pendulum's location on Earth. In addition to this, add code to display the pendulum... | import numpy as np
import matplotlib.pyplot as plt
def acceleration_due_to_gravity(latitude):
"""
Calculate the acceleration due to gravity based on the latitude.
The formula used is simplified for educational purposes.
"""
return 9.780327 * (1 + 0.0053024 * np.sin(np.radians(latitude)) ** 2 - 0.00... | from solution import acceleration_due_to_gravity, pendulum_motion
def test_gravity_equator():
assert np.isclose(acceleration_due_to_gravity(0), 9.780327, atol=0.0001)
def test_gravity_poles():
assert np.isclose(acceleration_due_to_gravity(90), 9.832186, atol=0.0001)
def test_pendulum_velocity():
time, ve... | [
{
"docstring": "Calculate the acceleration due to gravity based on the latitude.\nThe formula used is simplified for educational purposes.",
"function_declaration": "def acceleration_due_to_gravity(latitude):",
"function_name": "acceleration_due_to_gravity",
"parameter_list": "(latitude)"
},
{
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\n\ndef calculate_gravity(latitude):\n \"\"\"\n Returns the acceleration due to gravity at a given latitude.\n Simplified model cons... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042498",
"row_id": 42498,
"seed_ids": "['Qwen2-72B-Instruct_92183']"
} | 0.320039 | Filter_42498 | I | [
"acceleration_due_to_gravity",
"pendulum_motion",
"generate_report"
] | 3 | [
[
"generate_report",
"pendulum_motion"
],
[
"pendulum_motion",
"acceleration_due_to_gravity"
]
] | 2 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy"
] | false | 6c1f6be0675250ef46cdd12004473859f49c151a | be829e522b9e6a4e498058aec44f3e2e1a04cc37 | |||
v1.0 | instruct | Filter | Filter_42538_I | Construct the Fibonacci series up to the 20th position using Python programming language, employing a looping mechanism. Also, once the Fibonacci series is constructed, write a function to find the Nth Fibonacci number from the series created. Remember, the function should be designed to handle exceptions efficiently, ... | def generate_fibonacci(n):
"""
Returns the Fibonacci series up to the nth position.
"""
if n < 0:
raise ValueError("n must be a non-negative integer")
fib_series = [0, 1]
for i in range(2, n+1):
fib_series.append(fib_series[-1] + fib_series[-2])
return fib_series[:n+1]
def g... | import pytest
from solution import generate_fibonacci, get_nth_fibonacci
def test_generate_fibonacci():
assert generate_fibonacci(0) == [0]
assert generate_fibonacci(1) == [0, 1]
assert generate_fibonacci(5) == [0, 1, 1, 2, 3, 5]
assert generate_fibonacci(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
d... | [
{
"docstring": "Returns the Fibonacci series up to the nth position.",
"function_declaration": "def generate_fibonacci(n):",
"function_name": "generate_fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def get_nth_fibonacc... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def construct_fibonacci_series(limit=20):\n \"\"\"\n Constructs the Fibonacci series up to the specified limit.\n Default limit is 20.\n \"\"\"\n if limit < 0:\n raise Va... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042538",
"row_id": 42538,
"seed_ids": "['Qwen2-72B-Instruct_92253']"
} | 0.758886 | Filter_42538 | I | [
"generate_fibonacci",
"get_nth_fibonacci"
] | 2 | [
[
"get_nth_fibonacci",
"generate_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e705ab50ec8e2252f310b6f16953c52809be5cd0 | 100bdfe28d12d43376466f79c4b22a243ced324f | |||
v1.0 | instruct | Filter | Filter_42558_I | Write a function call_hopper which takes in three parameters, prime, default_val, and random_val. The expected behavior is that it should initially check if the input prime is indeed a prime number. If the input prime is a prime number, it should randomly hop between the default_val and random_val when the function is ... | import random
def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import call_hopper, is_prime
def test_is_prime():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(30) == False
assert is_prime(-5) == False
def test_non_prime_initial_val... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a function that checks if prime is indeed a prime number.\nIf it is a prime number, it randomly hops between default_val a... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042558",
"row_id": 42558,
"seed_ids": "['Qwen2-72B-Instruct_92286']"
} | 0.504174 | Filter_42558 | I | [
"is_prime",
"call_hopper"
] | 2 | [
[
"call_hopper",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 377430847d551ec15c7fe512a9fc23780a0d67e7 | 31912f8bdd002cd98c8a908852e89a52201bbf90 | |||
v1.0 | instruct | Filter | Filter_42561_I | Develop an iterative method using Python language to yield the Prime number series up to a defined limit. Also, improve the efficiency of your function by incorporating the Sieve of Eratosthenes algorithm, and add functionality so that your program can determine whether a list of given m numbers are in the range of the... | def sieve_of_eratosthenes(limit):
"""
Returns a list of primes up to the given limit using the Sieve of Eratosthenes algorithm.
"""
if limit < 2:
return []
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers.
for start in range(2, int(limit**0.... | from solution import sieve_of_eratosthenes, are_numbers_in_prime_series
def test_sieve_of_eratosthenes_basic():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
def test_sieve_of_eratosthenes_limit_2():
assert sieve_of_eratosthenes(2) == [2]
def test_sieve_of_eratosthenes_limit_1():
assert sieve_of_erato... | [
{
"docstring": "Returns a list of primes up to the given limit using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Determines whether the numbers in ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generates a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_prime = [True] * (limi... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042561",
"row_id": 42561,
"seed_ids": "['Qwen2-72B-Instruct_92290']"
} | 0.655894 | Filter_42561 | I | [
"sieve_of_eratosthenes",
"are_numbers_in_prime_series"
] | 2 | [
[
"are_numbers_in_prime_series",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4139e3dc80b695b0c39a46f3dec8e516ceb517bb | 291d756b37dc8bc763fba3ec1e24b926418aef7e | |||
v1.0 | instruct | Filter | Filter_42598_I | Programmatically, how can one construct a list of all three-digit prime numbers in Python, and print the resulting list? In addition, How can you incorporate exception handling for potential errors that might arise during the execution of the program? | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def list_three_digit_primes():
... | from solution import is_prime, list_three_digit_primes
def test_is_prime():
assert is_prime(101) == True
assert is_prime(102) == False
assert is_prime(2) == True
assert is_prime(1) == False
assert is_prime(97) == True
assert is_prime(99) == False
def test_list_three_digit_primes():
primes ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return a list of all three-digit prime numbers.",
"function_declaration": "def list_three_digit_primes():",
"function_name... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042598",
"row_id": 42598,
"seed_ids": "['Qwen2-72B-Instruct_92353']"
} | 0.55207 | Filter_42598 | I | [
"is_prime",
"list_three_digit_primes"
] | 2 | [
[
"list_three_digit_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 825aec09032f2488c3e8cf985d50d3b959f7c7d9 | daf7ec22b9d44b9ec120fc38d6bb4a802f4b7349 | |||
v1.0 | instruct | Filter | Filter_42613_I | Generate the first 10 prime numbers using a python program and then define a function to check whether a given number is prime or not using the Sieve of Eratosthenes algorithm. Use the function to validate your generated prime numbers. Besides, optimize your program to efficiently handle large number inputs. | def generate_primes(n):
"""
Generates the first n prime numbers.
"""
primes = []
candidate = 2
while len(primes) < n:
for prime in primes:
if candidate % prime == 0:
break
else:
primes.append(candidate)
candidate += 1
return pri... | from solution import generate_primes, is_prime
def test_generate_primes():
# Test the first 10 primes
first_10_primes = generate_primes(10)
assert first_10_primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_is_prime_with_generated_primes():
# Validate each prime number generated
first_10_prim... | [
{
"docstring": "Generates the first n prime numbers.",
"function_declaration": "def generate_primes(n):",
"function_name": "generate_primes",
"parameter_list": "(n)"
},
{
"docstring": "Implements the Sieve of Eratosthenes to check for prime numbers up to max_number.",
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(n):\n \"\"\"\n Generate the first n prime numbers using the Sieve of Eratosthenes algorithm.\n \"\"\"\n if n < 1:\n return []\n \n primes = []\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042613",
"row_id": 42613,
"seed_ids": "['Qwen2-72B-Instruct_92381']"
} | 0.611774 | Filter_42613 | I | [
"generate_primes",
"sieve_of_eratosthenes",
"is_prime"
] | 3 | [
[
"is_prime",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 06a5af81cc6527c8e0f2faca2026f1130d28ea5c | 94926727da37a069037a56a6586646d4c490aaf0 | |||
v1.0 | instruct | Filter | Filter_42646_I | Write a python script that serves the purpose of a basic subscription reminder app.Use pickle to save subscribers information locally ; when the application starts , load any existing subscribers information . Information should include when the subscriber subscribed and needed to be reminded through email .Your script... | import pickle
import os
import time
from datetime import datetime, timedelta
SUBSCRIBERS_FILE = "subscribers.pickle"
def load_subscribers():
if os.path.exists(SUBSCRIBERS_FILE):
with open(SUBSCRIBERS_FILE, 'rb') as f:
subscribers = pickle.load(f)
else:
subscribers = []
return s... | import os
import pickle
from datetime import datetime, timedelta
from io import StringIO
import pytest
import time
# Import solution functions here to be tested
from solution import add_subscriber, load_subscribers, send_reminder, check_and_send_reminders, save_subscribers, SUBSCRIBERS_FILE
def test_add_subscriber():... | [
{
"docstring": null,
"function_declaration": "def load_subscribers():",
"function_name": "load_subscribers",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def save_subscribers(subscribers):",
"function_name": "save_subscribers",
"parameter_list": "(subsc... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import pickle\nimport os\nimport time\nfrom datetime import datetime, timedelta\n\nSUBSCRIBERS_FILE = \"subscribers.pickle\"\n\ndef load_subscribers():\n if os.path.exists(SUBSCRIBERS_FILE)... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042646",
"row_id": 42646,
"seed_ids": "['Qwen2-72B-Instruct_92451']"
} | 0.328745 | Filter_42646 | I | [
"load_subscribers",
"save_subscribers",
"add_subscriber",
"send_reminder",
"check_and_send_reminders"
] | 5 | [
[
"add_subscriber",
"load_subscribers"
],
[
"add_subscriber",
"save_subscribers"
],
[
"check_and_send_reminders",
"load_subscribers"
],
[
"check_and_send_reminders",
"save_subscribers"
],
[
"check_and_send_reminders",
"send_reminder"
]
] | 5 | [] | false | [] | false | pytest | true | [] | true | 9dc3c6534848c7c7f398722fdddc76d3a088fb64 | 8d4b23c34840f135d15943dab1918ca54a9ae841 | |||
v1.0 | instruct | Filter | Filter_42652_I | Complete the program by filling in the missing code to call the appropriate function and perform the necessary conversion. The program should take a user input angle in either degrees or radians and output the same angle in the opposite unit (if input is in degrees, output should be in radians, and vice versa). You sho... | def degrees_to_radians(degrees):
"""Convert degrees to radians."""
pi = 3.141592653589793
radians = degrees * (pi / 180)
return radians
def radians_to_degrees(radians):
"""Convert radians to degrees."""
pi = 3.141592653589793
degrees = radians * (180 / pi)
return degrees
def convert_an... | from solution import degrees_to_radians, radians_to_degrees, convert_angle
def test_degrees_to_radians():
assert abs(degrees_to_radians(180) - 3.141592653589793) < 1e-9
assert abs(degrees_to_radians(90) - 1.5707963267948966) < 1e-9
assert abs(degrees_to_radians(0) - 0) < 1e-9
def test_radians_to_degrees()... | [
{
"docstring": "Convert degrees to radians.",
"function_declaration": "def degrees_to_radians(degrees):",
"function_name": "degrees_to_radians",
"parameter_list": "(degrees)"
},
{
"docstring": "Convert radians to degrees.",
"function_declaration": "def radians_to_degrees(radians):",
... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def degrees_to_radians(degrees):\n \"\"\"\n Convert degrees to radians.\n \"\"\"\n pi = 3.141592653589793\n return degrees * (pi / 180)\n\ndef radians_to_degrees(radians):\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042652",
"row_id": 42652,
"seed_ids": "['Qwen2-72B-Instruct_92459']"
} | 0.671899 | Filter_42652 | I | [
"degrees_to_radians",
"radians_to_degrees",
"convert_angle"
] | 3 | [
[
"convert_angle",
"degrees_to_radians"
],
[
"convert_angle",
"radians_to_degrees"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cf7c94437e05f7e7923aa55bd69a0e98017bf3d7 | 4dcc3701daed264939548621e1cc05d9e6273735 | |||
v1.0 | instruct | Filter | Filter_42656_I | Use a for loop to print all prime numbers from 1 to 100 in separate lines. Additionally, the program should calculate and print the sum of all prime numbers in the given range. | def is_prime(n):
"""
Check if a number n is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def prime_numbers_sum_in_range(start, end):
"""
Print all prime numbers in the range from start... | import pytest
from solution import is_prime, prime_numbers_sum_in_range
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-3) == False
de... | [
{
"docstring": "Check if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Print all prime numbers in the range from start to end (inclusive),\nand return the sum of these prime numbers.",
"... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042656",
"row_id": 42656,
"seed_ids": "['Qwen2-72B-Instruct_92467']"
} | 0.546371 | Filter_42656 | I | [
"is_prime",
"prime_numbers_sum_in_range"
] | 2 | [
[
"prime_numbers_sum_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e230e684c7e61596b54eea0e1d4ff5230a11ab4 | a727417f39351ee675aecd515b988bf4c92d215c | |||
v1.0 | instruct | Filter | Filter_42659_I | Write a function to find the path from a source point to a destination point in a given 2D array grid with obstacles. The function should consider the obstacle locations and ensure the path does not intersect with these obstacles. | from collections import deque
def is_valid_move(grid, visited, x, y):
rows, cols = len(grid), len(grid[0])
return 0 <= x < rows and 0 <= y < cols and not grid[x][y] and not visited[x][y]
def find_path(grid, start, end):
if not grid or start == end:
return []
rows, cols = len(grid), len(grid[0... | from solution import find_path
def test_find_path_no_obstacle():
grid = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
start = (0, 0)
end = (2, 2)
assert find_path(grid, start, end) == [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)]
def test_find_path_with_obstacle():
grid = [
[0... | [
{
"docstring": null,
"function_declaration": "def is_valid_move(grid, visited, x, y):",
"function_name": "is_valid_move",
"parameter_list": "(grid, visited, x, y)"
},
{
"docstring": null,
"function_declaration": "def find_path(grid, start, end):",
"function_name": "find_path",
"p... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef find_path(grid, src, dest):\n \"\"\"\n Finds the shortest path from src to dest in a grid with obstacles.\n \n :param grid: List of lists repre... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042659",
"row_id": 42659,
"seed_ids": "['Qwen2-72B-Instruct_92473']"
} | 0.648867 | Filter_42659 | I | [
"is_valid_move",
"find_path"
] | 2 | [
[
"find_path",
"is_valid_move"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 59fe1abd38852e50c7893b8222e52f9d5ec7928f | c79cd697c30d3c3cbc767b78904d8f558ebb02d2 | |||
v1.0 | instruct | Filter | Filter_42664_I | Given a list of student and teacher names, I want you to create a python dictionary where the keys are the student names, and the values are lists of their individual birthdays. Each teacher can specify the birthdays of their students, and I will input the dates manually in YYYY-MM-DD format. To match teacher and stude... | from datetime import datetime
def is_valid_name(name):
"""
Validates if a given name string contains only alphabetic characters.
"""
return name.isalpha()
def is_valid_date(date_string):
"""
Validates if a given string is a valid date in YYYY-MM-DD format.
"""
try:
datetime.str... | from solution import is_valid_name, is_valid_date, create_birthdays_dict
def test_is_valid_name():
assert is_valid_name("Alice") == True
assert is_valid_name("Bob") == True
assert is_valid_name("Alice Bob") == False
assert is_valid_name("Alice123") == False
def test_is_valid_date():
assert is_vali... | [
{
"docstring": "Validates if a given name string contains only alphabetic characters.",
"function_declaration": "def is_valid_name(name):",
"function_name": "is_valid_name",
"parameter_list": "(name)"
},
{
"docstring": "Validates if a given string is a valid date in YYYY-MM-DD format.",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime\n\ndef validate_date(date_text):\n try:\n datetime.strptime(date_text, '%Y-%m-%d')\n return True\n except ValueError:\n return False\n\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042664",
"row_id": 42664,
"seed_ids": "['Qwen2-72B-Instruct_92480']"
} | 0.500805 | Filter_42664 | I | [
"is_valid_name",
"is_valid_date",
"create_birthdays_dict"
] | 3 | [
[
"create_birthdays_dict",
"is_valid_date"
],
[
"create_birthdays_dict",
"is_valid_name"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 69a5be8b4cdf1888087ba343075d9d28ddfe8f0b | bd4b5cb797a5696c6c8efa11102dfc3f970890e5 | |||
v1.0 | instruct | Filter | Filter_42668_I | Write a generator method that generates numbers in a Fibonacci-like sequence, but modifying the sequence such that after 1 and 1 the numbers follow the formula nth number = (n-1)th number + 2*(n-2)th number. Then, create a function to retrieve the nth number in this series. Your implementation should ideally use a gene... | def fibonacci_like_sequence():
a, b = 1, 1
yield a
yield b
while True:
a, b = b, b + 2 * a
yield b
def get_nth_fibonacci_like_number(n):
if n <= 0:
raise ValueError("n should be a positive integer.")
if n == 1 or n == 2:
return 1
gen = fibonacci_lik... | from solution import fibonacci_like_sequence, get_nth_fibonacci_like_number
def test_fibonacci_like_sequence():
gen = fibonacci_like_sequence()
assert next(gen) == 1
assert next(gen) == 1
assert next(gen) == 3 # 1 + 2*1
assert next(gen) == 5 # 3 + 2*1
assert next(gen) == 11 # 5 + 2*3
def te... | [
{
"docstring": null,
"function_declaration": "def fibonacci_like_sequence():",
"function_name": "fibonacci_like_sequence",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def get_nth_fibonacci_like_number(n):",
"function_name": "get_nth_fibonacci_like_number",... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def modified_fibonacci_generator():\n \"\"\"\n A generator that yields numbers in a modified Fibonacci sequence.\n After the initial two 1's, each number in the sequence is defined as... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042668",
"row_id": 42668,
"seed_ids": "['Qwen2-72B-Instruct_92489']"
} | 0.689518 | Filter_42668 | I | [
"fibonacci_like_sequence",
"get_nth_fibonacci_like_number"
] | 2 | [
[
"get_nth_fibonacci_like_number",
"fibonacci_like_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae1c5b687924d45d243c01c9c0583cd9ce572749 | d1a509f755ea1a493f2b4af452f838b5b77501fc | |||
v1.0 | instruct | Filter | Filter_42678_I | Develop a Python program that creates a random password with at least one uppercase, one lowercase, one number, and one special character. The length of the password should be configurable by the user with a maximum of 32 characters. Additionally, enhance the program to create multiple passwords according to user-defin... | import random
import string
def generate_password(length=12):
"""
Generates a random password with at least one uppercase, one lowercase,
one number, and one special character. The length of the password should be
at most 32 characters.
"""
if length > 32:
raise ValueError("Password len... | from solution import generate_password, generate_multiple_passwords
def test_generate_password_length():
password = generate_password(12)
assert len(password) == 12
def test_generate_password_max_length():
password = generate_password(32)
assert len(password) == 32
def test_generate_password_exceed_m... | [
{
"docstring": "Generates a random password with at least one uppercase, one lowercase,\none number, and one special character. The length of the password should be\nat most 32 characters.",
"function_declaration": "def generate_password(length=12):",
"function_name": "generate_password",
"parameter... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_password(length):\n if length > 32:\n raise ValueError(\"Password length cannot exceed 32 characters\")\n \n if length < 4:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042678",
"row_id": 42678,
"seed_ids": "['Qwen2-72B-Instruct_92507']"
} | 0.74776 | Filter_42678 | I | [
"generate_password",
"generate_multiple_passwords"
] | 2 | [
[
"generate_multiple_passwords",
"generate_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d86128056a1859caa57c8e9fba7bc71621347254 | 44f07492c601082d7e571c94b2a254ea491e9b1b | |||
v1.0 | instruct | Filter | Filter_42679_I | Implement the Sieve of Eratosthenes algorithm in a programming language of your choice to generate an array of the first 10001 prime numbers, each having at least four digits. After generating the primes, use them to create a hash map where each key-value pair corresponds to the prime number (key) and its reverse (valu... | def sieve_of_eratosthenes(limit):
"""
Generate a list of primes up to the limit using the Sieve of Eratosthenes.
"""
sieve = [True] * (limit + 1)
sieve[0], sieve[1] = False, False
primes = []
for start in range(2, limit + 1):
if sieve[start]:
primes.append(start)
... | import pytest
from solution import sieve_of_eratosthenes, generate_primes, create_prime_reverse_map, has_four_digits_and_is_unique
def test_sieve_of_eratosthenes():
primes = sieve_of_eratosthenes(30)
assert primes == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_generate_primes():
primes = generate_primes... | [
{
"docstring": "Generate a list of primes up to the limit using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Generate the first 'count' primes each having at ... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generate all primes up to the specified limit using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_prime = [True] * (limit + 1)\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042679",
"row_id": 42679,
"seed_ids": "['Qwen2-72B-Instruct_92510']"
} | 0.482863 | Filter_42679 | I | [
"sieve_of_eratosthenes",
"generate_primes",
"create_prime_reverse_map",
"has_four_digits_and_is_unique"
] | 4 | [
[
"generate_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b5015885fb9f76e8b8c5dcefccd5ee721cc6fd06 | bbbfa80e97f6c7fe5623016a10da9a8cf8d0085a | |||
v1.0 | instruct | Filter | Filter_42692_I | Increase the complexity in the given coding test by extending the list_of_items to a nested structure, handling varied depth levels with unique alphabetical characters, no sequential numbers, duplicating items identification and count besides sorting. Additionally, incorporate more distinct items with duplicate criteri... | from collections import Counter
def flatten_list(nested_list):
"""
Helper function to flatten a nested list.
"""
flat_list = []
for item in nested_list:
if isinstance(item, list):
flat_list.extend(flatten_list(item))
else:
flat_list.append(item)
return fl... | from solution import process_items
def test_single_level_list():
nested_list = ['a', 'b', 'a', 'c', 'b']
duplicates_count, sorted_items = process_items(nested_list)
assert duplicates_count == {'a': 2, 'b': 2}
assert sorted_items == ['a', 'a', 'b', 'b', 'c']
def test_two_level_list():
nested_list =... | [
{
"docstring": "Helper function to flatten a nested list.",
"function_declaration": "def flatten_list(nested_list):",
"function_name": "flatten_list",
"parameter_list": "(nested_list)"
},
{
"docstring": "Process the nested list to identify duplicates, count them, and sort the list.",
"fu... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\n\ndef flatten_list(nested_list):\n \"\"\"\n Flattens a nested list.\n \"\"\"\n result = []\n for item in nested_list:\n if isinstance(ite... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042692",
"row_id": 42692,
"seed_ids": "['Qwen2-72B-Instruct_92541']"
} | 0.436299 | Filter_42692 | I | [
"flatten_list",
"process_items"
] | 2 | [
[
"process_items",
"flatten_list"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7b47c7fadbda0e34f87fb6ca97f2ec28fedccf7 | 67a52ee7d24953c491e7dc581d14ae542dd42d97 | |||
v1.0 | instruct | Filter | Filter_42700_I | Given two binary search trees, write a function that returns the intersection of their elements, considering only prime numbers in each tree. You need to propose and implement your own data structure for representing the binary search trees instead of using existing standard library implementations. Also, handle duplic... | class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
def insert(self, key):
if self.root is None:
self.root = TreeNode(key)
else:
s... | from solution import TreeNode, BinarySearchTree, prime_intersection
def test_is_prime():
from solution import is_prime
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(13)
def test_prime_inters... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.key = key\n self.left = None\n self.right = None\n\nclass BinarySearchTree:\n def __init__(self):\n self.roo... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042700",
"row_id": 42700,
"seed_ids": "['Qwen2-72B-Instruct_92553']"
} | 0.570221 | Filter_42700 | I | [
"is_prime",
"prime_intersection"
] | 2 | [
[
"prime_intersection",
"is_prime"
]
] | 1 | [] | false | [
"TreeNode",
"BinarySearchTree"
] | true | pytest | true | [] | true | 9454beeeb3997fb600b12471417d748d939c6815 | 527b90e9adab1d085aebc6b392bbf392a5b61701 | |||
v1.0 | instruct | Filter | Filter_42707_I | Create a vector in Python that contains the first 10 prime numbers. Additionally, implement a function to check if a given number is prime and use it to validate the vector. Then, optimize the function to reduce complexity. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True... | from solution import is_prime, find_first_n_primes, validate_prime_vector
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a list of the first n prime numbers.",
"function_declaration": "def find_first_n_primes(n):",
"function_name": "f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_prime_vector(n):\n \"\"\"\n Generate a list of the first n prime numbers.\n \"\"\"\n primes = []\n candidate = 2\n while len(primes) < n:\n if is_prime(ca... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042707",
"row_id": 42707,
"seed_ids": "['Qwen2-72B-Instruct_92564']"
} | 0.634098 | Filter_42707 | I | [
"is_prime",
"find_first_n_primes",
"validate_prime_vector"
] | 3 | [
[
"find_first_n_primes",
"is_prime"
],
[
"validate_prime_vector",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d3681fd8a199cd8f1a30142ad36bf1679f19201b | 7dd70953491882683c8d9ddb77c8d9142f21931c | |||
v1.0 | instruct | Filter | Filter_42710_I | Modify the following block of code to use a dictionary comprehension and include in the dictionary only keys that are prime numbers and values that are Fibonacci numbers. The function should still maintain its original functionality of comparing the size of the two parameters and printing the larger one. | def is_prime(num):
"""
Check if a number is a prime number.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def fibonacci(n):
"""
Returns the nth Fibonacci number.
"""
a, b = 0, 1
for _... | from solution import is_prime, fibonacci, create_dict, compare_and_print
import pytest
from io import StringIO
import sys
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
def test_fibonacci():
assert fibonacci(0) == 0... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042710",
"row_id": 42710,
"seed_ids": "['Qwen2-72B-Instruct_92567']"
} | 0.620885 | Filter_42710 | I | [
"is_prime",
"fibonacci",
"create_dict",
"compare_and_print"
] | 4 | [
[
"create_dict",
"fibonacci"
],
[
"create_dict",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 63e4152cc181c76ebad1aac70941663e0fc43d3a | 5b29d988bcfcf0d3888f32efc13c671579eacd32 | |||
v1.0 | instruct | Filter | Filter_42724_I | You are asked to print text in red that has been converted to uppercase. However, you are restricted from using any built-in functions or methods for converting the text to uppercase and printing in red. How would you approach this challenge using only basic string manipulation and control structures? | def to_uppercase(text):
"""
Converts the input text to uppercase without using built-in functions.
"""
upper_text = ""
for char in text:
if 'a' <= char <= 'z':
upper_text += chr(ord(char) - 32)
else:
upper_text += char
return upper_text
def print_in_red(t... | from solution import to_uppercase, print_in_red, print_uppercase_in_red
import io
import sys
def test_to_uppercase():
assert to_uppercase("hello") == "HELLO"
assert to_uppercase("world") == "WORLD"
assert to_uppercase("Hello World") == "HELLO WORLD"
assert to_uppercase("HELLO WORLD") == "HELLO WORLD"
... | [
{
"docstring": "Converts the input text to uppercase without using built-in functions.",
"function_declaration": "def to_uppercase(text):",
"function_name": "to_uppercase",
"parameter_list": "(text)"
},
{
"docstring": "Prints the input text in red color without using built-in functions.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def to_uppercase_without_builtin(string):\n \"\"\"\n Converts a given string to uppercase without using any built-in functions.\n \"\"\"\n result = ''\n for char in string:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042724",
"row_id": 42724,
"seed_ids": "['Qwen2-72B-Instruct_92591']"
} | 0.58633 | Filter_42724 | I | [
"to_uppercase",
"print_in_red",
"print_uppercase_in_red"
] | 3 | [
[
"print_uppercase_in_red",
"print_in_red"
],
[
"print_uppercase_in_red",
"to_uppercase"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ed6adc33d2de73cc5186d9c122fff2dbf9f53489 | 1393fa4e697800c3fb17534cb8d8fd26df4f3d83 | |||
v1.0 | instruct | Filter | Filter_42732_I | Given the name of an image in the format 'test≪complexity-list≫.png' where 'complexity-list' is a comma-separated list of integers enclosed by angle brackets, write a Python function that extracts and sums these integers. The function should also check if the sum is a prime number. | def is_prime(n):
"""
Check if a number is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | def test_is_prime():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
def test_extract_and_sum_complexity():
assert extract_and_sum_complexity('test≪1,2,3≫.png') == (6, False)
assert extract_and_sum_complexity(... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Extracts the complexity list from the given filename, sums the integers and\nchecks if the sum is a prime number.\n\nArgs... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042732",
"row_id": 42732,
"seed_ids": "['Qwen2-72B-Instruct_92602']"
} | 0.537871 | Filter_42732 | I | [
"is_prime",
"extract_and_sum_complexity"
] | 2 | [
[
"extract_and_sum_complexity",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8fd0498629a2004cefde7baef1b71dc4d85b44f2 | 4271bb3f7fda9f4690e7a6fc8271bc594c484d9b | |||
v1.0 | instruct | Filter | Filter_42753_I | Given an input dictionary, write a function that prints the keys along with their associated values in reverse order by their insertion order. Moreover, if the value is a string, you have to reverse it as well. You are not allowed to use any built-in reversing methods or functions; you have to implement this functional... | def reverse_string(s):
"""
Manually reverses a given string.
"""
reversed_str = ""
for char in s:
reversed_str = char + reversed_str
return reversed_str
def reverse_dict_and_values(input_dict):
"""
Prints dictionary keys in reverse order of their insertion,
additionally reve... | from solution import reverse_string, reverse_dict_and_values
def test_reverse_string():
assert reverse_string("apple") == "elppa"
assert reverse_string("") == ""
assert reverse_string("abcd") == "dcba"
assert reverse_string("12345") == "54321"
def test_reverse_dict_and_values(capsys):
input_dict =... | [
{
"docstring": "Manually reverses a given string.",
"function_declaration": "def reverse_string(s):",
"function_name": "reverse_string",
"parameter_list": "(s)"
},
{
"docstring": "Prints dictionary keys in reverse order of their insertion,\nadditionally reverses string values manually.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_string(s):\n \"\"\"\n Manually reverse a given string.\n \"\"\"\n reversed_str = \"\"\n for char in s:\n reversed_str = char + reversed_str\n return revers... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042753",
"row_id": 42753,
"seed_ids": "['Qwen2-72B-Instruct_92637']"
} | 0.581424 | Filter_42753 | I | [
"reverse_string",
"reverse_dict_and_values"
] | 2 | [
[
"reverse_dict_and_values",
"reverse_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2e4582e5a1d1925eaf42ec558bf6dc13159fd9ce | aa693d4c9d2ee53f0d5cf0abd5ba9fabb47cb8d7 | |||
v1.0 | instruct | Filter | Filter_42770_I | Code a script that prints out the first n elements of the Fibonacci sequence, where n is a prime number. Additionally, ensure that the script handles cases where n is less than or equal to 1, and prints an error message in such cases. | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def fibonacci(n):
if not is_prime(n):
return "Error: n must be a prime number greater than 1."
fib_sequence = []
a, b = 0, 1
for _... | from solution import fibonacci, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(15) == False
def test_fibonacci_prime_n():
assert fibonacci(2) == [0, 1]
assert fibonacci(3) == [0, 1,... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
}
] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n return False\n return True\n\ndef fibonacci(n):\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042770",
"row_id": 42770,
"seed_ids": "['Qwen2-72B-Instruct_92666']"
} | 0.701503 | Filter_42770 | I | [
"is_prime",
"fibonacci"
] | 2 | [
[
"fibonacci",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4138eb2724c467f818595c62fc46f62d8dbb96b8 | 059fc5c0a976bc6cae372286d690da82480d7c13 | |||
v1.0 | instruct | Filter | Filter_42801_I | Create an array of elements that are the cubes of the prime numbers between 10 and 100. Implement error handling to handle any potential errors that may occur during the execution of the program, including handling situations where the cube of a prime number exceeds the maximum value that can be stored in the array. Ad... | import math
def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return Fals... | from solution import cube_of_prime_numbers_between_10_and_100, is_prime
def test_is_prime_basic_cases():
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert is_prime(5)
assert not is_prime(4)
assert not is_prime(9)
def test_is_prime_range():
primes = [11, 13, 17, 19, 23, 29... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns an array of cubes of the prime numbers between 10 and 100.\nThrows an error if the cube of a prime numb... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import isqrt\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n wh... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042801",
"row_id": 42801,
"seed_ids": "['Qwen2-72B-Instruct_92718']"
} | 0.574863 | Filter_42801 | I | [
"is_prime",
"cube_of_prime_numbers_between_10_and_100"
] | 2 | [
[
"cube_of_prime_numbers_between_10_and_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 620ec8ac49e26a04fd9864ed48c21a43e53b8b3e | 0ae9077dc65a9037af8c4401379af177136721d6 | |||
v1.0 | instruct | Filter | Filter_42813_I | Given two strings, create a function to find the total number of occurrences of the second string in the first string. This function should also account for overlapping occurrences. Additionally, implement a case-sensitive and a case-insensitive version of this function. | def count_overlapping_occurrences(haystack, needle):
"""
Returns the total number of overlapping occurrences of `needle` in `haystack`.
This function is case-sensitive.
"""
count = start = 0
while True:
start = haystack.find(needle, start) + 1
if start > 0:
count += 1... | from solution import count_overlapping_occurrences, count_overlapping_occurrences_case_insensitive
def test_count_overlapping_occurrences():
assert count_overlapping_occurrences("abababa", "aba") == 3
assert count_overlapping_occurrences("aaaa", "aa") == 3
assert count_overlapping_occurrences("abcdef", "gh... | [
{
"docstring": "Returns the total number of overlapping occurrences of `needle` in `haystack`.\nThis function is case-sensitive.",
"function_declaration": "def count_overlapping_occurrences(haystack, needle):",
"function_name": "count_overlapping_occurrences",
"parameter_list": "(haystack, needle)"
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_overlapping_occurrences(haystack, needle):\n \"\"\"\n Returns the total number of overlapping occurrences of `needle` in `haystack`.\n This function is case-sensitive.\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042813",
"row_id": 42813,
"seed_ids": "['Qwen2-72B-Instruct_92740']"
} | 0.68535 | Filter_42813 | I | [
"count_overlapping_occurrences",
"count_overlapping_occurrences_case_insensitive"
] | 2 | [
[
"count_overlapping_occurrences_case_insensitive",
"count_overlapping_occurrences"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c0469efc01917c44e600e07c93676c5ad87575e2 | 1f8b7725df9e2a6ee916d7fa771d603bace9c56f | |||
v1.0 | instruct | Filter | Filter_42822_I | How can I create a Python program to monitor the CPU usage of a remote server and alert me via email if the usage exceeds a certain threshold? | import psutil
import smtplib
from email.mime.text import MIMEText
def check_cpu_usage(threshold, host, port):
"""
Check the CPU usage of the given host and alert via email if it exceeds the threshold.
Note: This function expects that it is running on the remote server to monitor.
"""
# Get the CPU ... | # Since we cannot directly test the CPU usage or sending emails in an automated test,
# we will mock these parts of the code for our unit tests.
import pytest
from unittest.mock import patch, Mock
from solution import check_cpu_usage, send_alert
@patch("psutil.cpu_percent", return_value=90)
@patch("solution.send_aler... | [
{
"docstring": "Check the CPU usage of the given host and alert via email if it exceeds the threshold.\nNote: This function expects that it is running on the remote server to monitor.",
"function_declaration": "def check_cpu_usage(threshold, host, port):",
"function_name": "check_cpu_usage",
"parame... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport psutil\nimport time\nfrom email.mime.text import MIMEText\nfrom email.mime.multipart import MIMEMultipart\n\ndef send_email_alert(subject, body, to_email):\n from_ema... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042822",
"row_id": 42822,
"seed_ids": "['Qwen2.5-72B-Instruct_92756']"
} | 0.591395 | Filter_42822 | I | [
"check_cpu_usage",
"send_alert"
] | 2 | [
[
"check_cpu_usage",
"send_alert"
]
] | 1 | [] | false | [] | false | pytest | true | [
"psutil"
] | false | 91bf46b8a8a2df7ead001bc893b3a5cb9f3c737c | fd5b10aa9298ad24be20d71c169aa5612861b644 | |||
v1.0 | instruct | Filter | Filter_42845_I | Can you help me with some coding in Python? I'm trying to create a simple program that generates a list of prime numbers up to a certain limit. I want to be able to input the limit and get all the prime numbers up to that limit. Can you guide me through creating this program? | def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def genera... | from solution import is_prime, generate_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == F... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers up to the given limit.",
"function_declaration": "def generate_p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n elif n <= 3:\n return True\n elif n % 2... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042845",
"row_id": 42845,
"seed_ids": "['Qwen2.5-72B-Instruct_92785']"
} | 0.653204 | Filter_42845 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | feb30659c50460448de1926c57e7e8667204e9a2 | a4d05aa0f170f21a4f106aa76085c4b5f74b7a03 | |||
v1.0 | instruct | Filter | Filter_42868_I | How can I implement a basic version of a recommendation system using Python for a movie recommendation platform? I have a dataset of user ratings for movies and I want to recommend movies to users based on their past ratings. Can you provide a step-by-step guide, including the necessary Python libraries and a simple ex... | import pandas as pd
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
def create_user_movie_matrix(ratings):
user_movie_matrix = ratings.pivot(index='userId', columns='movieId', values='rating')
return user_movie_matrix
def calculate_similarity(user_movie_matrix):
user_similarity =... | from solution import create_user_movie_matrix, calculate_similarity, recommend_movies
import pandas as pd
def test_create_user_movie_matrix():
ratings = pd.DataFrame({
'userId': [1, 1, 2, 2, 3, 3],
'movieId': [1, 2, 2, 3, 3, 4],
'rating': [4, 5, 4, 3, 5, 4]
})
user_movie_matrix = cr... | [
{
"docstring": null,
"function_declaration": "def create_user_movie_matrix(ratings):",
"function_name": "create_user_movie_matrix",
"parameter_list": "(ratings)"
},
{
"docstring": null,
"function_declaration": "def calculate_similarity(user_movie_matrix):",
"function_name": "calculat... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import pandas as pd\nfrom sklearn.metrics.pairwise import cosine_similarity\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nimport numpy as np\n\n# Step-by-step guide to implemen... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042868",
"row_id": 42868,
"seed_ids": "['Qwen2.5-72B-Instruct_92816']"
} | 0.477506 | Filter_42868 | I | [
"create_user_movie_matrix",
"calculate_similarity",
"get_top_n_similar_users",
"recommend_movies"
] | 4 | [
[
"recommend_movies",
"get_top_n_similar_users"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"pandas",
"sklearn"
] | false | 69fd72b566acba17952179f5c9a93bcab9019984 | 64b260fbd33b40f40f151e04b40ed6c724e06dd1 | |||
v1.0 | instruct | Filter | Filter_42870_I | Is there a way to automate the process of checking the availability of domain names in bulk using Python? I have a list of about 500 domain names that I need to verify if they are registered or not. Can you provide a script that can help with this task? | import socket
def is_domain_available(domain):
"""
Checks if the given domain is available.
"""
try:
# If the domain has an IP address, it means it's registered
socket.gethostbyname(domain)
return False
except socket.gaierror:
# If the domain does not have any record... | from solution import is_domain_available, check_bulk_domain_availability
def test_is_domain_available():
# Assuming an extremely unlikely domain name to be taken
assert is_domain_available("veryunlikelydomainnametobetaken123456.com") == True
# Popular domain that should be taken
assert is_domain_availa... | [
{
"docstring": "Checks if the given domain is available.",
"function_declaration": "def is_domain_available(domain):",
"function_name": "is_domain_available",
"parameter_list": "(domain)"
},
{
"docstring": "Checks a list of domains for their availability.\n\n:param domains: List of domain na... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import socket\n\ndef is_domain_available(domain):\n \"\"\"\n Checks if the given domain is available.\n \"\"\"\n try:\n # If the domain has an IP address, it means it's regi... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042870",
"row_id": 42870,
"seed_ids": "['Qwen2.5-72B-Instruct_92818']"
} | 0.657988 | Filter_42870 | I | [
"is_domain_available",
"check_bulk_domain_availability"
] | 2 | [
[
"check_bulk_domain_availability",
"is_domain_available"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 38c1f47a5cdd3094cb85864fee61360fd62ab1cb | 723bff87f1ca923ebc28269382c26e9b28cfc179 | |||
v1.0 | instruct | Filter | Filter_42873_I | I need to write a Python program that takes a list of integers and returns the largest number that is also prime. If there are no prime numbers in the list, the program should return -1. How can I achieve this? | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for divisor in range(3, max_divisor, 2):
if n % divisor == 0:
return False
return... | from solution import is_prime, largest_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(-1) == Fals... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest prime number in the given list of integers. \nIf there are no prime numbers, returns -1.",
"function_decl... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ret... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042873",
"row_id": 42873,
"seed_ids": "['Qwen2.5-72B-Instruct_92822']"
} | 0.658219 | Filter_42873 | I | [
"is_prime",
"largest_prime"
] | 2 | [
[
"largest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f8c38dc2c44e92fbea48e3d835aa2ecc2a2521f3 | 2e22d154d312b3dc45407bf36bffb39fa469398e | |||
v1.0 | instruct | Filter | Filter_42909_I | Write a Python program that generates the Fibonacci sequence up to a number n, and then find the sum of all even-valued terms in the sequence. | def generate_fibonacci(n):
"""
Generates the Fibonacci sequence up to the number n.
"""
sequence = [0, 1]
while True:
next_term = sequence[-1] + sequence[-2]
if next_term > n:
break
sequence.append(next_term)
return sequence
def sum_of_even_fibonacci(n):
... | from solution import generate_fibonacci, sum_of_even_fibonacci
def test_generate_fibonacci():
assert generate_fibonacci(10) == [0, 1, 1, 2, 3, 5, 8]
assert generate_fibonacci(1) == [0, 1, 1]
assert generate_fibonacci(0) == [0, 1]
def test_sum_of_even_fibonacci():
assert sum_of_even_fibonacci(10) == 10... | [
{
"docstring": "Generates the Fibonacci sequence up to the number n.",
"function_declaration": "def generate_fibonacci(n):",
"function_name": "generate_fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Finds the sum of all even-valued terms in the Fibonacci sequence up to the number n."... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_sum_even(n):\n \"\"\"\n Generates the Fibonacci sequence up to number n and returns the sum of all even-valued terms.\n \"\"\"\n a, b = 0, 1\n sum_even = 0\n wh... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042909",
"row_id": 42909,
"seed_ids": "['Qwen2.5-72B-Instruct_92879']"
} | 0.686005 | Filter_42909 | I | [
"generate_fibonacci",
"sum_of_even_fibonacci"
] | 2 | [
[
"sum_of_even_fibonacci",
"generate_fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7a0a0062e6356855938e933a92745c402e9730a7 | ad2a8d614b824c4c72be73984555bc7863a15d5b | |||
v1.0 | instruct | Filter | Filter_42922_I | I want to write a Python script that will create a directory, write a file to it, and then delete the file and the directory. Can you provide a script that does this, with error handling for common issues like the directory or file already existing or not existing when trying to delete them? | import os
def create_directory(directory_path):
"""
Creates a directory if it doesn't already exist.
"""
try:
os.makedirs(directory_path, exist_ok=True)
return True
except Exception as e:
print(f"Error creating directory: {e}")
return False
def write_file(directory_... | import os
from solution import create_directory, write_file, delete_file, delete_directory
def test_create_directory():
test_directory = "test_dir"
assert create_directory(test_directory) == True
assert os.path.exists(test_directory) == True
os.rmdir(test_directory) # cleanup
def test_write_file():
... | [
{
"docstring": "Creates a directory if it doesn't already exist.",
"function_declaration": "def create_directory(directory_path):",
"function_name": "create_directory",
"parameter_list": "(directory_path)"
},
{
"docstring": "Writes content to a file in the specified directory. Creates the di... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\n\ndef create_directory(dir_name):\n \"\"\"\n Creates a directory. If the directory already exists, it skips creation.\n \"\"\"\n try:\n os.makedirs(dir_name, exis... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042922",
"row_id": 42922,
"seed_ids": "['Qwen2.5-72B-Instruct_92898']"
} | 0.586992 | Filter_42922 | I | [
"create_directory",
"write_file",
"delete_file",
"delete_directory"
] | 4 | [
[
"write_file",
"create_directory"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8f03e0194fe2ed8a4adf8dae15152f2093e5abb6 | a8f35225d7b23bbdbc6b1040f0d5d9db85d7d013 | |||
v1.0 | instruct | Filter | Filter_42930_I | Write a Python program to calculate the Fibonacci sequence up to the 50th term using recursion and memoization. Make sure to use a dictionary for memoization to optimize the performance. Display the first 50 terms of the Fibonacci sequence. | def fibonacci(n, memo={}):
"""
Returns the nth term in the Fibonacci sequence using memoization.
"""
if n in memo:
return memo[n]
if n <= 1:
return n
memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo)
return memo[n]
def fibonacci_sequence(terms):
"""
Ret... | from solution import fibonacci, fibonacci_sequence
def test_fibonacci_base_cases():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
def test_fibonacci_recursive_case_5():
assert fibonacci(5) == 5
def test_fibonacci_recursive_case_10():
assert fibonacci(10) == 55
def test_fibonacci_sequence_10():
... | [
{
"docstring": "Returns the nth term in the Fibonacci sequence using memoization.",
"function_declaration": "def fibonacci(n, memo={}):",
"function_name": "fibonacci",
"parameter_list": "(n, memo={})"
},
{
"docstring": "Returns the Fibonacci sequence up to the specified number of terms.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n, memo=None):\n \"\"\"\n Returns the nth term in the Fibonacci sequence, using memoization.\n \n Parameters:\n - n: The position of the term in the Fibonacci sequ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042930",
"row_id": 42930,
"seed_ids": "['Qwen2.5-72B-Instruct_92915']"
} | 0.745365 | Filter_42930 | I | [
"fibonacci",
"fibonacci_sequence"
] | 2 | [
[
"fibonacci_sequence",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 194f5d61a8c421e47cd0eaf1cc14bf86f6fe5497 | c71a9a142098c72f79ae133bd0d5f001d7ff7886 | |||
v1.0 | instruct | Filter | Filter_42960_I | How can I create a Python script to automate the process of checking if my website is up and running, and notify me via email if it goes down? | import smtplib
import requests
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(subject, body, to_email, from_email, smtp_server, smtp_port, smtp_login, smtp_password):
"""
Sends an email with the given subject and body to the specified email address.
... | import pytest
from unittest.mock import patch
from solution import check_website, send_email, monitor_website
def test_check_website_up():
with patch('requests.get') as mocked_get:
mocked_get.return_value.status_code = 200
assert check_website('http://example.com') == True
def test_check_website_d... | [
{
"docstring": "Sends an email with the given subject and body to the specified email address.\n\nParameters:\n- subject: Subject of the email\n- body: Body text of the email\n- to_email: Recipient email address\n- from_email: Sender email address\n- smtp_server: SMTP server address\n- smtp_port: SMTP server po... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport requests\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\n\ndef check_website(url):\n \"\"\"\n Check if the website is up and... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042960",
"row_id": 42960,
"seed_ids": "['Qwen2.5-72B-Instruct_92961']"
} | 0.497145 | Filter_42960 | I | [
"send_email",
"check_website",
"monitor_website"
] | 3 | [
[
"monitor_website",
"check_website"
],
[
"monitor_website",
"send_email"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 9426692349c82c95e07ac69059999809c6813986 | 898f0b90afa5033bb5979fdc074252aac40726bf | |||
v1.0 | instruct | Filter | Filter_42968_I | Write a Python function to generate a list of all prime numbers between two given numbers, inclusive. The function should be efficient and work well for generating prime numbers in a range up to 10^6. Ensure the function is well-documented and includes a check function to verify its correctness with provided data point... | def is_prime(n):
"""
Check if a given number n is prime.
Parameters:
n (int): The number to check for primality.
Returns:
bool: True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
... | from solution import generate_primes, is_prime
def test_generate_primes_small_range():
assert generate_primes(1, 10) == [2, 3, 5, 7]
def test_generate_primes_single_prime():
assert generate_primes(11, 11) == [11]
def test_generate_primes_no_primes():
assert generate_primes(8, 10) == []
def test_generate... | [
{
"docstring": "Check if a given number n is prime.\n\nParameters:\nn (int): The number to check for primality.\n\nReturns:\nbool: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 o... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042968",
"row_id": 42968,
"seed_ids": "['Qwen2.5-72B-Instruct_92971']"
} | 0.630902 | Filter_42968 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 755c3cb8935cda42da09f4d65b4598dde63a3993 | bbf67806a0071c7504322414b992c694ed63166b | |||
v1.0 | instruct | Filter | Filter_42972_I | Write a Python function that simulates the rolling of a six-sided die. The function should return a random number between 1 and 6, inclusive. Additionally, create a function to simulate rolling the die multiple times and return the results as a list. Use these functions to roll the die 10 times and print the results. | import random
def roll_die():
"""
Simulates the rolling of a six-sided die and returns a random number between 1 and 6, inclusive.
"""
return random.randint(1, 6)
def roll_die_multiple_times(n):
"""
Simulates rolling the six-sided die 'n' times and returns the results as a list.
Param... | from solution import roll_die, roll_die_multiple_times
# Mocking random.randint to generate a predictable output for testing
import random
def test_roll_die():
random.seed(0) # Set a seed for reproducibility
result = roll_die()
assert 1 <= result <= 6
def test_roll_die_multiple_times_length():
rando... | [
{
"docstring": "Simulates the rolling of a six-sided die and returns a random number between 1 and 6, inclusive.",
"function_declaration": "def roll_die():",
"function_name": "roll_die",
"parameter_list": "()"
},
{
"docstring": "Simulates rolling the six-sided die 'n' times and returns the r... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a six-sided die and returns a random number between 1 and 6.\n \"\"\"\n return random.randint(1, 6)\n\ndef roll_die_mu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00042972",
"row_id": 42972,
"seed_ids": "['Qwen2.5-72B-Instruct_92979']"
} | 0.641196 | Filter_42972 | I | [
"roll_die",
"roll_die_multiple_times"
] | 2 | [
[
"roll_die_multiple_times",
"roll_die"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b20ee1c406aa6c85765a989f8aff740b9ef29f38 | 9d3c1610b33441450214670418f20d5e2235f7e5 | |||
v1.0 | instruct | Filter | Filter_42988_I | I need to create a Python script that will read a list of file paths from a text file, then compress each file into a separate zip archive. The script should also log the process, including the name of the file being compressed and the name of the resulting zip archive. How can I do this? | import os
import zipfile
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
logger = logging.getLogger()
def compress_file(file_path):
"""
Compress a single file into a zip archive.
Args:
file_path (str): The full path to the file to compress.
Retu... | import os
import zipfile
# Prepare testing environment
def setup_module(module):
os.makedirs('test_files', exist_ok=True)
# Create sample files to compress
with open('test_files/sample1.txt', 'w') as f:
f.write("This is a sample file.")
with open('test_files/sample2.txt', 'w') as f:
... | [
{
"docstring": "Compress a single file into a zip archive.\n\nArgs:\nfile_path (str): The full path to the file to compress.\n\nReturns:\nstr: The path to the resulting zip archive.",
"function_declaration": "def compress_file(file_path):",
"function_name": "compress_file",
"parameter_list": "(file_... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport zipfile\nimport logging\n\nlogging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')\nlogger = logging.getLogger()\n\ndef compress_file(file_path):\n \"\... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00042988",
"row_id": 42988,
"seed_ids": "['Qwen2.5-72B-Instruct_93000']"
} | 0.71428 | Filter_42988 | I | [
"compress_file",
"compress_files_from_list"
] | 2 | [
[
"compress_files_from_list",
"compress_file"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 239f9d3dbee63c613ecf1f29ba674f6002bf4d9f | 0e5c39017e5c7e87887eb424122cfc04efee6c49 | |||
v1.0 | instruct | Filter | Filter_42995_I | Write a Python program to generate a list of prime numbers up to a given number n, and then find the sum of these prime numbers. The program should take an input n from the user and output the list of prime numbers and their sum. Ensure the program is efficient for values of n up to 1,000,000. | def sieve_of_eratosthenes(n):
"""
Returns a list of prime numbers up to n using the Sieve of Eratosthenes.
"""
primes = []
is_prime = [True] * (n + 1)
is_prime[0], is_prime[1] = False, False
for i in range(2, n + 1):
if is_prime[i]:
primes.append(i)
for j in ... | from solution import sieve_of_eratosthenes, sum_of_primes, generate_primes_and_sum
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(2) == [2]
def test_sum_of_primes():
assert sum_of_primes(10) == 17 #... | [
{
"docstring": "Returns a list of prime numbers up to n using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of prime numbers up to n.",
"function_d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00042995",
"row_id": 42995,
"seed_ids": "['Qwen2.5-72B-Instruct_93009']"
} | 0.649507 | Filter_42995 | I | [
"sieve_of_eratosthenes",
"sum_of_primes",
"generate_primes_and_sum"
] | 3 | [
[
"generate_primes_and_sum",
"sieve_of_eratosthenes"
],
[
"sum_of_primes",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 32769fe253038cc1ba57e5874f14c51e34b8c151 | 0f002d085925d887fc67c09c6e85381fd44dc3c3 | |||
v1.0 | instruct | Filter | Filter_43008_I | Write a Python program to simulate the rolling of two six-sided dice. The program should roll the dice 1000 times and print out the frequency of each possible sum (2 through 12). Additionally, calculate and print the average roll value. | import random
from collections import defaultdict
def roll_dice():
"""
Rolls two six-sided dice and returns their sum.
"""
return random.randint(1, 6) + random.randint(1, 6)
def simulate_dice_rolls(num_rolls=1000):
"""
Simulates rolling two six-sided dice for a specified number of rolls.
R... | import pytest
from solution import roll_dice, simulate_dice_rolls
def test_roll_dice_within_range():
for _ in range(1000):
roll_sum = roll_dice()
assert 2 <= roll_sum <= 12
def test_simulate_dice_rolls_frequency():
frequency, _ = simulate_dice_rolls(1000)
# Ensure that all possible sums be... | [
{
"docstring": "Rolls two six-sided dice and returns their sum.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates rolling two six-sided dice for a specified number of rolls.\nReturns the frequency of each possible ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_dice(num_rolls=1000):\n \"\"\"\n Rolls two six-sided dice num_rolls times and returns a dictionary with the frequency of each possible sum (2 through 12).\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043008",
"row_id": 43008,
"seed_ids": "['Qwen2.5-72B-Instruct_93033']"
} | 0.670228 | Filter_43008 | I | [
"roll_dice",
"simulate_dice_rolls"
] | 2 | [
[
"simulate_dice_rolls",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa8eb5858b67066383e68eae1bd1be5ac7c0d609 | 46fb3bd00a47618b0a3641f034bb86ab80bd5946 | |||
v1.0 | instruct | Filter | Filter_43013_I | Write a program in Python that prints the Fibonacci sequence up to the n-th number, where n is a user input. Make sure to handle invalid inputs, such as non-integer and negative numbers, by prompting the user to enter a valid positive integer. | def fibonacci_sequence(n):
"""
Returns the Fibonacci sequence up to the n-th number.
"""
if not isinstance(n, int) or n <= 0:
raise ValueError("Please enter a valid positive integer.")
sequence = []
a, b = 0, 1
for _ in range(n):
sequence.append(a)
a, b = b, a + ... | import pytest
from solution import fibonacci_sequence
def test_fibonacci_sequence_with_valid_input():
assert fibonacci_sequence(1) == [0]
assert fibonacci_sequence(2) == [0, 1]
assert fibonacci_sequence(5) == [0, 1, 1, 2, 3]
assert fibonacci_sequence(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test_f... | [
{
"docstring": "Returns the Fibonacci sequence up to the n-th number.",
"function_declaration": "def fibonacci_sequence(n):",
"function_name": "fibonacci_sequence",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def get_fibonacci_sequence():",
"function_name... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Returns the Fibonacci sequence up to the n-th number.\n \"\"\"\n if not isinstance(n, int) or n <= 0:\n raise ValueError(\"Please enter... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043013",
"row_id": 43013,
"seed_ids": "['Qwen2.5-72B-Instruct_93043']"
} | 0.780865 | Filter_43013 | I | [
"fibonacci_sequence",
"get_fibonacci_sequence"
] | 2 | [
[
"get_fibonacci_sequence",
"fibonacci_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 050d2b0c565a84d121c313ad8a3bdfcdf4822232 | dd0746ad7d034a41b3be59a19d4a01830bbb9552 | |||
v1.0 | instruct | Filter | Filter_43018_I | Explain how to use the `map` function in Python, and provide an example that converts a list of temperatures from Celsius to Fahrenheit. | def celsius_to_fahrenheit(celsius):
"""
Converts a temperature from Celsius to Fahrenheit.
"""
return celsius * 9/5 + 32
def convert_list_celsius_to_fahrenheit(temperatures_celsius):
"""
Converts a list of temperatures from Celsius to Fahrenheit using map.
"""
return list(map(celsius_to... | from solution import convert_list_celsius_to_fahrenheit
def test_convert_all_zeros():
assert convert_list_celsius_to_fahrenheit([0, 0, 0]) == [32.0, 32.0, 32.0]
def test_convert_mixed_temperatures():
assert convert_list_celsius_to_fahrenheit([0, 20, 37, 100]) == [32.0, 68.0, 98.6, 212.0]
def test_convert_neg... | [
{
"docstring": "Converts a temperature from Celsius to Fahrenheit.",
"function_declaration": "def celsius_to_fahrenheit(celsius):",
"function_name": "celsius_to_fahrenheit",
"parameter_list": "(celsius)"
},
{
"docstring": "Converts a list of temperatures from Celsius to Fahrenheit using map.... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def celsius_to_fahrenheit(celsius):\n \"\"\"\n Converts a temperature from Celsius to Fahrenheit.\n \"\"\"\n return (celsius * 9/5) + 32\n\ndef convert_temperatures(celsius_list):\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043018",
"row_id": 43018,
"seed_ids": "['Qwen2.5-72B-Instruct_93053']"
} | 0.457233 | Filter_43018 | I | [
"celsius_to_fahrenheit",
"convert_list_celsius_to_fahrenheit"
] | 2 | [
[
"convert_list_celsius_to_fahrenheit",
"celsius_to_fahrenheit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0c1c6b92cf82b614d237b735b9889a53c99bc710 | 343054b46a1d4dafd7d0c3f751483fcc61b60dd9 | |||
v1.0 | instruct | Filter | Filter_43029_I | Write a Python program that creates a simple calculator which can perform addition, subtraction, multiplication, and division based on user input. The program should continue to prompt the user for operations until they choose to exit. Include error handling for division by zero and invalid inputs. | def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def calculator():
while True:
print("Select operation:")
print("1. Add")
print("2.... | from solution import add, subtract, multiply, divide
import pytest
def test_add():
assert add(5, 3) == 8
assert add(-1, -1) == -2
assert add(0, 0) == 0
def test_subtract():
assert subtract(5, 3) == 2
assert subtract(-1, -1) == 0
assert subtract(5, -3) == 8
def test_multiply():
assert mult... | [
{
"docstring": null,
"function_declaration": "def add(a, b):",
"function_name": "add",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def subtract(a, b):",
"function_name": "subtract",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"fu... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def add(a, b):\n return a + b\n\ndef subtract(a, b):\n return a - b\n\ndef multiply(a, b):\n return a * b\n\ndef divide(a, b):\n if b == 0:\n raise ValueError(\"Cannot divid... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043029",
"row_id": 43029,
"seed_ids": "['Qwen2.5-72B-Instruct_93072']"
} | 0.597353 | Filter_43029 | I | [
"add",
"subtract",
"multiply",
"divide",
"calculator"
] | 5 | [
[
"calculator",
"add"
],
[
"calculator",
"divide"
],
[
"calculator",
"multiply"
],
[
"calculator",
"subtract"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 69e145e95bb8220ea3d9870eeea2a3d0a57aca20 | 7ccdebdb78dfc1280fa6326bd2089985bf7c991c | |||
v1.0 | instruct | Filter | Filter_43080_I | I want to learn how to code a simple game in Python. Can you guide me through the process? | import random
def generate_number():
"""
Generates a random number between 1 and 100.
"""
return random.randint(1, 100)
def check_guess(random_number, user_guess):
"""
Compares the user's guess with the random number and returns a hint.
Parameters:
random_number (int): The randoml... | from solution import generate_number, check_guess
def test_generate_number():
for _ in range(100): # Test multiple times to ensure randomness and range
number = generate_number()
assert 1 <= number <= 100
def test_check_guess_correct():
assert check_guess(50, 50) == 'correct'
def test_check_... | [
{
"docstring": "Generates a random number between 1 and 100.",
"function_declaration": "def generate_number():",
"function_name": "generate_number",
"parameter_list": "()"
},
{
"docstring": "Compares the user's guess with the random number and returns a hint.\n\nParameters:\nrandom_number (i... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef guess_the_number():\n \"\"\"\n Function to play the 'Guess the Number' game.\n \"\"\"\n number_to_guess = random.randint(1, 100)\n attempts = 0\n guess =... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043080",
"row_id": 43080,
"seed_ids": "['Qwen2.5-72B-Instruct_93155']"
} | 0.419237 | Filter_43080 | I | [
"generate_number",
"check_guess",
"guessing_game"
] | 3 | [
[
"guessing_game",
"check_guess"
],
[
"guessing_game",
"generate_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 893864ef68d8e88cedfc811c67b1e3143efe26bd | 037b79c755046f9aa65f0f2892324f68eafd16c3 | |||
v1.0 | instruct | Filter | Filter_43088_I | Write a Python program that simulates a simple game of rock, paper, scissors. The program should allow a human player to play against the computer. The computer's choice should be randomly generated. The game should be a best-of-3 series, where the first to win 2 out of 3 rounds wins the game. Display the result of eac... | import random
def get_computer_choice():
choices = ["rock", "paper", "scissors"]
return random.choice(choices)
def determine_winner(player, computer):
if player == computer:
return "tie"
elif (player == "rock" and computer == "scissors") or \
(player == "paper" and computer == "rock")... | from solution import determine_winner, get_computer_choice, play_round
def test_determine_winner():
assert determine_winner("rock", "scissors") == "player"
assert determine_winner("rock", "paper") == "computer"
assert determine_winner("rock", "rock") == "tie"
assert determine_winner("paper", "rock") ==... | [
{
"docstring": null,
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def determine_winner(player, computer):",
"function_name": "determine_winner",
"parameter_lis... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_choice():\n choices = [\"rock\", \"paper\", \"scissors\"]\n return random.choice(choices)\n\ndef determine_winner(player, computer):\n if player == c... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043088",
"row_id": 43088,
"seed_ids": "['Qwen2.5-72B-Instruct_93170']"
} | 0.521168 | Filter_43088 | I | [
"get_computer_choice",
"determine_winner",
"play_round",
"play_game"
] | 4 | [
[
"play_game",
"play_round"
],
[
"play_round",
"determine_winner"
],
[
"play_round",
"get_computer_choice"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 02d4031d5ed22fb97aad5ef2c754e667fe457cde | db6b51423776cfa5e1fd996473e116588faf2d68 | |||
v1.0 | instruct | Filter | Filter_43103_I | Write a function in Python that takes a list of numbers and returns a new list with the elements sorted in ascending order without using Python's built-in `sort()` or `sorted()` functions. The function should be efficient and use a sorting algorithm that is not bubble sort. Provide a brief explanation of the algorithm ... | def merge_sort(lst):
"""
Sorts a list in ascending order using the merge sort algorithm.
"""
if len(lst) <= 1:
return lst
# Divide the list into two halves
mid = len(lst) // 2
left_half = lst[:mid]
right_half = lst[mid:]
# Recursively split and merge
left_sorted = merge... | from solution import merge_sort
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_sort_single_element():
assert merge_sort([1]) == [1]
def test_merge_sort_sorted_list():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_reverse_list():
assert merge_sort(... | [
{
"docstring": "Sorts a list in ascending order using the merge sort algorithm.",
"function_declaration": "def merge_sort(lst):",
"function_name": "merge_sort",
"parameter_list": "(lst)"
},
{
"docstring": "Merges two sorted lists into one sorted list.",
"function_declaration": "def merge... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort(arr):\n \"\"\"\n Sorts a list of numbers in ascending order using the quicksort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043103",
"row_id": 43103,
"seed_ids": "['Qwen2.5-72B-Instruct_93193']"
} | 0.668969 | Filter_43103 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4e42d993f6c1b232b3cb8257ee0205052cd6e28e | e96c189b7435b486783cf8b49c6149c993f1ce27 | |||
v1.0 | instruct | Filter | Filter_43112_I | How can I create a Python function that calculates the distance between two points on the Earth's surface given their latitude and longitude? The function should use the Haversine formula for this calculation. Additionally, I want the function to be able to handle a list of coordinates and return the total distance of ... | import math
def haversine(lat1, lon1, lat2, lon2):
"""
Calculate the distance between two points on the Earth's surface using the Haversine formula.
Parameters:
- lat1, lon1: Latitude and Longitude of the first point
- lat2, lon2: Latitude and Longitude of the second point
Returns:
... | from solution import haversine, total_distance
def test_haversine_same_point():
assert haversine(0, 0, 0, 0) == 0
def test_haversine_known_distance():
# Distance between New York (40.7128° N, 74.0060° W) and London (51.5074° N, 0.1278° W)
ny_lat, ny_lon = 40.7128, -74.0060
lon_lat, lon_lon = 51.5074, ... | [
{
"docstring": "Calculate the distance between two points on the Earth's surface using the Haversine formula.\n\nParameters:\n- lat1, lon1: Latitude and Longitude of the first point\n- lat2, lon2: Latitude and Longitude of the second point\n\nReturns:\n- Distance in kilometers",
"function_declaration": "def... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import radians, cos, sin, sqrt, atan2\n\ndef haversine_distance(lat1, lon1, lat2, lon2):\n \"\"\"\n Calculate the Haversine distance between two points on the Earth specified i... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043112",
"row_id": 43112,
"seed_ids": "['Qwen2.5-72B-Instruct_93210']"
} | 0.709494 | Filter_43112 | I | [
"haversine",
"total_distance"
] | 2 | [
[
"total_distance",
"haversine"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 26e777877686e0c308a677bc9abc911bbcd72dc6 | 8acd7f0c0a5f1995689f73d6309842ce5e6e02e7 | |||
v1.0 | instruct | Filter | Filter_43117_I | I need to write a Python script that can automatically generate and print a random integer between 1 and 100, and then check if this number is a prime number. If it is a prime, the script should print "The number is a prime number.", otherwise, it should print "The number is not a prime number." Can you help me with th... | import random
def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(13) == True
assert is_prime(25) == False
assert is_prime(97) == True
assert is... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a random number between 1 and 100 and check if it is a prime number.",
"function_declaration": "def generate... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef is_prime(n):\n \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 =... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043117",
"row_id": 43117,
"seed_ids": "['Qwen2.5-72B-Instruct_93219']"
} | 0.664397 | Filter_43117 | I | [
"is_prime",
"generate_random_and_check_prime"
] | 2 | [
[
"generate_random_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8a8151f1c673d808e050f152b7c40e8bbc4151a7 | be7d771d0b27a60320909ead43b6b5f184257086 | |||
v1.0 | instruct | Filter | Filter_43119_I | Write a Python program that implements a simple text-based tic-tac-toe game for two players. The program should allow players to take turns inputting their moves, and it should check for a winner or a draw after each move. The game should be played on a 3x3 grid, and the program should display the grid after each move. | def print_board(board):
for row in board:
print(" | ".join(row))
print("-" * 5)
def check_winner(board):
# Check rows
for row in board:
if row[0] == row[1] == row[2] and row[0] != " ":
return True, row[0]
# Check columns
for col in range(3):
if b... | from solution import play_tic_tac_toe
def test_tic_tac_toe_win_row():
moves = [(0, 0), (1, 0), (0, 1), (1, 1), (0, 2)]
assert play_tic_tac_toe(moves) == "Player X wins!"
def test_tic_tac_toe_win_col():
moves = [(0, 0), (0, 1), (1, 0), (1, 1), (2, 0)]
assert play_tic_tac_toe(moves) == "Player X wins!"
... | [
{
"docstring": null,
"function_declaration": "def print_board(board):",
"function_name": "print_board",
"parameter_list": "(board)"
},
{
"docstring": null,
"function_declaration": "def check_winner(board):",
"function_name": "check_winner",
"parameter_list": "(board)"
},
{
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TicTacToe:\n def __init__(self):\n self.board = [[' ' for _ in range(3)] for _ in range(3)]\n self.current_player = 'X'\n\n def display_board(self):\n for row ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043119",
"row_id": 43119,
"seed_ids": "['Qwen2.5-72B-Instruct_93221']"
} | 0.426265 | Filter_43119 | I | [
"print_board",
"check_winner",
"check_draw",
"play_tic_tac_toe",
"main"
] | 5 | [
[
"play_tic_tac_toe",
"check_draw"
],
[
"play_tic_tac_toe",
"check_winner"
],
[
"play_tic_tac_toe",
"print_board"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | d93b38ceaf2bbaddf136113151c6c85ee27e35e6 | 63d49880d1dbbd914d8d75d4a51c3b4b783454d4 | |||
v1.0 | instruct | Filter | Filter_43137_I | How can I create a Python script that checks the availability of a website and sends an email alert if the site is down? | import smtplib
import requests
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def check_website(url):
"""
Check the availability of a website.
Parameters:
url (str): The URL of the website to check.
Returns:
bool: True if the website is ava... | import pytest
from unittest.mock import patch
from solution import check_website, send_email_alert, monitor_website
def test_check_website_up():
with patch('requests.get') as mocked_get:
mocked_get.return_value.status_code = 200
assert check_website('http://example.com') == True
def test_check_web... | [
{
"docstring": "Check the availability of a website.\n\nParameters:\n url (str): The URL of the website to check.\n\nReturns:\n bool: True if the website is available, False otherwise.",
"function_declaration": "def check_website(url):",
"function_name": "check_website",
"parameter_list": "(ur... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport requests\n\ndef check_website(url):\n \"\"\"\n Checks the availability of a website.\n Returns True if the website is up, False if the website is down.\n \"\... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043137",
"row_id": 43137,
"seed_ids": "['Qwen2.5-72B-Instruct_93243']"
} | 0.559583 | Filter_43137 | I | [
"check_website",
"send_email_alert",
"monitor_website"
] | 3 | [
[
"monitor_website",
"check_website"
],
[
"monitor_website",
"send_email_alert"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | c4fc7ee097aa7c79e64d83832ed15d0139f3c860 | a3deaef91b617cac734a07df2f79ffd885039885 | |||
v1.0 | instruct | Filter | Filter_43138_I | Write a Python function that simulates a simple text-based game where a player rolls a die to move forward on a board with 20 spaces. The game ends when the player reaches or passes the 20th space. The function should return the number of rolls it took to finish the game. Use a while loop to keep the game running until... | import random
def roll_die():
"""
Simulates rolling a six-sided die.
"""
return random.randint(1, 6)
def play_game():
"""
Simulates a game where a player rolls a die to move forward on a board with 20 spaces.
The game ends when the player reaches or passes the 20th space.
Returns the n... | from solution import play_game
def test_play_game():
# Since play_game involves randomness, we can't predict the exact number of rolls,
# but we can test that the function returns an integer and that it is greater than zero.
rolls = play_game()
assert isinstance(rolls, int)
assert rolls > 0
# The ... | [
{
"docstring": "Simulates rolling a six-sided die.",
"function_declaration": "def roll_die():",
"function_name": "roll_die",
"parameter_list": "()"
},
{
"docstring": "Simulates a game where a player rolls a die to move forward on a board with 20 spaces.\nThe game ends when the player reaches... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef play_game():\n \"\"\"\n Simulates a game where a player rolls a die to move forward on a board with 20 spaces.\n The function returns the number of rolls it took ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00043138",
"row_id": 43138,
"seed_ids": "['Qwen2.5-72B-Instruct_93244']"
} | 0.56927 | Filter_43138 | I | [
"roll_die",
"play_game"
] | 2 | [
[
"play_game",
"roll_die"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 004309effeef7d0b91766b3230cfb6ffbfcc0eec | 0bc838bd427f09524f5bd3560fa0952f86d09cc5 | |||
v1.0 | instruct | Filter | Filter_43234_I | Write a Python program that implements a basic version of the game "Rock, Paper, Scissors". The program should allow a human player to play against the computer. The computer's choice should be randomly generated. The game should keep track of the score and allow the player to play multiple rounds until they choose to ... | import random
def get_computer_choice():
"""
Returns randomly one of 'rock', 'paper', or 'scissors'.
"""
return random.choice(['rock', 'paper', 'scissors'])
def determine_winner(player_choice, computer_choice):
"""
Determines the winner of a rock, paper, scissors match.
Returns 'playe... | from solution import get_computer_choice, determine_winner, play_round
def test_get_computer_choice():
choices = set(get_computer_choice() for _ in range(100))
assert 'rock' in choices
assert 'paper' in choices
assert 'scissors' in choices
def test_determine_winner():
assert determine_winner('rock... | [
{
"docstring": "Returns randomly one of 'rock', 'paper', or 'scissors'.",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner of a rock, paper, scissors match.\n\nReturns 'player', 'comp... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_choice():\n \"\"\"\n Returns randomly one of 'rock', 'paper', or 'scissors'.\n \"\"\"\n return random.choice(['rock', 'paper', 'scissors'])\n\ndef... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00043234",
"row_id": 43234,
"seed_ids": "['Qwen2.5-72B-Instruct_93390']"
} | 0.520137 | Filter_43234 | I | [
"get_computer_choice",
"determine_winner",
"play_round"
] | 3 | [
[
"play_round",
"determine_winner"
],
[
"play_round",
"get_computer_choice"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ae01f46777c7415236e34f255deae13bab9a8753 | 29981bce2a59b87b631e510e83f80283b6c904b5 | |||
v1.0 | instruct | Filter | Filter_43235_I | Can you help me understand how to implement a basic chatbot using Python and Flask? I'm new to both Python and web development, so a simple explanation would be great. | from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/chatbot', methods=['POST'])
def chatbot():
user_message = request.json.get('message')
response_message = generate_response(user_message)
return jsonify({'response': response_message})
def generate_response(message):
if 'hell... | import pytest
from flask import Flask
from flask.testing import FlaskClient
from solution import app, generate_response
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_generate_response_hello():
assert generate_response('hello') == "Hello! How can I help you today... | [
{
"docstring": null,
"function_declaration": "def chatbot():",
"function_name": "chatbot",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def generate_response(message):",
"function_name": "generate_response",
"parameter_list": "(message)"
}
] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\n# Predefined responses for the chatbot\nRESPONSES = {\n \"hi\": \"Hello! How can I help you today?\",\n \"how are yo... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043235",
"row_id": 43235,
"seed_ids": "['Qwen2.5-72B-Instruct_93391']"
} | 0.405655 | Filter_43235 | I | [
"chatbot",
"generate_response"
] | 2 | [
[
"chatbot",
"generate_response"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 4dfcc01114c320c5da1dd8105948a5808b1a71c6 | 9dfe85f07afafb6f101f03641ea00713abe26a2c | |||
v1.0 | instruct | Filter | Filter_43236_I | How can I create a Python function that generates a random integer between 1 and 100, and then checks if the number is a prime number? | import random
def is_prime(n):
"""
Returns True if n is a prime number, otherwise False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return T... | from solution import is_prime, generate_and_check_prime
def test_is_prime_with_non_prime_numbers():
assert not is_prime(1)
assert not is_prime(4)
assert not is_prime(6)
assert not is_prime(9)
assert not is_prime(15)
assert not is_prime(20)
def test_is_prime_with_prime_numbers():
assert is_... | [
{
"docstring": "Returns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a random integer between 1 and 100,\nand checks if it is a prime number.\nReturns a tuple (ran... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef is_prime(n):\n \"\"\"\n Checks if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00043236",
"row_id": 43236,
"seed_ids": "['Qwen2.5-72B-Instruct_93392']"
} | 0.592617 | Filter_43236 | I | [
"is_prime",
"generate_and_check_prime"
] | 2 | [
[
"generate_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5071216eb8c15a4a700d4cad6c1a77f05e770262 | afa3318549eab3604d3cb17e9b4e3f95c8118c67 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.