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_30164_I
Given two sorted lists, merge the two lists into a new sorted list without using any built-in sort functions. Moreover, provide functionality to compare the performance of your function against the in-built sort function of python using time module.
import time def merge_sorted_lists(list1, list2): """ Merge two sorted lists into a new sorted list. """ merged_list = [] i = 0 j = 0 # Traverse both lists and append the smallest elements to the merged list while i < len(list1) and j < len(list2): if list1[i] <= list2[j]: ...
from solution import merge_sorted_lists, compare_performance def test_merge_sorted_lists(): assert merge_sorted_lists([1, 3, 5], [2, 4, 6]) == [1, 2, 3, 4, 5, 6] assert merge_sorted_lists([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6] assert merge_sorted_lists([4, 5, 6], [1, 2, 3]) == [1, 2, 3, 4, 5, 6] a...
[ { "docstring": "Merge two sorted lists into a new sorted list.", "function_declaration": "def merge_sorted_lists(list1, list2):", "function_name": "merge_sorted_lists", "parameter_list": "(list1, list2)" }, { "docstring": "Compare the performance of the custom merge_sorted_lists function \na...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef merge_sorted_lists(list1, list2):\n \"\"\"\n Merges two sorted lists into a new sorted list.\n \"\"\"\n merged_list = []\n i, j = 0, 0\n while i < len(list...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030164", "row_id": 30164, "seed_ids": "['Qwen2-72B-Instruct_70648']" }
0.538531
Filter_30164
I
[ "merge_sorted_lists", "compare_performance" ]
2
[ [ "compare_performance", "merge_sorted_lists" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb81b39f29f2f53c642548e70e3cf0744534268c
2c9dbde309cf47e16f2c6b38c4a06cc64e9457da
v1.0
instruct
Filter
Filter_30206_I
Given an undirected graph, write a function to check if the graph is connected using Breadth-First Search. Also modify the function to accommodate a weighted graph.
from collections import deque, defaultdict def is_connected_bfs(graph): """ Check if an undirected graph is connected using BFS. Parameters: graph (dict): The adjacency list representing the graph. Returns: bool: True if the graph is connected, False otherwise. """ if not grap...
from solution import is_connected_bfs, is_connected_weighted_bfs def test_is_connected_bfs(): graph = { 0: [(1, 1), (2, 1)], 1: [(0, 1), (3, 1)], 2: [(0, 1), (3, 1)], 3: [(1, 1), (2, 1)] } assert is_connected_bfs(graph) == True def test_is_connected_bfs_disconnected(): ...
[ { "docstring": "Check if an undirected graph is connected using BFS.\n\nParameters:\ngraph (dict): The adjacency list representing the graph.\n\nReturns:\nbool: True if the graph is connected, False otherwise.", "function_declaration": "def is_connected_bfs(graph):", "function_name": "is_connected_bfs",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef is_connected(graph):\n \"\"\"\n This function checks if an undirected graph is connected using BFS.\n Args:\n - graph: dict, adjacency list for...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030206", "row_id": 30206, "seed_ids": "['Qwen2-72B-Instruct_70707']" }
0.519715
Filter_30206
I
[ "is_connected_bfs", "is_connected_weighted_bfs" ]
2
[ [ "is_connected_weighted_bfs", "is_connected_bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
50d03632f9d499ad61746223c781ee6d3f747faf
f0598ac5da3923a804fc9cb2c4de5fe5454d7b10
v1.0
instruct
Filter
Filter_30226_I
Given two flat, space-delimited files, file1.txt and file2.txt, your task is to write a function that prints the symmetric difference of the two files' contents. Each file contains a collection of numbers, with each number on a separate line. The function should read the numbers from both files, compute the symmetric d...
def read_numbers_from_file(file_path): with open(file_path, 'r') as f: numbers = map(int, f.readlines()) return list(numbers) def symmetric_difference(file1, file2): from collections import Counter numbers1 = read_numbers_from_file(file1) numbers2 = read_numbers_from_file(file2) ...
import os from solution import read_numbers_from_file, symmetric_difference def test_read_numbers_from_file(tmpdir): # Create temporary files file1 = tmpdir.join("file1.txt") file1.write("1\n2\n3\n4\n") numbers1 = read_numbers_from_file(str(file1)) assert numbers1 == [1, 2, 3, 4] def tes...
[ { "docstring": null, "function_declaration": "def read_numbers_from_file(file_path):", "function_name": "read_numbers_from_file", "parameter_list": "(file_path)" }, { "docstring": null, "function_declaration": "def symmetric_difference(file1, file2):", "function_name": "symmetric_dif...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def read_numbers_from_file(file_path):\n with open(file_path, 'r') as f:\n numbers = map(int, f.readlines())\n return list(numbers)\n\ndef symmetric_difference(file1, file2):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030226", "row_id": 30226, "seed_ids": "['Qwen2-72B-Instruct_70747']" }
0.588198
Filter_30226
I
[ "read_numbers_from_file", "symmetric_difference" ]
2
[ [ "symmetric_difference", "read_numbers_from_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f3cd16a9a27d160c952ada5b96f83766cb09b15
3a2eb956ebf867b1dab0bdbe8e9939415a24a41f
v1.0
instruct
Filter
Filter_30228_I
Write a program that subtracts one integer from another and returns the result. However, you are not allowed to use any arithmetic operators (+, -, *, /) or built-in functions (such as abs() or divmod()) to perform the subtraction. Additionally, you are not allowed to use any bitwise operators (such as &, |, ~, ^) or a...
def subtract_strings(a, b): """ Subtracts integer b from integer a using string manipulation. Assumes a >= b and both are non-negative integers represented as strings. """ def subtract_digits(d1, d2, borrow): d1 = int(d1) d2 = int(d2) if borrow: if d...
from solution import subtract def test_subtract_no_borrow(): assert subtract(9, 4) == 5 def test_subtract_with_borrow(): assert subtract(9, 8) == 1 def test_subtract_same_number(): assert subtract(5, 5) == 0 def test_subtract_with_multiple_borrows(): assert subtract(1002, 999) == 3 def test_subtrac...
[ { "docstring": "Subtracts integer b from integer a using string manipulation.\nAssumes a >= b and both are non-negative integers represented as strings.", "function_declaration": "def subtract_strings(a, b):", "function_name": "subtract_strings", "parameter_list": "(a, b)" }, { "docstring": ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def subtract_strings(a, b):\n \"\"\"\n Subtracts integer b from integer a using string manipulation.\n Assumes a >= b and both are non-negative integers represented as strings.\n \...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030228", "row_id": 30228, "seed_ids": "['Qwen2-72B-Instruct_70753']" }
0.645828
Filter_30228
I
[ "subtract_strings", "subtract" ]
2
[ [ "subtract", "subtract_strings" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d14b9a697c328b5db4e499b56c7e3f73b9e149fc
fe4ebaefe7b351758c1adc98a8ab00ab9876d785
v1.0
instruct
Filter
Filter_30257_I
Write an algorithm to search for the first occurrence of a specific element in a linked list and return its index. If the element is not found, return -1. Additionally, implement a function that checks whether the linked list is circular or not before performing the search. The time complexity of both functions should ...
class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def is_circular_linked_list(head): """ Check if the linked list is circular. :param head: The head of the linked list. :return: True if the linked list is circular, False otherwise. """ ...
import pytest from solution import ListNode, is_circular_linked_list, search_element_in_linked_list def test_is_circular_linked_list(): # Test empty linked list assert not is_circular_linked_list(None) # Test linked list with one node node1 = ListNode(1) assert not is_circular_linked_list(node...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef is_circular_linked_list(head):\n \"\"\"\n Checks whether the lin...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030257", "row_id": 30257, "seed_ids": "['Qwen2-72B-Instruct_70798']" }
0.491496
Filter_30257
I
[ "is_circular_linked_list", "search_element_in_linked_list" ]
2
[ [ "search_element_in_linked_list", "is_circular_linked_list" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
88473f06419c947d6f0e5dc7efcc0be136931bc7
7d7ffed3c0c2610118b688666a580a4401390cdb
v1.0
instruct
Filter
Filter_30259_I
Iterate over the given array and print the prime numbers in ascending order. Implement the isPrime() function to check if a number is prime or not.
def isPrime(n): """ Check if a given number n is prime. Args: n (int): The number to check. Returns: bool: True if n is prime, False otherwise. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** ...
from solution import isPrime, getPrimes def test_isPrime(): # Test for non-prime numbers assert isPrime(1) == False assert isPrime(4) == False assert isPrime(0) == False assert isPrime(-7) == False # Test for prime numbers assert isPrime(2) == True assert isPrime(3) == True ass...
[ { "docstring": "Check if a given number n is prime.\n\nArgs:\nn (int): The number to check.\n\nReturns:\nbool: True if n is prime, False otherwise.", "function_declaration": "def isPrime(n):", "function_name": "isPrime", "parameter_list": "(n)" }, { "docstring": "Get a list of prime numbers ...
[ 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 <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030259", "row_id": 30259, "seed_ids": "['Qwen2-72B-Instruct_70803']" }
0.59886
Filter_30259
I
[ "isPrime", "getPrimes" ]
2
[ [ "getPrimes", "isPrime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
42e747fc69e339313ec6fa39f44537a7c70662be
906b4baa37183bb9e6c3e7f865b081286ffcf965
v1.0
instruct
Filter
Filter_30262_I
Create a function in Python that finds the sum of all prime numbers between two given numbers. Additionally, ensure that the function checks if the given numbers are positive integers and returns an error message if they are not. The function should also validate if the first number is smaller than the second number, a...
def is_prime(n): """ Checks whether the given number n 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 sum_of_primes(num1, num2): """ Returns the sum of all prime numbers between num1 and n...
from solution import sum_of_primes def test_positive_case(): assert sum_of_primes(1, 10) == 17 # primes are 2, 3, 5, 7 def test_single_prime(): assert sum_of_primes(10, 11) == 11 # only prime in range is 11 def test_no_primes(): assert sum_of_primes(14, 16) == 0 # no primes between 14 and 16 def test...
[ { "docstring": "Checks whether the given number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers between num1 and num2.\nEnsures that:\n- num1 and num2 are positive integers\...
[ 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 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_2
{ "original_instruction": "", "prompt_id": "00030262", "row_id": 30262, "seed_ids": "['Qwen2-72B-Instruct_70810']" }
0.641034
Filter_30262
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e6f665dd5693aca5d1ba02545eec1a02033f16c0
69ca038247138e082ab04a93d1e23ea6f9ddb8be
v1.0
instruct
Filter
Filter_30264_I
I have a list of stock tickers as ["AAPL", "AMZN", "MSFT", "TSLA", "NFLX"]. I want to implement a function to find the ticker with the highest price. For this, assume that there is a function get_quote(ticker) which returns a dictionary with the keys "ticker" and "price" for the given ticker. For example, get_quote("AA...
def get_quote(ticker): """ Mock function to simulate getting a stock quote. Returns a dictionary with ticker and price. In a real application, this should fetch real stock data. """ # Mock data for demonstration quotes = { "AAPL": {"ticker": "AAPL", "price": 165.62}, "AMZN": {"ti...
from solution import find_max_price_ticker def test_find_max_price_ticker(): tickers = ["AAPL", "AMZN", "MSFT", "TSLA", "NFLX"] assert find_max_price_ticker(tickers) == "TSLA" def test_find_max_price_ticker_with_different_order(): tickers = ["NFLX", "TSLA", "MSFT", "AAPL", "AMZN"] assert find_max_pric...
[ { "docstring": "Mock function to simulate getting a stock quote. Returns a dictionary with ticker and price.\nIn a real application, this should fetch real stock data.", "function_declaration": "def get_quote(ticker):", "function_name": "get_quote", "parameter_list": "(ticker)" }, { "docstri...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_highest_priced_ticker(tickers, get_quote):\n \"\"\"\n Returns the ticker with the highest price from a list of tickers.\n \n :param tickers: List of stock ticker symbols\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030264", "row_id": 30264, "seed_ids": "['Qwen2-72B-Instruct_70813']" }
0.621757
Filter_30264
I
[ "get_quote", "find_max_price_ticker" ]
2
[ [ "find_max_price_ticker", "get_quote" ] ]
1
[]
false
[]
false
pytest
true
[]
true
482876e7bb2928776e757f4503876ff76a5ddc76
28c2a8e5c5321363853b98362c34c1876509bb25
v1.0
instruct
Filter
Filter_30276_I
Modify the given code to calculate the sum of all negative numbers in the array instead of the sum of positive numbers. In addition, add a requirement that the solution must use recursion rather than a loop to iterate over the array. Finally, include a message that displays the result of the sum of negative numbers.
def sum_negative_recursive(arr): """ Returns the sum of all negative numbers in the array using recursion. """ if not arr: return 0 head, tail = arr[0], arr[1:] if head < 0: return head + sum_negative_recursive(tail) else: return sum_negative_recursive(tail) def ...
from solution import sum_negative_recursive, display_sum_of_negatives def test_sum_negative_recursive_empty_array(): assert sum_negative_recursive([]) == 0 def test_sum_negative_recursive_all_positive(): assert sum_negative_recursive([1, 2, 3]) == 0 def test_sum_negative_recursive_all_negative(): assert ...
[ { "docstring": "Returns the sum of all negative numbers in the array using recursion.", "function_declaration": "def sum_negative_recursive(arr):", "function_name": "sum_negative_recursive", "parameter_list": "(arr)" }, { "docstring": "Displays the sum of all negative numbers in the array.",...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_negative_numbers(arr):\n \"\"\"\n Recursively calculates the sum of all negative numbers in the array.\n\n Args:\n arr: List of integers\n\n Returns:\n Sum of all neg...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030276", "row_id": 30276, "seed_ids": "['Qwen2-72B-Instruct_70834']" }
0.662992
Filter_30276
I
[ "sum_negative_recursive", "display_sum_of_negatives" ]
2
[ [ "display_sum_of_negatives", "sum_negative_recursive" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cdeecc014c4707a05f8f4f084a06f46fd19f7b79
ba415b38afdcefe643bae9e67bb879d9d165e585
v1.0
instruct
Filter
Filter_30286_I
Write a code to print out an array of prime numbers from 0 to 100, but the code should not use any built-in functions or libraries to check for prime numbers. You should implement your own function to determine whether a number is prime or not.
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False if n == 2: return True for i in range(2, n): if n % i == 0: return False return True def prime_numbers_up_to_100(): """ Returns a list of prime numbers from 0 to 100. ...
from solution import is_prime, prime_numbers_up_to_100 def test_is_prime(): assert is_prime(0) == False assert is_prime(1) == False 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 def test_prime_numb...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from 0 to 100.", "function_declaration": "def prime_numbers_up_to_100():", "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(num):\n \"\"\"\n Returns True if the given number is prime, otherwise False.\n A prime number is a number greater than 1 with no divisors other than 1 and itself.\n \"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030286", "row_id": 30286, "seed_ids": "['Qwen2-72B-Instruct_70848']" }
0.597788
Filter_30286
I
[ "is_prime", "prime_numbers_up_to_100" ]
2
[ [ "prime_numbers_up_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0cd937d3f1788e13879313cf7c19dfb49be94238
3009ad5d100b27e11a918845c53db1f5145ffaf5
v1.0
instruct
Filter
Filter_30312_I
Write a function in Python that takes a list of positive integers and returns the index of the first occurrence of the smallest prime number in the list. If there are no prime numbers in the list, the function should return -1.
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False i = 3 while i * i <= num: if num % i == 0: return False i += 2 return True def find_smallest_p...
from solution import find_smallest_prime_index def test_no_primes(): assert find_smallest_prime_index([4, 6, 8, 10]) == -1 def test_single_element_prime(): assert find_smallest_prime_index([7]) == 0 def test_multiple_primes(): assert find_smallest_prime_index([10, 17, 11, 20, 17, 19, 11, 5]) == 7 def te...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the index of the first occurrence of the smallest prime number in the list.\nIf there are no prime numbers in the lis...
[ 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 Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n retur...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030312", "row_id": 30312, "seed_ids": "['Qwen2-72B-Instruct_70892']" }
0.677667
Filter_30312
I
[ "is_prime", "find_smallest_prime_index" ]
2
[ [ "find_smallest_prime_index", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
290f37c966ffd73ba232510daacb43b99844f223
df6569fd94d9c93b582ce36ee505a2c5be86d483
v1.0
instruct
Filter
Filter_30332_I
Develop a program that can solve a Rubik's cube. The program should be able to solve it in the minimum possible number of moves. Additionally, the program should also be able to handle cubes of different sizes, not just the standard 3x3x3. The program should also provide a step-by-step solution for the user to follow a...
def solve_3x3x3_rubiks_cube(): """ Provides a step-by-step solution for a 3x3x3 Rubik's cube using a simplified method. Steps will include orienting the faces as if following a beginner's method. """ steps = [ "1. Make a white cross on the top face.", "2. Solve the white corners to c...
from solution import solve_3x3x3_rubiks_cube, solve_rubiks_cube def test_solve_3x3x3_rubiks_cube(): steps = solve_3x3x3_rubiks_cube() assert steps == [ "1. Make a white cross on the top face.", "2. Solve the white corners to complete the first layer.", "3. Solve the middle layer edges."...
[ { "docstring": "Provides a step-by-step solution for a 3x3x3 Rubik's cube using a simplified method.\nSteps will include orienting the faces as if following a beginner's method.", "function_declaration": "def solve_3x3x3_rubiks_cube():", "function_name": "solve_3x3x3_rubiks_cube", "parameter_list": ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def solve_rubiks_cube(cube_state, size=3):\n \"\"\"\n Solves a Rubik's Cube of a given size.\n Args:\n - cube_state (str): A string representation of the cube state\n - size (in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030332", "row_id": 30332, "seed_ids": "['Qwen2-72B-Instruct_70929']" }
0.454957
Filter_30332
I
[ "solve_3x3x3_rubiks_cube", "solve_rubiks_cube" ]
2
[ [ "solve_rubiks_cube", "solve_3x3x3_rubiks_cube" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9062b4e9965133d34d9a953ff76a7414cdc80c8
2b40d45b03891ebabcf9f85eef8ee48254c8a541
v1.0
instruct
Filter
Filter_30340_I
Write a Python program to find all the prime numbers in the range between 1 to 1000 and print the sum of all the prime numbers found.
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_of_primes(limit): """ Returns the sum of all prime numbers up to the given li...
from solution import is_prime, sum_of_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(20) == False assert is_prime(1) == False def test_sum_of_primes_small_range(): assert sum_of_prime...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers up to the given limit.", "function_declaration": "def sum_of_primes(...
[ 0, 0, 1 ]
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 Check if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030340", "row_id": 30340, "seed_ids": "['Qwen2-72B-Instruct_70943']" }
0.628629
Filter_30340
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8fec41f536f34e810aea2825bdf99b70ac8430cb
74b6677ae7530a31f5ce516805c36f0e3ed1f91f
v1.0
instruct
Filter
Filter_30343_I
Generate a Python script using the Flask micro web framework to greet a customer online. The script should use a personalized message for the customer based on their name, location, and browsing history. Additionally, the script should include a table of recommended products based on the customer's previous purchases a...
from flask import Flask, request, render_template_string app = Flask(__name__) @app.route('/') def greet_customer(): customer_name = request.args.get('name', 'Customer') location = request.args.get('location', 'your location') browsing_history = request.args.getlist('browsing_history') recommendations...
import pytest from flask import Flask from solution import app, get_recommendations @pytest.fixture def client(): with app.test_client() as client: yield client def test_greet_customer_no_params(client): response = client.get('/') assert b"Hello, Customer from your location!" in response.data def...
[ { "docstring": null, "function_declaration": "def greet_customer():", "function_name": "greet_customer", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def handle_feedback():", "function_name": "handle_feedback", "parameter_list": "()" }, { "docst...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from flask import Flask, request, render_template_string, jsonify\n\napp = Flask(__name__)\n\n@app.route('/')\ndef greet_customer():\n name = request.args.get('name', 'Customer')\n locat...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030343", "row_id": 30343, "seed_ids": "['Qwen2-72B-Instruct_70948']" }
0.393662
Filter_30343
I
[ "greet_customer", "handle_feedback", "get_recommendations" ]
3
[ [ "greet_customer", "get_recommendations" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
e0eca960b7cc01fd2f1472f83e65dca4846ac511
b9a4474da3a6dd45a5948b6cbe40474fad465e61
v1.0
instruct
Filter
Filter_30353_I
Write a function to sort a list of numbers using merge sort, but you are not allowed to use any built-in sorting functions or libraries. Additionally, you are required to implement the merge sort algorithm iteratively instead of recursively. The input list may contain duplicate numbers. The function should return the s...
def merge_sort_iterative(arr): """ Sorts a list of numbers using an iterative merge sort algorithm. :param arr: List of numbers to sort. :return: Sorted list of numbers. """ width = 1 n = len(arr) while width < n: for i in range(0, n, 2 * width): left = arr[i:i +...
from solution import merge_sort_iterative def test_merge_sort_empty_list(): assert merge_sort_iterative([]) == [] def test_merge_sort_single_element(): assert merge_sort_iterative([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort_iterative([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merg...
[ { "docstring": "Sorts a list of numbers using an iterative merge sort algorithm.\n:param arr: List of numbers to sort.\n:return: Sorted list of numbers.", "function_declaration": "def merge_sort_iterative(arr):", "function_name": "merge_sort_iterative", "parameter_list": "(arr)" }, { "docstr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort_iterative(arr):\n \"\"\"\n Sorts a list of numbers using an iterative merge sort.\n \"\"\"\n if not arr:\n return []\n\n width = 1\n n = len(arr)\n w...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030353", "row_id": 30353, "seed_ids": "['Qwen2-72B-Instruct_70961']" }
0.724708
Filter_30353
I
[ "merge_sort_iterative", "merge" ]
2
[ [ "merge_sort_iterative", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b5964aea522dc70fede14b83fc3e9ca420b97ce8
c69207a0c383ace874b480e7c27ed84acc899883
v1.0
instruct
Filter
Filter_30369_I
Draft a Python code snippet to construct a function that calculates the aggregate of all prime numerals contained within an array.
def is_prime(n): if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_of_primes(arr): """ Calculates the sum of all prime numbers in the array. """ return sum(num for num in arr if is_prime(num))
from solution import sum_of_primes, is_prime def test_is_prime(): # Test with prime numbers assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True # Test with non-prime numbers assert is_prime(1) == False assert is_prime(4) == False ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Calculates the sum of all prime numbers in the array.", "function_declaration": "def sum_of_primes(arr):", "function_name": "sum_of_primes", "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 the number n is prime, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030369", "row_id": 30369, "seed_ids": "['Qwen2-72B-Instruct_70991']" }
0.67663
Filter_30369
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7505afb327e7861b2c8c921f2e55feca3881a5ba
680859941caf2a7fb95729c554d0428edd15a4b2
v1.0
instruct
Filter
Filter_30371_I
Create a python program to simulate a simple dice game between two players. Each player rolls a six-sided dice and the player with the highest number wins. If both players roll the same number, it's a tie. The program should display the result of each roll and announce the winner.
import random def roll_dice(): """ Simulates rolling a six-sided dice. """ return random.randint(1, 6) def dice_game(): """ Simulates a simple dice game between two players. Each player rolls a six-sided dice and the player with the highest number wins. If both players roll the same number...
from solution import roll_dice, dice_game def test_roll_dice(): for _ in range(100): # Rolling 100 times to check the distribution roll = roll_dice() assert 1 <= roll <= 6 def test_dice_game_tie(monkeypatch): # Mocking roll_dice to return same value for both players monkeypatch.setattr('so...
[ { "docstring": "Simulates rolling a six-sided dice.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Simulates a simple dice game between two players. Each player rolls a six-sided dice\nand the player with the highest numb...
[ 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():\n \"\"\"\n Simulates rolling a six-sided dice.\n \"\"\"\n return random.randint(1, 6)\n\ndef dice_game():\n \"\"\"\n Simulates a simple dice...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030371", "row_id": 30371, "seed_ids": "['Qwen2-72B-Instruct_70994']" }
0.514217
Filter_30371
I
[ "roll_dice", "dice_game" ]
2
[ [ "dice_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76d0b94adcf3a463e73d9399402fcaa6de8b078f
c3bcb8db360299e30c449e3e1a71a57f3efd78f8
v1.0
instruct
Filter
Filter_30377_I
Write a web scraping program to extract and count the frequency of unique words from a given webpage, while filtering out common stop words and ensuring proper handling of special characters.
import requests from bs4 import BeautifulSoup import re from collections import Counter def extract_text_from_webpage(url): response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') text = soup.get_text() return text def clean_and_tokenize_text(text): text = re.sub(r'[^\...
def test_extract_text_from_webpage(monkeypatch): class MockResponse: def __init__(self, text): self.text = text def mock_get(url): return MockResponse("<html><body>This is a test webpage. Testing, 1, 2, 3!</body></html>") monkeypatch.setattr(requests, "get",...
[ { "docstring": null, "function_declaration": "def extract_text_from_webpage(url):", "function_name": "extract_text_from_webpage", "parameter_list": "(url)" }, { "docstring": null, "function_declaration": "def clean_and_tokenize_text(text):", "function_name": "clean_and_tokenize_text"...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import requests\nfrom bs4 import BeautifulSoup\nfrom collections import Counter\nimport re\nimport nltk\nfrom nltk.corpus import stopwords\n\nnltk.download('stopwords')\n\ndef web_scrape_word_...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030377", "row_id": 30377, "seed_ids": "['Qwen2-72B-Instruct_71007']" }
0.662271
Filter_30377
I
[ "extract_text_from_webpage", "clean_and_tokenize_text", "remove_stop_words", "count_word_frequencies", "get_word_frequency_from_webpage" ]
5
[ [ "get_word_frequency_from_webpage", "clean_and_tokenize_text" ], [ "get_word_frequency_from_webpage", "count_word_frequencies" ], [ "get_word_frequency_from_webpage", "extract_text_from_webpage" ], [ "get_word_frequency_from_webpage", "remove_stop_words" ] ]
4
[]
false
[]
false
pytest
false
[ "bs4", "requests" ]
false
80f15b34fc77d211730cda3383ee4e4b26c9978f
1ddae59b7869db72e6a4686b7e27634845ff4e82
v1.0
instruct
Filter
Filter_30388_I
Define a custom Exception for an invalid data type and implement a function that takes a list of integers and returns the sum of all prime numbers in the list. The function should have a time complexity of O(n^2), where n is the length of the input list, and should not use any built-in libraries or functions for determ...
class InvalidDataTypeError(Exception): """ Custom exception for invalid data types being passed to the function. """ pass def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False for i in range(2, num): if num % i == 0: ...
from solution import sum_of_primes, InvalidDataTypeError def test_sum_of_primes_with_primes_only(): assert sum_of_primes([2, 3, 5, 7, 11]) == 28 def test_sum_of_primes_with_mixed_numbers(): assert sum_of_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 17 def test_sum_of_primes_with_non_primes(): assert sum_of...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class InvalidDataTypeException(Exception):\n pass\n\ndef is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n for i in range(2, n):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030388", "row_id": 30388, "seed_ids": "['Qwen2-72B-Instruct_71024']" }
0.569686
Filter_30388
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[ "InvalidDataTypeError" ]
true
pytest
true
[]
true
70e6efb3908793afe2a140a488e4eb4662554b6e
495b2b64e9504eb55c1785d77c6b43b1c6f34439
v1.0
instruct
Filter
Filter_30397_I
Create a sequence that displays the first 10 numbers of the Fibonacci series, commencing from 0 and 1, by utilizing recursive function methodology in Python programming language. Additionally, your function should handle input checking for invalid cases like negative numbers and non-integer types.
def fibonacci(n): """ Returns the nth Fibonacci number, where n is the position in the Fibonacci sequence. Handles invalid inputs like negative numbers and non-integer types. """ if not isinstance(n, int) or n < 0: raise ValueError("Input must be a non-negative integer.") if n == 0: ...
from solution import fibonacci, first_n_fibonacci 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 def test_fibonacci_inv...
[ { "docstring": "Returns the nth Fibonacci number, where n is the position in the Fibonacci sequence.\nHandles invalid inputs like negative numbers and non-integer types.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Re...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the n-th Fibonacci number.\n \"\"\"\n if not isinstance(n, int):\n raise ValueError(\"Input must be an integer.\")\n if n < 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030397", "row_id": 30397, "seed_ids": "['Qwen2-72B-Instruct_71041']" }
0.750546
Filter_30397
I
[ "fibonacci", "first_n_fibonacci" ]
2
[ [ "first_n_fibonacci", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb0fc029c69e35b78b60490bfc93a58f5312dc56
22755056e30c93129152342b1162f766a3ad1f67
v1.0
instruct
Filter
Filter_30399_I
Write a Python function that accepts a list of words and returns the word with the highest number of vowels. In case of a tie, return the word that comes first lexicographically. Consider 'y' as a vowel only if it is at the end of the word and no other vowels are present in the word.
def count_vowels(word): vowels = "aeiou" count = sum(1 for char in word if char in vowels) if count == 0 and word.endswith('y'): count = 1 return count def word_with_most_vowels(words): if not words: return None max_vowels = 0 result_word = "" for word in words...
from solution import word_with_most_vowels, count_vowels def test_no_words(): assert word_with_most_vowels([]) is None def test_single_word(): assert word_with_most_vowels(["hello"]) == "hello" def test_multiple_words(): assert word_with_most_vowels(["hello", "world", "python"]) == "hello" def test_tie_...
[ { "docstring": null, "function_declaration": "def count_vowels(word):", "function_name": "count_vowels", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def word_with_most_vowels(words):", "function_name": "word_with_most_vowels", "parameter_list": "(w...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def word_with_most_vowels(words):\n \"\"\"\n Returns the word with the highest number of vowels. In case of a tie, returns\n the word that comes first lexicographically. Considers 'y'...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030399", "row_id": 30399, "seed_ids": "['Qwen2-72B-Instruct_71045']" }
0.789792
Filter_30399
I
[ "count_vowels", "word_with_most_vowels" ]
2
[ [ "word_with_most_vowels", "count_vowels" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e90222a2f0b8d4eb32c24009858f06f521f70255
c435104d2eefa177ccd86adac34e00aa06f3b159
v1.0
instruct
Filter
Filter_30423_I
Write a Python function called 'remove_duplicates' that takes a list as an argument and returns a new list where all duplicate elements are removed, keeping only the first occurrence of each element. Additionally, the function should maintain the order of the elements. After completing this, write another function call...
def remove_duplicates(lst): """ Remove duplicates from the list while maintaining the order of first occurrences. """ seen = set() unique_list = [] for item in lst: if item not in seen: unique_list.append(item) seen.add(item) return unique_list def reverse_un...
from solution import remove_duplicates, reverse_unique def test_remove_duplicates(): assert remove_duplicates([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [3, 1, 4, 5, 9, 2, 6] assert remove_duplicates([1, 2, 2, 3, 4, 4, 5]) == [1, 2, 3, 4, 5] assert remove_duplicates([]) == [] assert remove_duplicates([1, 1,...
[ { "docstring": "Remove duplicates from the list while maintaining the order of first occurrences.", "function_declaration": "def remove_duplicates(lst):", "function_name": "remove_duplicates", "parameter_list": "(lst)" }, { "docstring": "Reverse the list, then remove duplicates while maintai...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def remove_duplicates(lst):\n \"\"\"\n Returns a new list with duplicate elements removed, keeping only the first occurrence of each element.\n Maintains the order of the elements.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030423", "row_id": 30423, "seed_ids": "['Qwen2-72B-Instruct_71082']" }
0.750389
Filter_30423
I
[ "remove_duplicates", "reverse_unique" ]
2
[ [ "reverse_unique", "remove_duplicates" ] ]
1
[]
false
[]
false
pytest
true
[]
true
15cb1a6d7fe63fcfbf4c63cbdf072e227af606b1
c5c9993853e87f8a747ac1f22e84902e8f204922
v1.0
instruct
Filter
Filter_30489_I
Write a program in Python that takes a large list of integers as input and uses a parallel computing approach to filter out all the odd numbers and return only the even ones. Make sure to utilize all the cores on the computer to increase processing speed. Additionally, include a functionality that allows the user to sp...
from multiprocessing import Pool, cpu_count def is_even(n): return n % 2 == 0 def filter_even_numbers(nums): """ Filters and returns even numbers from the given list. """ with Pool(cpu_count()) as p: return list(filter(is_even, p.map(int, nums))) def filter_even_numbers_in_range(nums, sta...
from solution import filter_even_numbers, filter_even_numbers_in_range def test_filter_even_numbers(): assert filter_even_numbers([1, 2, 3, 4, 5, 6]) == [2, 4, 6] assert filter_even_numbers([11, 13, 15]) == [] assert filter_even_numbers([2, 4, 6, 8]) == [2, 4, 6, 8] assert filter_even_numbers([]) == []...
[ { "docstring": null, "function_declaration": "def is_even(n):", "function_name": "is_even", "parameter_list": "(n)" }, { "docstring": "Filters and returns even numbers from the given list.", "function_declaration": "def filter_even_numbers(nums):", "function_name": "filter_even_numbe...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import multiprocessing\nfrom itertools import islice\n\ndef is_even(n):\n return n % 2 == 0\n\ndef filter_evens(numbers):\n \"\"\"\n Filters out odd numbers from the given list of num...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030489", "row_id": 30489, "seed_ids": "['Qwen2-72B-Instruct_71178']" }
0.534884
Filter_30489
I
[ "is_even", "filter_even_numbers", "filter_even_numbers_in_range" ]
3
[ [ "filter_even_numbers", "is_even" ], [ "filter_even_numbers_in_range", "filter_even_numbers" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6a4ba7720ee7b84d86d485f64d131c7219ec520f
2c9b622db2653405fd27e3b66d7b9bb0d6aafc23
v1.0
instruct
Filter
Filter_30490_I
Create a Python script that takes an integer as input and prints the first n prime numbers, where n is the input integer. The script should also check if the input is a positive integer and handle invalid inputs appropriately.
def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def first_n_pri...
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(29) == True assert is_prime(1) == False assert is_prime(-7) == False def test_first_n_primes(): assert first_n_primes(1) ...
[ { "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 first n prime numbers.", "function_declaration": "def first_n_primes(n):", "function_name": "firs...
[ 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 Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030490", "row_id": 30490, "seed_ids": "['Qwen2-72B-Instruct_71179']" }
0.704432
Filter_30490
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a82f8142048852bf6c3c36ec2e322da47b1ec1e8
378cd6f3902f56993fad437b51f232d4a276e9b3
v1.0
instruct
Filter
Filter_30491_I
Develop a recursive function to generate and display the Fibonacci sequence, specifically focusing on the 34th and 35th elements.
def fibonacci(n, memo={}): """ Returns the nth Fibonacci number using memoization to optimize recursion. """ 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 get_fibonacci_numbers(n1, n2): """ R...
from solution import fibonacci, get_fibonacci_numbers def test_fibonacci_base_cases(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 def test_fibonacci_memoization(): assert fibonacci(10) == 55 # Fib(10) is 55 assert fibonacci(20) == 6765 # Fib(20) is 6765 def test_get_fibonacci_numbers(): ...
[ { "docstring": "Returns the nth Fibonacci number using memoization to optimize recursion.", "function_declaration": "def fibonacci(n, memo={}):", "function_name": "fibonacci", "parameter_list": "(n, memo={})" }, { "docstring": "Returns the n1-th and n2-th Fibonacci numbers.", "function_d...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Recursively calculates the nth Fibonacci number.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must be a positive integer.\")\n if n == 1 or n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030491", "row_id": 30491, "seed_ids": "['Qwen2-72B-Instruct_71180']" }
0.643582
Filter_30491
I
[ "fibonacci", "get_fibonacci_numbers" ]
2
[ [ "get_fibonacci_numbers", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b362ddd0f2a7292121d491593ac5fec04a53d18
afd92203c508b265bbb503a48d8dd6b288f7275a
v1.0
instruct
Filter
Filter_30520_I
Let's first define a function in Python that determines if a given number is a prime number. Then, we will use this function to identify and display all prime numbers between 1 and 100.
def is_prime(n): """ Determines if n is a prime number. Parameters: n (int): The number to check. Returns: bool: True if n is a prime number, False otherwise. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for ...
from solution import is_prime, prime_numbers_between_1_and_100 def test_is_prime(): # Test some prime numbers assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True # Test some non-prime numbers assert is_prime(1) == False assert is_p...
[ { "docstring": "Determines if n is a prime number.\n\nParameters:\nn (int): The number to check.\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": "Identifies a...
[ 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 Determines if n is a prime number.\n \n A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n \n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030520", "row_id": 30520, "seed_ids": "['Qwen2-72B-Instruct_71224']" }
0.673127
Filter_30520
I
[ "is_prime", "prime_numbers_between_1_and_100" ]
2
[ [ "prime_numbers_between_1_and_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f10988b1c195a3ea7164f3d50f2873de8cc50ef
99473fefd35125604851b2135612b8a64731b0d4
v1.0
instruct
Filter
Filter_30546_I
Using any language or approach, write a program to generate the first 10 Fibonacci numbers when a user inputs "fibonacci". To increase complexity, ensure the program can handle and return proper feedback for other user queries.
def generate_fibonacci(n=10): """ Returns the first n Fibonacci numbers as a list. """ if n <= 0: return [] fibonacci_list = [0] if n > 1: fibonacci_list.append(1) for i in range(2, n): fibonacci_list.append(fibonacci_list[-1] + fibonacci_list[-2]) return fibonacc...
from solution import handle_user_input, generate_fibonacci def test_generate_fibonacci(): assert generate_fibonacci() == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] assert generate_fibonacci(1) == [0] assert generate_fibonacci(2) == [0, 1] assert generate_fibonacci(5) == [0, 1, 1, 2, 3] assert generate_fibon...
[ { "docstring": "Returns the first n Fibonacci numbers as a list.", "function_declaration": "def generate_fibonacci(n=10):", "function_name": "generate_fibonacci", "parameter_list": "(n=10)" }, { "docstring": "Handles the user input and responds with appropriate messages.\nIf the input is \"f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_input(input_str):\n \"\"\"\n Processes the user input and returns the first 10 Fibonacci numbers if the input is 'fibonacci',\n otherwise returns a feedback message.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030546", "row_id": 30546, "seed_ids": "['Qwen2-72B-Instruct_71262']" }
0.707988
Filter_30546
I
[ "generate_fibonacci", "handle_user_input" ]
2
[ [ "handle_user_input", "generate_fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7c1d81e07c7b88f7ece76a3f04c0e677c549cc7
c3fd9c1b322519ec26f9f8f20390eb52c36fb3a1
v1.0
instruct
Filter
Filter_30553_I
I have a list of strings that I need to sort in ascending order based on the numeric values they contain. However, some strings might contain non-numeric characters which should be ignored. For instance, "123A" should be treated as "123". Can you help me write a Python function that achieves this? Also, let's make the ...
import re def extract_numeric(s): """ Extracts all the numeric characters from the string s and returns them as an integer. """ numeric_string = ''.join(filter(str.isdigit, s)) return int(numeric_string) if numeric_string else 0 def sort_strings_by_numeric_value(strings): """ Sorts a list ...
from solution import extract_numeric, sort_strings_by_numeric_value def test_extract_numeric(): assert extract_numeric("123A") == 123 assert extract_numeric("A123") == 123 assert extract_numeric("1A2B3C") == 123 assert extract_numeric("ABC") == 0 assert extract_numeric("a1b2c3") == 123 assert e...
[ { "docstring": "Extracts all the numeric characters from the string s and returns them as an integer.", "function_declaration": "def extract_numeric(s):", "function_name": "extract_numeric", "parameter_list": "(s)" }, { "docstring": "Sorts a list of strings based on the numeric values they c...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef extract_numeric(s):\n \"\"\"\n Extracts all the numeric characters from the string s and returns them as an integer.\n \"\"\"\n numeric_string = ''.join(filter(str...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030553", "row_id": 30553, "seed_ids": "['Qwen2-72B-Instruct_71272']" }
0.670546
Filter_30553
I
[ "extract_numeric", "sort_strings_by_numeric_value" ]
2
[ [ "sort_strings_by_numeric_value", "extract_numeric" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9bbd6dc1f5e30a8cbe017288437c7926fbf20c6
7ac7d00763f02708afa837634b73e03cf8e1b216
v1.0
instruct
Filter
Filter_30557_I
In Python, write a code snippet to calculate the average of prime numbers in a list. The list of numbers is provided as listOfNumbers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]. Implement a function called is_prime(number) that takes in a number as input and returns True if the number is prime and False otherwise. A number is ...
def is_prime(number): """ Check if a number is prime. """ if number <= 1: return False for i in range(2, int(number ** 0.5) + 1): if number % i == 0: return False return True def calculate_average_of_primes(list_of_numbers): """ Calculate the average of prime...
from solution import is_prime, calculate_average_of_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(6) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prim...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Calculate the average of prime numbers in a list.", "function_declaration": "def calculate_average_of_primes(list_of...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(number):\n \"\"\"\n Determines whether a number is a prime number.\n :param number: int\n :return: bool\n \"\"\"\n if number <= 1:\n return False\n for...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030557", "row_id": 30557, "seed_ids": "['Qwen2-72B-Instruct_71277']" }
0.711172
Filter_30557
I
[ "is_prime", "calculate_average_of_primes" ]
2
[ [ "calculate_average_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
171107b777f086e0d7c035aae3e76654466000df
fa0d8fceddafa5173cba040b7ec81df324f71114
v1.0
instruct
Filter
Filter_30566_I
Create a Python program that not only displays the even numbers within a given range, but also calculates the average of these even numbers. Additionally, identify any prime numbers that are part of this sequence.
def is_prime(num): """ Checks if a number is prime. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def even_numbers_and_avg(start, end): """ Finds even numbers in the range [start, end], calcula...
from solution import even_numbers_and_avg def test_even_numbers_and_avg_standard_range(): even_numbers, average, prime_numbers = even_numbers_and_avg(1, 10) assert even_numbers == [2, 4, 6, 8, 10] assert average == 6 assert prime_numbers == [2] def test_even_numbers_and_avg_with_no_evens(): even_n...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Finds even numbers in the range [start, end], calculates their average, and identifies prime numbers among them.\nReturns a t...
[ 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 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_1
{ "original_instruction": "", "prompt_id": "00030566", "row_id": 30566, "seed_ids": "['Qwen2-72B-Instruct_71295']" }
0.673458
Filter_30566
I
[ "is_prime", "even_numbers_and_avg" ]
2
[ [ "even_numbers_and_avg", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ddcbcceb7235f43fee0b15a4b9aee3fb8188e979
e9cd0f97686e6406f008250e99ea64af1e5f485d
v1.0
instruct
Filter
Filter_30610_I
Develop code to calculate the circumference of a circle, but you are not allowed to use the mathematical constant π. Additionally, you should implement the calculation using only integer arithmetic and bitwise operations. Your code should be able to handle both positive and negative integer inputs for the radius of the...
def approximate_pi(): """ Approximates the value of Pi using a fraction. Returns 355/113. """ return 355 // 113 def circumference(radius): """ Calculates the circumference of a circle using an integer approximation of Pi and integer arithmetic. Args: radius (int): The radius of...
from solution import circumference def test_circumference_positive_radius(): assert circumference(1) == 355 // 113 * 2 assert circumference(7) == 7 * (355 // 113) * 2 assert circumference(10) == 10 * (355 // 113) * 2 def test_circumference_zero_radius(): assert circumference(0) == 0 def test_circumfe...
[ { "docstring": "Approximates the value of Pi using a fraction. Returns 355/113.", "function_declaration": "def approximate_pi():", "function_name": "approximate_pi", "parameter_list": "()" }, { "docstring": "Calculates the circumference of a circle using an integer approximation\nof Pi and i...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_circumference(radius):\n \"\"\"\n Calculate the circumference of a circle using only integer arithmetic and bitwise operations,\n without using the mathematical constant...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030610", "row_id": 30610, "seed_ids": "['Qwen2-72B-Instruct_71375']" }
0.583666
Filter_30610
I
[ "approximate_pi", "circumference" ]
2
[ [ "circumference", "approximate_pi" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5418bae3c725a4082e2de43a43cb830ed11557ed
1fdee23ad7b8c8e4ab92e9498f3f0711db639418
v1.0
instruct
Filter
Filter_30622_I
How can I save a list of integers in a compressed format in an XML file using Python? I want to be able to load the integers back into a Python list after decompressing the data from the XML. The integers are all positive and I want this compression to be lossless. One way to save space is by saving the difference betw...
import zlib import base64 import xml.etree.ElementTree as ET def compress_and_save_to_xml(integers, filename): """ Compresses a list of integers and saves it to an XML file. Args: integers (list of int): The list of integers to be compressed and saved. filename (str): The name of the X...
import os import pytest from solution import compress_and_save_to_xml, load_from_xml_and_decompress def test_compress_and_save_to_xml_and_load_from_xml_and_decompress(): test_integers = [1, 2, 3, 50, 100, 1000] filename = 'test_integers.xml' # Compress and save to XML compress_and_save_to_xml(test...
[ { "docstring": "Compresses a list of integers and saves it to an XML file.\n\nArgs:\n integers (list of int): The list of integers to be compressed and saved.\n filename (str): The name of the XML file to save the compressed data.", "function_declaration": "def compress_and_save_to_xml(integers, filen...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import zlib\nimport base64\nimport xml.etree.ElementTree as ET\n\ndef compress_and_save_to_xml(integers, filename):\n \"\"\"\n Compresses a list of integers and saves it to an XML file.\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030622", "row_id": 30622, "seed_ids": "['Qwen2-72B-Instruct_71399']" }
0.504311
Filter_30622
I
[ "compress_and_save_to_xml", "load_from_xml_and_decompress", "int_list_to_byte_string", "byte_string_to_int_list" ]
4
[ [ "compress_and_save_to_xml", "int_list_to_byte_string" ], [ "load_from_xml_and_decompress", "byte_string_to_int_list" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7ed3051a63466992e7c8d910da4ea6d7fa04c112
0bcb808af288d1207e7601558cf6413c1f84a798
v1.0
instruct
Filter
Filter_30632_I
You are a 10x engineer. You have the ability to read and write code 10 times faster than the normal engineer. You also have the ability to identify and fix bugs 10 times faster than the normal engineer. Given these abilities, write a program to find the shortest path between two points in a two-dimensional array.
from collections import deque def is_valid_move(grid, visited, row, col): return 0 <= row < len(grid) and 0 <= col < len(grid[0]) and grid[row][col] == 0 and not visited[row][col] def shortest_path(grid, start, end): """ Finds the shortest path between start and end in a 2D grid. :param grid: Lis...
import pytest from solution import shortest_path def test_shortest_path_empty_grid(): assert shortest_path([], (0, 0), (0, 0)) == [] def test_shortest_path_same_start_end(): assert shortest_path([[0, 0], [0, 0]], (0, 0), (0, 0)) == [(0, 0)] def test_shortest_path_simple_grid(): grid = [ [0, 1...
[ { "docstring": null, "function_declaration": "def is_valid_move(grid, visited, row, col):", "function_name": "is_valid_move", "parameter_list": "(grid, visited, row, col)" }, { "docstring": "Finds the shortest path between start and end in a 2D grid.\n\n:param grid: List of lists where each ...
[ 1, 1, 0 ]
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 shortest_path(grid, start, end):\n \"\"\"\n Returns the shortest path from start to end in a grid.\n \n :param grid: List[List[int]], a 2D grid...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030632", "row_id": 30632, "seed_ids": "['Qwen2-72B-Instruct_71421']" }
0.537638
Filter_30632
I
[ "is_valid_move", "shortest_path" ]
2
[ [ "shortest_path", "is_valid_move" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb027211d77e907618a1bd070f5c64e5c9cd6095
c6bf3d1b512a64b51a4f8d4875f61405c84cd671
v1.0
instruct
Filter
Filter_30651_I
Implement the quick sort algorithm to sort a given list of integers in ascending order. The input list may contain duplicate elements. The algorithm should have a time complexity of O(n log n) and should not use any additional data structures or recursion. Additionally, you are not allowed to use any built-in sorting f...
def quick_sort(arr): """ Sorts the given list of integers using the Quick Sort algorithm. This function uses an iterative approach. Parameters: arr (list): A list of integers to be sorted. Returns: list: A sorted list of integers in ascending order. """ stack = [(0, len(arr) - 1)] ...
from solution import quick_sort def test_empty_list(): assert quick_sort([]) == [] def test_single_element(): assert quick_sort([1]) == [1] def test_sorted_list(): assert quick_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_list(): assert quick_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4,...
[ { "docstring": "Sorts the given list of integers using the Quick Sort algorithm.\nThis function uses an iterative approach.\n\nParameters:\narr (list): A list of integers to be sorted.\n\nReturns:\nlist: A sorted list of integers in ascending order.", "function_declaration": "def quick_sort(arr):", "fun...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quick_sort(arr):\n \"\"\"\n Performs quicksort on a list of integers without recursion and additional data structures.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030651", "row_id": 30651, "seed_ids": "['Qwen2-72B-Instruct_71446']" }
0.569774
Filter_30651
I
[ "quick_sort", "partition" ]
2
[ [ "quick_sort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3eadd06ad6ba727c33727ceb7a077c2f6fbdef1e
fca0a638fe2843f3c42a36456a411c62619af759
v1.0
instruct
Filter
Filter_30684_I
Write a python program that implements a fast Fourier transform on a signal data set using the numpy library, and visualizes the results using the matplotlib library. The program should allow the user to input the signal data as a list or array and specify the time interval between samples. The program should then outp...
import numpy as np import matplotlib.pyplot as plt def fast_fourier_transform(signal_data, sample_interval): """ Computes the Fast Fourier Transform (FFT) of a given signal. Parameters: signal_data (list or array): Input signal data. sample_interval (float): Time interval between samples. ...
import numpy as np from solution import fast_fourier_transform, plot_signal_and_fft def test_fast_fourier_transform_simple(): signal_data = [0, 1, 0, -1] sample_interval = 1.0 frequencies, fft_magnitude = fast_fourier_transform(signal_data, sample_interval) # Expected frequencies expected_freq...
[ { "docstring": "Computes the Fast Fourier Transform (FFT) of a given signal.\n\nParameters:\nsignal_data (list or array): Input signal data.\nsample_interval (float): Time interval between samples.\n\nReturns:\ntuple: Two elements tuple containing:\n - frequencies (array): Array of frequency components.\n ...
[ 1, 0, 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\n\ndef fast_fourier_transform(signal_data, sample_interval):\n \"\"\"\n Computes the Fast Fourier Transform (FFT) of a given signal.\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030684", "row_id": 30684, "seed_ids": "['Qwen2-72B-Instruct_71495']" }
0.747832
Filter_30684
I
[ "fast_fourier_transform", "plot_signal_and_fft" ]
2
[ [ "plot_signal_and_fft", "fast_fourier_transform" ] ]
1
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
3c37fb00ede7fd3add46796410820aa6b8c77419
054f52a05cd2079d58ae180ebb079adc4180016f
v1.0
instruct
Filter
Filter_30710_I
Write a python code to implement Huffman Encoding and Decoding. Consider that the input is a string of lowercase alphabet characters, and implement the encoding using a binary tree structure. You should return the encoded string from the encoding function and reconstruct the original string from the encoded string in t...
import heapq from collections import defaultdict, Counter class HuffmanNode: def __init__(self, char=None, freq=None): self.char = char self.freq = freq self.left = None self.right = None def __lt__(self, other): return self.freq < other.freq def build_huffman_tree(tex...
from solution import huffman_encoding, huffman_decoding, is_same_string def test_huffman_encoding_simple(): text = "aabbcc" encoded_text, root = huffman_encoding(text) assert set(encoded_text) == {"0", "1"} def test_huffman_decoding_simple(): text = "aabbcc" encoded_text, root = huffman_encoding(t...
[]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom collections import defaultdict, Counter\n\nclass HuffmanNode:\n def __init__(self, char=None, freq=None):\n self.char = char\n self.freq = freq\n sel...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030710", "row_id": 30710, "seed_ids": "['Qwen2-72B-Instruct_71536']" }
0.586294
Filter_30710
I
[ "build_huffman_tree", "build_codes", "huffman_encoding", "huffman_decoding", "is_same_string" ]
5
[ [ "huffman_encoding", "build_codes" ], [ "huffman_encoding", "build_huffman_tree" ], [ "is_same_string", "huffman_decoding" ] ]
3
[]
false
[ "HuffmanNode" ]
true
pytest
true
[]
true
ff83a96fc652d7450344e5491010850290f9ac40
22f4c55646177e5a6932730b31483fd309a81362
v1.0
instruct
Filter
Filter_30782_I
Given a list of integers, write a program to convert it into a list of strings in Roman numeral format. Additionally, implement a function to add these Roman numerals without converting them back to integers. Your solution should not use any built-in functions for the conversion between integers and Roman numerals.
def int_to_roman(num): """Convert an integer to a Roman numeral.""" val = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ] syb = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ] roman_num = '...
from solution import roman_to_int, int_to_roman, add_roman_numerals, convert_list_to_roman def test_int_to_roman(): assert int_to_roman(1) == 'I' assert int_to_roman(4) == 'IV' assert int_to_roman(9) == 'IX' assert int_to_roman(58) == 'LVIII' assert int_to_roman(1994) == 'MCMXCIV' def test_roman_t...
[ { "docstring": "Convert an integer to a Roman numeral.", "function_declaration": "def int_to_roman(num):", "function_name": "int_to_roman", "parameter_list": "(num)" }, { "docstring": "Convert a Roman numeral string to an integer.", "function_declaration": "def roman_to_int(s):", "fu...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class RomanConverter:\n def __init__(self):\n self.value_map = [\n (1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'),\n (100, 'C'), (90, 'XC'), (50, 'L'), (40, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030782", "row_id": 30782, "seed_ids": "['Qwen2-72B-Instruct_71658']" }
0.574282
Filter_30782
I
[ "int_to_roman", "roman_to_int", "add_roman_numerals", "convert_list_to_roman" ]
4
[ [ "add_roman_numerals", "int_to_roman" ], [ "add_roman_numerals", "roman_to_int" ], [ "convert_list_to_roman", "int_to_roman" ] ]
3
[]
false
[]
false
pytest
true
[]
true
855334b05de6469499ebbbf3f43de7ec97c9d03d
e37b6f9e9aef905b5328839e9c91a61cc3717c69
v1.0
instruct
Filter
Filter_30786_I
Below is an algorithm for sorting an array of numbers. Your task is to implement this algorithm in a programming language of your choice and then use it to sort an array of 1 million random numbers between 1 and 100. After sorting the array, you need to find the median of the sorted array and return it.
def quicksort(arr): """ This function implements the quicksort algorithm. """ 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(left) + mi...
import random import pytest from solution import quicksort, find_median, sort_and_find_median def test_quicksort_empty(): assert quicksort([]) == [] def test_quicksort_single_element(): assert quicksort([1]) == [1] def test_quicksort_sorted(): assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def tes...
[ { "docstring": "This function implements the quicksort algorithm.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "This function returns the median of a sorted array.", "function_declaration": "def find_median(arr...
[ 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 quicksort(arr):\n \"\"\"\n Sorts an array using the quicksort algorithm.\n \"\"\"\n if len(arr) < 2:\n return arr\n \n pivot = arr[len(arr) // 2]\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030786", "row_id": 30786, "seed_ids": "['Qwen2-72B-Instruct_71663']" }
0.563977
Filter_30786
I
[ "quicksort", "find_median", "sort_and_find_median" ]
3
[ [ "sort_and_find_median", "find_median" ], [ "sort_and_find_median", "quicksort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
924955d5a614d0e6d048ecdfa8a41b498de31700
4fc0666af2dd613926299715edf7ea855088ef90
v1.0
instruct
Filter
Filter_30799_I
Write a Python code to create a list of prime numbers from 1 to 100.
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def primes_up_to_100(): """ Returns a list of prime numbers from 1 to 100. """ ...
from solution import is_prime, primes_up_to_100 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(17) == True assert is_prime(20) == False def test_primes_up_to_100(...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from 1 to 100.", "function_declaration": "def primes_up_to_100():", "...
[ 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 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_2
{ "original_instruction": "", "prompt_id": "00030799", "row_id": 30799, "seed_ids": "['Qwen2-72B-Instruct_71682']" }
0.613624
Filter_30799
I
[ "is_prime", "primes_up_to_100" ]
2
[ [ "primes_up_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
602911fac5d11b91c649d36eab47248bbb62c2bf
ba95fec74d9fc92eef1a38ca7194ee505b00da77
v1.0
instruct
Filter
Filter_30815_I
Given a set of words, generate a python program that can determine if there exists a pair of distinct indices (i, j) in the array such that the words at those indices are anagrams of each other.
def are_anagrams(word1, word2): """ Check if two words are anagrams of each other. """ return sorted(word1) == sorted(word2) def find_anagram_pair(words): """ Determine if there exists a pair of distinct indices (i, j) in the array such that the words at those indices are anagrams of each o...
from solution import find_anagram_pair def test_find_anagram_pair_with_anagrams(): words = ["listen", "silent", "enlist"] assert find_anagram_pair(words) == True def test_find_anagram_pair_with_no_anagrams(): words = ["apple", "banana", "cherry"] assert find_anagram_pair(words) == False def test_find...
[ { "docstring": "Check if two words are anagrams of each other.", "function_declaration": "def are_anagrams(word1, word2):", "function_name": "are_anagrams", "parameter_list": "(word1, word2)" }, { "docstring": "Determine if there exists a pair of distinct indices (i, j) in the array\nsuch th...
[ 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 are_anagrams(word1, word2):\n \"\"\"\n Helper function to check if two words are anagrams.\n \"\"\"\n return Counter(word1) == Counter(word2)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030815", "row_id": 30815, "seed_ids": "['Qwen2-72B-Instruct_71712']" }
0.583361
Filter_30815
I
[ "are_anagrams", "find_anagram_pair" ]
2
[ [ "find_anagram_pair", "are_anagrams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9b0dbab0bcad3a860a76a0eebdb2272a57bbeadf
fdf94722a09e2920af64d751dff8b4fb33ec5180
v1.0
instruct
Filter
Filter_30818_I
Write an algorithm in Python that counts from 0 to 100, but only prints the prime numbers.
def is_prime(n): """ Determines 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_primes_to_100(): """ Prints prime numbers from 0 to 100. """ primes = [] for nu...
from solution import is_prime, print_primes_to_100 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(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) ==...
[ { "docstring": "Determines if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Prints prime numbers from 0 to 100.", "function_declaration": "def print_primes_to_100():", "function_name": "print_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 Helper function to 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 ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030818", "row_id": 30818, "seed_ids": "['Qwen2-72B-Instruct_71719']" }
0.700398
Filter_30818
I
[ "is_prime", "print_primes_to_100" ]
2
[ [ "print_primes_to_100", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c886628f8518f70d278155b357dfebaa0d3403f3
298bdbf2f3443c96a5263754e5575b0d0c2c5b55
v1.0
instruct
Filter
Filter_30823_I
Write a computational routine that executes matrix multiplication by employing the principles of Strassen's Algorithm, an efficient technique for multiplying square matrices. The algorithm should employ recursion to break down the multiplication process into smaller submatrices, achieving lower complexity than the stan...
def strassen_multiply(A, B): """ Multiplies two matrices, A and B, using Strassen's Algorithm. This function assumes that A and B are square matrices of size 2^n x 2^n. """ n = len(A) if n == 1: return [[A[0][0] * B[0][0]]] # Splitting the matrices into quarters new_size = ...
from solution import strassen_multiply, matrix_add, matrix_subtract, combine_matrix, split_matrix import pytest def test_strassen_multiply(): A = [[1, 2], [3, 4]] B = [[5, 6], [7, 8]] expected_result = [[19, 22], [43, 50]] assert strassen_multiply(A, B) == ex...
[ { "docstring": "Multiplies two matrices, A and B, using Strassen's Algorithm.\nThis function assumes that A and B are square matrices of size 2^n x 2^n.", "function_declaration": "def strassen_multiply(A, B):", "function_name": "strassen_multiply", "parameter_list": "(A, B)" }, { "docstring"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef add_matrix(A, B):\n return np.add(A, B)\n\ndef subtract_matrix(A, B):\n return np.subtract(A, B)\n\ndef strassen_multiply(A, B):\n n = len(A)\n \n # Ba...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030823", "row_id": 30823, "seed_ids": "['Qwen2-72B-Instruct_71725']" }
0.49099
Filter_30823
I
[ "strassen_multiply", "split_matrix", "matrix_add", "matrix_subtract", "combine_matrix" ]
5
[ [ "strassen_multiply", "combine_matrix" ], [ "strassen_multiply", "matrix_add" ], [ "strassen_multiply", "matrix_subtract" ], [ "strassen_multiply", "split_matrix" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0cd7c9956057f870e3ca00a2642f6e604b3d188c
900b00f8617a616b6cff29dd95af01da47f83772
v1.0
instruct
Filter
Filter_30824_I
Create a python function that takes in a list of integers and returns a new list with all the prime numbers from the original list.
def is_prime(n): """ Helper function to 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 filter_primes...
from solution import filter_primes def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_mix(): assert filter_primes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 10, ...
[ { "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 a list of prime numbers from the given list of integers.", "function_declaration": "def filter_prim...
[ 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 Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n retu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030824", "row_id": 30824, "seed_ids": "['Qwen2-72B-Instruct_71727']" }
0.652432
Filter_30824
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
77d58be577080533c2d0b266b83a1f383a0bfd84
edcbab8cc73e5cac142812e8683d9c258ea32d79
v1.0
instruct
Filter
Filter_30829_I
Create a Python script that prints out all prime numbers from 1 to 1000, but do so in a way that introduces delay of 1 second between each prime number output. Apart from this, ensure that your code is well-documented and utilizes functions for code reusability.
import time def is_prime(n): """Check 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_primes_with_delay(start, end, delay): """Print all prime numbers between start and end inclusive ...
import pytest from solution import is_prime, print_primes_with_delay 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(19) == True def test_print_primes_with_delay(capf...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Print all prime numbers between start and end inclusive with a delay in seconds.", "function_declaration": "def print_primes_w...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\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": "00030829", "row_id": 30829, "seed_ids": "['Qwen2-72B-Instruct_71736']" }
0.541864
Filter_30829
I
[ "is_prime", "print_primes_with_delay" ]
2
[ [ "print_primes_with_delay", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
586742d02089c9b7813db16b0cc0ef79cc171f0a
f40366cefdd85a3c1acf092839c820c9afca518b
v1.0
instruct
Filter
Filter_30830_I
Create a Python dictionary that stores square roots of prime numbers from 1 to 15. Also, implement functionality to update the dictionary dynamically whenever a new prime number's square root is requested that isn't already in the dictionary. The square root values should be rounded to three decimal places.
import math def is_prime(num): """ Check if a number is prime. """ if num <= 1: return False for i in range(2, int(math.sqrt(num)) + 1): if num % i == 0: return False return True def compute_square_root(num): """ Compute the square root rounded to three decimal places. ...
from solution import is_prime, compute_square_root, get_prime_square_roots, update_prime_square_roots def test_is_prime(): assert is_prime(2) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False def test_compute_square_root(): assert compute_square_root(4) =...
[ { "docstring": "Check if a number is prime. ", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Compute the square root rounded to three decimal places. ", "function_declaration": "def compute_square_root(num):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\nprimes = {2, 3, 5, 7, 11, 13}\n\ndef is_prime(n):\n \"\"\"\n Checks if the number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n re...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030830", "row_id": 30830, "seed_ids": "['Qwen2-72B-Instruct_71738']" }
0.546548
Filter_30830
I
[ "is_prime", "compute_square_root", "get_prime_square_roots", "update_prime_square_roots" ]
4
[ [ "get_prime_square_roots", "compute_square_root" ], [ "get_prime_square_roots", "is_prime" ], [ "update_prime_square_roots", "compute_square_root" ], [ "update_prime_square_roots", "is_prime" ] ]
4
[]
false
[]
false
pytest
true
[]
true
3627fe33363709b8ac8236a8d56a197769649056
f6dd2fe66408c78258c3c8d5379a864e797a3949
v1.0
instruct
Filter
Filter_30833_I
Create a Python program that takes two integers as input from the user, representing a range of numbers. The program should print out all the prime numbers within that range. The input integers will be positive and the first integer will always be smaller than the second integer.
def is_prime(n): """ Returns True if n is a prime number, else False. """ 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_in_range(start, end): """ Returns a list of prime numbers in the ra...
from solution import is_prime, prime_numbers_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(-3) == False def test_prime_numbers_in_range(): assert prime_...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers in the range [start, end].", "function_declaration": "def prime_numbers_i...
[ 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 <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030833", "row_id": 30833, "seed_ids": "['Qwen2-72B-Instruct_71743']" }
0.661597
Filter_30833
I
[ "is_prime", "prime_numbers_in_range" ]
2
[ [ "prime_numbers_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92f80b514e6c5efd1a1bfe08a2eb1464afc3cb2b
fc9c35d68054ba349cf163954997ea200613ce35
v1.0
instruct
Filter
Filter_30837_I
Given a Wikipedia dump file named 'wiki\_data.xml', write a Python program that reads the dump file, extracts all the individual pages, and saves each page as a separate text file. Additionally, ensure that any internal wiki links within the page content are converted to their corresponding filenames.
import re import os from xml.etree.ElementTree import iterparse, Element def extract_pages_from_wiki_dump(dump_file, output_dir): """ Extracts individual pages from a Wikipedia dump file and saves each page as a separate text file. Converts internal wiki links to their filenames. :param dump_file: Pat...
import os import shutil from solution import extract_pages_from_wiki_dump, convert_internal_links def test_convert_internal_links(): text = "This is a link to [[Main Page]] and another link to [[Help:Contents|Help Contents]]." converted_text = convert_internal_links(text) assert converted_text == "This is ...
[ { "docstring": "Extracts individual pages from a Wikipedia dump file and saves each page as a separate text file.\nConverts internal wiki links to their filenames.\n\n:param dump_file: Path to the Wikipedia dump file (XML format)\n:param output_dir: Directory to save the extracted pages as text files", "fun...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\nimport xml.etree.ElementTree as ET\n\ndef extract_pages_from_wiki(wiki_dump_file):\n \"\"\"\n Reads a Wikipedia dump file, extracts all individual pages,\n and saves each p...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030837", "row_id": 30837, "seed_ids": "['Qwen2-72B-Instruct_71748']" }
0.49833
Filter_30837
I
[ "extract_pages_from_wiki_dump", "convert_internal_links", "save_page" ]
3
[ [ "extract_pages_from_wiki_dump", "convert_internal_links" ], [ "extract_pages_from_wiki_dump", "save_page" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a664d7380af34eac391e010805771030e69f6c5a
428ea20090e1c7cf464dc3aa5728cf868fa3dd22
v1.0
instruct
Filter
Filter_30842_I
Write a python code that implements quicksort or mergesort algorithm on a linked list. The code should also handle edge cases such as an empty linked list or a linked list with only one node. Discuss the runtime complexity of your solution.
class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def merge_sorted_lists(l1, l2): if not l1: return l2 if not l2: return l1 if l1.value < l2.value: new_head = l1 new_head.next = merge_sorted_lists(l1.next, l2...
from solution import ListNode, merge_sort def linked_list_to_list(head): result = [] while head: result.append(head.value) head = head.next return result def test_merge_sort_empty_list(): assert merge_sort(None) == None def test_merge_sort_single_element(): node = ListNode(1) ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef merge_sort_linked_list(head):\n \"\"\"\n Sort a linked list using merg...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030842", "row_id": 30842, "seed_ids": "['Qwen2-72B-Instruct_71754']" }
0.472507
Filter_30842
I
[ "merge_sorted_lists", "split_list", "merge_sort" ]
3
[ [ "merge_sort", "merge_sorted_lists" ], [ "merge_sort", "split_list" ] ]
2
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
eb0340110feef8bc566b616dddb630d3853c9c16
243cfed417747d04954523a5294afa58df893aec
v1.0
instruct
Filter
Filter_30874_I
Create a Python function that takes an integer as input and returns the nth prime number. The function should include error handling for cases where the input is not an integer or is less than 1.
def is_prime(n): """ Helper function to determine 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 nth_prime(n): """ Returns the nth prime number. Parameters: n ...
from solution import nth_prime, is_prime def test_nth_prime_valid_inputs(): assert nth_prime(1) == 2 assert nth_prime(2) == 3 assert nth_prime(3) == 5 assert nth_prime(10) == 29 assert nth_prime(20) == 71 def test_nth_prime_invalid_inputs(): try: nth_prime(0) except ValueError as e...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the nth prime number.\n\nParameters:\n n (int): The position of the prime number to return.\n\nR...
[ 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 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_1
{ "original_instruction": "", "prompt_id": "00030874", "row_id": 30874, "seed_ids": "['Qwen2-72B-Instruct_71806']" }
0.720513
Filter_30874
I
[ "is_prime", "nth_prime" ]
2
[ [ "nth_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a392117eec3b1686bf191b08245417178f9a7d0c
38b2e22c6efa895e36ec913ade3ed0d99ca4b9f3
v1.0
instruct
Filter
Filter_30886_I
Write a Python program which prints all perfect numbers between 1 and a given number N (both inclusive).
def is_perfect_number(num): """Check if a given number is perfect.""" if num < 2: return False divisors = [1] # 1 is always a divisor for i in range(2, int(num ** 0.5) + 1): if num % i == 0: divisors.append(i) if i != (num // i): # Avoid adding square root twice...
from solution import is_perfect_number, find_perfect_numbers def test_is_perfect_number(): assert is_perfect_number(6) == True assert is_perfect_number(28) == True assert is_perfect_number(1) == False assert is_perfect_number(12) == False def test_find_perfect_numbers(): assert find_perfect_number...
[ { "docstring": "Check if a given number is perfect.", "function_declaration": "def is_perfect_number(num):", "function_name": "is_perfect_number", "parameter_list": "(num)" }, { "docstring": "Find and return all perfect numbers between 1 and N (inclusive).", "function_declaration": "def ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def perfect_numbers_up_to_n(n):\n \"\"\"\n Prints all perfect numbers between 1 and a given number N (both inclusive).\n A perfect number is a positive integer that is equal to the su...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030886", "row_id": 30886, "seed_ids": "['Qwen2-72B-Instruct_71823']" }
0.614794
Filter_30886
I
[ "is_perfect_number", "find_perfect_numbers" ]
2
[ [ "find_perfect_numbers", "is_perfect_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e78b0e7376774c209618d95b4c292c0dab9df5a
e1dc1152af7e481d271e837d0f8bdf534c511687
v1.0
instruct
Filter
Filter_30890_I
Create a program that generates an array of prime numbers from 0 to 100 in descending order. Implement the solution using a recursive function and ensure that the prime numbers are sorted within the array. Additionally, optimize the program to have a time complexity of O(n√n) by using the Sieve of Eratosthenes algorith...
def sieve_of_eratosthenes(n): """ Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm. """ primes = [True] * (n + 1) p = 2 while p * p <= n: if primes[p]: for i in range(p * p, n + 1, p): primes[i] = False p += 1 pri...
from solution import sieve_of_eratosthenes, generate_primes_descending def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_generate_primes_descending(): assert generate_primes_descending(10) ==...
[ { "docstring": "Generates a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from 0 to n in ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Use Sieve of Eratosthenes to generate an array of prime numbers from 0 to limit\n \"\"\"\n is_prime = [True] * (limit + 1)\n p = 2\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030890", "row_id": 30890, "seed_ids": "['Qwen2-72B-Instruct_71830']" }
0.628737
Filter_30890
I
[ "sieve_of_eratosthenes", "generate_primes_descending" ]
2
[ [ "generate_primes_descending", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bb5aa667bde9cb1e5488f07ecd125993c0f3b1af
66740eb690b0ef30355d5d77c894e0b78a5b950d
v1.0
instruct
Filter
Filter_30909_I
I want to create a basic web application using Flask, where a GET request at the path "/factorial/" should return the factorial of a given number. If the input is not a number or if it's a negative number, the application should return an error message. Can you provide a code example on how to achieve this?
from flask import Flask, request, jsonify app = Flask(__name__) def factorial(n): if n < 0: return None if n == 0: return 1 result = 1 for i in range(1, n+1): result *= i return result @app.route('/factorial/', methods=['GET']) def get_factorial(): num = request.args.g...
import pytest from solution import app, factorial def test_factorial(): assert factorial(0) == 1 assert factorial(1) == 1 assert factorial(5) == 120 assert factorial(-1) == None @pytest.fixture def client(): with app.test_client() as client: yield client def test_get_factorial(client): ...
[ { "docstring": null, "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def get_factorial():", "function_name": "get_factorial", "parameter_list": "()" } ]
[ 1, 1, 1 ]
3
easy
1
{ "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\ndef factorial(n):\n if n < 0:\n return None\n if n == 0:\n return 1\n result = 1\n for i in rang...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00030909", "row_id": 30909, "seed_ids": "['Qwen2-72B-Instruct_71856']" }
0.493272
Filter_30909
I
[ "factorial", "get_factorial" ]
2
[ [ "get_factorial", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[ "flask" ]
false
00fc0e389289a0c2392faa3103b2c0abc74fec61
24d08b4a9ea7aa02f8068f5ce8a99a787c346671
v1.0
instruct
Filter
Filter_30911_I
Write a script in Python that takes the first 1000 prime numbers and creates a list. Also, include functionality to search these prime numbers. The search should return the index of a prime number if it is in the list of the first 1000 prime numbers. If the number is not prime or does not exist in the list, return 'Not...
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 generate_primes(limit): """ ...
from solution import is_prime, generate_primes, search_prime, first_1000_primes 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) == F...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate the first `limit` prime numbers.", "function_declaration": "def generate_primes(limit):", "function_name": "gener...
[ 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, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030911", "row_id": 30911, "seed_ids": "['Qwen2-72B-Instruct_71858']" }
0.529044
Filter_30911
I
[ "is_prime", "generate_primes", "search_prime" ]
3
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a6ffa424775a6ceb680761040b6fc9e645a3e3f1
27c7b31ae7f0d86ed3f213d6d6c1cd709f42381d
v1.0
instruct
Filter
Filter_30927_I
Write a Python program to find the sum of Fibonacci numbers till the number n, where n is a positive integer input by the user. The program should also check if the input is a valid positive integer and display an error message if it is not. Additionally, the program should use recursion to calculate the Fibonacci sequ...
def fibonacci(n): """ Recursive function to calculate the nth Fibonacci number. """ if n <= 0: raise ValueError("The input must be a positive integer.") elif n == 1: return 0 elif n == 2: return 1 else: return fibonacci(n-1) + fibonacci(n-2) def sum_of_fibona...
import pytest from solution import fibonacci, sum_of_fibonacci_numbers def test_fibonacci(): assert fibonacci(1) == 0 assert fibonacci(2) == 1 assert fibonacci(3) == 1 assert fibonacci(4) == 2 assert fibonacci(5) == 3 def test_fibonacci_invalid(): with pytest.raises(ValueError): fibona...
[ { "docstring": "Recursive function to calculate the nth Fibonacci number.", "function_declaration": "def fibonacci(n):", "function_name": "fibonacci", "parameter_list": "(n)" }, { "docstring": "Function to calculate the sum of Fibonacci numbers till the number n.", "function_declaration"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Returns the nth Fibonacci number.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n return 1\n else:\n return fibonacci(n - ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030927", "row_id": 30927, "seed_ids": "['Qwen2-72B-Instruct_71884']" }
0.695657
Filter_30927
I
[ "fibonacci", "sum_of_fibonacci_numbers" ]
2
[ [ "sum_of_fibonacci_numbers", "fibonacci" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2c098c8159c071d5abe42bf82f6d48dda672aa8b
05d26780eb986161f9391eab499478c17d4be490
v1.0
instruct
Filter
Filter_30947_I
Write a Python program to generate a list that contains only the non-unique elements from a given mixed type list. The list can contain integers, strings and nested lists. Handle these different data types in your function. Also, ensure that for nested lists, elements in them are considered in the main list for uniquen...
from collections import Counter def extract_elements(mixed_list): flat_list = flatten(mixed_list) count = Counter(flat_list) non_unique_elements = [element for element, freq in count.items() if freq > 1] return non_unique_elements def flatten(nested_list): for item in nested_list: if isins...
from solution import extract_elements def test_non_unique_elements_in_mixed_list(): assert extract_elements([1, 2, 2, 3, 4, 4, 5]) == [2, 4] def test_non_unique_elements_with_strings(): assert extract_elements([1, "apple", 2, "apple", "banana", "banana", 3]) == ["apple", "banana"] def test_non_unique_element...
[ { "docstring": null, "function_declaration": "def extract_elements(mixed_list):", "function_name": "extract_elements", "parameter_list": "(mixed_list)" }, { "docstring": null, "function_declaration": "def flatten(nested_list):", "function_name": "flatten", "parameter_list": "(nes...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def flatten_list(nested_list):\n \"\"\"\n Helper function to flatten a nested list.\n \"\"\"\n for item in nested_list:\n if isinstance(item, list):\n yield from ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030947", "row_id": 30947, "seed_ids": "['Qwen2-72B-Instruct_71919']" }
0.694193
Filter_30947
I
[ "extract_elements", "flatten" ]
2
[ [ "extract_elements", "flatten" ] ]
1
[]
false
[]
false
pytest
true
[]
true
350537870eced59f12b8d6b5354f7dff1b57b6e2
f73782d257ee6ad6d88ece72b0c546c9274816b9
v1.0
instruct
Filter
Filter_30966_I
Write a Python code snippet that generates a multiplication table for a given number along with the associated prime factors of each multiple in the table. The output should display the number, its multiple, and the prime factorization of the multiple.
def prime_factors(n): """ Returns the list of prime factors of a given number n. """ i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors def multiplic...
from solution import prime_factors, multiplication_table_with_prime_factors def test_prime_factors(): assert prime_factors(1) == [] assert prime_factors(2) == [2] assert prime_factors(3) == [3] assert prime_factors(4) == [2, 2] assert prime_factors(6) == [2, 3] assert prime_factors(15) == [3, 5...
[ { "docstring": "Returns the list of prime factors of a given number n.", "function_declaration": "def prime_factors(n):", "function_name": "prime_factors", "parameter_list": "(n)" }, { "docstring": "Generates a multiplication table for a given number and includes the prime factors of each mu...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom typing import List, Tuple, Dict\n\ndef prime_factors(n: int) -> List[int]:\n \"\"\" \n Returns a list of prime factors of the given number.\n \"\"\"\n factors = [...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00030966", "row_id": 30966, "seed_ids": "['Qwen2-72B-Instruct_71954']" }
0.673712
Filter_30966
I
[ "prime_factors", "multiplication_table_with_prime_factors" ]
2
[ [ "multiplication_table_with_prime_factors", "prime_factors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fbc1ad2b113b50c99f3d5975466e73ac4585042
ace65ab4c105198befd6a0b01657be710f62d9be
v1.0
instruct
Filter
Filter_30982_I
Using Python programming language, build a function that can identify whether the given integer is a Mersenne prime number, considering that a Mersenne prime is a prime number that is one less than a power of two. The function should include a verification mechanism to ensure that the submitted integer is a Mersenne pr...
import math 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 T...
from solution import is_mersenne_prime def test_known_mersenne_primes(): assert is_mersenne_prime(3) == True # 2^2 - 1 = 3 assert is_mersenne_prime(31) == True # 2^5 - 1 = 31 assert is_mersenne_prime(127) == True # 2^7 - 1 = 127 def test_non_mersenne_primes(): assert is_mersenne_prime(2) == False ...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a given number is a Mersenne prime.\nA Mersenne prime is a prime number that is one less than a power of two.", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(number):\n \"\"\"\n Check if the given number is a prime number.\n \"\"\"\n if number <= 1:\n return False\n if number <= 3:\n return True\n if num...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00030982", "row_id": 30982, "seed_ids": "['Qwen2-72B-Instruct_71987']" }
0.670635
Filter_30982
I
[ "is_prime", "is_mersenne_prime" ]
2
[ [ "is_mersenne_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7771e24a0ecc9fd32220076812227b23c942fa1c
3ae5d9642be072ca7f7b8fbf305885a0e51ad1db
v1.0
instruct
Filter
Filter_31012_I
Considering the new, convenient function below that performs a merge sort on an input array, your job is to accomplish several tasks. Initially, you are required to examine this function and identify any potential flaws, inaccuracies, or inefficiencies. Moving forward, you should construct a detailed pseudo code that p...
def merge_sort(arr): """ Performs a merge sort on the provided array. :param arr: List[int] - the array to be sorted :return: List[int] - the sorted array """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[m...
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_reversed_list(): assert merge_sort...
[ { "docstring": "Performs a merge sort on the provided array.\n:param arr: List[int] - the array to be sorted\n:return: List[int] - the sorted array", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Perform merge sort on the input array.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n mid = len(arr) // 2\n left_half = merge_sort(arr[:...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031012", "row_id": 31012, "seed_ids": "['Qwen2-72B-Instruct_72027']" }
0.586354
Filter_31012
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c425d3ce155c4c3882b32228ce1fdcea9c68b400
3def5e3f2cd58da7245290f3b47bc15469225347
v1.0
instruct
Filter
Filter_31016_I
Write a Python program to represent the given mathematical expression in the form of an Expression Tree, and then evaluate the expression using the expression tree. You also need to design your own parser to convert the infix expression to a postfix expression before constructing the expression tree. The parser should ...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def infix_to_postfix(expression): precedence = {'+': 1, '-': 1, '*': 2, '/': 2} output = [] stack = [] for char in expression: if char.isnumeric(): outpu...
def test_infix_to_postfix(): assert infix_to_postfix("3+5") == "35+" assert infix_to_postfix("3+5*2") == "352*+" assert infix_to_postfix("(1+2)*3") == "12+3*" assert infix_to_postfix("3+(5*2)-(3*4)/2") == "352*+34*2/-" def test_evaluate_expression(): assert evaluate_expression("3+5") == 8 asser...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef infix_to_postfix(expression):\n precedence = {'+': 1,...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031016", "row_id": 31016, "seed_ids": "['Qwen2-72B-Instruct_72034']" }
0.514571
Filter_31016
I
[ "infix_to_postfix", "construct_expression_tree", "evaluate_expression_tree", "evaluate_expression" ]
4
[ [ "evaluate_expression", "construct_expression_tree" ], [ "evaluate_expression", "evaluate_expression_tree" ], [ "evaluate_expression", "infix_to_postfix" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
5085f43d241edf88d6f797f05f4f6e63a0bea2c4
f57f095ff1da61a23345f07ba76d7212f1d22113
v1.0
instruct
Filter
Filter_31030_I
Write a Python program to check if a given number is a Tejas number or not. A Tejas number is a number that remains the same when its digits are reversed, and it is also a prime number.
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_tejas_number def test_is_tejas_number_prime_palindrome(): assert is_tejas_number(11) == True assert is_tejas_number(101) == True def test_is_tejas_number_non_palindrome(): assert is_tejas_number(13) == False assert is_tejas_number(123) == False def test_is_tejas_number_non_pri...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check if a given number is a Tejas number.\nA Tejas number is a number that is prime and remains the same when its digits are reve...
[ 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 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 False...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031030", "row_id": 31030, "seed_ids": "['Qwen2-72B-Instruct_72059']" }
0.582429
Filter_31030
I
[ "is_prime", "is_tejas_number" ]
2
[ [ "is_tejas_number", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24df4868a3ce58fe5a12f828f628c4328ac342e9
93a5abd6457adb035e0483a4bb611c981923dad3
v1.0
instruct
Filter
Filter_31037_I
Create a Python program that generates a list of twin primes between 1 and N, where N is a positive integer provided by the user. Twin primes are pairs of prime numbers that differ by two (e.g., (3, 5), (5, 7), (11, 13)). The program should also compute the total number of twin prime pairs and display the largest twin ...
def is_prime(num): """ Returns True if the number is prime, otherwise False. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True...
from solution import is_prime, twin_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 def test_twin_primes_with_small_n(): twin_prime_list, total_twin_primes, largest_twin_prime...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generates a list of twin primes (pairs of prime numbers that differ by two) between 1 and N.\nReturn...
[ 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(num):\n \"\"\"\n Returns True if the number is prime, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031037", "row_id": 31037, "seed_ids": "['Qwen2-72B-Instruct_72070']" }
0.676902
Filter_31037
I
[ "is_prime", "twin_primes" ]
2
[ [ "twin_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1c80d626b35abbb1866562f8bb2f355cb21b2d44
58e928a2dab64ce1d41e7d16f77a4b6e377a7eaf
v1.0
instruct
Filter
Filter_31047_I
Create a code to generate a list of all prime numbers between a given start and end number, also displaying their binary representation. The code should handle erroneous inputs gracefully.
def is_prime(n): """ Checks if a number n 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 prime_numbers_with_binary(start, end): """ Returns a list of prime numbers along with their binar...
from solution import is_prime, prime_numbers_with_binary import pytest 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 ...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers along with their binary representations\nbetween the start and end numbers (inclusive).", "...
[ 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 if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n ret...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031047", "row_id": 31047, "seed_ids": "['Qwen2-72B-Instruct_72087']" }
0.593068
Filter_31047
I
[ "is_prime", "prime_numbers_with_binary" ]
2
[ [ "prime_numbers_with_binary", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
547a3b450d8c2013d90f5fa87065540843f422c5
2cc34b5a986d40d387d9776f1b9942db4df639f2
v1.0
instruct
Filter
Filter_31053_I
Change the following code to a yield statement so that it can be used as a generator. Additionally, add error handling to the code to handle cases where the input is not a positive integer and return an error message instead of yielding anything. The generator should only yield even numbers. The code should also check ...
def is_prime(n): if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def even_numbers_generator(n): if not isinstance(n, int) or n <= 0: yield "Error: Input must be a positive integer" return for num in rang...
from solution import even_numbers_generator, 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_even_numbers_generator_positive_input(): result = list(even_numbers_gen...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def even_numbers_generator(n):", "function_name": "even_numbers_generator", "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 generate_even_numbers(n):\n \"\"\"\n A generator that yields even numbers from 1 to n (inclusive).\n If n is not a positive integer, it returns an error message.\n\n Args:\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031053", "row_id": 31053, "seed_ids": "['Qwen2-72B-Instruct_72099']" }
0.590228
Filter_31053
I
[ "is_prime", "even_numbers_generator" ]
2
[ [ "even_numbers_generator", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b5b2ac141f78dc68058fb9425b23ec0a84ed44c1
a46a9b2acec605b07be2134410d5086ea454a483
v1.0
instruct
Filter
Filter_31057_I
Write a code to create a 5x5 matrix with all elements as integers, where each row and column must have unique values and the sum of the elements in each row and column must be prime numbers.
import sympy def is_prime(num): """ Check if a given number is a prime. """ return sympy.isprime(num) def get_valid_prime_sums(): """ Generate a list of prime numbers that could be possible row/column sums for the matrix. These must be primes that can be generated using sums of unique valu...
from solution import generate_5x5_matrix_with_prime_sums, is_prime def test_matrix_has_unique_elements(): matrix = generate_5x5_matrix_with_prime_sums() for row in matrix: assert len(row) == len(set(row)) for col in range(5): col_elements = [row[col] for row in matrix] assert l...
[ { "docstring": "Check if a given number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generate a list of prime numbers that could be possible row/column sums for the matrix.\nThese must be primes that can...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sympy\n\ndef is_prime(num):\n \"\"\"\n Check if a given number is a prime.\n \"\"\"\n return sympy.isprime(num)\n\ndef get_valid_prime_sums():\n \"\"\"\n Generate a li...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031057", "row_id": 31057, "seed_ids": "['Qwen2-72B-Instruct_72107']" }
0.525084
Filter_31057
I
[ "is_prime", "get_valid_prime_sums", "generate_5x5_matrix_with_prime_sums" ]
3
[ [ "generate_5x5_matrix_with_prime_sums", "get_valid_prime_sums" ], [ "generate_5x5_matrix_with_prime_sums", "is_prime" ], [ "get_valid_prime_sums", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[ "sympy" ]
false
7ae7ef6b55be2818277c952edba34f5b051085d9
cc6496d6f252817a1b6c151eb35b3b410aa9c51b
v1.0
instruct
Filter
Filter_31058_I
Write a Python function that takes in two parameters: `n`, an integer representing the size of a square matrix, and `x`, an integer representing the target sum. The function should generate a magic square of size `n` and return `True` if the magic square contains a diagonal (either main or secondary) with a sum equal t...
def generate_magic_square(n): """ Generate a magic square of size n. """ if n % 2 == 0: raise ValueError("Magic squares are not possible for even sizes") magic_square = [[0] * n for _ in range(n)] num = 1 i, j = 0, n // 2 while num <= n**2: magic_square[i][j] = ...
from solution import magic_square_contains_diagonal_with_sum def test_odd_size_magic_square_with_valid_sum(): assert magic_square_contains_diagonal_with_sum(3, 15) == True assert magic_square_contains_diagonal_with_sum(5, 65) == True def test_odd_size_magic_square_with_invalid_sum(): assert magic_square_c...
[ { "docstring": "Generate a magic square of size n.", "function_declaration": "def generate_magic_square(n):", "function_name": "generate_magic_square", "parameter_list": "(n)" }, { "docstring": "Check if either the main diagonal or the secondary diagonal of the magic square has a sum equal t...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def generate_magic_square(n):\n \"\"\"\n Generate a magic square of size n.\n \"\"\"\n if n % 2 == 0:\n raise ValueError(\"Magic squares are not possible for even sizes\")\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031058", "row_id": 31058, "seed_ids": "['Qwen2-72B-Instruct_72108']" }
0.713164
Filter_31058
I
[ "generate_magic_square", "has_diagonal_with_sum", "magic_square_contains_diagonal_with_sum" ]
3
[ [ "magic_square_contains_diagonal_with_sum", "generate_magic_square" ], [ "magic_square_contains_diagonal_with_sum", "has_diagonal_with_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e288ddd24a5b69bc2e0e1959335791696c023eb3
7bac963f53c1a9a53b1bf76a7bee91d022bd114b
v1.0
instruct
Filter
Filter_31083_I
Consider the situation in which a heuristic evaluation is performed to determine the similarity between two strings using the Levenshtein algorithm. Furthermore, assume there's an additional condition in that the similarity score will only be computed for strings whose lengths differ by at most two characters. Given th...
def levenshtein_distance(s1, s2): """ Compute the Levenshtein distance between two strings. """ if len(s1) > len(s2): s1, s2 = s2, s1 distances = range(len(s1) + 1) for i2, c2 in enumerate(s2): distances_ = [i2+1] for i1, c1 in enumerate(s1): if c1 == c2: ...
from solution import compare_strings def test_compare_strings_equal(): assert compare_strings("kitten", "kitten") == 0 def test_compare_strings_one_edit(): assert compare_strings("kitten", "sitten") == 1 def test_compare_strings_two_edits(): assert compare_strings("kitten", "kitte") == 1 def test_compar...
[ { "docstring": "Compute the Levenshtein distance between two strings.", "function_declaration": "def levenshtein_distance(s1, s2):", "function_name": "levenshtein_distance", "parameter_list": "(s1, s2)" }, { "docstring": "Compare two strings using Levenshtein distance if their lengths differ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def levenshtein_dist(str1, str2):\n \"\"\"\n Compute the Levenshtein distance between two strings.\n \"\"\"\n if abs(len(str1) - len(str2)) > 2:\n # Strings' lengths differ ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031083", "row_id": 31083, "seed_ids": "['Qwen2-72B-Instruct_72159']" }
0.649038
Filter_31083
I
[ "levenshtein_distance", "compare_strings" ]
2
[ [ "compare_strings", "levenshtein_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9392fd740f9448d47e04149cc48fb692c3980f5f
3bc9820b63ed823713fa0f81c2ad216d191909bd
v1.0
instruct
Filter
Filter_31110_I
Create a program that generates an array of 100,000 random integers between -1,000,000 and 1,000,000. The program should then sort the array in ascending order using a quicksort algorithm implemented recursively. The program should output the sorted array.
import random def quicksort(arr): """ Recursively sorts an array using the quicksort algorithm. """ 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] retu...
from solution import quicksort, generate_and_sort_array def test_quicksort_empty_array(): assert quicksort([]) == [] def test_quicksort_single_element_array(): 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_...
[ { "docstring": "Recursively sorts an array using the quicksort algorithm.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "Generates an array of 100,000 random integers between -1,000,000 and 1,000,000,\nand sorts it ...
[ 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 Sorts an array in ascending order using the quicksort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n pivot = arr[l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031110", "row_id": 31110, "seed_ids": "['Qwen2-72B-Instruct_72209']" }
0.542921
Filter_31110
I
[ "quicksort", "generate_and_sort_array" ]
2
[ [ "generate_and_sort_array", "quicksort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d78a3a9349c29be677c9da4aec61ba062c25d81b
94cde99ea627ceea03e4a79fc5d5aaeee4e1bd66
v1.0
instruct
Filter
Filter_31114_I
Convert the equation y = 2x^2 - 4x + 3 into a Python function that can be used to generate a table of values for x ranging from -5 to 5 in increments of 0.5. Also, plot the curve for the same range of x using any suitable Python plotting library.
import numpy as np import matplotlib.pyplot as plt def equation(x): """ Given the equation y = 2x^2 - 4x + 3, calculate the value of y for a given x. """ return 2 * x**2 - 4 * x + 3 def generate_table(start, end, step): """ Generate a table of values for the equation y = 2x^2 - 4x + 3 from sta...
from solution import equation, generate_table def test_equation(): assert equation(0) == 3 # y = 2(0)^2 - 4(0) + 3 = 3 assert equation(1) == 1 # y = 2(1)^2 - 4(1) + 3 = 1 assert equation(-1) == 9 # y = 2(-1)^2 - 4(-1) + 3 = 9 assert equation(2) == 3 # y = 2(2)^2 - 4(2) + 3 = 3 def test_generate_ta...
[ { "docstring": "Given the equation y = 2x^2 - 4x + 3, calculate the value of y for a given x.", "function_declaration": "def equation(x):", "function_name": "equation", "parameter_list": "(x)" }, { "docstring": "Generate a table of values for the equation y = 2x^2 - 4x + 3 from start to end ...
[ 1, 0, 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\n\ndef quadratic_function(x):\n \"\"\"\n Given x, calculate the value of y = 2x^2 - 4x + 3\n \"\"\"\n return 2 * x ** 2 - 4 * x ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031114", "row_id": 31114, "seed_ids": "['Qwen2-72B-Instruct_72216']" }
0.558573
Filter_31114
I
[ "equation", "generate_table", "plot_curve" ]
3
[ [ "generate_table", "equation" ], [ "plot_curve", "equation" ] ]
2
[]
false
[]
false
pytest
true
[ "matplotlib", "numpy" ]
false
56d47a514beea7356afae1484c1c3ca2c38c84a8
90af2105ace9d02a296f4423f18fdd0fcfcb2cd6
v1.0
instruct
Filter
Filter_31132_I
Write a piece of code that not only generates a list of numbers between 1 and 50 which are divisible by 7, but also finds the sum and average of those numbers. Additionally, implement a function that finds the factorial of each number in this list, and returns a new list with these factorials. Calculate and print the s...
def generate_divisible_by_seven(): """ Generates a list of numbers between 1 and 50 which are divisible by 7. """ return [i for i in range(1, 51) if i % 7 == 0] def sum_and_average(numbers): """ Returns the sum and average of the given list of numbers. """ total_sum = sum(numbers) a...
from solution import generate_divisible_by_seven, sum_and_average, factorial, factorials def test_generate_divisible_by_seven(): expected_list = [7, 14, 21, 28, 35, 42, 49] assert generate_divisible_by_seven() == expected_list def test_sum_and_average(): numbers = [7, 14, 21, 28, 35, 42, 49] expected_...
[ { "docstring": "Generates a list of numbers between 1 and 50 which are divisible by 7.", "function_declaration": "def generate_divisible_by_seven():", "function_name": "generate_divisible_by_seven", "parameter_list": "()" }, { "docstring": "Returns the sum and average of the given list of nu...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef generate_numbers():\n \"\"\"\n Generates a list of numbers between 1 and 50 which are divisible by 7.\n \"\"\"\n return [x for x in range(1, 51) if x % 7 == 0]\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031132", "row_id": 31132, "seed_ids": "['Qwen2-72B-Instruct_72245']" }
0.540513
Filter_31132
I
[ "generate_divisible_by_seven", "sum_and_average", "factorial", "factorials" ]
4
[ [ "factorials", "factorial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
618e7b442af95b255674bfd1a0d037f421ab38b6
ec4641c7660b490dbc48fa922482c45c63529424
v1.0
instruct
Filter
Filter_31143_I
Write a Python program to reverse every word of a sentence given as input, preserving the order of words. Also, if a word contains any special characters (e.g., punctuation), those special characters should be left in their original positions within the reversed word.
def reverse_word(word): """ Helper function to reverse a word while preserving the positions of special characters. """ special_chars = {i: c for i, c in enumerate(word) if not c.isalnum()} reversed_word = [c for c in word if c.isalnum()][::-1] for i, c in special_chars.items(): rev...
from solution import reverse_sentence def test_single_word(): assert reverse_sentence("hello") == "olleh" def test_single_word_with_special_characters(): assert reverse_sentence("he*l*lo!") == "ol*l*eh!" def test_multiple_words(): assert reverse_sentence("hello world") == "olleh dlrow" def test_multiple...
[ { "docstring": "Helper function to reverse a word while preserving the positions of special characters.", "function_declaration": "def reverse_word(word):", "function_name": "reverse_word", "parameter_list": "(word)" }, { "docstring": "Reverses every word in the sentence, preserving the orde...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reverse_word(word):\n \"\"\"\n Reverses the alphabetical characters in a word, leaving any special characters in their original positions.\n \"\"\"\n # Extract only the alphabe...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031143", "row_id": 31143, "seed_ids": "['Qwen2-72B-Instruct_72268']" }
0.661842
Filter_31143
I
[ "reverse_word", "reverse_sentence" ]
2
[ [ "reverse_sentence", "reverse_word" ] ]
1
[]
false
[]
false
pytest
true
[]
true
427fabb2ad826c120af449cac820748d22742c48
e9b4b84bdb3b599d6ab418822f2a58ba07aca267
v1.0
instruct
Filter
Filter_31145_I
Write the backpropagation algorithm formula for a 3-layer neural network with a sigmoid activation function. Additionally, implement the algorithm in Python using only NumPy library, without using any deep learning frameworks.
import numpy as np def sigmoid(x): """ Sigmoid activation function. """ return 1 / (1 + np.exp(-x)) def sigmoid_derivative(x): """ Derivative of the sigmoid function. """ return x * (1 - x) def initialize_parameters(input_size, hidden_size, output_size): """ Initializes weight...
import pytest import numpy as np from solution import sigmoid, sigmoid_derivative, initialize_parameters, forward_propagation, compute_cost, backward_propagation, update_parameters, neural_network def test_sigmoid(): x = np.array([0]) assert sigmoid(x) == 0.5 def test_sigmoid_derivative(): x = np.array([0...
[ { "docstring": "Sigmoid activation function.", "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": "Derivative of the sigmoid function.", "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_deriv...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef sigmoid(z):\n \"\"\"\n Compute the sigmoid function\n \"\"\"\n return 1 / (1 + np.exp(-z))\n\ndef sigmoid_derivative(z):\n \"\"\"\n Compute the deri...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031145", "row_id": 31145, "seed_ids": "['Qwen2-72B-Instruct_72270']" }
0.400352
Filter_31145
I
[ "sigmoid", "sigmoid_derivative", "initialize_parameters", "forward_propagation", "compute_cost", "backward_propagation", "update_parameters", "neural_network" ]
8
[ [ "backward_propagation", "sigmoid_derivative" ], [ "forward_propagation", "sigmoid" ], [ "neural_network", "backward_propagation" ], [ "neural_network", "compute_cost" ], [ "neural_network", "forward_propagation" ], [ "neural_network", "initialize...
7
[]
false
[]
false
pytest
true
[ "numpy" ]
false
9fae4e7e935e20f19587adacffc236b82601cdba
8a00515b2594020c449b45fe610877ae8ec38879
v1.0
instruct
Filter
Filter_31150_I
Write a program that simulates a basic calculator. The calculator should be able to perform addition, subtraction, multiplication, and division on two numbers. It should also handle division by zero and invalid input.
def add(a, b): """ Returns the sum of a and b. """ return a + b def subtract(a, b): """ Returns the difference when b is subtracted from a. """ return a - b def multiply(a, b): """ Returns the product of a and b. """ return a * b def divide(a, b): """ Returns t...
from solution import calculator def test_addition(): assert calculator(2, 3, 'add') == 5 assert calculator(-1, 1, 'add') == 0 assert calculator(0, 0, 'add') == 0 def test_subtraction(): assert calculator(5, 3, 'subtract') == 2 assert calculator(3, 5, 'subtract') == -2 assert calculator(0, 0, '...
[ { "docstring": "Returns the sum of a and b.", "function_declaration": "def add(a, b):", "function_name": "add", "parameter_list": "(a, b)" }, { "docstring": "Returns the difference when b is subtracted from a.", "function_declaration": "def subtract(a, b):", "function_name": "subtrac...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def basic_calculator(operation, a, b):\n \"\"\"\n Simulates a basic calculator that can perform addition, subtraction, \n multiplication, and division. Handles division by zero and in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031150", "row_id": 31150, "seed_ids": "['Qwen2-72B-Instruct_72277']" }
0.507866
Filter_31150
I
[ "add", "subtract", "multiply", "divide", "calculator" ]
5
[ [ "calculator", "add" ], [ "calculator", "divide" ], [ "calculator", "multiply" ], [ "calculator", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
33fde4295076a9238d6fcc259f6172b2377947b1
f687129d10995ef3ec38a49de7384e58a4b709eb
v1.0
instruct
Filter
Filter_31152_I
Write a Python generator function that yields only the prime numbers in the range from 1 to n. Also, write a separate function to test if a given number is prime, and use this function within your generator. Test your generator by printing out the prime numbers between 1 and 100. The solution should handle large number...
def is_prime(num): """ Returns True if num is a prime number, False otherwise. """ 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: ...
from solution import is_prime, prime_generator def test_is_prime(): # Testing prime numbers assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True assert is_prime(11) == True assert is_prime(13) == True assert is_prime(17) == True ...
[ { "docstring": "Returns True if num is a prime number, False otherwise.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Generator that yields prime numbers from 1 to n.", "function_declaration": "def prime_generato...
[ 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 Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031152", "row_id": 31152, "seed_ids": "['Qwen2-72B-Instruct_72281']" }
0.63907
Filter_31152
I
[ "is_prime", "prime_generator" ]
2
[ [ "prime_generator", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
116b1c1d381fd50ed21101eee1065ea0747d5946
b6fd305555cc78756136627ff8478932427ab45c
v1.0
instruct
Filter
Filter_31155_I
Create a regex to identify valid IPV4 addresses, and then create a function that uses this regex to parse through a provided list of IP addresses, removing any that aren't valid. Additionally, justify any design decisions you make in your code.
import re def is_valid_ipv4_address(ip): """ Checks if the given IP address is a valid IPv4 address. """ pattern = re.compile(r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$') return bool(pattern.match(ip)) def filter_valid_ipv4_addresses(ip_list): """ ...
from solution import is_valid_ipv4_address, filter_valid_ipv4_addresses def test_is_valid_ipv4_address(): assert is_valid_ipv4_address("192.168.1.1") == True assert is_valid_ipv4_address("255.255.255.255") == True assert is_valid_ipv4_address("0.0.0.0") == True assert is_valid_ipv4_address("256.256.256...
[ { "docstring": "Checks if the given IP address is a valid IPv4 address.", "function_declaration": "def is_valid_ipv4_address(ip):", "function_name": "is_valid_ipv4_address", "parameter_list": "(ip)" }, { "docstring": "Filters out invalid IPv4 addresses from the provided list.", "function...
[ 1, 1, 0 ]
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_ipv4(ip):\n \"\"\"\n Uses regular expression to check if the provided IP address is a valid IPV4 address.\n \"\"\"\n pattern = re.compile(r\"^(25[0-5]|2[0...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031155", "row_id": 31155, "seed_ids": "['Qwen2-72B-Instruct_72284']" }
0.642834
Filter_31155
I
[ "is_valid_ipv4_address", "filter_valid_ipv4_addresses" ]
2
[ [ "filter_valid_ipv4_addresses", "is_valid_ipv4_address" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9ee7825e5adab91b3d3ab8aa74c5d5bd5abc774e
afeee45ebbb11c18783321bcbc2dcf629939e671
v1.0
instruct
Filter
Filter_31156_I
Create a code to generate a unique 7-character string of random numbers and letters, ensuring that no two generated strings are the same. Additionally, implement a function to check if a given string is already present in a list of generated strings, and if so, generate a new unique string. Here's a Python code that ge...
import random import string generated_strings = set() def generate_unique_string(): """ Generates a unique 7-character string of random numbers and letters. """ while True: new_string = ''.join(random.choices(string.ascii_letters + string.digits, k=7)) if new_string not in generated_st...
from solution import generate_unique_string, is_present_and_generate_unique, generated_strings def test_generate_unique_string(): generated_strings.clear() str1 = generate_unique_string() str2 = generate_unique_string() assert len(str1) == 7 and len(str2) == 7 assert str1 != str2 assert str1 in...
[ { "docstring": "Generates a unique 7-character string of random numbers and letters.", "function_declaration": "def generate_unique_string():", "function_name": "generate_unique_string", "parameter_list": "()" }, { "docstring": "Checks if a given string is present in the existing list.\nIf y...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport string\n\ngenerated_strings = set()\n\ndef generate_unique_string():\n \"\"\"\n Generates a unique 7-character string of random numbers and letters.\n Ensures no...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031156", "row_id": 31156, "seed_ids": "['Qwen2-72B-Instruct_72285']" }
0.667859
Filter_31156
I
[ "generate_unique_string", "is_present_and_generate_unique" ]
2
[ [ "is_present_and_generate_unique", "generate_unique_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
99a422ded3bfb55de8bf84c28e9ae579f8fd1e7f
6a77217473a0c3becaa359750b814a7473ca1006
v1.0
instruct
Filter
Filter_31157_I
Write a code to create a 3 x 3 matrix containing all 0s, but the matrix must be initialized using a recursive algorithm instead of a simple loop.
def create_zero_matrix(n, m): """ Create an n x m matrix initialized with zeros using a recursive algorithm. """ if n == 0: return [] else: return [create_zero_matrix_row(m)] + create_zero_matrix(n - 1, m) def create_zero_matrix_row(m): """ Create a row with m zeros. """...
from solution import create_3x3_zero_matrix, create_zero_matrix, create_zero_matrix_row def test_create_3x3_zero_matrix(): matrix = create_3x3_zero_matrix() assert matrix == [[0, 0, 0], [0, 0, 0], [0, 0, 0]] def test_create_zero_matrix_2x2(): matrix = create_zero_matrix(2, 2) assert matrix == [[0, 0],...
[ { "docstring": "Create an n x m matrix initialized with zeros using a recursive algorithm.", "function_declaration": "def create_zero_matrix(n, m):", "function_name": "create_zero_matrix", "parameter_list": "(n, m)" }, { "docstring": "Create a row with m zeros.", "function_declaration": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def create_zero_matrix(n, row=0, col=0, matrix=None):\n \"\"\"\n Recursively creates an n x n matrix filled with 0s.\n \"\"\"\n if matrix is None:\n matrix = [[0] * n for _ ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031157", "row_id": 31157, "seed_ids": "['Qwen2-72B-Instruct_72287']" }
0.521103
Filter_31157
I
[ "create_zero_matrix", "create_zero_matrix_row", "create_3x3_zero_matrix" ]
3
[ [ "create_3x3_zero_matrix", "create_zero_matrix" ], [ "create_zero_matrix", "create_zero_matrix_row" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c96af3e56203a600279059078c8672cfeba96c98
550700f7fd93785cb71c3ea010698c453aea7309
v1.0
instruct
Filter
Filter_31164_I
Given an erroneous piece of code that is supposed to check if a number is a palindrome, find and correct the mistake(s) in the code. Additionally, extend the function to not only check if a number is a palindrome but also return the smallest palindrome larger than the given number.
def is_palindrome(n): """ Checks if a given number n is a palindrome. """ str_n = str(n) return str_n == str_n[::-1] def next_palindrome(n): """ Finds the smallest palindrome number larger than the given number n. """ n += 1 while not is_palindrome(n): n += 1 return ...
from solution import is_palindrome, next_palindrome def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(0) == True assert is_palindrome(1) == True assert is_palindrome(1221) == True assert is_palindrome(12321) == True assert is...
[ { "docstring": "Checks if a given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Finds the smallest palindrome number larger than the given number n.", "function_declaration": "def ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(num):\n \"\"\"\n Checks if a number is a palindrome.\n Returns True if the number is a palindrome, False otherwise.\n \"\"\"\n str_num = str(num)\n return s...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031164", "row_id": 31164, "seed_ids": "['Qwen2-72B-Instruct_72306']" }
0.73072
Filter_31164
I
[ "is_palindrome", "next_palindrome" ]
2
[ [ "next_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cea16acc7a31c81cfcf5b6c96ea9d5bf5f1d3377
a2b442c5741667f2dd0ccb9e13d818c9e1dd3491
v1.0
instruct
Filter
Filter_31167_I
Write a Python program that simulates a game of chance. The game works as follows: the player rolls two dice. If the sum of the two dice is equal to 7 or 11, the player wins. If the sum is 2, 3, or 12, the player loses. For any other result, the player rolls the dice again. On subsequent rolls, if the sum is equal to t...
import random def roll_dice(): """ Simulates rolling two dice. Returns a tuple with the result of each dice. """ return random.randint(1, 6), random.randint(1, 6) def dice_sum(dice_roll): """ Calculate the sum of the two dice. """ return sum(dice_roll) def game_of_chance(): ""...
import pytest from solution import roll_dice, dice_sum, game_of_chance def test_roll_dice(): dice_values = roll_dice() assert len(dice_values) == 2 assert 1 <= dice_values[0] <= 6 assert 1 <= dice_values[1] <= 6 def test_dice_sum(): assert dice_sum((1, 1)) == 2 assert dice_sum((6, 6)) == 12 ...
[ { "docstring": "Simulates rolling two dice.\nReturns a tuple with the result of each dice.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Calculate the sum of the two dice.", "function_declaration": "def dice_sum(dice...
[ 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 roll_dice():\n \"\"\"\n Simulates rolling two dice and returns their sum.\n \"\"\"\n die1 = random.randint(1, 6)\n die2 = random.randint(1, 6)\n return d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031167", "row_id": 31167, "seed_ids": "['Qwen2-72B-Instruct_72309']" }
0.530919
Filter_31167
I
[ "roll_dice", "dice_sum", "game_of_chance" ]
3
[ [ "game_of_chance", "dice_sum" ], [ "game_of_chance", "roll_dice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b30c7168692b8fe9b823a8e414aee83e1fee8654
a04268194bfff1bc44c35ee9611a705bc482136f
v1.0
instruct
Filter
Filter_31171_I
Could you write a Python program for a game called 'Create Hero'? In this game, you are tasked with adding a new hero to your collection. Each hero is uniquely defined by their name, health points, attack damage, and type. The existing hero collection is stored as a list of hero dictionaries. Your task is to create a n...
class HeroAlreadyExistsError(Exception): """Exception raised when trying to add a hero that already exists.""" pass class InvalidHeroAttributesError(Exception): """Exception raised when hero attributes are invalid.""" pass def validate_hero(name, health_points, attack_damage, type_): """ Valid...
import pytest from solution import create_hero, display_heroes, HeroAlreadyExistsError, InvalidHeroAttributesError def test_create_hero_success(): hero_collection = [] new_hero = create_hero('Thor', 100, 20, 'Warrior', hero_collection) assert new_hero == {'name': 'Thor', 'health_points': 100, 'attack_damag...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class HeroExistsError(Exception):\n pass\n\nclass InvalidHeroError(Exception):\n pass\n\ndef add_hero(collection, name, health, attack, type_):\n \"\"\"\n Adds a new hero to the co...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031171", "row_id": 31171, "seed_ids": "['Qwen2-72B-Instruct_72314']" }
0.446534
Filter_31171
I
[ "validate_hero", "create_hero", "display_heroes" ]
3
[ [ "create_hero", "validate_hero" ] ]
1
[]
false
[ "HeroAlreadyExistsError", "InvalidHeroAttributesError" ]
true
pytest
true
[]
true
4e0dae6d7c60630786a7ebcdb85c603fe6531d53
530aca9a1520e90e279593ea55535eff4049d75b
v1.0
instruct
Filter
Filter_31175_I
Write a Python generator function that yields the first n square numbers. Additionally, implement a function that uses this generator to calculate the sum of these square numbers. Test your functions with multiple values of n to ensure they work as expected.
def square_numbers(n): """ Generator function that yields the first n square numbers. """ for i in range(1, n+1): yield i * i def sum_of_squares(n): """ Uses the square_numbers generator to calculate the sum of the first n square numbers. """ return sum(square_numbers(n))
from solution import square_numbers, sum_of_squares def test_square_numbers(): assert list(square_numbers(5)) == [1, 4, 9, 16, 25] assert list(square_numbers(0)) == [] assert list(square_numbers(1)) == [1] assert list(square_numbers(3)) == [1, 4, 9] def test_sum_of_squares(): assert sum_of_squares...
[ { "docstring": "Generator function that yields the first n square numbers.", "function_declaration": "def square_numbers(n):", "function_name": "square_numbers", "parameter_list": "(n)" }, { "docstring": "Uses the square_numbers generator to calculate the sum of the first n square numbers.",...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def square_numbers(n):\n \"\"\"\n Generator function that yields the first n square numbers.\n \"\"\"\n for i in range(1, n+1):\n yield i * i\n\ndef sum_of_squares(n):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031175", "row_id": 31175, "seed_ids": "['Qwen2-72B-Instruct_72321']" }
0.746597
Filter_31175
I
[ "square_numbers", "sum_of_squares" ]
2
[ [ "sum_of_squares", "square_numbers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ed7a72fcacda504537f08ded1a9bd65b4073acf
f15634e64b0179c3c2fcd42256202cab6698ab03
v1.0
instruct
Filter
Filter_31179_I
Write a function that takes in a list of strings and returns the longest palindrome within the list. If there are multiple palindromes with the same maximum length, return the one that occurs first in the list. If there are no palindromes in the list, return an empty string. Note: The list can contain lower-case Englis...
def is_palindrome(s): """ Helper function to check if a given string is a palindrome. """ return s == s[::-1] def longest_palindrome(strings): """ Returns the longest palindrome in the list of strings. If multiple palindromes have the same length, returns the one that occurs first. If n...
from solution import longest_palindrome def test_no_palindromes(): assert longest_palindrome(["apple", "banana", "cherry"]) == "" def test_single_character_palindromes(): assert longest_palindrome(["a", "b", "c"]) == "a" def test_single_palindrome_in_list(): assert longest_palindrome(["racecar", "apple",...
[ { "docstring": "Helper function to check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns the longest palindrome in the list of strings.\nIf multiple palindromes have the...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef longest_palindrome(strings):\n \"\"\"\n Ret...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031179", "row_id": 31179, "seed_ids": "['Qwen2-72B-Instruct_72326']" }
0.784618
Filter_31179
I
[ "is_palindrome", "longest_palindrome" ]
2
[ [ "longest_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
500fb42313eca80c9db5d79a96adb89c803a3b0b
f0dcafc5f50f9f3967755103e81938f0f6d08637
v1.0
instruct
Filter
Filter_31187_I
Create an in-memory list of strings in Python with 1 million strings, where each string is a combination of random alphanumeric characters of length between 10 and 20 characters. Additionally, all strings in the list must be unique and must not contain any repeating characters. The strings should also not contain any v...
import random import string def generate_unique_string(existing_strings, length): """ Generates a unique string of a given length. The string will be composed of random alphanumeric characters excluding vowels and numbers divisible by 3. """ chars = string.ascii_letters + ''.join(str(i) for i in ra...
from solution import generate_unique_strings_list def test_generate_unique_strings_list_length(): result = generate_unique_strings_list(1000, 10, 20) assert len(result) == 1000 def test_generate_unique_strings_list_sorted(): result = generate_unique_strings_list(1000, 10, 20) assert result == sorted(r...
[ { "docstring": "Generates a unique string of a given length.\nThe string will be composed of random alphanumeric characters excluding vowels and numbers divisible by 3.", "function_declaration": "def generate_unique_string(existing_strings, length):", "function_name": "generate_unique_string", "para...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport string\n\ndef generate_unique_string():\n \"\"\"\n Generate a unique string of length between 10 and 20, consisting of alphanumeric chars.\n No vowels or numbers...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031187", "row_id": 31187, "seed_ids": "['Qwen2-72B-Instruct_72336']" }
0.693382
Filter_31187
I
[ "generate_unique_string", "generate_unique_strings_list" ]
2
[ [ "generate_unique_strings_list", "generate_unique_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3950d5dc88238b7dfed85fdfd1630ca5de6e7c1c
c29912c721d669c7553f54bf4f385e237f95765c
v1.0
instruct
Filter
Filter_31193_I
Consider the following Python function that computes the highest shared divisor of two numbers. Your task is to make modifications to this function to not only handle the case of finding the greatest common divisor (GCD) of two positive integers, but also extend its functionality to calculate the least common multiple ...
from math import gcd from functools import reduce def find_gcd(a, b): """ Returns the Greatest Common Divisor (GCD) of a and b. """ return gcd(a, b) def find_lcm(a, b): """ Returns the Least Common Multiple (LCM) of a and b. """ return (a * b) // find_gcd(a, b) def lcm_multiple(number...
from solution import find_gcd, find_lcm, lcm_multiple def test_find_gcd(): assert find_gcd(54, 24) == 6 assert find_gcd(48, 18) == 6 assert find_gcd(101, 103) == 1 # prime numbers def test_find_lcm(): assert find_lcm(4, 5) == 20 assert find_lcm(12, 15) == 60 assert find_lcm(7, 9) == 63 as...
[ { "docstring": "Returns the Greatest Common Divisor (GCD) of a and b.", "function_declaration": "def find_gcd(a, b):", "function_name": "find_gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the Least Common Multiple (LCM) of a and b.", "function_declaration": "def find_lcm(a,...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef gcd(a, b):\n \"\"\"\n Returns the greatest common divisor (GCD) of a and b.\n \"\"\"\n while b:\n a, b = b, a % b\n retur...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031193", "row_id": 31193, "seed_ids": "['Qwen2-72B-Instruct_72346']" }
0.788636
Filter_31193
I
[ "find_gcd", "find_lcm", "lcm_multiple" ]
3
[ [ "find_lcm", "find_gcd" ], [ "lcm_multiple", "find_lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
02d4313b013aa3f816aed874ddc880d3e713764b
60ad1e0835fc9c3f77af54baf08ab43597a308c8
v1.0
instruct
Filter
Filter_31202_I
Create a Python program that reads a specific CSV file and provides a variety of operations such as printing the entire file, printing a specific row, printing a specific column, and finding a specific value in the file. The program should have a user-friendly interface with menu options for the user to select from, im...
import csv def read_csv(file_path): """ Reads the CSV file and returns its content as a list of lists. """ try: with open(file_path, mode='r') as file: reader = csv.reader(file) return list(reader) except FileNotFoundError: print("The specified file does not ...
import pytest from solution import read_csv, print_specific_row, print_specific_column, find_value def test_read_csv_valid_file(tmpdir): csv_file = tmpdir.join("test.csv") csv_file.write("col1,col2\nval1,val2\nval3,val4") content = read_csv(str(csv_file)) assert content == [["col1", "col2"], ["val1", "...
[ { "docstring": "Reads the CSV file and returns its content as a list of lists.", "function_declaration": "def read_csv(file_path):", "function_name": "read_csv", "parameter_list": "(file_path)" }, { "docstring": "Prints the entire CSV content.", "function_declaration": "def print_entire_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import csv\n\ndef read_csv(file_path):\n \"\"\"\n Reads the CSV file and returns its content as a list of lists.\n \"\"\"\n try:\n with open(file_path, mode='r') as file:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031202", "row_id": 31202, "seed_ids": "['Qwen2-72B-Instruct_72361']" }
0.59812
Filter_31202
I
[ "read_csv", "print_entire_file", "print_specific_row", "print_specific_column", "find_value", "user_interface" ]
6
[ [ "user_interface", "find_value" ], [ "user_interface", "print_entire_file" ], [ "user_interface", "print_specific_column" ], [ "user_interface", "print_specific_row" ], [ "user_interface", "read_csv" ] ]
5
[]
false
[]
false
pytest
true
[]
true
1b8db7afadfe2d0cd684a457ad6203f5e4911ec7
ca088081d9a3a0ff1a0a8492a101839a443b07e1
v1.0
instruct
Filter
Filter_31258_I
Increase the complexity of the code snippet below, which includes correcting the error in the existing function and designing a unique, non-repetitive helper function. Your task is to create an error-free main function that checks if the list of integers has at least two elements that are both palindromes and primes.
def is_palindrome(n): """ Check if a number is a palindrome. """ s = str(n) return s == s[::-1] def is_prime(n): """ Check 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 T...
from solution import is_palindrome, is_prime, has_two_palindromic_primes def test_is_palindrome(): assert is_palindrome(121) assert is_palindrome(12321) assert not is_palindrome(123) assert is_palindrome(7) def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) ...
[ { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef is_prime(n):\n \"\"\"\n Check if a number is a prime...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031258", "row_id": 31258, "seed_ids": "['Qwen2-72B-Instruct_72445']" }
0.618434
Filter_31258
I
[ "is_palindrome", "is_prime", "has_two_palindromic_primes" ]
3
[ [ "has_two_palindromic_primes", "is_palindrome" ], [ "has_two_palindromic_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
367391726fd759e1644d9646a561e967526e5793
253f8c9bff165ea5ba449946e81e0798571b86d2
v1.0
instruct
Filter
Filter_31261_I
Write a Python program to subtract two matrices. In addition, implement a function to check if the matrices can be subtracted, i.e., they have the same dimensions.
def can_subtract_matrices(mat1, mat2): """ Check if two matrices can be subtracted. """ return len(mat1) == len(mat2) and all(len(row1) == len(row2) for row1, row2 in zip(mat1, mat2)) def subtract_matrices(mat1, mat2): """ Subtract two matrices if they have the same dimensions. """ if n...
from solution import can_subtract_matrices, subtract_matrices def test_can_subtract_matrices(): assert can_subtract_matrices([[1, 2], [3, 4]], [[1, 2], [3, 4]]) == True assert can_subtract_matrices([[1, 2, 3], [4, 5, 6]], [[1, 2], [3, 4]]) == False assert can_subtract_matrices([[1, 2], [3, 4]], [[1, 2, 3],...
[ { "docstring": "Check if two matrices can be subtracted.", "function_declaration": "def can_subtract_matrices(mat1, mat2):", "function_name": "can_subtract_matrices", "parameter_list": "(mat1, mat2)" }, { "docstring": "Subtract two matrices if they have the same dimensions.", "function_d...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_subtract_matrices(mat1, mat2):\n \"\"\"\n Check if two matrices can be subtracted.\n \"\"\"\n return len(mat1) == len(mat2) and all(len(row1) == len(row2) for row1, row2 in...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031261", "row_id": 31261, "seed_ids": "['Qwen2-72B-Instruct_72449']" }
0.511096
Filter_31261
I
[ "can_subtract_matrices", "subtract_matrices" ]
2
[ [ "subtract_matrices", "can_subtract_matrices" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5b4caba5493037792193c6a7e273df09c9b77c90
2c2c713baac3b68de94f93fffe8a8e7112e1727e
v1.0
instruct
Filter
Filter_31263_I
Develop a Python function that is adept at identifying prime numbers from an assortment of 2D arrays. This function should be designed to handle and rectify the errors arising from mixed data types (integers, floats, and strings) within these arrays, as well as disregard any list that includes non-integer types. Moreov...
import math def is_prime(n): """ Returns True if n is a prime number, else False. """ 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 Fa...
from solution import extract_primes def test_extract_primes_with_all_integers(): matrix = [ [2, 3, 4], [5, 6, 7], [8, 9, 10] ] assert extract_primes(matrix) == [2, 3, 5, 7] def test_extract_primes_with_mixed_data_types(): matrix = [ [2, 3.5, 4], [5, 6, "7"], ...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a 2D array (matrix), return all prime numbers in the matrix.\nOnly consider arrays (sub-arrays) that co...
[ 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 given 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 ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031263", "row_id": 31263, "seed_ids": "['Qwen2-72B-Instruct_72451']" }
0.655002
Filter_31263
I
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f30a850218c06ae69529aacad6d073858539f55a
82b5186500652fc096cc0cb453f58a7d607b8fa8
v1.0
instruct
Filter
Filter_31267_I
Compose a fragment of a python program designed to evaluate whether a provided number is prime. In addition, the program should be able to find and return the closest prime number less than the provided number if it is not a prime number itself.
def is_prime(n): """ Check if the 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, closest_prime_less_than def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-5) assert is_prime(13) assert not is_prime(15) def test_clo...
[ { "docstring": "Check if the number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the closest prime number less than the provided number.", "function_declaration": "def closest_prime_less_than...
[ 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 the 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 or n % 3 == ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031267", "row_id": 31267, "seed_ids": "['Qwen2-72B-Instruct_72456']" }
0.702704
Filter_31267
I
[ "is_prime", "closest_prime_less_than" ]
2
[ [ "closest_prime_less_than", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2376c0ced199f2b55627a3047900721667b7d081
7f54b9d51dba17cc785a2b8671bfa4b2225b9bf8
v1.0
instruct
Filter
Filter_31280_I
Develop a Python function to find the product of all prime numbers less than or equal to n. Also, modify the function to enable error handling for inputs that are non-integer or less than 2. Furthermore, implement a mechanism to track and return the total time taken to calculate the product. Here is a sample code with ...
import time def is_prime(num): """ Check if the number is a 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 product_of_primes(n): """ Returns the product of all prime numbers less than o...
from solution import product_of_primes def test_product_of_primes_normal_cases(): assert product_of_primes(10)[0] == 210 assert product_of_primes(5)[0] == 30 assert product_of_primes(2)[0] == 2 def test_product_of_primes_with_invalid_input(): try: product_of_primes(1) except ValueError...
[ { "docstring": "Check if the number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the product of all prime numbers less than or equal to n.\nIf n is less than 2 or not an integer, raises ValueErro...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef is_prime(num):\n \"\"\"\n Returns True if the number is a prime number, else False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n retu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031280", "row_id": 31280, "seed_ids": "['Qwen2-72B-Instruct_72477']" }
0.627935
Filter_31280
I
[ "is_prime", "product_of_primes" ]
2
[ [ "product_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e8fb6937e74ec9b1dde16ffd57b264ecdccfbee7
4d74025c61e4ee9059e3579a0af8506d8b8cb337
v1.0
instruct
Filter
Filter_31291_I
Implement a function to print the Fibonacci series up to the nth term, but also print the sum of the prime numbers in the series. Additionally, ensure that the function is optimized to have a time complexity of O(n) and a space complexity of O(1).
def is_prime(num): 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: return False i += 6 return True def fibonacci_and_prime_sum(n)...
from solution import fibonacci_and_prime_sum 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 assert is_prime(23) == True def test_fibonacci_and_prime_sum(capsys): # Capture the o...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Prints the Fibonacci series up to the nth term and the sum of the prime numbers in the series.", "function_declaration": "def fibonacci_and_prime_s...
[ 0, 1, 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 Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031291", "row_id": 31291, "seed_ids": "['Qwen2-72B-Instruct_72490']" }
0.668088
Filter_31291
I
[ "is_prime", "fibonacci_and_prime_sum" ]
2
[ [ "fibonacci_and_prime_sum", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1cb1294ca9a4335258fea9020064fd609143a432
5723a3c1d685f1b82fb9fc20f04f7660670f6633
v1.0
instruct
Filter
Filter_31298_I
Please write a generic code in Python for sorting an array using the quick sort algorithm. The code should handle arrays with duplicate elements and negative numbers. Additionally, you should implement the quick sort algorithm using an iterative approach instead of a recursive one. Your code should also ensure that the...
def quick_sort(array): """ Sorts the array in descending order using the quick sort algorithm (iterative approach). """ if len(array) < 2: return array stack = [(0, len(array) - 1)] while stack: low, high = stack.pop() if low < high: pivot_i...
from solution import quick_sort def test_quick_sort_empty_array(): assert quick_sort([]) == [] def test_quick_sort_single_element(): assert quick_sort([1]) == [1] def test_quick_sort_sorted_order(): assert quick_sort([5, 4, 3, 2, 1]) == [5, 4, 3, 2, 1] def test_quick_sort_reverse_order(): assert qui...
[ { "docstring": "Sorts the array in descending order using the quick sort algorithm (iterative approach).", "function_declaration": "def quick_sort(array):", "function_name": "quick_sort", "parameter_list": "(array)" }, { "docstring": null, "function_declaration": "def partition(array, lo...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quick_sort_iterative(arr):\n \"\"\"\n Sorts an array in descending order using the quick sort algorithm, implemented iteratively.\n \n :param arr: List[int] - array of integers...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031298", "row_id": 31298, "seed_ids": "['Qwen2-72B-Instruct_72501']" }
0.669896
Filter_31298
I
[ "quick_sort", "partition" ]
2
[ [ "quick_sort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
378f2643fc5e7eceb66a8d7c928905c32bb3ce6b
7f649f42fbf088fb2eb9fdcb76740de015108396
v1.0
instruct
Filter
Filter_31303_I
Write a Python script to find the prime factors of a number. The script should also print the exponent of each prime factor. Additionally, you are required to implement the Sieve of Eratosthenes algorithm to generate a list of prime numbers up to the given number before finding the prime factors.
def sieve_of_eratosthenes(n): """ Generate a list of prime numbers up to n using the Sieve of Eratosthenes algorithm. """ is_prime = [True] * (n + 1) p = 2 while p * p <= n: if is_prime[p]: for i in range(p * p, n + 1, p): is_prime[i] = False p += 1 ...
from solution import sieve_of_eratosthenes, prime_factors def test_sieve_of_eratosthenes_up_to_10(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] def test_sieve_of_eratosthenes_up_to_30(): assert sieve_of_eratosthenes(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_prime_factors_of_60(): assert ...
[ { "docstring": "Generate a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.", "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": "Find the prime factors of a given number n along...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of prime numbers up to n (inclusive) using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_prime = [True] * (n + 1)\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031303", "row_id": 31303, "seed_ids": "['Qwen2-72B-Instruct_72513']" }
0.718208
Filter_31303
I
[ "sieve_of_eratosthenes", "prime_factors" ]
2
[ [ "prime_factors", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1acddb75fed8653b0f1866fb5f15e54128bec574
18a2a8634edb86cf3d9e8ac426f68b805f5c9d25
v1.0
instruct
Filter
Filter_31316_I
Given a transform in three-dimensional space that multiplies the x-coordinate by two, leaves the y-coordinate the same, and subtracts one from the z-coordinate, write a function in Python to apply this transformation to a point. Your function should also be able to handle and apply this transformation to an array of n ...
def transform_point(point): """ Transforms a single point (x, y, z) in three-dimensional space. Multiplies the x-coordinate by 2, leaves the y-coordinate the same, and subtracts 1 from the z-coordinate. Params: point (tuple): A tuple representing the point (x, y, z). Returns: tuple: A ...
from solution import transform_point, transform_points def test_transform_point(): assert transform_point((1, 2, 3)) == (2, 2, 2) assert transform_point((0, 0, 0)) == (0, 0, -1) assert transform_point((-1, -2, -3)) == (-2, -2, -4) assert transform_point((2, 4, 6)) == (4, 4, 5) def test_transform_point...
[ { "docstring": "Transforms a single point (x, y, z) in three-dimensional space.\nMultiplies the x-coordinate by 2, leaves the y-coordinate the same, and subtracts 1 from the z-coordinate.\n\nParams:\npoint (tuple): A tuple representing the point (x, y, z).\n\nReturns:\ntuple: A transformed point (2*x, y, z-1)."...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def transform_point(point):\n \"\"\"\n Transforms a single point in three-dimensional space by:\n - Multiplying the x-coordinate by two\n - Leaving the y-coordinate the same\n -...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031316", "row_id": 31316, "seed_ids": "['Qwen2-72B-Instruct_72536']" }
0.500226
Filter_31316
I
[ "transform_point", "transform_points" ]
2
[ [ "transform_points", "transform_point" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b841cc955f9b86c6eff01e6d26aad0137365ff87
9da2368536a62a3798ef8ede4e97d42393833b1f
v1.0
instruct
Filter
Filter_31326_I
Write a code in Python that can support the conversion of a large number of hexadecimal numbers into their respective binary forms. Also, the code should be able to handle any possible errors or exceptions during the conversion process. Below is a piece of erroneous code. Identify its issues and provide the correct cod...
def hex_to_binary(hex_num): """ Converts a hexadecimal number to its binary representation. Parameters: hex_num (str): A string representing the hexadecimal number. Returns: str: A string representing the binary representation of the given hexadecimal number. """ try: #...
from solution import hex_to_binary, convert_hex_list_to_binary def test_hex_to_binary_valid_hex(): assert hex_to_binary('1A') == '11010' assert hex_to_binary('2F') == '101111' assert hex_to_binary('0') == '0' assert hex_to_binary('FF') == '11111111' def test_hex_to_binary_invalid_hex(): assert "Er...
[ { "docstring": "Converts a hexadecimal number to its binary representation.\n\nParameters:\nhex_num (str): A string representing the hexadecimal number.\n\nReturns:\nstr: A string representing the binary representation of the given hexadecimal number.", "function_declaration": "def hex_to_binary(hex_num):",...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def hex_to_binary(hex_numbers):\n \"\"\"\n Convert a list of hexadecimal numbers to their binary representations.\n \n Args:\n hex_numbers: List of hexadecimal numbers (strings)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031326", "row_id": 31326, "seed_ids": "['Qwen2-72B-Instruct_72551']" }
0.605233
Filter_31326
I
[ "hex_to_binary", "convert_hex_list_to_binary" ]
2
[ [ "convert_hex_list_to_binary", "hex_to_binary" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e6402c214009214303565fdc49e643ca0985a076
94d975fcf496a9d8e980cbc5b18bd9c55311d561
v1.0
instruct
Filter
Filter_31349_I
Create a program that not only outputs all prime numbers between 0 and 100, but also presents the result in a 10x10 grid. Moreover, your program should highlight those prime numbers that are part of the Fibonacci sequence in a different color. Your program should also have an option to output the results in reverse ord...
import math def is_prime(n): """ Function to check if n is a prime number. """ if n <= 1: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return False return True def fibonacci(n): """ Function to generate Fibonacci sequence up to the n...
from solution import is_prime, fibonacci, get_primes_in_range, create_grid def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True def test_fibonacci(): fib = fibonacci(10) assert fib == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34...
[ { "docstring": "Function to check if n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Function to generate Fibonacci sequence up to the n-th element.", "function_declaration": "def fibonacci(n):", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Function to check if n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(math.sqrt(n)) + 1):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00031349", "row_id": 31349, "seed_ids": "['Qwen2-72B-Instruct_72582']" }
0.59049
Filter_31349
I
[ "is_prime", "fibonacci", "get_primes_in_range", "create_grid", "display_grid", "main" ]
6
[ [ "get_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6947cb2fbd4495aeb8338612cc2e303d1154a108
9a5fcacb76cd40282a3b0ecab0343c75116123ab
v1.0
instruct
Filter
Filter_31364_I
Write a Python code to calculate the area of a triangle given the length of its base and height. Then, extend your code to handle a list of triangles, returning a list of their areas and validating the inputs to ensure that both base and height are non-negative numbers. If the input is invalid, do not include the trian...
def triangle_area(base, height): """ Calculate the area of a triangle given its base and height. Parameters: base (float): The base length of the triangle. height (float): The height of the triangle. Returns: float: The area of the triangle. """ if base < 0 or height < 0: ...
from solution import triangle_area, areas_of_triangles def test_triangle_area_valid(): assert triangle_area(10, 5) == 25.0 assert triangle_area(6, 8) == 24.0 assert triangle_area(0, 5) == 0.0 def test_triangle_area_invalid(): assert triangle_area(-10, 5) is None assert triangle_area(6, -8) is None...
[ { "docstring": "Calculate the area of a triangle given its base and height.\n\nParameters:\nbase (float): The base length of the triangle.\nheight (float): The height of the triangle.\n\nReturns:\nfloat: The area of the triangle.", "function_declaration": "def triangle_area(base, height):", "function_na...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_triangle_area(base, height):\n \"\"\"\n Calculates the area of a triangle given the base and height.\n \"\"\"\n if base < 0 or height < 0:\n return None\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031364", "row_id": 31364, "seed_ids": "['Qwen2-72B-Instruct_72613']" }
0.842475
Filter_31364
I
[ "triangle_area", "areas_of_triangles" ]
2
[ [ "areas_of_triangles", "triangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a6bb2dc9019dd3e6ec5d86c1e5d457b0e2365a9
11e0337d72af6774d3822765b3f39f05e63403f3
v1.0
instruct
Filter
Filter_31369_I
Write a program in Python that generates a list of all prime numbers within a given range. The program should take two integers as input, representing the start and end of the range, and should output a list of all prime numbers within that range. Make sure to handle edge cases, such as negative numbers or non-integer ...
def is_prime(n): """ Helper function to 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 generate_prim...
from solution import generate_primes def test_generate_primes_in_range(): assert generate_primes(10, 20) == [11, 13, 17, 19] def test_generate_primes_with_no_primes(): assert generate_primes(14, 16) == [] def test_generate_primes_with_negative_numbers(): assert generate_primes(-10, 5) == [2, 3, 5] def t...
[ { "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 a list of all prime numbers within the given range [start, end].", "function_declaration": "def gen...
[ 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 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 or n % 3 == 0:\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031369", "row_id": 31369, "seed_ids": "['Qwen2-72B-Instruct_72626']" }
0.618254
Filter_31369
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
64e71d31e0959e23a040c3fd4aefe966b8f8f67f
f27039c3b7ead470ed14c5159061bc16add8d20d
v1.0
instruct
Filter
Filter_31370_I
Create a Python function to compute the factorial of a given number using both iterative and recursive methods. Additionally, implement a variant of the function that calculates the factorial using a dynamic programming approach. Compare the performance of all three methods for a large input number.
import time def factorial_iterative(n): """ Returns the factorial of n computed iteratively. """ result = 1 for i in range(2, n + 1): result *= i return result def factorial_recursive(n): """ Returns the factorial of n computed recursively. """ if n <= 1: return...
from solution import factorial_iterative, factorial_recursive, factorial_dynamic_programming, compare_performance def test_factorial_iterative(): assert factorial_iterative(0) == 1 assert factorial_iterative(5) == 120 assert factorial_iterative(10) == 3628800 def test_factorial_recursive(): assert fac...
[ { "docstring": "Returns the factorial of n computed iteratively.", "function_declaration": "def factorial_iterative(n):", "function_name": "factorial_iterative", "parameter_list": "(n)" }, { "docstring": "Returns the factorial of n computed recursively.", "function_declaration": "def fac...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\n# Iterative method\ndef factorial_iterative(n):\n result = 1\n for i in range(2, n + 1):\n result *= i\n return result\n\n# Recursive method\ndef factorial_recur...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031370", "row_id": 31370, "seed_ids": "['Qwen2-72B-Instruct_72628']" }
0.637878
Filter_31370
I
[ "factorial_iterative", "factorial_recursive", "factorial_dynamic_programming", "compare_performance" ]
4
[ [ "compare_performance", "factorial_dynamic_programming" ], [ "compare_performance", "factorial_iterative" ], [ "compare_performance", "factorial_recursive" ] ]
3
[]
false
[]
false
pytest
true
[]
true
343d65493ff13c4547595857e330b5dfaf10cd35
437028560b6643c17a265d2e87c3f6e14d318314
v1.0
instruct
Filter
Filter_31373_I
Write a Python script to calculate and display the gap between a list of pairs of date and time values in years, months, days, hours, minutes and seconds. Each pair in the list represents a start and end datetime values. Also, include a feature to specify whether you want the total difference in just the mentioned unit...
from datetime import datetime from dateutil.relativedelta import relativedelta def calculate_time_difference(start_dt, end_dt, breakdown=False): start = datetime.strptime(start_dt, "%Y-%m-%d %H:%M:%S") end = datetime.strptime(end_dt, "%Y-%m-%d %H:%M:%S") diff = relativedelta(end, start) if breakdo...
from solution import calculate_gap_between_dates def test_calculate_gap_between_dates_breakdown(): pairs = [("2020-01-01 00:00:00", "2021-02-02 01:01:01")] assert calculate_gap_between_dates(pairs, breakdown=True) == [ {'years': 1, 'months': 1, 'days': 1, 'hours': 1, 'minutes': 1, 'seconds': 1} ] ...
[ { "docstring": null, "function_declaration": "def calculate_time_difference(start_dt, end_dt, breakdown=False):", "function_name": "calculate_time_difference", "parameter_list": "(start_dt, end_dt, breakdown=False)" }, { "docstring": null, "function_declaration": "def calculate_gap_betwe...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from datetime import datetime\nfrom dateutil.relativedelta import relativedelta\n\ndef calculate_time_difference(start_date, end_date, total_difference=False):\n \"\"\"\n Calculates the ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00031373", "row_id": 31373, "seed_ids": "['Qwen2-72B-Instruct_72631']" }
0.663814
Filter_31373
I
[ "calculate_time_difference", "calculate_gap_between_dates" ]
2
[ [ "calculate_gap_between_dates", "calculate_time_difference" ] ]
1
[]
false
[]
false
pytest
true
[ "dateutil" ]
false
d6ad3e9ebd2f817debcee76148a329a722f26b5e
0bdb996eb7dc53649c16055ad3241745c93f7baf
v1.0
instruct
Filter
Filter_31382_I
Write a code to generate the first n terms of the Fibonacci sequence, where n is a prime number. Additionally, the code should use dynamic programming to optimize the computation of the sequence. The code should also output the sum of the first n terms of the Fibonacci sequence.
def is_prime(n): """ Checks if a number n 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 T...
from solution import is_prime, generate_fibonacci 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(11) == True assert is_prime(15) == False assert is_prime(29) == True def test_generate_fibonac...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates the first n terms of the Fibonacci sequence using dynamic programming,\nwhere n is a prime number. Returns both the s...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "def fibonacci(n):\n \"\"\"\n Generates the first n terms of the Fibonacci sequence and returns\n the sequence along with the sum of its elements.\n Uses dy...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00031382", "row_id": 31382, "seed_ids": "['Qwen2-72B-Instruct_72643']" }
0.661306
Filter_31382
I
[ "is_prime", "generate_fibonacci" ]
2
[ [ "generate_fibonacci", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a406e8b77c61a830de6a756beaf6c4e3afca280
1d4aac73988964dd9c7c2e37803f6adbb01dcf67