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_35972_I | Implement a sorting algorithm to sort a list of 100,000 integers in descending order. The algorithm should have a time complexity of O(n log n) and should use an iterative approach. Additionally, you are not allowed to use any built-in sorting functions or libraries. You must also ensure that the sorting algorithm is s... | def merge_sort_descending(arr):
"""
Sorts a list of integers in descending order using an iterative merge sort algorithm.
"""
if len(arr) <= 1:
return arr
width = 1
n = len(arr)
while width < n:
left = 0
while left < n:
mid = min(left + width, n)
... | from solution import merge_sort_descending
def test_merge_sort_descending_empty_list():
assert merge_sort_descending([]) == []
def test_merge_sort_descending_single_element():
assert merge_sort_descending([1]) == [1]
def test_merge_sort_descending_sorted_list():
assert merge_sort_descending([5, 4, 3, 2, ... | [
{
"docstring": "Sorts a list of integers in descending order using an iterative merge sort algorithm.",
"function_declaration": "def merge_sort_descending(arr):",
"function_name": "merge_sort_descending",
"parameter_list": "(arr)"
},
{
"docstring": "Merges two halves of a list in descending ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def stable_descending_sort(arr):\n \"\"\"\n Sorts the input list of integers in descending order using an iterative merge sort algorithm.\n This implementation ensures the sorting is ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035972",
"row_id": 35972,
"seed_ids": "['Qwen2-72B-Instruct_80578']"
} | 0.554623 | Filter_35972 | I | [
"merge_sort_descending",
"merge"
] | 2 | [
[
"merge_sort_descending",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fc516b6cc175a69bbcde85c95342189ef2a128a8 | fa44c90027b08adb0cc6971025fb97e69dddae62 | |||
v1.0 | instruct | Filter | Filter_35983_I | You are provided with a piece of code that is meant to check if a given number is a perfect square using binary search, but it contains several errors. Your task is to correct the faulty code presented below and then extend it to also find the next perfect square after the given number, if it exists. | import math
def is_perfect_square(n):
"""
Return True if n is a perfect square, else False
"""
if n < 0:
return False
root = int(math.sqrt(n))
return root * root == n
def next_perfect_square(n):
"""
Returns the next perfect square greater than n.
If n is not a perfect squar... | from solution import is_perfect_square, next_perfect_square
def test_is_perfect_square_true():
assert is_perfect_square(1) == True
assert is_perfect_square(4) == True
assert is_perfect_square(9) == True
assert is_perfect_square(16) == True
assert is_perfect_square(25) == True
def test_is_perfect_s... | [
{
"docstring": "Return True if n is a perfect square, else False",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Returns the next perfect square greater than n.\nIf n is not a perfect square, return None.... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_perfect_square_and_next(n):\n \"\"\"\n Checks if the given number n is a perfect square.\n If it is, returns True and the next perfect square.\n If not, returns False.\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00035983",
"row_id": 35983,
"seed_ids": "['Qwen2-72B-Instruct_80597']"
} | 0.652754 | Filter_35983 | I | [
"is_perfect_square",
"next_perfect_square"
] | 2 | [
[
"next_perfect_square",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 013a2785ce354ef37d381e65f1cf0da333c8fc7a | f76534b20cc780f32f2280c002d7e9f8bbc94861 | |||
v1.0 | instruct | Filter | Filter_35992_I | Generate a Python program to perform matrix multiplication using only bitwise operations, without using any built-in functions or libraries, and the matrix size must be a power of 2. Additionally, the program must be able to handle matrices with negative values, and it must implement its own custom algorithm for matrix... | def bitwise_multiply(a, b):
result = 0
while b > 0:
if b & 1:
result += a
a <<= 1
b >>= 1
return result
def bitwise_multiply_negative(a, b):
if a < 0 and b < 0:
return bitwise_multiply(-a, -b)
elif a < 0:
return -bitwise_multiply(-a, b)
elif b... | from solution import bitwise_matrix_multiply
def test_bitwise_multiply_positive_elements():
matrix_a = [
[1, 2],
[3, 4]
]
matrix_b = [
[5, 6],
[7, 8]
]
expected_result = [
[19, 22],
[43, 50]
]
assert bitwise_matrix_multiply(matrix_a, matrix_b)... | [
{
"docstring": null,
"function_declaration": "def bitwise_multiply(a, b):",
"function_name": "bitwise_multiply",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def bitwise_multiply_negative(a, b):",
"function_name": "bitwise_multiply_negative",
"param... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def bitwise_add(a, b):\n \"\"\"\n Adds two numbers using bitwise operations.\n \"\"\"\n while b != 0:\n carry = a & b\n a = a ^ b\n b = carry << 1\n return ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00035992",
"row_id": 35992,
"seed_ids": "['Qwen2-72B-Instruct_80614']"
} | 0.567311 | Filter_35992 | I | [
"bitwise_multiply",
"bitwise_multiply_negative",
"bitwise_matrix_multiply"
] | 3 | [
[
"bitwise_matrix_multiply",
"bitwise_multiply_negative"
],
[
"bitwise_multiply_negative",
"bitwise_multiply"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1f47ae1feb36d7deb9ab741be7188fbc3780505d | 88d62d03bab20d694948597bf55f3ee9867a46c0 | |||
v1.0 | instruct | Filter | Filter_36005_I | Write a Python program that filters an input list to remove prime numbers and then computes the average of the remaining numbers. | def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def filter_non_prime... | from solution import is_prime, filter_non_primes, average_of_non_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(10) == False
assert is_prime(11) == True
assert is_prime(1) == False
... | [
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out the prime numbers from a list of numbers.",
"function_declaration": "def filter_non_primes(numbers):",... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Returns True if the number is prime, else False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036005",
"row_id": 36005,
"seed_ids": "['Qwen2-72B-Instruct_80641']"
} | 0.618483 | Filter_36005 | I | [
"is_prime",
"filter_non_primes",
"average_of_non_primes"
] | 3 | [
[
"average_of_non_primes",
"filter_non_primes"
],
[
"filter_non_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 21c2390583450ed21b067c309dec5b6738b9f420 | c7179a7c36af3572fc89fd116a59539a0cb513a8 | |||
v1.0 | instruct | Filter | Filter_36008_I | Given the erroneous Python program below, debug and modify it to calculate the product of all odd numbers between 1 and 20. Implement this using a recursive function. | def product_of_odds(n):
"""
Recursive function to return the product of all odd numbers between 1 and n (inclusive).
"""
if n < 1:
return 1
elif n % 2 == 0:
return product_of_odds(n - 1)
else:
return n * product_of_odds(n - 2)
def product_of_odds_between_1_and_20():
... | from solution import product_of_odds_between_1_and_20, product_of_odds
def test_product_of_odds_between_1_and_20():
assert product_of_odds_between_1_and_20() == 654729075
def test_product_of_odds():
assert product_of_odds(1) == 1
assert product_of_odds(3) == 3
assert product_of_odds(5) == 15
asser... | [
{
"docstring": "Recursive function to return the product of all odd numbers between 1 and n (inclusive).",
"function_declaration": "def product_of_odds(n):",
"function_name": "product_of_odds",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def product_of_odds_b... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def product_of_odds(n):\n \"\"\"\n Recursively calculates the product of all odd numbers from 1 to n (inclusive).\n \"\"\"\n if n < 1:\n return 1\n if n % 2 == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036008",
"row_id": 36008,
"seed_ids": "['Qwen2-72B-Instruct_80645']"
} | 0.611881 | Filter_36008 | I | [
"product_of_odds",
"product_of_odds_between_1_and_20"
] | 2 | [
[
"product_of_odds_between_1_and_20",
"product_of_odds"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 970108a32ca41f47ca34e17c6b4de1fa02ba5337 | 4cd623c50890f214d22735a2ed05c2aa9268f9eb | |||
v1.0 | instruct | Filter | Filter_36015_I | Please write a python code that simulates a restaurant dining experience for two people. The menu should include three starters, three main courses, and three desserts, each with their own price. The code should prompt the user to choose one starter, one main course, and one dessert for each person. The code should als... | import random
# Menu items with prices
menu = {
'starters': {
'Spring Rolls': 5.00,
'Tomato Soup': 4.50,
'Caesar Salad': 6.00
},
'mains': {
'Grilled Salmon': 15.00,
'Beef Steak': 20.00,
'Vegetable Stir Fry': 12.00
},
'desserts': {
'Chocolate C... | from solution import get_random_recommendation, calculate_total, order_history, save_feedback, view_previous_orders
def test_get_random_recommendation():
starter_recommendation = get_random_recommendation('starters')
assert starter_recommendation in menu['starters']
def test_calculate_total():
order = {'s... | [
{
"docstring": null,
"function_declaration": "def get_random_recommendation(course):",
"function_name": "get_random_recommendation",
"parameter_list": "(course)"
},
{
"docstring": null,
"function_declaration": "def take_order_for_person(person):",
"function_name": "take_order_for_per... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\n# Menu items with prices\nmenu = {\n 'starters': {\n 'Spring Rolls': 5.00,\n 'Tomato Soup': 4.50,\n 'Caesar Salad': 6.00\n },\n 'mains': {\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036015",
"row_id": 36015,
"seed_ids": "['Qwen2-72B-Instruct_80656']"
} | 0.525806 | Filter_36015 | I | [
"get_random_recommendation",
"take_order_for_person",
"calculate_total",
"view_previous_orders",
"save_feedback",
"simulate_experience"
] | 6 | [
[
"simulate_experience",
"calculate_total"
],
[
"simulate_experience",
"save_feedback"
],
[
"simulate_experience",
"take_order_for_person"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 1f60403da4790d8575e004c07229d8cd207cf825 | 859595a45d19e240c12e8c597e94a43811fd40fc | |||
v1.0 | instruct | Filter | Filter_36023_I | Implement a recursive function in Python to calculate the least common multiple (LCM) of two numbers. Now, add an extra level of complexity by computing the LCM of a list of integers instead of just two numbers. The function should accept a list of integers as input and return their least common multiple. You need to i... | from typing import List
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return abs(a * b) // gcd(a, b)
def lcm_of_list(numbers: List[int]) -> int:
if not all(isinstance(num, int) for num in numbers):
raise ValueError("All elements must be integers.")
if not all(num... | from solution import lcm_of_list, error_prone_lcm_of_list
def test_lcm_of_two_numbers():
assert lcm_of_list([6, 8]) == 24
def test_lcm_of_multiple_numbers():
assert lcm_of_list([2, 7, 3]) == 42
def test_lcm_with_one_number():
assert lcm_of_list([5]) == 5
def test_lcm_with_zero_input():
import pytest... | [
{
"docstring": null,
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_dec... | [
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(x, y):\n \"\"\"\n Returns the greatest common divisor of x and y.\n \"\"\"\n while y:\n x, y = y, x % y\n return x\n\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036023",
"row_id": 36023,
"seed_ids": "['Qwen2-72B-Instruct_80668']"
} | 0.521101 | Filter_36023 | I | [
"gcd",
"lcm",
"lcm_of_list",
"error_prone_lcm_of_list"
] | 4 | [
[
"lcm",
"gcd"
],
[
"lcm_of_list",
"lcm"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3529f600fcb63cfe1be27234a8e9594f482412b9 | 2a6d10cc75acf471ea9832716469532467245212 | |||
v1.0 | instruct | Filter | Filter_36046_I | Develop a python script utilizing the Global Scripter platform from Extron to enable consistent monitoring of a conference room's audio equipment. If any anomalies are detected in the audio signal, the script must send an alert to a designated email address listing the specifics of the problem and proposing a workable ... | import smtplib
from email.mime.text import MIMEText
from datetime import datetime, timedelta
import logging
# Setup logging
logging.basicConfig(filename='audio_equipment_monitor.log', level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
def send_alert_email(subject, message, to... | from solution import send_alert_email, monitor_audio_equipment, check_audio_status
def test_send_alert_email(monkeypatch):
def mock_send_mail(self, from_addr, to_addrs, msg, mail_options=(), rcpt_options=()):
assert from_addr == "your_email@example.com"
assert to_addrs == ["recipient@example.com"]
... | [
{
"docstring": "Sends an alert email.\n\nParameters:\nsubject (str): Subject of the email\nmessage (str): Body of the email\nto_email (str): Recipient email address",
"function_declaration": "def send_alert_email(subject, message, to_email):",
"function_name": "send_alert_email",
"parameter_list": "... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nfrom email.mime.text import MIMEText\nfrom datetime import datetime, timedelta\nimport logging\n\n# Setup logging\nlogging.basicConfig(filename='audio_equipment_monitor.log', l... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036046",
"row_id": 36046,
"seed_ids": "['Qwen2-72B-Instruct_80726']"
} | 0.410137 | Filter_36046 | I | [
"send_alert_email",
"monitor_audio_equipment",
"check_audio_status",
"schedule_monitoring"
] | 4 | [
[
"monitor_audio_equipment",
"check_audio_status"
],
[
"monitor_audio_equipment",
"send_alert_email"
],
[
"schedule_monitoring",
"monitor_audio_equipment"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | f5bb260fd4a548b54c03bd4bfc6a67df47c72bff | 213a53572f068420426ac57ae781d9eb663f6c8f | |||
v1.0 | instruct | Filter | Filter_36060_I | Using functions and classes, write a Python program to count the number of occurrences of a given word in several given strings. Additionally, validate the strings and words to ensure they only contain letters and spaces. Also, implement case sensitivity in your solution. | import re
def validate_string(input_string):
"""
Validates that the input_string contains only letters and spaces.
"""
return bool(re.match("^[A-Za-z ]*$", input_string))
def count_occurrences(word, strings):
"""
Counts the number of occurrences of the given word in a list of strings.
Case... | from solution import count_occurrences, WordCounter, validate_string
import pytest
def test_validate_string():
assert validate_string("Hello World") == True
assert validate_string("HelloWorld") == True
assert validate_string("H3llo World") == False
assert validate_string("Hello, World") == False
def t... | [] | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\nclass WordCounter:\n def __init__(self, word):\n if not self._is_valid_word(word):\n raise ValueError(\"Word must contain only letters and spaces\")\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036060",
"row_id": 36060,
"seed_ids": "['Qwen2-72B-Instruct_80752']"
} | 0.759929 | Filter_36060 | I | [
"validate_string",
"count_occurrences"
] | 2 | [
[
"count_occurrences",
"validate_string"
]
] | 1 | [] | false | [
"WordCounter"
] | true | pytest | true | [] | true | 3d5b4ed5120a7761ded4728c3d5c0879cd239bb2 | 42b975f2ab717f29fd8f43d7f31cac79892c89e1 | |||
v1.0 | instruct | Filter | Filter_36071_I | You are given an undirected graph and two vertices A and B. Write a Python function to determine the shortest path between A and B using the breadth-first search algorithm. Additionally, decompose the code into multiple functions that each perform a specific task such as checking if the graph is empty, conducting the b... | from collections import deque
def is_graph_empty(graph):
"""
Check if the input graph is empty.
:param graph: A dictionary representing the graph where keys are nodes and values are lists of adjacent nodes.
:return: True if the graph is empty, False otherwise.
"""
return len(graph) == 0
def bf... | import pytest
from solution import is_graph_empty, bfs_shortest_path, shortest_path
def test_is_graph_empty():
assert is_graph_empty({}) == True
assert is_graph_empty({'A': ['B', 'C'], 'B': ['A'], 'C': ['A']}) == False
def test_bfs_shortest_path():
graph = {'A': ['B', 'C'], 'B': ['A', 'D'], 'C': ['A', 'D'... | [
{
"docstring": "Check if the input graph is empty.\n:param graph: A dictionary representing the graph where keys are nodes and values are lists of adjacent nodes.\n:return: True if the graph is empty, False otherwise.",
"function_declaration": "def is_graph_empty(graph):",
"function_name": "is_graph_emp... | [
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 is_graph_empty(graph):\n \"\"\"\n Checks if the provided graph is empty.\n \"\"\"\n return not bool(graph)\n\ndef bfs_shortest_path(graph, star... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036071",
"row_id": 36071,
"seed_ids": "['Qwen2-72B-Instruct_80765']"
} | 0.574701 | Filter_36071 | I | [
"is_graph_empty",
"bfs_shortest_path",
"shortest_path"
] | 3 | [
[
"shortest_path",
"bfs_shortest_path"
],
[
"shortest_path",
"is_graph_empty"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cfd82c5291092e58a706c18e4d4b22170e3c0652 | c1d2dfad64f4015b7c354621b1cec9492f9aff11 | |||
v1.0 | instruct | Filter | Filter_36074_I | Write a python program to display the prime numbers between a and b, where a and b are taken as input from the user. | def is_prime(n):
"""
Checks if a number is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def prime_numbers_between(a, b):
"""
Returns a list of prime numbers between a and b (includin... | from solution import is_prime, prime_numbers_between
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(13)
assert not is_prime(1)
assert not is_prime(0)
assert not is_prime(-3)
def test_prime_numbers_between():
asse... | [
{
"docstring": "Checks if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers between a and b (including a and b if they are prime).",
"function_declaration": "de... | [
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 for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036074",
"row_id": 36074,
"seed_ids": "['Qwen2-72B-Instruct_80773']"
} | 0.64317 | Filter_36074 | I | [
"is_prime",
"prime_numbers_between"
] | 2 | [
[
"prime_numbers_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cd5c0bc0b81f6185baa176ac95b5c6f200ce26f9 | e8b8f9f2668eb5f2b1d0a3ddd3edceed1928a47f | |||
v1.0 | instruct | Filter | Filter_36080_I | Write a function to identify a valid IP address from a list of strings. The function should ignore any characters that are not numbers or periods and check whether the IP address is valid according to the standard IPv4 rules. A valid IP address must have four numbers separated by periods, each number cannot be greater ... | import re
def is_valid_ip(ip):
"""
Validates if the given string is a valid IPv4 address.
"""
parts = ip.split('.')
if len(parts) != 4:
return False
for part in parts:
if not part.isdigit() or (part.startswith('0') and len(part) > 1) or not 0 <= int(part) <= 255:
... | from solution import is_valid_ip, extract_valid_ips
def test_is_valid_ip():
assert is_valid_ip("192.168.1.1") == True
assert is_valid_ip("256.256.256.256") == False
assert is_valid_ip("192.168.1.01") == False
assert is_valid_ip("192.168.1") == False
assert is_valid_ip("192.168.1.256") == False
... | [
{
"docstring": "Validates if the given string is a valid IPv4 address.",
"function_declaration": "def is_valid_ip(ip):",
"function_name": "is_valid_ip",
"parameter_list": "(ip)"
},
{
"docstring": "Extracts valid IP addresses from a list of strings.",
"function_declaration": "def extract_... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_ip(ip):\n \"\"\"\n Returns True if ip is a valid IPv4 address, otherwise False.\n \"\"\"\n parts = ip.split('.')\n \n if len(parts) != 4:\n return False\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036080",
"row_id": 36080,
"seed_ids": "['Qwen2-72B-Instruct_80785']"
} | 0.646607 | Filter_36080 | I | [
"is_valid_ip",
"extract_valid_ips"
] | 2 | [
[
"extract_valid_ips",
"is_valid_ip"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50c211fed8b506e4d521083fff5974f63403c7b9 | a3e6ca00416bb4020ba7b9f109300bb76abba1df | |||
v1.0 | instruct | Filter | Filter_36086_I | Define a Python function that finds the kth smallest unique prime number in a given list of integers, where k is a positive integer less than or equal to the total number of unique prime numbers in the list. The function should return the kth smallest unique prime number, excluding any non-prime numbers. If there are f... | 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 kth_smallest_... | from solution import is_prime, kth_smallest_unique_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == False
assert is_prime... | [
{
"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 the kth smallest unique prime number in the list of numbers.\nRaises ValueError if there are fewer than... | [
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 if n == 2:\n return True\n if n % 2 == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036086",
"row_id": 36086,
"seed_ids": "['Qwen2-72B-Instruct_80792']"
} | 0.643626 | Filter_36086 | I | [
"is_prime",
"kth_smallest_unique_prime"
] | 2 | [
[
"kth_smallest_unique_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6fc7f5a4dbe849ff28c483b7a5fc8c4888874aa2 | 634d38eea55d8ce7d001e92dc79a3d802fee3b2c | |||
v1.0 | instruct | Filter | Filter_36135_I | Create a program that utilizes binary search algorithm to search for a specific word in a text file. The program should prompt the user to input the name of the text file, the word to search for, and the maximum number of lines to search. The program should then search for the word in the first n (maximum number of lin... | def binary_search(lines, word):
"""
Perform a binary search to find the word in the provided list of lines.
"""
left, right = 0, len(lines) - 1
result = []
while left <= right:
mid = left + (right - left) // 2
if word in lines[mid]:
result.append(mid + 1)
... | def test_binary_search():
lines = ["apple", "banana", "cherry", "date", "fig", "grape"]
assert binary_search(lines, "banana") == [2]
assert binary_search(lines, "cherry") == [3]
assert binary_search(lines, "kiwi") == []
assert binary_search(["apple banana cherry date", "fig grape"], "cherry") == [1]... | [
{
"docstring": "Perform a binary search to find the word in the provided list of lines.",
"function_declaration": "def binary_search(lines, word):",
"function_name": "binary_search",
"parameter_list": "(lines, word)"
},
{
"docstring": "Search for a specific word in the first max_lines lines ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_search(lines, word, max_lines):\n \"\"\"\n Performs binary search on the given list of lines.\n Returns the indices of the lines where the word is found.\n \"\"\"\n f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036135",
"row_id": 36135,
"seed_ids": "['Qwen2-72B-Instruct_80867']"
} | 0.603323 | Filter_36135 | I | [
"binary_search",
"search_word_in_file"
] | 2 | [
[
"search_word_in_file",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d1badf998b196d08167218001202ebf3b17ee50 | 14cf9fc509fd11ba282be00ff52de476165b2811 | |||
v1.0 | instruct | Filter | Filter_36163_I | Write a complex for loop in Python that iterates over a list of integers and prints only the prime numbers from it. The loop should also terminate when it encounters the first composite number in the list. Additionally, the loop should only consider positive integers greater than 1 as prime numbers. | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def print_primes_terminate_on_composite(numbers):
"""
Iterates over a list of integers and prints prime n... | from solution import is_prime, print_primes_terminate_on_composite
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(19) == True
assert is_prime(20) == False
assert is_prime(1) == False
def tes... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Iterates over a list of integers and prints prime numbers.\nTerminates on encountering the first composite number.",
"functio... | [
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 Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036163",
"row_id": 36163,
"seed_ids": "['Qwen2-72B-Instruct_80907']"
} | 0.618319 | Filter_36163 | I | [
"is_prime",
"print_primes_terminate_on_composite"
] | 2 | [
[
"print_primes_terminate_on_composite",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 924a1003a4a7393018ebfebe4f492706d96e95af | ff9d669c72e469ce73868ae1a54fd6b66a322e8c | |||
v1.0 | instruct | Filter | Filter_36165_I | Given the dietary needs of hippos, elephants, and giraffes, design an algorithm, using binary search, to efficiently find a specific fruit, "Oblongia", in a sorted list of potential foods. Note that the "Oblongia" is a fictional fruit and does not exist in reality. Then, implement the solution using a programming langu... | def binary_search(arr, target):
"""
Perform a binary search to find the target item in the sorted list arr.
Parameters:
arr (list): Sorted list of items.
target: Item to search for in the list.
Returns:
bool: True if the target is found, False otherwise.
"""
left, right = 0... | from solution import find_oblongia
def test_oblongia_found():
food_list = ["Apple", "Banana", "Cherry", "Date", "Oblongia", "Pineapple"]
assert find_oblongia(food_list) == True
def test_oblongia_not_found():
food_list = ["Apple", "Banana", "Cherry", "Date", "Pineapple"]
assert find_oblongia(food_list)... | [
{
"docstring": "Perform a binary search to find the target item in the sorted list arr.\n\nParameters:\narr (list): Sorted list of items.\ntarget: Item to search for in the list.\n\nReturns:\nbool: True if the target is found, False otherwise.",
"function_declaration": "def binary_search(arr, target):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_oblongia(food_list):\n \"\"\"\n Uses binary search to find \"Oblongia\" in a sorted list of potential foods.\n Returns the index if found, otherwise returns -1.\n \"\"\"\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036165",
"row_id": 36165,
"seed_ids": "['Qwen2-72B-Instruct_80910']"
} | 0.531865 | Filter_36165 | I | [
"binary_search",
"find_oblongia"
] | 2 | [
[
"find_oblongia",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1409cab8866101f559140259cd82c3791ef6bce5 | 9050231fa9ab2e282fe99aa61f46abe2f6720485 | |||
v1.0 | instruct | Filter | Filter_36173_I | Write a Python program that calls the same function 'f(x)' twice, but now also include a mathematical operation between the two results before displaying the final answer. The mathematical operation should be multiplication. Note that the value of 'x' for the second function call should be the result of the first funct... | def f(x):
"""
Sample function which we will call twice.
"""
return x + 1
def compute_twice_with_multiplication(x):
"""
Calls the function 'f' twice and includes a multiplication operation between the two results.
:param x: Initial input value for the function call
:return: Result of mul... | from solution import compute_twice_with_multiplication, f
def test_compute_twice_with_multiplication_positive():
assert compute_twice_with_multiplication(2) == f(2) * f(f(2))
def test_compute_twice_with_multiplication_zero():
assert compute_twice_with_multiplication(0) == f(0) * f(f(0))
def test_compute_twic... | [
{
"docstring": "Sample function which we will call twice.",
"function_declaration": "def f(x):",
"function_name": "f",
"parameter_list": "(x)"
},
{
"docstring": "Calls the function 'f' twice and includes a multiplication operation between the two results.\n:param x: Initial input value for t... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def f(x):\n \"\"\"\n Sample function that operates on x. Here we define f(x) as x + 1 for illustration.\n You can replace this with any other mathematical function as required.\n \... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036173",
"row_id": 36173,
"seed_ids": "['Qwen2-72B-Instruct_80928']"
} | 0.640401 | Filter_36173 | I | [
"f",
"compute_twice_with_multiplication"
] | 2 | [
[
"compute_twice_with_multiplication",
"f"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 15dbae1f9edf16dc05bef0f7b7ba22b706ea153a | 65231bed46e1d9524187b4ac2fec3b3faf068916 | |||
v1.0 | instruct | Filter | Filter_36174_I | Write a code to initialize an array with 10 elements of value 0, and then write a function to update the array with the prime numbers in the range 0 to 50. Additionally, the function should also return the sum of the prime numbers found. | def initialize_array():
"""
Initializes an array with 10 elements of value 0.
"""
return [0] * 10
def is_prime(n):
"""
Checks if a number n is a prime number.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
... | from solution import initialize_array, is_prime, update_array_with_primes
def test_initialize_array():
assert initialize_array() == [0] * 10
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == F... | [
{
"docstring": "Initializes an array with 10 elements of value 0.",
"function_declaration": "def initialize_array():",
"function_name": "initialize_array",
"parameter_list": "()"
},
{
"docstring": "Checks if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def initialize_array(size, value):\n \"\"\"\n Initialize an array with a specified size and fill it with the given value.\n \"\"\"\n return [value] * size\n\ndef is_prime(num):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036174",
"row_id": 36174,
"seed_ids": "['Qwen2-72B-Instruct_80929']"
} | 0.598675 | Filter_36174 | I | [
"initialize_array",
"is_prime",
"update_array_with_primes"
] | 3 | [
[
"update_array_with_primes",
"initialize_array"
],
[
"update_array_with_primes",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | da469347be05ed1df94f2b6022e106d8f0f6e442 | a43e8609963d728322c5b1f0a5469a20cb04091e | |||
v1.0 | instruct | Filter | Filter_36175_I | Create a python function that visualizes and compares the effectiveness of at least two different sorting algorithms by computing the speed of execution with a set of randomly-generated input list of specified large size n (for instance, n=10,000). Use a comparison-based sorting algorithm (like mergesort, quicksort) an... | import random
import time
import matplotlib.pyplot as plt
def merge_sort(arr):
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left = merge_sort(arr[:mid])
right = merge_sort(arr[mid:])
return merge(left, right)
def merge(left, right):
res = []
i = j = 0
while i < len(left) an... | from solution import merge_sort, counting_sort, visualize_sorting_algorithms
import time
import random
def test_merge_sort():
arr = [random.randint(-10000, 10000) for _ in range(1000)]
sorted_arr = merge_sort(arr)
assert sorted_arr == sorted(arr)
def test_counting_sort():
arr = [random.randint(-10000,... | [
{
"docstring": null,
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def merge(left, right):",
"function_name": "merge",
"parameter_list": "(left, right)"
},
{
"docst... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\nimport random\nimport matplotlib.pyplot as plt\n\ndef mergesort(arr):\n if len(arr) > 1:\n mid = len(arr)//2\n L = arr[:mid]\n R = arr[mid:]\n\n mer... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036175",
"row_id": 36175,
"seed_ids": "['Qwen2-72B-Instruct_80933']"
} | 0.552757 | Filter_36175 | I | [
"merge_sort",
"merge",
"counting_sort",
"visualize_sorting_algorithms"
] | 4 | [
[
"merge_sort",
"merge"
],
[
"visualize_sorting_algorithms",
"counting_sort"
],
[
"visualize_sorting_algorithms",
"merge_sort"
]
] | 3 | [] | false | [] | false | pytest | true | [
"matplotlib"
] | false | c4141ba3dc31ba4bb221522a555c9fc7a6132fe4 | de9666ed1255b1feb5833723e4cc9adf2c3b5aad | |||
v1.0 | instruct | Filter | Filter_36179_I | Write a Python function to compute the Fibonacci series up to a given number using recursion. Additionally, implement a memoization technique to optimize the recursive function for larger inputs. Then, extend the function to return the sequence in reverse order. Test it by generating standard Fibonacci sequences up to ... | def fibonacci(n, memo={}):
"""
Returns the nth Fibonacci number using recursion with memoization.
"""
if n <= 0:
return 0
elif n == 1:
return 1
if n not in memo:
memo[n] = fibonacci(n-1, memo) + fibonacci(n-2, memo)
return memo[n]
def generate_fibonacci_sequence_up_t... | from solution import fibonacci, generate_fibonacci_sequence_up_to
def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(10) == 55
def test_generate_fibonacci_sequence_up_to():
assert generate_fibonacci_sequenc... | [
{
"docstring": "Returns the nth Fibonacci number using recursion with memoization.",
"function_declaration": "def fibonacci(n, memo={}):",
"function_name": "fibonacci",
"parameter_list": "(n, memo={})"
},
{
"docstring": "Generates the Fibonacci sequence up to a given number 'n'.",
"funct... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci(n, memo={}):\n \"\"\"\n Compute the Fibonacci series up to the nth number using recursion with memoization.\n \n :param n: Number up to which the Fibonacci series is ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036179",
"row_id": 36179,
"seed_ids": "['Qwen2-72B-Instruct_80943']"
} | 0.736431 | Filter_36179 | I | [
"fibonacci",
"generate_fibonacci_sequence_up_to"
] | 2 | [
[
"generate_fibonacci_sequence_up_to",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b20352011a681e05bbcd0290c4ae9d12bdb9683c | 1270135926a3d591bcf0133fa030525eb24eaaff | |||
v1.0 | instruct | Filter | Filter_36183_I | Write a Python code to compare two given lists and return the elements that are present in both lists, but only if they are prime numbers greater than 10. Additionally, the code should return the elements in descending order and remove any duplicates. | 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 common_primes... | from solution import common_primes
def test_common_primes_with_no_common_elements():
assert common_primes([12, 14, 18], [13, 17, 19]) == []
def test_common_primes_with_primes_greater_than_10():
assert common_primes([11, 13, 17, 23], [23, 11, 29]) == [23, 11]
def test_common_primes_with_duplicates_in_list():
... | [
{
"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 the elements that are present in both lists, but only if they are prime numbers greater than 10.\nThe e... | [
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 if n == 2:\n return True\n if n % 2 == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036183",
"row_id": 36183,
"seed_ids": "['Qwen2-72B-Instruct_80953']"
} | 0.571672 | Filter_36183 | I | [
"is_prime",
"common_primes"
] | 2 | [
[
"common_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3b52650d66b8b2261578517723113fad6677a32c | 380eabe6a47fe39147d9d15d80e0fba6a4db1088 | |||
v1.0 | instruct | Filter | Filter_36187_I | Write a computer program which prints out every prime number less than 100. | def sieve_of_eratosthenes(limit):
"""
Returns a list of all prime numbers less than the given limit using the Sieve of Eratosthenes.
"""
primes = []
sieve = [True] * limit
for num in range(2, limit):
if sieve[num]:
primes.append(num)
for multiple in range(num * nu... | from solution import sieve_of_eratosthenes, prime_numbers_less_than_100
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
assert sieve_of_eratosthenes(2) == []
assert sieve_of_eratosthenes(3) == [2]
def t... | [
{
"docstring": "Returns a list of all prime numbers less than the given limit using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Prints all prime numbers less... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def primes_less_than_100():\n \"\"\"\n Returns a list of prime numbers less than 100.\n \"\"\"\n primes = []\n for num in range(2, 100):\n is_prime = True\n for i ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036187",
"row_id": 36187,
"seed_ids": "['Qwen2-72B-Instruct_80962']"
} | 0.563305 | Filter_36187 | I | [
"sieve_of_eratosthenes",
"prime_numbers_less_than_100"
] | 2 | [
[
"prime_numbers_less_than_100",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3fa19c896b562ecd392a79501418c47657583bf0 | 1be84778385404de51212ef0a8a330d54c1321c0 | |||
v1.0 | instruct | Filter | Filter_36188_I | Develop an algorithm for implementing the Fibonacci sequence utilizing matrix exponentiation. Your solution should be able to handle extremely large input values for N, where N can be up to 10^18. Ensure your method is highly optimized for performance. | def matrix_mult(A, B):
"""
Multiplies two 2x2 matrices A and B.
"""
return [[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],
[A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]]]
def matrix_pow(mat, power):
"""
Raises matrix `... | from solution import fib_matrix_exponentiation
def test_fib_0():
assert fib_matrix_exponentiation(0) == 0
def test_fib_1():
assert fib_matrix_exponentiation(1) == 1
def test_fib_2():
assert fib_matrix_exponentiation(2) == 1
def test_fib_3():
assert fib_matrix_exponentiation(3) == 2
def test_fib_4()... | [
{
"docstring": "Multiplies two 2x2 matrices A and B.",
"function_declaration": "def matrix_mult(A, B):",
"function_name": "matrix_mult",
"parameter_list": "(A, B)"
},
{
"docstring": "Raises matrix `mat` to the power `power` using binary exponentiation.",
"function_declaration": "def matr... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_matrix_exponentiation(n):\n \"\"\"\n Calculate the nth Fibonacci number using matrix exponentiation.\n \n Args:\n n (int): The position in the Fibonacci sequence t... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036188",
"row_id": 36188,
"seed_ids": "['Qwen2-72B-Instruct_80963']"
} | 0.594577 | Filter_36188 | I | [
"matrix_mult",
"matrix_pow",
"fib_matrix_exponentiation"
] | 3 | [
[
"fib_matrix_exponentiation",
"matrix_pow"
],
[
"matrix_pow",
"matrix_mult"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ec84c208b0ac70e4f5285aa28a4356efe0481bb2 | 7883a087b72a5bb42af546a58380b1bffe8830ad | |||
v1.0 | instruct | Filter | Filter_36196_I | Write a program that simulates the board game "Mastermind". The computer will generate a random four-color code using 6 different colors (Red, Green, Blue, Yellow, Orange, and Purple). The player will have 12 chances to guess the code. After each guess, the computer will provide feedback in the form of black and white ... | import random
# Colors available for the code
COLORS = ['Red', 'Green', 'Blue', 'Yellow', 'Orange', 'Purple']
def generate_code():
"""
Generates a random four-color code.
"""
return [random.choice(COLORS) for _ in range(4)]
def give_feedback(code, guess):
"""
Provides feedback for a guess com... | from solution import give_feedback, score_feedback, validate_guess
def test_give_feedback():
assert give_feedback(['Red', 'Green', 'Blue', 'Yellow'], ['Red', 'Green', 'Blue', 'Yellow']) == (4, 0)
assert give_feedback(['Red', 'Green', 'Blue', 'Yellow'], ['Yellow', 'Blue', 'Green', 'Red']) == (0, 4)
assert g... | [
{
"docstring": "Generates a random four-color code.",
"function_declaration": "def generate_code():",
"function_name": "generate_code",
"parameter_list": "()"
},
{
"docstring": "Provides feedback for a guess compared to the code.\nReturns the number of black and white pegs.",
"function_d... | [
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 generate_code():\n \"\"\"\n Generates a 4-color code from 6 possible colors.\n \"\"\"\n colors = [\"Red\", \"Green\", \"Blue\", \"Yellow\", \"Orange\", \"Purpl... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036196",
"row_id": 36196,
"seed_ids": "['Qwen2-72B-Instruct_80976']"
} | 0.569644 | Filter_36196 | I | [
"generate_code",
"give_feedback",
"score_feedback",
"validate_guess",
"play_mastermind"
] | 5 | [
[
"play_mastermind",
"generate_code"
],
[
"play_mastermind",
"give_feedback"
],
[
"play_mastermind",
"score_feedback"
],
[
"play_mastermind",
"validate_guess"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 9e6b06e083b261cf6bf3bb04b85207fbbc032a18 | f715f18a3c63e2677b3b3625e7a0e3d7e6a8719e | |||
v1.0 | instruct | Filter | Filter_36218_I | Create a for-loop in Python that iterates through a list of numbers and prints out only the prime numbers in the list that are divisible by 7, while also counting the total number of prime numbers found. The program should then print the total count of prime numbers at the end. | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
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... | from solution import is_prime, find_primes_divisible_by_seven
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(7) == True
assert is_prime(14) == False
assert is_prime(49) == False
def test_find_primes_divisible_by_seven():
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Function to find and print prime numbers divisible by 7 from the given list of numbers.\nAlso counts and re... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to 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 ==... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036218",
"row_id": 36218,
"seed_ids": "['Qwen2-72B-Instruct_81015']"
} | 0.633803 | Filter_36218 | I | [
"is_prime",
"find_primes_divisible_by_seven"
] | 2 | [
[
"find_primes_divisible_by_seven",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | de2d78dfd0b56e5b20cb9b474e95c1769ed6a8d7 | 01b790c1c4fdd72754de870467d9b0d9256de528 | |||
v1.0 | instruct | Filter | Filter_36220_I | Write a code generator for a music database, based on Tchaikovsky's symphony No.4. The generator should produce a series of random codes, each of which represents a unique piece of music in the database. The codes should be formatted as follows: the first 4 characters should be a random combination of letters, followed... | import random
import string
def generate_random_string(length):
letters = string.ascii_letters
return ''.join(random.choice(letters) for i in range(length))
def generate_random_code(year, min_num=1, max_num=99):
random_string = generate_random_string(4)
random_number = random.randint(min_num, max_num)... | from solution import generate_random_string, generate_random_code, generate_unique_code, music_code_generator
def test_generate_random_string():
random_string = generate_random_string(4)
assert len(random_string) == 4
assert all(c.isalpha() for c in random_string)
def test_generate_random_code():
rand... | [
{
"docstring": null,
"function_declaration": "def generate_random_string(length):",
"function_name": "generate_random_string",
"parameter_list": "(length)"
},
{
"docstring": null,
"function_declaration": "def generate_random_code(year, min_num=1, max_num=99):",
"function_name": "gene... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_code(existing_codes, year, unique_numbers):\n \"\"\"\n Generates a unique code for a piece of music.\n \n :param existing_codes: A set ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036220",
"row_id": 36220,
"seed_ids": "['Qwen2-72B-Instruct_81019']"
} | 0.496504 | Filter_36220 | I | [
"generate_random_string",
"generate_random_code",
"generate_unique_code",
"music_code_generator"
] | 4 | [
[
"generate_random_code",
"generate_random_string"
],
[
"generate_unique_code",
"generate_random_code"
],
[
"music_code_generator",
"generate_unique_code"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 7da29596bc4fbb5492ebfa0628dff5d682ec4c3e | 01e814b4c5ec83b084ca56748e07c9de3d78c424 | |||
v1.0 | instruct | Filter | Filter_36284_I | Design a Python script to evaluate the weighted median share value of a corporation over the past 7 days. The weights are defined by the volume of shares traded each day. Thus, days with high trading volume have more impact on the median value. Also, instead of retrieving the values directly, develop a function that ex... | import requests
def get_weighted_median(data):
"""
Returns the weighted median value based on share prices and corresponding trading volumes.
Parameters:
data (list of dict): List containing daily 'price' and 'volume' information.
Returns:
float: The weighted median share price.
"""
p... | from unittest.mock import patch
import pytest
from solution import get_weighted_median, fetch_share_prices_and_volumes, weighted_median_share_value
def test_get_weighted_median():
data = [
{"price": 100, "volume": 1},
{"price": 200, "volume": 2},
{"price": 300, "volume": 3}
]
asser... | [
{
"docstring": "Returns the weighted median value based on share prices and corresponding trading volumes.\n\nParameters:\ndata (list of dict): List containing daily 'price' and 'volume' information.\n\nReturns:\nfloat: The weighted median share price.",
"function_declaration": "def get_weighted_median(data... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport numpy as np\n\ndef fetch_share_data(api_url):\n \"\"\"\n Fetch share data from the provided JSON API URL.\n\n Parameters:\n api_url (str): The URL of th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036284",
"row_id": 36284,
"seed_ids": "['Qwen2-72B-Instruct_81124']"
} | 0.596927 | Filter_36284 | I | [
"get_weighted_median",
"fetch_share_prices_and_volumes",
"weighted_median_share_value"
] | 3 | [
[
"weighted_median_share_value",
"fetch_share_prices_and_volumes"
],
[
"weighted_median_share_value",
"get_weighted_median"
]
] | 2 | [] | false | [] | false | pytest | true | [
"requests"
] | false | 4ee1dd0109963eb1fb51da1f361d51cf5eaaf79a | 056d94bdd91b4f8e00c62f1b231c8c0f8e8bb4b9 | |||
v1.0 | instruct | Filter | Filter_36291_I | Translate the following pseudocode to python that takes an array of integers as input and returns a list of all the prime numbers. | import math
def is_prime(n):
"""
Check if a number n 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
... | from solution import find_primes
def test_find_primes_with_primes_and_nonprimes():
assert find_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7]
def test_find_primes_all_primes():
assert find_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def test_find_primes_no_prime... | [
{
"docstring": "Check if a number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all prime numbers from the input array.",
"function_declaration": "def find_primes(arr):",
"f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036291",
"row_id": 36291,
"seed_ids": "['Qwen2-72B-Instruct_81136']"
} | 0.649621 | Filter_36291 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 927fd5658dd92fd3822be1613370b8abd485ebf5 | a400416721b2ce16a40909ecb44a334fdb4f8266 | |||
v1.0 | instruct | Filter | Filter_36292_I | how can i find steady state solution of a system of nonlinear differential equations using python? can you provide an example code? | import numpy as np
from scipy.optimize import fsolve
def system_equations(vars):
"""
Defines the system of nonlinear equations.
Args:
vars: A list or array containing the variables [x, y].
Returns:
A list containing the evaluation of the system equations at the given vars.
"""
... | from solution import system_equations, find_steady_state
import numpy as np
def test_system_equations():
x, y = 1.0, 2.0
result = system_equations([x, y])
expected = [-2.0, -5.0]
assert np.allclose(result, expected, atol=1e-5)
def test_steady_state_solution():
initial_guess = [0.5, 0.5]
soluti... | [
{
"docstring": "Defines the system of nonlinear equations.\n\nArgs:\nvars: A list or array containing the variables [x, y].\n\nReturns:\nA list containing the evaluation of the system equations at the given vars.",
"function_declaration": "def system_equations(vars):",
"function_name": "system_equations... | [
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\nfrom scipy.optimize import fsolve\n\ndef system_of_equations(vars):\n x, y = vars\n # Example of a nonlinear system of equations:\n # x^2 + y^2 - 4 = 0\n # x^3 ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036292",
"row_id": 36292,
"seed_ids": "['Qwen2-72B-Instruct_81138']"
} | 0.312073 | Filter_36292 | I | [
"system_equations",
"find_steady_state"
] | 2 | [
[
"find_steady_state",
"system_equations"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy",
"scipy"
] | false | 32e6f828a81b7bd25d07fcc1566cc47482d5c517 | aebf3dda5a765bd1a30d20ad265bbe1602077284 | |||
v1.0 | instruct | Filter | Filter_36308_I | Create a Python console program for a simple hangman game which will randomly choose a word from a text file. | import random
def load_words(file_path):
"""
Loads words from a specified text file. Each word should be on a new line.
"""
with open(file_path, 'r') as file:
words = file.read().splitlines()
return words
def choose_word(words):
"""
Randomly chooses a word from a list of words.
... | import pytest
from unittest.mock import patch, mock_open
from solution import load_words, choose_word
def test_load_words():
mock_data = "apple\nbanana\ncherry\n"
with patch("builtins.open", mock_open(read_data=mock_data)):
words = load_words("fake_path.txt")
assert words == ["apple", "banana",... | [
{
"docstring": "Loads words from a specified text file. Each word should be on a new line.",
"function_declaration": "def load_words(file_path):",
"function_name": "load_words",
"parameter_list": "(file_path)"
},
{
"docstring": "Randomly chooses a word from a list of words.",
"function_d... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef load_words(file_path):\n \"\"\"\n Loads words from the given file and returns them as a list.\n \"\"\"\n with open(file_path, 'r') as file:\n words = fi... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036308",
"row_id": 36308,
"seed_ids": "['Qwen2-72B-Instruct_81162']"
} | 0.525428 | Filter_36308 | I | [
"load_words",
"choose_word",
"hangman"
] | 3 | [
[
"hangman",
"choose_word"
],
[
"hangman",
"load_words"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 12aa0929d80c6cfa409179b925f16c1a7fca38ef | bf22f1b1708062ade1c5eb34e51a8bc974911f00 | |||
v1.0 | instruct | Filter | Filter_36311_I | Create a loop that prints all prime numbers between 1 and 100. Additionally, your program should also display the sum of these prime numbers. Extend this further by implementing the Sieve of Eratosthenes algorithm for improved performance. | def sieve_of_eratosthenes(n):
"""
Finds all prime numbers up to n using the Sieve of Eratosthenes algorithm
and returns them in a list.
"""
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
... | from solution import sieve_of_eratosthenes, prime_numbers_and_sum
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(2) == [2]
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
def test_pr... | [
{
"docstring": "Finds all prime numbers up to n using the Sieve of Eratosthenes algorithm\nand returns them in a list.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Finds all prime numbers up to... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_numbers_and_sum(limit):\n \"\"\"\n Prints all prime numbers between 1 and the specified limit (inclusive).\n Returns the sum of these prime numbers.\n \"\"\"\n if limi... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036311",
"row_id": 36311,
"seed_ids": "['Qwen2-72B-Instruct_81166']"
} | 0.534713 | Filter_36311 | I | [
"sieve_of_eratosthenes",
"prime_numbers_and_sum"
] | 2 | [
[
"prime_numbers_and_sum",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ecac4749cc43daae151dfd5d4f1b5060add042bf | c20d5189b8c48c576ac660a78de5cb82a171c489 | |||
v1.0 | instruct | Filter | Filter_36317_I | Write a Python program to simulate a Dice game where a prson rolls two dice and the sum is calculated, if the sum is 7 or 11, the person wins, if the sum is 2, 3, or 12, the person looses, in all other cases, the sum becomes the person's "point". The person then continues to roll the dice until they either roll their "... | import random
def roll_dice():
"""
Simulates rolling two dice and returns their sum.
"""
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
return die1 + die2
def play_game():
"""
Simulates playing the dice game.
"""
initial_roll = roll_dice()
print(f"Initial roll: {in... | from solution import roll_dice, play_game
def test_roll_dice():
for _ in range(100):
result = roll_dice()
assert 2 <= result <= 12
# Since play_game involves randomness and user interaction,
# we need to mock/stub input and output for testing.
# Here, we'll use the unittest.mock library to simulat... | [
{
"docstring": "Simulates rolling two dice and returns their sum.",
"function_declaration": "def roll_dice():",
"function_name": "roll_dice",
"parameter_list": "()"
},
{
"docstring": "Simulates playing the dice game.",
"function_declaration": "def play_game():",
"function_name": "pla... | [
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 Rolls two six-sided dice and returns their sum.\n \"\"\"\n die1 = random.randint(1, 6)\n die2 = random.randint(1, 6)\n return die... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036317",
"row_id": 36317,
"seed_ids": "['Qwen2-72B-Instruct_81177']"
} | 0.577904 | Filter_36317 | I | [
"roll_dice",
"play_game",
"main"
] | 3 | [
[
"play_game",
"roll_dice"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 802e0a715bcbb92966052b8d2005dd0d5f636c17 | 8d22239b798aa9c52c13b2e2a5f489e85fde543e | |||
v1.0 | instruct | Filter | Filter_36323_I | Define an algorithm in Python for computing the maximum subarray of an array of integers using the divide-and-conquer approach. | def max_crossing_subarray(arr, low, mid, high):
left_sum = float('-inf')
sum_left = 0
for i in range(mid, low - 1, -1):
sum_left += arr[i]
if sum_left > left_sum:
left_sum = sum_left
right_sum = float('-inf')
sum_right = 0
for j in range(mid + 1, high + 1):
s... | from solution import maximum_subarray
def test_single_element():
assert maximum_subarray([1], 0, 0) == 1
assert maximum_subarray([-1], 0, 0) == -1
def test_positive_numbers():
assert maximum_subarray([1, 2, 3, 4], 0, 3) == 10
def test_negative_numbers():
assert maximum_subarray([-1, -2, -3, -4], 0, 3... | [
{
"docstring": null,
"function_declaration": "def max_crossing_subarray(arr, low, mid, high):",
"function_name": "max_crossing_subarray",
"parameter_list": "(arr, low, mid, high)"
},
{
"docstring": null,
"function_declaration": "def maximum_subarray(arr, low, high):",
"function_name"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_crossing_sum(arr, left, mid, right):\n \"\"\"\n Find the maximum possible sum in arr[] such that\n the sum is formed by elements spanning across the mid.\n \"\"\"\n sum ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036323",
"row_id": 36323,
"seed_ids": "['Qwen2-72B-Instruct_81185']"
} | 0.699414 | Filter_36323 | I | [
"max_crossing_subarray",
"maximum_subarray"
] | 2 | [
[
"maximum_subarray",
"max_crossing_subarray"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 01c96e9fa64018ab91b0daf6f4332bc46d8f69cd | c9105385852f47769ed8c73e87bca32502e57ee7 | |||
v1.0 | instruct | Filter | Filter_36331_I | Write a Python script that accepts astrological sign inputs, calculates compatible signs based on element affinity (Fire, Earth, Air, Water), converting them into Chinese zodiac years, then scrapes horoscopes from astrology websites for the current day. The program should store the scraped data into a csv and logs erro... | import requests
from bs4 import BeautifulSoup
import csv
from datetime import datetime
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def get_element(sign):
fire_signs = ['Aries', 'Leo', 'Sagittarius']
earth_signs = ['Taurus', 'Virgo', 'Capricorn']
air_si... | from solution import (
get_element, get_compatible_signs, sign_to_chinese_zodiac, scrape_horoscopes, save_to_csv, log_error
)
def test_get_element():
assert get_element('Aries') == 'Fire'
assert get_element('Taurus') == 'Earth'
assert get_element('Gemini') == 'Air'
assert get_element('Cancer') == '... | [
{
"docstring": null,
"function_declaration": "def get_element(sign):",
"function_name": "get_element",
"parameter_list": "(sign)"
},
{
"docstring": null,
"function_declaration": "def get_compatible_signs(element):",
"function_name": "get_compatible_signs",
"parameter_list": "(ele... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\nimport logging\n\ndef get_element(sign):\n \"\"\"\n Returns the element associated with the given astrological sign.\n \"\"\"\n elements = {\n 'Aries': 'Fire', '... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036331",
"row_id": 36331,
"seed_ids": "['Qwen2-72B-Instruct_81198']"
} | 0.439974 | Filter_36331 | I | [
"get_element",
"get_compatible_signs",
"sign_to_chinese_zodiac",
"scrape_horoscopes",
"save_to_csv",
"log_error",
"send_email_alert",
"main"
] | 8 | [
[
"log_error",
"send_email_alert"
]
] | 1 | [] | false | [] | false | pytest | true | [
"bs4",
"requests"
] | false | 727d9c00e295f0f6b79101ce2129908f2486697b | 80fe743045b30630b5616ee1c6bb2a0e372004d4 | |||
v1.0 | instruct | Filter | Filter_36353_I | Write a Python function to identify all numbers in the given list that are prime, and return them in descending order. Additionally, for each prime number found, determine and include its position in the original list in a separate returned structure. Your function must not only confirm primality but also preserve the ... | def is_prime(n):
"""
Helper function to determine if a given 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 find_primes_descending(lst):
"""
Identify all primes in the list and retu... | from solution import find_primes_descending
def test_find_primes_descending():
# Test with mixed numbers
input_lst = [29, 15, 3, 22, 13, 9, 5]
expected_primes = [29, 13, 5, 3]
expected_positions = [0, 4, 6, 2]
assert find_primes_descending(input_lst) == (expected_primes, expected_positions)
# ... | [
{
"docstring": "Helper function to determine if a given number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Identify all primes in the list and return them in descending order along with their positions.\n\nPa... | [
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, False otherwise.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True # 2 ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036353",
"row_id": 36353,
"seed_ids": "['Qwen2-72B-Instruct_81236']"
} | 0.681765 | Filter_36353 | I | [
"is_prime",
"find_primes_descending"
] | 2 | [
[
"find_primes_descending",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 141bab718972144ed3c0138a22609f6f90f88fbb | c4ab88b5e02de850880268129362eaaf8cb5d82e | |||
v1.0 | instruct | Filter | Filter_36369_I | Suppose you have a binary matrix 'a' of size 164x250. You need to place the bits from this matrix into another matrix of a size 54x500, named 'b'. Each value located in matrix 'a' should be gradually relocated to matrix 'b', starting from the first row till the last, while always filling every row in matrix 'b' entirel... | import numpy as np
def fill_matrix(a, b):
"""
Fills the matrix `b` with bits from matrix `a` starting from the first row till the last,
filling every row in `b` entirely. If `a` is insufficient to fill `b`, it cycles back
to the start of `a`.
Parameters:
a (numpy.ndarray): Input matrix of ... | import numpy as np
from solution import fill_matrix
def test_fill_matrix():
a = np.array([[1, 0], [0, 1]])
b = np.zeros((2, 4), dtype=int)
expected_output = np.array([
[1, 0, 0, 1],
[1, 0, 0, 1]
])
filled_b = fill_matrix(a, b)
assert np.array_equal(filled_b, expec... | [
{
"docstring": "Fills the matrix `b` with bits from matrix `a` starting from the first row till the last,\nfilling every row in `b` entirely. If `a` is insufficient to fill `b`, it cycles back\nto the start of `a`.\n\nParameters:\na (numpy.ndarray): Input matrix of size 164x250\nb (numpy.ndarray): Output matrix... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def relocate_bits(a):\n \"\"\"\n Relocates bits from matrix 'a' of size 164x250 to matrix 'b' of size 54x500.\n If 'a' is insufficient to fill 'b', it cycles back through 'a'.\n \n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036369",
"row_id": 36369,
"seed_ids": "['Qwen2-72B-Instruct_81263']"
} | 0.471565 | Filter_36369 | I | [
"fill_matrix",
"example"
] | 2 | [
[
"example",
"fill_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | 2188972296042e90f9be3c78888099ae6ac59858 | 810886840d1c4265e8f295c0bba223e4fa001073 | |||
v1.0 | instruct | Filter | Filter_36378_I | Write Python code to generate a random integer between 1 and 10,000 (inclusive), without using the random library. The code should also ensure that the generated integer is divisible by both 3 and 7, and is a perfect square. Additionally, the code should be optimized to have a time complexity of O(log(n)) where n is th... | def is_perfect_square(n):
"""
Check if a number is a perfect square.
"""
root = int(n ** 0.5)
return root * root == n
def generate_random_integer():
"""
Generate a random integer between 1 and 10,000 that is divisible by both 3 and 7,
and is a perfect square.
"""
import secrets ... | from solution import is_perfect_square, generate_random_integer
def test_is_perfect_square():
assert is_perfect_square(1) == True
assert is_perfect_square(4) == True
assert is_perfect_square(9) == True
assert is_perfect_square(16) == True
assert is_perfect_square(21) == False
assert is_perfect_... | [
{
"docstring": "Check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Generate a random integer between 1 and 10,000 that is divisible by both 3 and 7,\nand is a perfect s... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_perfect_square(n):\n \"\"\"\n Check if a number is a perfect square.\n \"\"\"\n root = int(n ** 0.5)\n return root * root == n\n\ndef generate_random_integer():\n \"\"... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036378",
"row_id": 36378,
"seed_ids": "['Qwen2-72B-Instruct_81278']"
} | 0.545068 | Filter_36378 | I | [
"is_perfect_square",
"generate_random_integer"
] | 2 | [
[
"generate_random_integer",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9fde56e74753c4822d64c112af7b014b541614c3 | d975be5441d1e16e2b84a39cfc2bed347df0c0c8 | |||
v1.0 | instruct | Filter | Filter_36381_I | Write a code to find the kth smallest element in an unsorted array using QuickSelect algorithm. The solution should have a time complexity of O(n) and a space complexity of O(1). Additionally, you are not allowed to use any extra data structures or sorting algorithms. | def partition(arr, low, high):
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quickselect(arr, low, high, k):
if low == high:
... | from solution import kth_smallest
def test_kth_smallest_regular_case():
assert kth_smallest([3, 2, 1, 5, 6, 4], 2) == 2
def test_kth_smallest_larger_k():
assert kth_smallest([3, 2, 1, 5, 6, 4], 5) == 5
def test_kth_smallest_single_element():
assert kth_smallest([1], 1) == 1
def test_kth_smallest_all_sam... | [
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quickselect(arr, k):\n \"\"\"\n Returns the k-th smallest element in the array using the QuickSelect algorithm.\n \"\"\"\n def partition(left, right, pivot_index):\n piv... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036381",
"row_id": 36381,
"seed_ids": "['Qwen2-72B-Instruct_81286']"
} | 0.615081 | Filter_36381 | I | [
"partition",
"quickselect",
"kth_smallest"
] | 3 | [
[
"kth_smallest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a190d0a6f70f446fdce4fae1b58952bb0beb788c | 82dd562e843dca0df6e066591c51ea61a8d6ac44 | |||
v1.0 | instruct | Filter | Filter_36404_I | Write a Python program to generate the first n Fibonacci numbers and display them in reverse order. Additionally, the program should only use recursion to calculate the Fibonacci sequence and should not use any loops or built-in functions for calculating the Fibonacci sequence. The program should also handle the case w... | def fibonacci(n):
"""
Recursively calculates the nth Fibonacci number.
"""
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
def generate_fibonacci_reverse(n):
"""
Recursively generates the first n Fibonacci numbers and re... | from solution import generate_fibonacci_reverse
def test_negative_n():
assert generate_fibonacci_reverse(-5) == "Error: n should be a positive integer."
def test_zero_n():
assert generate_fibonacci_reverse(0) == "Error: n should be a positive integer."
def test_single_fibonacci_number():
assert generate_... | [
{
"docstring": "Recursively calculates the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Recursively generates the first n Fibonacci numbers and returns them in reverse order.\nIf n is zero or neg... | [
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 using recursion.\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must be a positive integer\")\n elif n == 1:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036404",
"row_id": 36404,
"seed_ids": "['Qwen2-72B-Instruct_81324']"
} | 0.748362 | Filter_36404 | I | [
"fibonacci",
"generate_fibonacci_reverse"
] | 2 | [
[
"generate_fibonacci_reverse",
"fibonacci"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 911250c875f47ebcc50cf03e4d703a695996067f | 1ce4886892085987371a3aae18a84b32dbaa2aff | |||
v1.0 | instruct | Filter | Filter_36408_I | Implement a recursive function in your preferred programming language that generates and returns the prime numbers within a given range. Be sure to handle the possible edge cases, such as generating primes between two equal numbers, or when the lower range is greater than the upper range. | def is_prime(n):
"""
Checks if a number is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
... | from solution import is_prime, generate_primes_recursive
def test_is_prime():
# Test known primes
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(13) == True
# Test non-primes
assert is_prime(1) == False
assert is_prime(4) == False
as... | [
{
"docstring": "Checks if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Recursively generates prime numbers within a given range [start, end].",
"function_declaration": "def generate_prime... | [
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, divisor=2):\n \"\"\"\n Helper function to determine if a given number n is prime.\n \"\"\"\n # Base case: 1 is not a prime number\n if n <= 1:\n return Fa... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036408",
"row_id": 36408,
"seed_ids": "['Qwen2-72B-Instruct_81330']"
} | 0.583644 | Filter_36408 | I | [
"is_prime",
"generate_primes_recursive"
] | 2 | [
[
"generate_primes_recursive",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4294d25517f159e496471dfda88ad96741767e65 | f510ec02e4bde9e3f6f0c9860c35fc1a094a4a1e | |||
v1.0 | instruct | Filter | Filter_36427_I | Write a Python function to calculate the Lowest Common Multiple (LCM) of two or more integers. The function should be able to handle edge cases like negative numbers and zero. Also, provide a piece of erroneous code and explain how to fix it. | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Returns the Lowest Common Multiple (LCM) of two integers a and b.
"""
if a == 0 or b == 0:
return 0
return abs(a * b) // gcd(a, b)
def lcm_multiple(*args):
"""
Returns the Lowest Common Multiple (LCM) of multiple ... | from solution import lcm, lcm_multiple
def test_lcm_positive_numbers():
assert lcm(4, 6) == 12
def test_lcm_with_zero():
assert lcm(0, 5) == 0
assert lcm(5, 0) == 0
def test_lcm_negative_numbers():
assert lcm(-4, 6) == 12
assert lcm(4, -6) == 12
assert lcm(-4, -6) == 12
def test_lcm_multiple... | [
{
"docstring": "Returns the Lowest Common Multiple (LCM) of two integers a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the Lowest Common Multiple (LCM) of multiple integers.",
"function_declaration": "de... | [
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 lcm(a, b):\n \"\"\"\n Returns the lowest common multiple of two integers.\n Handles negative numbers by considering their absolute values.\n Returns None when an... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036427",
"row_id": 36427,
"seed_ids": "['Qwen2-72B-Instruct_81356']"
} | 0.668149 | Filter_36427 | I | [
"lcm",
"lcm_multiple"
] | 2 | [
[
"lcm_multiple",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8548d3670f9db337c0ae9331039fc41751f6a5c | 09119feff0cea76184118735bf123709c27b6060 | |||
v1.0 | instruct | Filter | Filter_36431_I | Set up a annotations.Welcome in a FastAPI application. Implement a dependency for the welcome message using dependency injection. Create a pydantic model for request and response. Define path operations to return different welcome messages based on the user's level, which must be provided in the URL path as a path para... | from fastapi import FastAPI, Depends
from pydantic import BaseModel
app = FastAPI()
class WelcomeRequest(BaseModel):
user_name: str
class WelcomeResponse(BaseModel):
message: str
def welcome_message(user_level: str, user_name: str = None, custom_message: str = None) -> WelcomeResponse:
base_message = f"... | from fastapi.testclient import TestClient
from solution import app, WelcomeRequest, WelcomeResponse
client = TestClient(app)
def test_welcome_basic():
response = client.get("/welcome/basic")
assert response.status_code == 200
assert response.json() == {"message": "Welcome. Enjoy your stay!"}
def test_wel... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from fastapi import FastAPI, Depends\nfrom pydantic import BaseModel\nfrom typing import Optional\n\napp = FastAPI()\n\nclass WelcomeRequest(BaseModel):\n name: str\n level: str\n\nclass... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036431",
"row_id": 36431,
"seed_ids": "['Qwen2-72B-Instruct_81363']"
} | 0.317123 | Filter_36431 | I | [
"welcome_message",
"get_welcome"
] | 2 | [
[
"get_welcome",
"welcome_message"
]
] | 1 | [] | false | [
"WelcomeRequest",
"WelcomeResponse"
] | true | pytest | true | [
"fastapi",
"pydantic"
] | false | 6178ec315a4579f90b4c72547420c92f9a6af844 | fe07c6cb2baf859246e69a9e71b6b6e999c2d2b1 | |||
v1.0 | instruct | Filter | Filter_36433_I | Please write a python program to convert a string into a list of characters. Additionally, implement a function that transforms this list by removing all vowel characters, replacing them with their respective ASCII values, and then reinserting them at their original positions in the list. You should define your own fun... | def is_vowel(char):
"""
Determine if a given character is a vowel.
"""
vowels = 'aeiouAEIOU'
return char in vowels
def string_to_list(s):
"""
Convert a string into a list of characters.
"""
return list(s)
def transform_list(char_list):
"""
Transform the given list of charac... | from solution import is_vowel, string_to_list, transform_list
# Tests for is_vowel function
def test_is_vowel():
assert is_vowel('a') == True
assert is_vowel('e') == True
assert is_vowel('i') == True
assert is_vowel('o') == True
assert is_vowel('u') == True
assert is_vowel('A') == True
asse... | [
{
"docstring": "Determine if a given character is a vowel.",
"function_declaration": "def is_vowel(char):",
"function_name": "is_vowel",
"parameter_list": "(char)"
},
{
"docstring": "Convert a string into a list of characters.",
"function_declaration": "def string_to_list(s):",
"func... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_vowel(char):\n \"\"\"\n Determines if a character is a vowel (both lowercase and uppercase).\n \"\"\"\n vowels = \"aeiouAEIOU\"\n return char in vowels\n\ndef string_to_l... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036433",
"row_id": 36433,
"seed_ids": "['Qwen2-72B-Instruct_81367']"
} | 0.759272 | Filter_36433 | I | [
"is_vowel",
"string_to_list",
"transform_list"
] | 3 | [
[
"transform_list",
"is_vowel"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a8412b74427e9efc5a93794f1fcb89875710612f | 0fe35e0853cadcaa65423f6cd40b05f4e3becf9a | |||
v1.0 | instruct | Filter | Filter_36453_I | Can you help me create a Python dictionary that represents the roster of current Los Angeles Lakers players, including their jersey number as the key and position as the value? Also, can you show me how to print the position of a player given their jersey number? | def get_lakers_roster():
"""
Returns a dictionary containing Los Angeles Lakers roster with jersey number as key and position as value.
"""
return {
6: "Forward",
7: "Guard",
10: "Guard",
12: "Forward",
14: "Forward",
15: "Guard",
20: "Forward",
... | from solution import get_player_position
def test_get_player_position_found():
assert get_player_position(6) == "Forward"
assert get_player_position(21) == "Center"
assert get_player_position(55) == "Guard"
def test_get_player_position_not_found():
assert get_player_position(99) == "Jersey number not ... | [
{
"docstring": "Returns a dictionary containing Los Angeles Lakers roster with jersey number as key and position as value.",
"function_declaration": "def get_lakers_roster():",
"function_name": "get_lakers_roster",
"parameter_list": "()"
},
{
"docstring": "Returns the position of the player ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "# Define the dictionary containing the roster of current Los Angeles Lakers players\nlakers_roster = {\n 0: 'Point Guard', # Russell Westbrook\n 1: 'Small Forward', # Talen Horton-Tu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036453",
"row_id": 36453,
"seed_ids": "['Qwen2-72B-Instruct_81391']"
} | 0.499992 | Filter_36453 | I | [
"get_lakers_roster",
"get_player_position"
] | 2 | [
[
"get_player_position",
"get_lakers_roster"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6922dd9f0cb7a4e196a8cbe2ea6835c0683279b0 | e6c5ddd54d5cda42ac98f391e82e764c26ffebab | |||
v1.0 | instruct | Filter | Filter_36455_I | Write a recursive code to output all prime numbers less than a given number n while ensuring you are not using any built-in Python library to check for primes. The code should be efficient to handle large values of n. Practice good programming habits and offer complexity analysis for your solution. | def is_prime(num, divisor=2):
"""
Recursively checks if a number is prime.
"""
if num <= 2:
return num == 2
if num % divisor == 0:
return False
if divisor * divisor > num:
return True
return is_prime(num, divisor + 1)
def find_primes(n, current=2, primes=None):
"... | from solution import is_prime, find_primes
def test_is_prime():
assert not is_prime(1) # 1 is not a prime number
assert is_prime(2) # 2 is a prime number
assert is_prime(3) # 3 is a prime number
assert not is_prime(4) # 4 is not a prime number
assert is_prime(5) # 5 is a prime number
asser... | [
{
"docstring": "Recursively checks if a number is prime.",
"function_declaration": "def is_prime(num, divisor=2):",
"function_name": "is_prime",
"parameter_list": "(num, divisor=2)"
},
{
"docstring": "Recursively finds all prime numbers less than n.",
"function_declaration": "def find_pr... | [
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, divisor=None):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if number <= 1:\n return False\n if divisor is None:\n div... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036455",
"row_id": 36455,
"seed_ids": "['Qwen2-72B-Instruct_81394']"
} | 0.709769 | Filter_36455 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 46d3d6dfc5228c9d50c6f72c5943b29f1c8dda23 | c682c5295398e0f0ee1f17256ddfd9c8f3a95caf | |||
v1.0 | instruct | Filter | Filter_36457_I | Suggest a code to get the smallest and largest number in an unsorted list with a time complexity of O(n log n), without using any built-in sorting functions. | def merge_sort(arr):
"""
Sorts an array using Merge Sort algorithm.
"""
if len(arr) > 1:
mid = len(arr) // 2 # Finding the middle of the array
left_half = arr[:mid] # Dividing the elements into 2 halves
right_half = arr[mid:]
merge_sort(left_half) # Sorting the first ... | from solution import find_min_max
def test_find_min_max_single_element():
assert find_min_max([1]) == (1, 1)
def test_find_min_max_two_elements():
assert find_min_max([2, 1]) == (1, 2)
def test_find_min_max_multiple_elements():
assert find_min_max([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == (1, 9)
def test_fi... | [
{
"docstring": "Sorts an array using Merge Sort algorithm.",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the smallest and largest number in an unsorted list.",
"function_declaration": "def find_min_ma... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_smallest_and_largest(nums):\n \"\"\"\n Returns the smallest and largest number in an unsorted list.\n \n Args:\n nums (list of int): A list of unsorted integers\n \n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036457",
"row_id": 36457,
"seed_ids": "['Qwen2-72B-Instruct_81400']"
} | 0.569453 | Filter_36457 | I | [
"merge_sort",
"find_min_max"
] | 2 | [
[
"find_min_max",
"merge_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4a7adbf32d75745b72b7b5614f8f5346f48cbc0b | 1c202c0ba1bd4f5065e482c5ef2676645c1648c4 | |||
v1.0 | instruct | Filter | Filter_36459_I | Write a code to filter out numbers which are divisible by 3 and 5 from a given list and also determine if the sum of the filtered numbers is prime. The filtered numbers should be stored in a new list, and the final result should be a tuple containing the new list and a boolean indicating whether the sum is prime or not... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def filter_and_check_prime(numbers):
"""
Filters numbers divisible by 3 and 5 from the given list and
... | from solution import filter_and_check_prime
def test_filter_and_check_prime_with_no_numbers():
assert filter_and_check_prime([]) == ([], False)
def test_filter_and_check_prime_with_no_divisible_numbers():
assert filter_and_check_prime([1, 2, 4, 7, 11]) == ([], False)
def test_filter_and_check_prime_with_divi... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters numbers divisible by 3 and 5 from the given list and \ndetermines if the sum of the filtered numbers is prime.\n\n:param ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n 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_2 | {
"original_instruction": "",
"prompt_id": "00036459",
"row_id": 36459,
"seed_ids": "['Qwen2-72B-Instruct_81402']"
} | 0.600524 | Filter_36459 | I | [
"is_prime",
"filter_and_check_prime"
] | 2 | [
[
"filter_and_check_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6ad4ed4bdc9450eb1a0179da4a1619cca712867c | b4a3aacec2a5e1de263c5c24b7cfa3287cf1332e | |||
v1.0 | instruct | Filter | Filter_36471_I | Create a python program to print the cube of the first N prime numbers. | def is_prime(n):
"""
Check if a number is prime.
A prime number is only divisible by 1 and itself.
"""
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(n):
"""
Generate the first N prime... | from solution import is_prime, prime_numbers, cube_of_primes
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(1) == False
def test_prime_numbers():
assert prime_numbers(0) == []
assert prime_n... | [
{
"docstring": "Check if a number is prime.\nA prime number is only divisible by 1 and itself.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate the first N prime numbers.",
"function_declaration": "def prime_nu... | [
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 Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036471",
"row_id": 36471,
"seed_ids": "['Qwen2-72B-Instruct_81427']"
} | 0.703725 | Filter_36471 | I | [
"is_prime",
"prime_numbers",
"cube_of_primes"
] | 3 | [
[
"cube_of_primes",
"prime_numbers"
],
[
"prime_numbers",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bef7c5e02d2caaf152b8af0bdbfca8124524dbcc | 47413c955250ff4db812a4f26f1a2aba1bc71b6b | |||
v1.0 | instruct | Filter | Filter_36472_I | Build a function in Python using loops that can print all prime numbers between two given numbers (inclusive). | def is_prime(n):
"""
Helper function to 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 primes_between(a, b):
"""
Returns a list of all prime numbers between a and b (incl... | from solution import primes_between
def test_primes_between_no_primes():
assert primes_between(0, 1) == []
assert primes_between(14, 16) == []
def test_primes_between_single_prime():
assert primes_between(2, 2) == [2]
assert primes_between(10, 13) == [11, 13]
def test_primes_between_multiple_primes()... | [
{
"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 between a and b (inclusive).",
"function_declaration": "def primes_betw... | [
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 determine if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036472",
"row_id": 36472,
"seed_ids": "['Qwen2-72B-Instruct_81428']"
} | 0.677375 | Filter_36472 | I | [
"is_prime",
"primes_between"
] | 2 | [
[
"primes_between",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 01553e2e563f20f084c179c9d2456b2ab90ccfd5 | 390aefba6972980101ce70e5c7ce7db156383d1e | |||
v1.0 | instruct | Filter | Filter_36487_I | Create a program which takes a list of strings as an input and prints the length of each string using a for loop. However, you are not allowed to use the built-in function len() to calculate the length of each string. Instead, you need to implement your own function to count the characters in each string. | def count_characters(s):
"""
Count the number of characters in the string s without using len().
"""
count = 0
for _ in s:
count += 1
return count
def print_lengths(strings):
"""
Prints the length of each string in the given list of strings.
"""
for s in strings:
... | from solution import count_characters, print_lengths
def test_count_characters_empty_string():
assert count_characters("") == 0
def test_count_characters_single_character():
assert count_characters("a") == 1
def test_count_characters_word():
assert count_characters("hello") == 5
def test_count_character... | [
{
"docstring": "Count the number of characters in the string s without using len().",
"function_declaration": "def count_characters(s):",
"function_name": "count_characters",
"parameter_list": "(s)"
},
{
"docstring": "Prints the length of each string in the given list of strings.",
"func... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def custom_len(s):\n \"\"\"\n A custom implementation to calculate the length of a string s without using the built-in len() function.\n \"\"\"\n count = 0\n for char in s:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036487",
"row_id": 36487,
"seed_ids": "['Qwen2-72B-Instruct_81449']"
} | 0.761551 | Filter_36487 | I | [
"count_characters",
"print_lengths"
] | 2 | [
[
"print_lengths",
"count_characters"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c878cb919b60e7acf2b918b3b36a7a721e10144b | aa0e716ebf647206752de4caba2b790a2fa6e18b | |||
v1.0 | instruct | Filter | Filter_36492_I | Write in python a program that prints the sum of the squares of the first 100 prime numbers. Additionally, you are not allowed to use any built-in functions or libraries for prime number generation or checking. You must implement your own prime number generator and checker. | 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 prime_generator(limit):
"""Generate prime numbers up to a specified limit."""
primes = []
num = 2
whil... | from solution import is_prime, prime_generator, sum_of_squares_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(19) == True
assert is_prime(20) == False
def test_prime_generator():
assert prime_generator(5) == [2, ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate prime numbers up to a specified limit.",
"function_declaration": "def prime_generator(limit):",
"function_name": ... | [
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(num):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036492",
"row_id": 36492,
"seed_ids": "['Qwen2-72B-Instruct_81456']"
} | 0.596861 | Filter_36492 | I | [
"is_prime",
"prime_generator",
"sum_of_squares_of_primes"
] | 3 | [
[
"prime_generator",
"is_prime"
],
[
"sum_of_squares_of_primes",
"prime_generator"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1c2495af46fc8b79a17cc518a991e190c0b14d71 | dfade036fb80870a7ae9a1470ff5394be581a58b | |||
v1.0 | instruct | Filter | Filter_36496_I | Raise the difficulty of this programming test question by asking the solution not only to avoid the use of inbuilt Python set functions but also to handle tuples with nested tuples, considering all elements for uniqueness check (including elements of nested tuples). Additionally, the solution needs to retain the origin... | def flatten(tup):
"""
Helper function to flatten the tuple.
Yields elements deeply from nested tuples.
"""
for item in tup:
if isinstance(item, tuple):
yield from flatten(item)
else:
yield item
def unique_tuple_elements(tup):
"""
Returns a tuple with ... | from solution import unique_tuple_elements
def test_unique_simple_tuple():
assert unique_tuple_elements((1, 2, 3, 2, 1)) == (1, 2, 3)
def test_unique_nested_tuple():
assert unique_tuple_elements((1, (2, 3), 2, (1, 3))) == (1, 2, 3)
def test_unique_deeply_nested_tuple():
assert unique_tuple_elements((1, (... | [
{
"docstring": "Helper function to flatten the tuple.\nYields elements deeply from nested tuples.",
"function_declaration": "def flatten(tup):",
"function_name": "flatten",
"parameter_list": "(tup)"
},
{
"docstring": "Returns a tuple with unique elements while preserving the order.",
"fu... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def tuple_unique_elements(tpl):\n \"\"\"\n Remove duplicate elements from the tuple (including nested tuples) while retaining original order.\n \"\"\"\n seen = set()\n def make_... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036496",
"row_id": 36496,
"seed_ids": "['Qwen2-72B-Instruct_81463']"
} | 0.68191 | Filter_36496 | I | [
"flatten",
"unique_tuple_elements"
] | 2 | [
[
"unique_tuple_elements",
"flatten"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4a0e94e1c2fac5050eb830ed45f4220c3a62fdff | e691263a2b4a1d4b28b695871cdf5d177da6e60c | |||
v1.0 | instruct | Filter | Filter_36499_I | Reimplement the quicksort algorithm using an iterative approach instead of a recursive approach. Additionally, optimize the algorithm to have a time complexity of O(nlogn) and a space complexity of O(logn). | def quicksort_iterative(arr):
"""
Perform an iterative quicksort on the provided array.
"""
if len(arr) <= 1:
return arr
stack = [(0, len(arr) - 1)]
while stack:
low, high = stack.pop()
if low < high:
p = partition(arr, low, high)
st... | from solution import quicksort_iterative
def test_sorted_array():
arr = [1, 2, 3, 4, 5]
assert quicksort_iterative(arr) == [1, 2, 3, 4, 5]
def test_reverse_sorted_array():
arr = [5, 4, 3, 2, 1]
assert quicksort_iterative(arr) == [1, 2, 3, 4, 5]
def test_random_array():
arr = [3, 1, 4, 1, 5, 9, 2,... | [
{
"docstring": "Perform an iterative quicksort on the provided array.",
"function_declaration": "def quicksort_iterative(arr):",
"function_name": "quicksort_iterative",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"functi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def iterative_quicksort(arr):\n \"\"\"\n Sorts the array using an iterative quicksort algorithm.\n \"\"\"\n size = len(arr)\n stack = [(0, size - 1)]\n \n while stack:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036499",
"row_id": 36499,
"seed_ids": "['Qwen2-72B-Instruct_81469']"
} | 0.530015 | Filter_36499 | I | [
"quicksort_iterative",
"partition"
] | 2 | [
[
"quicksort_iterative",
"partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4dadf71e53080da2688e7ea78c9e21052f428b80 | 93fb676901d8c3f366e0d70ce81a1611e5366751 | |||
v1.0 | instruct | Filter | Filter_36502_I | Write a Python function that takes a list of integers and returns True if all of the numbers in the list are prime. If any number in the list is not prime, the function should return False. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import all_primes
def test_all_primes_with_prime_numbers():
assert all_primes([2, 3, 5, 7, 11]) == True
def test_all_primes_with_non_prime_number():
assert all_primes([2, 3, 4, 5, 7]) == False
def test_all_primes_with_all_non_prime_numbers():
assert all_primes([1, 4, 6, 8, 9]) == False
def... | [
{
"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 True if all numbers in lst are prime, otherwise False.",
"function_declaration": "def all_primes(ls... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True # 2 is the only ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036502",
"row_id": 36502,
"seed_ids": "['Qwen2-72B-Instruct_81478']"
} | 0.828798 | Filter_36502 | I | [
"is_prime",
"all_primes"
] | 2 | [
[
"all_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ab013b8585654dd026da3083c67412d0315d8d25 | 108872dc9f8adaa6ff862edab7e7ebe6a3843493 | |||
v1.0 | instruct | Filter | Filter_36515_I | Given two 3-dimensional numpy arrays A and B, write a numpy program to compute the matrix product of A and B. Also, optimize the computation using Strassen’s Matrix multiplication algorithm for better performance in higher dimensional matrices. | import numpy as np
def strassen_multiply(A, B):
"""
Perform Strassen's matrix multiplication algorithm on 3-dimensional numpy arrays A and B.
"""
assert A.shape == B.shape, "Matrices must be of the same shape"
assert A.shape[1] == A.shape[2], "Matrices should be square in the last two dimensions"
... | import numpy as np
from solution import matrix_product
def test_multiply_simple_case():
A = np.array([[[1, 2], [3, 4]]])
B = np.array([[[5, 6], [7, 8]]])
expected = np.array([[[19, 22], [43, 50]]])
assert np.array_equal(matrix_product(A, B), expected)
def test_multiply_identity():
A = np.array([[[... | [
{
"docstring": "Perform Strassen's matrix multiplication algorithm on 3-dimensional numpy arrays A and B.",
"function_declaration": "def strassen_multiply(A, B):",
"function_name": "strassen_multiply",
"parameter_list": "(A, B)"
},
{
"docstring": "Compute the matrix product of two 3-dimensio... | [
1,
0
] | 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 strassen_multiply(A, B):\n \"\"\"\n Perform Strassen's matrix multiplication algorithm on 3-dimensional numpy arrays A and B.\n \"\"\"\n assert A.shape ==... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036515",
"row_id": 36515,
"seed_ids": "['Qwen2-72B-Instruct_81497']"
} | 0.595096 | Filter_36515 | I | [
"strassen_multiply",
"matrix_product"
] | 2 | [
[
"matrix_product",
"strassen_multiply"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | b3a45010c6ed47fb970ed732903ff1f5c1142092 | 99d7123b66fde0da65c98ce590877b62d3c608d5 | |||
v1.0 | instruct | Filter | Filter_36552_I | I want to make a sketch program like Shazam, that's able to recognize music from an audio stream. I want to draw the results out using block diagrams with boxes and lines instead of using regular output methods such as text or audio. Can you guide me through making a program like this? | import numpy as np
import matplotlib.pyplot as plt
import librosa
import librosa.display
# Placeholder function: Record or capture the audio stream
def record_audio(duration=5, sr=22050):
"""
Simulates recording audio for a given duration and sample rate.
Returns a numpy array representing the audio.
"... | import numpy as np
from solution import record_audio, extract_features, match_song, draw_block_diagram, music_recognition_pipeline
def test_record_audio():
audio, sr = record_audio(duration=2)
assert isinstance(audio, np.ndarray)
assert sr == 22050
assert len(audio) > 0
def test_extract_features():
... | [
{
"docstring": "Simulates recording audio for a given duration and sample rate.\nReturns a numpy array representing the audio.",
"function_declaration": "def record_audio(duration=5, sr=22050):",
"function_name": "record_audio",
"parameter_list": "(duration=5, sr=22050)"
},
{
"docstring": "E... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom scipy.io import wavfile\nfrom scipy.fftpack import fft\nimport matplotlib.pyplot as plt\n\ndef read_audio(file_path):\n \"\"\"\n Reads an audio file and returns ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036552",
"row_id": 36552,
"seed_ids": "['Qwen2-72B-Instruct_81562']"
} | 0.309784 | Filter_36552 | I | [
"record_audio",
"extract_features",
"match_song",
"draw_block_diagram",
"music_recognition_pipeline"
] | 5 | [
[
"music_recognition_pipeline",
"draw_block_diagram"
],
[
"music_recognition_pipeline",
"extract_features"
],
[
"music_recognition_pipeline",
"match_song"
],
[
"music_recognition_pipeline",
"record_audio"
]
] | 4 | [] | false | [] | false | pytest | true | [
"librosa",
"matplotlib",
"numpy"
] | false | 2971ddd195caf40e6374341aceff42a3990ce757 | b16ad85f0c9a0fafc3712e321d273ca8b2cd1da7 | |||
v1.0 | instruct | Filter | Filter_36557_I | Explain how mutual recursion between even and odd functions can be implemented in programming to determine if a number is even or odd. Then, using this concept, write a program in your preferred language that firstly, establishes two mutually recursive functions named 'isEven' and 'isOdd'. These should accept an intege... | def isEven(n):
"""
Returns True if the number n is even, otherwise returns False.
Utilizes mutual recursion with isOdd function.
"""
if n < 0:
n = -n
if n == 0:
return True
else:
return isOdd(n - 1)
def isOdd(n):
"""
Returns True if the number n is odd, other... | from solution import isEven, isOdd
def test_isEven():
assert isEven(2) == True
assert isEven(0) == True
assert isEven(-2) == True
assert isEven(1) == False
assert isEven(-1) == False
def test_isOdd():
assert isOdd(2) == False
assert isOdd(0) == False
assert isOdd(-2) == False
asser... | [
{
"docstring": "Returns True if the number n is even, otherwise returns False.\nUtilizes mutual recursion with isOdd function.",
"function_declaration": "def isEven(n):",
"function_name": "isEven",
"parameter_list": "(n)"
},
{
"docstring": "Returns True if the number n is odd, otherwise retu... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def isEven(n):\n \"\"\"\n Returns True if the number n is even, otherwise returns False.\n Utilizes mutual recursion with isOdd function.\n \"\"\"\n if n < 0:\n n = -n\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036557",
"row_id": 36557,
"seed_ids": "['Qwen2-72B-Instruct_81570']"
} | 0.551569 | Filter_36557 | I | [
"isEven",
"isOdd",
"main"
] | 3 | [
[
"isEven",
"isOdd"
],
[
"isOdd",
"isEven"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d9fa42b94774931c1aabcee5d1b793e6da7b84f0 | 9bac37b2ae4da2a20b666664adb5dcceddf55799 | |||
v1.0 | instruct | Filter | Filter_36563_I | Use recursion to not only find the maximum value in a given list of integers, but also determine its index. Additionally, write a function that determines if more than one index contains this maximum value, and return all the indices where it appears. | def find_max_with_index(arr):
"""
Finds the maximum value in a given list and its index using recursion.
"""
def helper(arr, idx, max_val, max_idx):
if idx == len(arr):
return (max_val, max_idx)
elif arr[idx] > max_val:
return helper(arr, idx + 1, arr[idx], idx)
... | from solution import find_max_with_index, find_all_max_indices
def test_find_max_with_index_single_element():
assert find_max_with_index([5]) == (5, 0)
def test_find_max_with_index_multiple_elements():
assert find_max_with_index([1, 2, 3, 2, 1]) == (3, 2)
assert find_max_with_index([1, 3, 3, 2, 1]) == (3,... | [
{
"docstring": "Finds the maximum value in a given list and its index using recursion.",
"function_declaration": "def find_max_with_index(arr):",
"function_name": "find_max_with_index",
"parameter_list": "(arr)"
},
{
"docstring": "Finds all the indices containing the maximum value found in t... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_value_and_index(arr, index=0):\n \"\"\"\n Finds the maximum value and its index in a list recursively.\n \"\"\"\n if len(arr) == 1:\n return arr[0], index\n\n max... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036563",
"row_id": 36563,
"seed_ids": "['Qwen2-72B-Instruct_81581']"
} | 0.826136 | Filter_36563 | I | [
"find_max_with_index",
"find_all_max_indices"
] | 2 | [
[
"find_all_max_indices",
"find_max_with_index"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2068be5d28e20be762e5e10bbec7efa18cacd22c | 6aa1769178f648825b65ede334d915d5cf4e1643 | |||
v1.0 | instruct | Filter | Filter_36564_I | Write a Flask view to handle a GET request with the url "/hello". Additionally, include functionality to check if a user is logged in before accessing this view. If the user is not logged in, they should be redirected to a login page. The login check should be done using Flask's session. Add proper error handling for u... | from flask import Flask, session, redirect, url_for
from flask import jsonify # Just for returning a JSON response
app = Flask(__name__)
app.secret_key = 'supersecretkey' # This should be moved to a secure environment variable in production
def is_logged_in():
"""
Check if the user is logged in by checking ... | import pytest
from flask import Flask, session
from solution import app, is_logged_in
@pytest.fixture
def client():
app.config['TESTING'] = True
app.config['SECRET_KEY'] = 'supersecretkey'
with app.test_client() as client:
with app.app_context():
yield client
def test_hello_not_logged_... | [
{
"docstring": "Check if the user is logged in by checking the session.",
"function_declaration": "def is_logged_in():",
"function_name": "is_logged_in",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def hello():",
"function_name": "hello",
"parameter_li... | [
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, session, redirect, url_for, request\n\napp = Flask(__name__)\napp.secret_key = 'your_secret_key' # Needed for session management\n\n\n@app.route('/hello')\ndef hello(... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036564",
"row_id": 36564,
"seed_ids": "['Qwen2-72B-Instruct_81585']"
} | 0.582655 | Filter_36564 | I | [
"is_logged_in",
"hello",
"login"
] | 3 | [
[
"hello",
"is_logged_in"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 2c0cbcb00a5598398e1e28007e3647d1e398e335 | c747c59d5287188d0fb35668373403fae27d7342 | |||
v1.0 | instruct | Filter | Filter_36567_I | Can you explain the nuances behind the Python decorator process in a way that's understandable for a beginner? It would be helpful if you could provide concrete examples. | def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
def repeat(n):
def decorator(func):
def wrapper(*args, **kwargs):
for _ in ra... | from solution import my_decorator, repeat, say_hello, greet
def test_my_decorator(capsys):
say_hello()
captured = capsys.readouterr()
assert "Something is happening before the function is called." in captured.out
assert "Hello!" in captured.out
assert "Something is happening after the function is c... | [
{
"docstring": null,
"function_declaration": "def my_decorator(func):",
"function_name": "my_decorator",
"parameter_list": "(func)"
},
{
"docstring": null,
"function_declaration": "def repeat(n):",
"function_name": "repeat",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def my_decorator(func):\n def wrapper():\n print(\"Something is happening before the function is called.\")\n func()\n print(\"Something is happening after the function... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036567",
"row_id": 36567,
"seed_ids": "['Qwen2-72B-Instruct_81594']"
} | 0.380274 | Filter_36567 | I | [
"my_decorator",
"repeat",
"say_hello",
"greet"
] | 4 | [
[
"greet",
"repeat"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84f3a355e431317e8cf081283bded1712bbade58 | 5c5fa6db6404d844b31d47d1dd27050787069c4c | |||
v1.0 | instruct | Filter | Filter_36572_I | Implement an for loop in Python to iterate through a given list of numbers and print the square of each number, but only if the number is prime. The time complexity of your solution should be O(n√m), where n is the number of elements in the list and m is the maximum number in the list. | 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 print_prime_squares(numbers):
"""
Iterate through the provided list of numb... | from io import StringIO
import sys
import math
from solution import is_prime, print_prime_squares
def captured_output(func, *args, **kwargs):
old_stdout = sys.stdout
sys.stdout = StringIO()
try:
func(*args, **kwargs)
return sys.stdout.getvalue().strip()
finally:
sys.stdout = old... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Iterate through the provided list of numbers and print the square of \neach number if it is prime.",
"function_declaration... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n for i in range(3, int(num ** 0.5) + 1, 2):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036572",
"row_id": 36572,
"seed_ids": "['Qwen2-72B-Instruct_81600']"
} | 0.642287 | Filter_36572 | I | [
"is_prime",
"print_prime_squares"
] | 2 | [
[
"print_prime_squares",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa34b9cf4c6ca08235b3426ae13045bab6c94220 | 267dc6da20263ac4e2c6a465390c52053b310b6d | |||
v1.0 | instruct | Filter | Filter_36586_I | Write a script in Python to make an http request and extract the title of the webpage. However, you are not allowed to use any third-party libraries or modules for making the http request or parsing the HTML. You must implement the entire functionality from scratch using only built-in Python modules. | import socket
def get_http_response(url):
"""
Makes a simple HTTP GET request to the given URL and returns the raw response.
"""
host = url.split("//")[-1].split("/")[0]
path = "/" + "/".join(url.split("//")[-1].split("/")[1:])
port = 80
request = f"GET {path} HTTP/1.1\r\nHost: {host}\r\nC... | from solution import get_http_response, extract_title, get_webpage_title
def test_get_http_response():
response = get_http_response("http://example.com")
assert "Example Domain" in response
def test_extract_title():
html = "<html><head><title>Test Title</title></head><body></body></html>"
title = extr... | [
{
"docstring": "Makes a simple HTTP GET request to the given URL and returns the raw response.",
"function_declaration": "def get_http_response(url):",
"function_name": "get_http_response",
"parameter_list": "(url)"
},
{
"docstring": "Extracts the title from the given HTML string.",
"fun... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import socket\n\ndef get_http_response(url):\n \"\"\"\n Makes a simple HTTP GET request to the given URL and returns the raw response.\n \"\"\"\n host = url.split(\"//\")[-1].split... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036586",
"row_id": 36586,
"seed_ids": "['Qwen2-72B-Instruct_81632']"
} | 0.710223 | Filter_36586 | I | [
"get_http_response",
"extract_title",
"get_webpage_title"
] | 3 | [
[
"get_webpage_title",
"extract_title"
],
[
"get_webpage_title",
"get_http_response"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 094ebb19aab432af9f17268b33dc8ddff1372be3 | 1f6ed17dbfee9ce5d25d5c6e83d939ed87053164 | |||
v1.0 | instruct | Filter | Filter_36597_I | Convert a JSON string to an XML string with Python, while also handling nested JSON objects and arrays. | import json
from xml.etree.ElementTree import Element, tostring
def json_to_xml(json_obj, line_padding=""):
"""
Converts JSON object to XML string.
"""
def _to_xml_recurse(parent, data):
if isinstance(data, dict):
for key, value in data.items():
elem = Element(key)
... | from solution import convert_json_to_xml_string
def test_simple_json():
json_str = '{"a": 1, "b": "text"}'
expected_xml = '<root><a>1</a><b>text</b></root>'
assert convert_json_to_xml_string(json_str) == expected_xml
def test_nested_json():
json_str = '{"a": {"b": 2, "c": {"d": 3}}}'
expected_xml ... | [
{
"docstring": "Converts JSON object to XML string.",
"function_declaration": "def json_to_xml(json_obj, line_padding=''):",
"function_name": "json_to_xml",
"parameter_list": "(json_obj, line_padding='')"
},
{
"docstring": "Converts JSON string to XML string",
"function_declaration": "de... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import json\nfrom xml.etree.ElementTree import Element, tostring\n\ndef json_to_xml(json_obj, line_padding=\"\"):\n \"\"\"\n Converts a JSON object to an XML string.\n\n Args:\n js... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036597",
"row_id": 36597,
"seed_ids": "['Qwen2-72B-Instruct_81655']"
} | 0.743831 | Filter_36597 | I | [
"json_to_xml",
"convert_json_to_xml_string"
] | 2 | [
[
"convert_json_to_xml_string",
"json_to_xml"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d7c61d8f1a90e78a1fe51857e8af8d1d161c27a3 | ef1bffc60b8c645def8581fac8460c64388c77f3 | |||
v1.0 | instruct | Filter | Filter_36620_I | In Python, can you explain how one could implement a function that takes an integer 'n' and returns the smallest integer whose prime factors include all primes within 'n'? | import math
def sieve_of_eratosthenes(n):
"""
Generate all prime numbers up to n using the Sieve of Eratosthenes.
"""
is_prime = [True] * (n + 1)
is_prime[0], is_prime[1] = False, False # 0 and 1 are not primes
for i in range(2, int(n**0.5) + 1):
if is_prime[i]:
for j in ra... | from solution import smallest_multiple_with_all_primes
def test_smallest_multiple_with_all_primes():
assert smallest_multiple_with_all_primes(1) == 1 # no primes <= 1, so result is 1
assert smallest_multiple_with_all_primes(2) == 2 # only prime <= 2 is 2
assert smallest_multiple_with_all_primes(3) == 6 ... | [
{
"docstring": "Generate all prime numbers up to n using the Sieve of Eratosthenes.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Calculate the Least Common Multiple of two numbers a and b.",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef sieve_of_eratosthenes(n):\n \"\"\"\n Generate all prime numbers up to n using the Sieve of Eratosthenes.\n \"\"\"\n is_prime = [True] * (n + 1)\n is_prime[0],... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036620",
"row_id": 36620,
"seed_ids": "['Qwen2-72B-Instruct_81703']"
} | 0.725172 | Filter_36620 | I | [
"sieve_of_eratosthenes",
"lcm",
"smallest_multiple_with_all_primes"
] | 3 | [
[
"smallest_multiple_with_all_primes",
"lcm"
],
[
"smallest_multiple_with_all_primes",
"sieve_of_eratosthenes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2e6af86d7b195e8d32fd004c22f9de5a8b09b262 | b9cae20c461c5a82529d14a9b0f0813e52dfabba | |||
v1.0 | instruct | Filter | Filter_36623_I | How can I use Flask framework to create a web application that allows users to input a sentence and displays the same sentence in upper case? Additionally, what measures can I take to ensure that the user's input is properly sanitized to prevent any potential security vulnerabilities? Also, how can I implement a featur... | from flask import Flask, request, render_template_string
import logging
app = Flask(__name__)
# Set up logging
logging.basicConfig(filename='user_inputs.log', level=logging.INFO, format='%(asctime)s - %(message)s')
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
input_s... | # To test the application, Flask testing utilities and pytest are required.
from solution import app, sanitize_input
def test_index_get(client):
response = client.get('/')
assert response.status_code == 200
assert b'Sentence:' in response.data
def test_index_post(client):
response = client.post('/', ... | [
{
"docstring": null,
"function_declaration": "def index():",
"function_name": "index",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def sanitize_input(user_input):",
"function_name": "sanitize_input",
"parameter_list": "(user_input)"
}
] | [
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\nimport logging\n\napp = Flask(__name__)\n\n# Setting up logging\nlogging.basicConfig(filename='user_inputs.log', level=logging.INFO)\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036623",
"row_id": 36623,
"seed_ids": "['Qwen2-72B-Instruct_81710']"
} | 0.467496 | Filter_36623 | I | [
"index",
"sanitize_input"
] | 2 | [
[
"index",
"sanitize_input"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | a61cb3f52c23fe337a697ae64e7ab3d548ab1745 | 24e1f43822f3ad065bd79bf7648611c4cf8be3f2 | |||
v1.0 | instruct | Filter | Filter_36627_I | Write a program to print out the first 30 prime numbers, implementing the Sieve of Eratosthenes algorithm. | def sieve_of_eratosthenes(limit):
"""
Returns a list of prime numbers up to the specified limit using the Sieve of Eratosthenes algorithm.
"""
sieve = [True] * (limit + 1)
sieve[0] = sieve[1] = False
for start in range(2, int(limit**0.5) + 1):
if sieve[start]:
for multiple in... | 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]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(2) == [2]
def test_first_n_primes():
assert first_n_primes(5) == [2, 3, 5, 7... | [
{
"docstring": "Returns a list of prime numbers up to the specified limit using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Returns the first n pri... | [
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 all primes less than n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n sieve = [True] * n\n p = 2\n while p *... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036627",
"row_id": 36627,
"seed_ids": "['Qwen2-72B-Instruct_81715']"
} | 0.555634 | Filter_36627 | I | [
"sieve_of_eratosthenes",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | fca340a541c227241f17cf6773921400786ab1f1 | f5625b8185ce42735342e3bf3d814c2db39670ff | |||
v1.0 | instruct | Filter | Filter_36633_I | Imagine you are a scientist working on a project where you need to simulate an asteroid traveling through space and impacting a planet. Your goal is to visualize the asteroid's journey and the impact it makes using Python. To do this, you will need to create a program that can generate a 3D animation of the asteroid's ... | import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
def asteroid_trajectory():
"""
Simulates an asteroid traveling through space and generates a 3D animation
of its trajectory and the resulting impact crater.
"""
... | from solution import asteroid_trajectory, plot_crater
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def test_asteroid_trajectory():
"""
Test the asteroid_trajectory function by checking that it produces a figure
and axes.
"""
fig = plt.figure()
ax = fig.add_subplot(11... | [
{
"docstring": "Simulates an asteroid traveling through space and generates a 3D animation\nof its trajectory and the resulting impact crater.",
"function_declaration": "def asteroid_trajectory():",
"function_name": "asteroid_trajectory",
"parameter_list": "()"
},
{
"docstring": "Plots an im... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nfrom matplotlib.animation import FuncAnimation\n\n# Function to generate a 3D animation of an aste... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036633",
"row_id": 36633,
"seed_ids": "['Qwen2-72B-Instruct_81725']"
} | 0.416191 | Filter_36633 | I | [
"asteroid_trajectory",
"plot_crater"
] | 2 | [
[
"asteroid_trajectory",
"plot_crater"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"mpl_toolkits",
"numpy"
] | false | 22bd7a7a918ea7b89708038fb7134eaa989ef6c8 | f12572fec7e2cca2e9bac4fac346fcba92b4cd90 | |||
v1.0 | instruct | Filter | Filter_36634_I | Write a program to find all prime numbers between 2 and 100 using a list comprehension in Python. Additionally, optimize the code by incorporating the fact that all primes are of the form 6k ± 1. | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import is_prime, find_primes
def test_is_prime():
# Testing known primes
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
assert is_prime(97) == True
# Testing known non-primes
assert is_prime(1) == False
... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find all prime numbers between 2 and 100 using a list comprehension.",
"function_declaration": "def find_pr... | [
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_2 | {
"original_instruction": "",
"prompt_id": "00036634",
"row_id": 36634,
"seed_ids": "['Qwen2-72B-Instruct_81726']"
} | 0.643295 | Filter_36634 | I | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 619186b944941216e219157b11ebf07f6b65b921 | 3a2c8983bfbafc92d5849bc47b32b863e2b2b34e | |||
v1.0 | instruct | Filter | Filter_36650_I | Write a program in Python for implementing the K-means clustering algorithm on the `Iris` dataset from the scikit-learn library. Additionally, include a visualization of the clusters using the matplotlib library. Your program should include options to select different initializations methods ('k-means++' or random) and... | import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
def plot_clusters(data, labels, centers, title):
"""
Plots the clusters and cluster centers.
:param data: The data points.
:param label... | from solution import kmeans_clustering
def test_kmeans_initialization_kmeans_plus_plus():
inertia = kmeans_clustering(init_method='k-means++')
assert inertia > 0, "SSE should be positive."
def test_kmeans_initialization_random():
inertia = kmeans_clustering(init_method='random')
assert inertia > 0, "S... | [
{
"docstring": "Plots the clusters and cluster centers.\n\n:param data: The data points.\n:param labels: The cluster labels.\n:param centers: The cluster centers.\n:param title: The title for the plot.",
"function_declaration": "def plot_clusters(data, labels, centers, title):",
"function_name": "plot_c... | [
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\nimport matplotlib.pyplot as plt\nfrom sklearn import datasets\nfrom sklearn.cluster import KMeans\n\ndef load_iris_data():\n iris = datasets.load_iris()\n return iris... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036650",
"row_id": 36650,
"seed_ids": "['Qwen2-72B-Instruct_81754']"
} | 0.623171 | Filter_36650 | I | [
"plot_clusters",
"kmeans_clustering"
] | 2 | [
[
"kmeans_clustering",
"plot_clusters"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy",
"sklearn"
] | false | febf0d5c0c84c47397823f6bb9512bf6c4bffdd9 | 85f49de75c1a6b0de581d0f179eb2d834107466d | |||
v1.0 | instruct | Filter | Filter_36677_I | Write a code that prints a given decimal number in binary, ternary, and octal representation, but with a twist. Instead of directly converting the number, you need to calculate its square, then convert that result to binary, ternary, and octal. Accomplish this, by writing functions for each conversion, without using in... | def to_binary(n):
"""
Convert a given positive integer n into its binary representation.
"""
if n == 0:
return "0"
binary = []
while n > 0:
binary.append(str(n % 2))
n = n // 2
return "".join(binary[::-1])
def to_ternary(n):
"""
Convert a given positive integ... | from solution import to_binary, to_ternary, to_octal, convert
def test_to_binary():
assert to_binary(0) == "0"
assert to_binary(1) == "1"
assert to_binary(2) == "10"
assert to_binary(5) == "101"
assert to_binary(10) == "1010"
def test_to_ternary():
assert to_ternary(0) == "0"
assert to_ter... | [
{
"docstring": "Convert a given positive integer n into its binary representation.",
"function_declaration": "def to_binary(n):",
"function_name": "to_binary",
"parameter_list": "(n)"
},
{
"docstring": "Convert a given positive integer n into its ternary (base-3) representation.",
"funct... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def to_binary(n):\n \"\"\"\n Convert a given positive integer n into its binary representation.\n \"\"\"\n if n == 0:\n return \"0\"\n binary = []\n while n > 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036677",
"row_id": 36677,
"seed_ids": "['Qwen2-72B-Instruct_81807']"
} | 0.602406 | Filter_36677 | I | [
"to_binary",
"to_ternary",
"to_octal",
"convert"
] | 4 | [
[
"convert",
"to_binary"
],
[
"convert",
"to_octal"
],
[
"convert",
"to_ternary"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 25af5fcbf983d19cd3bed0d158fb38dfa07ec224 | 8567441969f936ab23f7c3666a3e5e0c6e4ee75e | |||
v1.0 | instruct | Filter | Filter_36681_I | Given a list of words, create a reverse lookup dictionary (word as key, indices as values), and additionally implement a function that can handle variations of the words (uppercase, lowercase, or starting/ending white spaces). The function should return all index locations of the original case-sensitive word, as well a... | def create_reverse_lookup_dict(word_list):
"""
Given a list of words, create a reverse lookup dictionary where the word
is the key and the value is a list of indices where the word can be found.
"""
reverse_lookup = {}
# Populate the reverse lookup dictionary
for index, word in enumerat... | from solution import create_reverse_lookup_dict, find_word_indices
def test_create_reverse_lookup_dict():
word_list = ["apple", "Banana", " apple", "APPLE ", "bAnAnA"]
expected = {
"apple": [0, 2, 3],
"banana": [1, 4]
}
assert create_reverse_lookup_dict(word_list) == expected
def test_... | [
{
"docstring": "Given a list of words, create a reverse lookup dictionary where the word\nis the key and the value is a list of indices where the word can be found.",
"function_declaration": "def create_reverse_lookup_dict(word_list):",
"function_name": "create_reverse_lookup_dict",
"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 create_reverse_lookup(words):\n \"\"\"\n Create a reverse lookup dictionary from a list of words.\n \n Args:\n words (list of str): The list of words to process.\n \n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036681",
"row_id": 36681,
"seed_ids": "['Qwen2-72B-Instruct_81817']"
} | 0.589975 | Filter_36681 | I | [
"create_reverse_lookup_dict",
"find_word_indices"
] | 2 | [
[
"find_word_indices",
"create_reverse_lookup_dict"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9fd6024c1faf159f54f7dd6e5ff56a8223f011cd | 21a0bcc132df3de5fd9d0d33f9db7e751a3906b6 | |||
v1.0 | instruct | Filter | Filter_36683_I | Write a Python program that uses recursion to print all prime numbers between 1 and a given positive integer n, in reverse order. Consider implementing an auxiliary function for the primality test. | def is_prime(num):
"""
Returns True if num is a prime number, else 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
d... | from solution import is_prime, print_primes_reverse
def test_is_prime():
# Test known prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
# Test known non-prime numbers
assert is_prime(1) == False
assert is_prime(4) =... | [
{
"docstring": "Returns True if num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Recursively prints all prime numbers between 1 and n in reverse order.",
"function_declaration": "d... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036683",
"row_id": 36683,
"seed_ids": "['Qwen2-72B-Instruct_81819']"
} | 0.680103 | Filter_36683 | I | [
"is_prime",
"print_primes_reverse"
] | 2 | [
[
"print_primes_reverse",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fa77cd97581d2fd86cfbad31648e606163bcbdee | 58e170de17008e61b98de9db1969f1b4aac01b5f | |||
v1.0 | instruct | Filter | Filter_36704_I | Given an array of integers, rotate the array to the right by a given number of steps, in place and in an optimized manner, such that the operation does not exceed O(n) time and O(1) space complexity. | def rotate_array(arr, k):
"""
Rotates the array to the right by k steps.
"""
if not arr or k % len(arr) == 0:
return
k = k % len(arr)
arr.reverse()
reverse_segment(arr, 0, k - 1)
reverse_segment(arr, k, len(arr) - 1)
def reverse_segment(arr, start, end):
while start < e... | from solution import rotate_array
def test_rotate_array_by_zero():
arr = [1, 2, 3, 4, 5]
rotate_array(arr, 0)
assert arr == [1, 2, 3, 4, 5]
def test_rotate_array_by_length():
arr = [1, 2, 3, 4, 5]
rotate_array(arr, 5)
assert arr == [1, 2, 3, 4, 5]
def test_rotate_array_less_than_length():
... | [
{
"docstring": "Rotates the array to the right by k steps.",
"function_declaration": "def rotate_array(arr, k):",
"function_name": "rotate_array",
"parameter_list": "(arr, k)"
},
{
"docstring": null,
"function_declaration": "def reverse_segment(arr, start, end):",
"function_name": "r... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def rotate(nums, k):\n \"\"\"\n Rotates the array nums to the right by k steps.\n \n :param nums: List[int] -- List of integers\n :param k: int -- Number of steps to rotate the ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036704",
"row_id": 36704,
"seed_ids": "['Qwen2-72B-Instruct_81857']"
} | 0.591781 | Filter_36704 | I | [
"rotate_array",
"reverse_segment"
] | 2 | [
[
"rotate_array",
"reverse_segment"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aff0a112afba5754fd87533081708154507df318 | b8e234bcf1f10e8a1544049c64204506e077d72f | |||
v1.0 | instruct | Filter | Filter_36708_I | Write a code to filter out all prime numbers from an array which contains both prime and non-prime numbers. The filtered array should be sorted in ascending order. | def is_prime(n):
"""
Returns True if the number 'n' is a prime number, else returns 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 filter_and_sort_primes(arr):
"""
Filters out prime numbers f... | from solution import is_prime, filter_and_sort_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
def test_filter_and_sort_primes_empty_list():
assert filter_and_sort_primes([]) ... | [
{
"docstring": "Returns True if the number 'n' is a prime number, else returns False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out prime numbers from input array 'arr', and returns them sorted in ascending o... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036708",
"row_id": 36708,
"seed_ids": "['Qwen2-72B-Instruct_81863']"
} | 0.61452 | Filter_36708 | I | [
"is_prime",
"filter_and_sort_primes"
] | 2 | [
[
"filter_and_sort_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e232915bb94f3004acb2ed324873e6a950c906ce | 20394fe2fdf44f7a82c3bbe6beaf1f296a6efb23 | |||
v1.0 | instruct | Filter | Filter_36726_I | In Python, create a while loop that starts counting from -50 and ends at 0, displaying only the numbers that are divisible by 3 and 5. Additionally, you must use a function to check if the number is divisible by both 3 and 5, and the loop must not use a conditional statement to check the number's divisibility. | def is_divisible_by_3_and_5(number):
"""
Check if a number is divisible by both 3 and 5.
"""
return number % 3 == 0 and number % 5 == 0
def print_numbers_divisible_by_3_and_5():
"""
Print numbers from -50 to 0 that are divisible by both 3 and 5.
"""
number = -50
while number <= 0:
... | from solution import is_divisible_by_3_and_5, print_numbers_divisible_by_3_and_5
def test_is_divisible_by_3_and_5():
assert is_divisible_by_3_and_5(-15) == True
assert is_divisible_by_3_and_5(0) == True
assert is_divisible_by_3_and_5(15) == True
assert is_divisible_by_3_and_5(-30) == True
assert is... | [
{
"docstring": "Check if a number is divisible by both 3 and 5.",
"function_declaration": "def is_divisible_by_3_and_5(number):",
"function_name": "is_divisible_by_3_and_5",
"parameter_list": "(number)"
},
{
"docstring": "Print numbers from -50 to 0 that are divisible by both 3 and 5.",
... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def check_divisibility(num):\n \"\"\"\n Returns True if num is divisible by both 3 and 5, otherwise False.\n \"\"\"\n return num % 15 == 0\n\ndef display_n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036726",
"row_id": 36726,
"seed_ids": "['Qwen2-72B-Instruct_81893']"
} | 0.539362 | Filter_36726 | I | [
"is_divisible_by_3_and_5",
"print_numbers_divisible_by_3_and_5"
] | 2 | [
[
"print_numbers_divisible_by_3_and_5",
"is_divisible_by_3_and_5"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 233a112bae016893e50609852c55b2b076f78396 | 92659ae2c9294b4cfddde7cc32f10b8cffddea32 | |||
v1.0 | instruct | Filter | Filter_36735_I | Create a program that generates a list of 25 distinct prime numbers between 10 and 200. However, the program should not use any built-in functions or libraries to determine whether a number is prime. Instead, you should implement your own algorithm to check for primality. Additionally, provide an error handling mechani... | def is_prime(n):
"""
Checks if a number is prime.
"""
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def generate_primes(min_range, max_range, number_of_primes):
"""
Generates a list of distinct prime num... | from solution import is_prime, generate_primes
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(-10)
assert is_prime(199)
def test_generate_primes_standard():
prime... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates a list of distinct prime numbers within a given range.",
"function_declaration": "def generate_primes(min_range, ma... | [
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 prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036735",
"row_id": 36735,
"seed_ids": "['Qwen2-72B-Instruct_81911']"
} | 0.554301 | Filter_36735 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 30fec4d2b36b88b84b15dcda64a316381c084de0 | 5b71b110699026a4d4b5f666074d801695ce3384 | |||
v1.0 | instruct | Filter | Filter_36741_I | We have a list of numbers, some of which are prime. Write a python function "filter_primes" that takes in a list of integers and filters out all the non-prime numbers. Additionally, the function should only consider numbers greater than 100. The function should return a new list containing only the prime numbers from t... | def is_prime(n):
"""
Helper function to check if a number is a 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... | from solution import filter_primes
def test_filter_primes_basic():
assert filter_primes([101, 102, 103, 104, 105, 106, 107]) == [101, 103, 107]
def test_filter_primes_with_non_primes():
assert filter_primes([110, 111, 112, 113, 114, 115, 116, 117]) == [113]
def test_filter_primes_only_primes():
assert fi... | [
{
"docstring": "Helper function to check if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filters out non-prime numbers and numbers <= 100 from the given list,\nreturning a new list with only prime n... | [
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 a prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036741",
"row_id": 36741,
"seed_ids": "['Qwen2-72B-Instruct_81922']"
} | 0.634265 | Filter_36741 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e2d374fed09ee51de35eab8d35672ea7a19bd0a8 | 89ecbcbf62731b7bfe9b8ae4f03c558d6c922e4f | |||
v1.0 | instruct | Filter | Filter_36764_I | Use a for loop to print all prime numbers from 1 to 100 in separate lines, and calculate the sum of these prime numbers. In addition, your program should also calculate and print the average of these prime numbers. Finally, modify your program to print the prime numbers in a pyramid pattern. | def is_prime(num):
"""Check 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 prime_numbers_up_to_100():
"""Finds and processes prime numbers from 1 to 100."""
primes = []
for nu... | from solution import is_prime, prime_numbers_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(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_prime_numbe... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Finds and processes prime numbers from 1 to 100.",
"function_declaration": "def prime_numbers_up_to_100():",
"function... | [
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(num):\n \"\"\"\n Check if `num` is a prime number.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036764",
"row_id": 36764,
"seed_ids": "['Qwen2-72B-Instruct_81962']"
} | 0.576637 | Filter_36764 | I | [
"is_prime",
"prime_numbers_up_to_100"
] | 2 | [
[
"prime_numbers_up_to_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e3d5f64791660a9144049081295a8c9afadc2ef0 | 788349dfe2e4804c006dd22bb32ecd2d678b7ad7 | |||
v1.0 | instruct | Filter | Filter_36784_I | Create a function in Python that takes in a positive integer n as input and returns an array of size n, where the elements are in descending order from n to 1. Additionally, each element in the array must be a prime number. | def is_prime(num):
"""
Check if a given number is prime.
"""
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
... | from solution import is_prime, prime_desc_array
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(25) == False
def test_prime_desc_array_single_element():
assert prime_desc_array(1) == [2]
def tes... | [
{
"docstring": "Check if a given number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns an array of size n, where the elements are prime numbers in descending order.",
"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 is_prime(num):\n \"\"\"\n Check if a given number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00036784",
"row_id": 36784,
"seed_ids": "['Qwen2-72B-Instruct_81991']"
} | 0.757896 | Filter_36784 | I | [
"is_prime",
"prime_desc_array"
] | 2 | [
[
"prime_desc_array",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6d1e669f4cdcbf53eb62ca24bb34ad428c12f5fc | 4b4b9bf973e014f648d50e3ebac8bd933b3037ac | |||
v1.0 | instruct | Filter | Filter_36817_I | Write a Python program that performs an in-place quick sort on an array of integers. The program should use a non-recursive implementation of the quicksort algorithm using a stack to manage the subarray indices, and it should handle dublicates values well. Additionally, include a method to measure the time taken to sor... | import time
def quick_sort(arr):
"""
Performs an in-place quick sort on the provided array of integers using a non-recursive implementation.
"""
if len(arr) <= 1:
return arr
# Create a stack for storing subarray indices
stack = [(0, len(arr) - 1)]
# Loop until the stack is em... | from solution import quick_sort, timed_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_array():
assert quick_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_quick_sort_reverse_sorte... | [
{
"docstring": "Performs an in-place quick sort on the provided array of integers using a non-recursive implementation. ",
"function_declaration": "def quick_sort(arr):",
"function_name": "quick_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Partition the array into two parts and return... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\n\ndef in_place_quick_sort(arr):\n \"\"\"\n Performs an in-place non-recursive quicksort on an array of integers.\n \"\"\"\n if not arr:\n return\n\n # Create... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036817",
"row_id": 36817,
"seed_ids": "['Qwen2-72B-Instruct_82046']"
} | 0.570642 | Filter_36817 | I | [
"quick_sort",
"partition",
"timed_quick_sort"
] | 3 | [
[
"quick_sort",
"partition"
],
[
"timed_quick_sort",
"quick_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 99c7a67c6e00df40634cd8557dcd4e23b2a3d60d | 6b5c730bfa50b729c55fac371bbe1d475a703ac8 | |||
v1.0 | instruct | Filter | Filter_36866_I | Develop a Python program to generate a list with numbers in range 3 to 12. The program should only include odd numbers in the list, and the solution should be implemented using a recursive function. | def generate_odd_numbers(start, end):
"""
Recursively generate a list of odd numbers from start to end (inclusive).
Assumes start and end are both integers and start <= end.
"""
if start > end:
return []
if start % 2 == 0:
return generate_odd_numbers(start + 1, end)
return [s... | from solution import odd_numbers_in_range
def test_generate_odd_numbers_entire_range():
assert odd_numbers_in_range(3, 12) == [3, 5, 7, 9, 11]
def test_generate_odd_numbers_with_start_offset():
assert odd_numbers_in_range(5, 12) == [5, 7, 9, 11]
def test_generate_odd_numbers_with_end_before_12():
assert ... | [
{
"docstring": "Recursively generate a list of odd numbers from start to end (inclusive).\nAssumes start and end are both integers and start <= end.",
"function_declaration": "def generate_odd_numbers(start, end):",
"function_name": "generate_odd_numbers",
"parameter_list": "(start, end)"
},
{
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_odd_numbers(start, end):\n \"\"\"\n Generates a list of odd numbers recursively within the given range [start, end].\n\n Args:\n start (int): The starting number of th... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036866",
"row_id": 36866,
"seed_ids": "['Qwen2-72B-Instruct_82141']"
} | 0.677005 | Filter_36866 | I | [
"generate_odd_numbers",
"odd_numbers_in_range"
] | 2 | [
[
"odd_numbers_in_range",
"generate_odd_numbers"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 291cee3512e74080883accd252d65226c01135cb | 2a737b109b99d6eec97c9c105924ca5b79f0f1cc | |||
v1.0 | instruct | Filter | Filter_36868_I | Implement an algorithm using Python programming language that changes the color codes of multiple web elements from hexadecimal to RGB format. The elements are enclosed in a Python list. Also, the function should be able to handle any invalid hexadecimal color codes gracefully. | import re
def hex_to_rgb(hex_code):
"""
Converts a hexadecimal color code to an RGB tuple.
Returns (None, None, None) if the input is not a valid hex code.
"""
# Check for valid hexadecimal color code format
if re.match(r"^#[0-9A-Fa-f]{6}$", hex_code):
r = int(hex_code[1:3], 16)
... | from solution import hex_to_rgb, convert_hex_list_to_rgb
def test_valid_hex_to_rgb():
assert hex_to_rgb("#FFFFFF") == (255, 255, 255)
assert hex_to_rgb("#000000") == (0, 0, 0)
assert hex_to_rgb("#FF5733") == (255, 87, 51)
def test_invalid_hex_to_rgb():
assert hex_to_rgb("FFFFFF") == (None, None, None)... | [
{
"docstring": "Converts a hexadecimal color code to an RGB tuple.\nReturns (None, None, None) if the input is not a valid hex code.",
"function_declaration": "def hex_to_rgb(hex_code):",
"function_name": "hex_to_rgb",
"parameter_list": "(hex_code)"
},
{
"docstring": "Converts a list of hexa... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef hex_to_rgb(hex_color):\n \"\"\"\n Converts a hexadecimal color code to an RGB tuple.\n Handles invalid hexadecimal color codes by returning None.\n \"\"\"\n if ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036868",
"row_id": 36868,
"seed_ids": "['Qwen2-72B-Instruct_82146']"
} | 0.478624 | Filter_36868 | I | [
"hex_to_rgb",
"convert_hex_list_to_rgb"
] | 2 | [
[
"convert_hex_list_to_rgb",
"hex_to_rgb"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a11e8e4a7f4ac0297571ed43508ae00c5cc4f3e0 | 7d78a952ee0dc58603d1529e85932940d8bef653 | |||
v1.0 | instruct | Filter | Filter_36873_I | Write a Python program to generate ten distinct random alphanumeric strings of varying lengths from 6 to 12 characters. Each string should contain at least one lowercase letter, one uppercase letter, one digit, and one special character from the set [!, @, #, $, %, ^, &, *]. Store these strings in a list and output the... | import random
import string
def generate_char_set():
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
digits = string.digits
specials = '!@#$%^&*'
return lowercase, uppercase, digits, specials
def generate_random_string(length):
lowercase, uppercase, digits, specials = gen... | from solution import generate_unique_strings
def test_generate_unique_strings():
results = generate_unique_strings()
assert len(results) == 10
for random_string in results:
assert 6 <= len(random_string) <= 12
assert any(char.islower() for char in random_string)
assert any(char... | [
{
"docstring": null,
"function_declaration": "def generate_char_set():",
"function_name": "generate_char_set",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def generate_random_string(length):",
"function_name": "generate_random_string",
"parameter_list"... | [
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\ndef generate_random_string(length):\n \"\"\"\n Generate a random alphanumeric string of given length that includes at least one lowercase letter,\n one... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036873",
"row_id": 36873,
"seed_ids": "['Qwen2-72B-Instruct_82152']"
} | 0.739237 | Filter_36873 | I | [
"generate_char_set",
"generate_random_string",
"generate_unique_strings"
] | 3 | [
[
"generate_random_string",
"generate_char_set"
],
[
"generate_unique_strings",
"generate_random_string"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0a5f5aba3467bed13d8bbf96aed5d1d7c63c74de | 0638ca89ccad35446ad80427466f3e6eac69a12e | |||
v1.0 | instruct | Filter | Filter_36911_I | Use a while loop to add all prime numbers between 1 and 500 to a list. Include error handling that will prevent the program from crashing if it encounters a value that cannot be analyzed as a numerical value. | def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False
p = 3
while p * p <= n:
if n % p == 0:
return False
p += 2
return True
def pri... | from solution import is_prime, prime_numbers_between_1_and_500, safe_prime_numbers_between_1_and_500
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(-1)
def test_prime_num... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return a list of all prime numbers between 1 and 500.",
"function_declaration": "def prime_numbers_between_1_and_500():",
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if nu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036911",
"row_id": 36911,
"seed_ids": "['Qwen2-72B-Instruct_82216']"
} | 0.576754 | Filter_36911 | I | [
"is_prime",
"prime_numbers_between_1_and_500",
"safe_prime_numbers_between_1_and_500"
] | 3 | [
[
"prime_numbers_between_1_and_500",
"is_prime"
],
[
"safe_prime_numbers_between_1_and_500",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ab3a2baca93938bccf616a3f081a17c0178481b5 | 7015579546c67aa1782f142eceba281606e6f714 | |||
v1.0 | instruct | Filter | Filter_36924_I | Modify and correct the given erroneous code to delete an element from the following list at a given index. Additionally, write a function to validate the input for index. If the index is out of range or not an integer, your function should return a message: "Please enter a valid index". Also, incorporate a functionalit... | def validate_index(index, lst):
"""
Validates the index for deletion.
Args:
index (int): The index to be validated.
lst (list): The list from which an element needs to be deleted.
Returns:
bool: True if index is valid, otherwise False.
"""
if not isinstance(index, int) or i... | import pytest
from unittest.mock import patch
def test_validate_index():
test_list = [1, 2, 3, 4, 5]
assert validate_index(2, test_list) == True
assert validate_index(-1, test_list) == False
assert validate_index(5, test_list) == False
assert validate_index('a', test_list) == False
@patch('builtin... | [
{
"docstring": "Validates the index for deletion.\n\nArgs:\nindex (int): The index to be validated.\nlst (list): The list from which an element needs to be deleted.\n\nReturns:\nbool: True if index is valid, otherwise False.",
"function_declaration": "def validate_index(index, lst):",
"function_name": "... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def validate_index(index, lst):\n \"\"\"\n Validates if the index is an integer and within the range of the list.\n \n Parameters:\n index (int): The index to validate.\n lst... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036924",
"row_id": 36924,
"seed_ids": "['Qwen2-72B-Instruct_82239']"
} | 0.436886 | Filter_36924 | I | [
"validate_index",
"delete_element"
] | 2 | [
[
"delete_element",
"validate_index"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 79bc977308c57d1e016cfe200f18e2566ffc7a11 | 1de7432ce1ec9f77437b3186af1ed4a7fc7d4ea8 | |||
v1.0 | instruct | Filter | Filter_36936_I | Write a Python program to generate the first n Fibonacci numbers, where n is a positive integer input from the user. Also, modify the code to handle larger inputs efficiently using memoization. Ensure that there are no floating-point precision issues by only using integer calculations. | def fibonacci(n, memo={}):
"""
Generate the first n Fibonacci numbers efficiently using memoization.
Parameters:
- n: The number of Fibonacci numbers to generate (positive integer).
Returns:
- A list of the first n Fibonacci numbers.
"""
if n <= 0:
return []
if n ==... | from solution import fibonacci
def test_fibonacci_zero():
assert fibonacci(0) == []
def test_fibonacci_one():
assert fibonacci(1) == [0]
def test_fibonacci_two():
assert fibonacci(2) == [0, 1]
def test_fibonacci_five():
assert fibonacci(5) == [0, 1, 1, 2, 3]
def test_fibonacci_ten():
assert fib... | [
{
"docstring": "Generate the first n Fibonacci numbers efficiently using memoization.\n\nParameters:\n- n: The number of Fibonacci numbers to generate (positive integer).\n\nReturns:\n- A list of the first n Fibonacci numbers.",
"function_declaration": "def fibonacci(n, memo={}):",
"function_name": "fib... | [
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 first n Fibonacci numbers using memoization.\n \"\"\"\n if n <= 0:\n return []\n \n memo = [0] * (n + 2)\n memo[1] = 1\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036936",
"row_id": 36936,
"seed_ids": "['Qwen2-72B-Instruct_82258']"
} | 0.738484 | Filter_36936 | I | [
"fibonacci",
"fib"
] | 2 | [
[
"fibonacci",
"fib"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 30f89be6f73571854992faf529dd024290bb645e | 8b73d074dae115c507d077a8c355e365f1d0c480 | |||
v1.0 | instruct | Filter | Filter_36942_I | numbers = [19, 3, 4, 5, 8, 12, 33, 1, 2]. Implement Partition exchange sort (also known as quick sort) in Python to sort this list. Also, implement functionality to choose the pivot as the median of the first, middle and last element to improve the performance on already or nearly sorted lists. | def quick_sort(arr):
"""
Function to sort an array using quick sort algorithm with pivot
as the median of the first, middle, and last elements.
"""
if len(arr) <= 1:
return arr
else:
pivot = median_of_three(arr)
less = [x for x in arr if x < pivot]
equal = [x for ... | from solution import quick_sort
def test_quick_sort_unsorted_list():
assert quick_sort([19, 3, 4, 5, 8, 12, 33, 1, 2]) == [1, 2, 3, 4, 5, 8, 12, 19, 33]
def test_quick_sort_empty_list():
assert quick_sort([]) == []
def test_quick_sort_single_element_list():
assert quick_sort([1]) == [1]
def test_quick_s... | [
{
"docstring": "Function to sort an array using quick sort algorithm with pivot\nas the median of the first, middle, and last elements.",
"function_declaration": "def quick_sort(arr):",
"function_name": "quick_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Function to find the median of... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def partition(arr, low, high):\n \"\"\"\n This function takes the median of first, middle, and last element as the pivot,\n partitions the array around the pivot and returns the index... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036942",
"row_id": 36942,
"seed_ids": "['Qwen2-72B-Instruct_82268']"
} | 0.655682 | Filter_36942 | I | [
"quick_sort",
"median_of_three"
] | 2 | [
[
"quick_sort",
"median_of_three"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 62908c289ef10807a1048f357c357c94f849323d | 04c720cdb89872dbb6c8fb539881cd46dbc08937 | |||
v1.0 | instruct | Filter | Filter_36950_I | Given a dataset of 1000 images varying in size, the task is to create thumbnail images of all these. The images should not become out of shape in the process, and it must be carried out using Python code. Additionally, the thumbnails should adhere to a specific aspect ratio and resolution requirements, and the resultin... | from PIL import Image
import os
def create_thumbnail(image_path, thumbnail_path, size):
"""
Creates a thumbnail for an image while maintaining aspect ratio.
:param image_path: Path to the original image
:param thumbnail_path: Path where the thumbnail will be saved
:param size: Tuple (width, he... | import os
from PIL import Image
from solution import create_thumbnail, create_thumbnails_for_folder
def test_create_thumbnail():
image_path = 'test_image.jpg'
thumbnail_path = 'test_thumbnail.jpg'
size = (100, 100)
# Create a test image
img = Image.new('RGB', (200, 200), color = (73, 109, 137))
... | [
{
"docstring": "Creates a thumbnail for an image while maintaining aspect ratio.\n\n:param image_path: Path to the original image\n:param thumbnail_path: Path where the thumbnail will be saved\n:param size: Tuple (width, height) of the thumbnail",
"function_declaration": "def create_thumbnail(image_path, th... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nfrom PIL import Image\n\ndef create_thumbnail(image_path, thumb_size=(128, 128), thumb_folder=\"thumbnails\"):\n \"\"\"\n Creates a thumbnail for the given image and saves it ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036950",
"row_id": 36950,
"seed_ids": "['Qwen2-72B-Instruct_82276']"
} | 0.446321 | Filter_36950 | I | [
"create_thumbnail",
"create_thumbnails_for_folder"
] | 2 | [
[
"create_thumbnails_for_folder",
"create_thumbnail"
]
] | 1 | [] | false | [] | false | pytest | true | [
"PIL"
] | false | 4488add002d682690326b585b7c9b8fde4e6029a | d6c60d1980ce26fc906d188cb36d83630751bf13 | |||
v1.0 | instruct | Filter | Filter_36953_I | Write code for displaying the Fibonacci sequence up to the nth term, where the nth term is provided as input by the user. Additionally, implement a method to calculate the sum of all the Fibonacci numbers up to the nth term and display it. The code should also check if the nth term is a prime number and display a messa... | def fibonacci_sequence(n):
"""
Returns the Fibonacci sequence up to the nth term.
"""
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
sequence = [0, 1]
for i in range(2, n):
sequence.append(sequence[-1] + sequence[-2])
return s... | from solution import fibonacci_sequence, sum_fibonacci_sequence, is_prime, display_fibonacci_info
def test_fibonacci_sequence():
assert fibonacci_sequence(0) == []
assert fibonacci_sequence(1) == [0]
assert fibonacci_sequence(2) == [0, 1]
assert fibonacci_sequence(5) == [0, 1, 1, 2, 3]
assert fibon... | [
{
"docstring": "Returns the Fibonacci sequence up to the nth term.",
"function_declaration": "def fibonacci_sequence(n):",
"function_name": "fibonacci_sequence",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of the Fibonacci sequence up to the nth term.",
"function_declarati... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def fibonacci_sequence(n):\n \"\"\"\n Returns a list containing Fibonacci sequence up to the nth term.\n \"\"\"\n if n <= 0:\n return []\n sequence = [0, 1]\n for i in... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00036953",
"row_id": 36953,
"seed_ids": "['Qwen2-72B-Instruct_82282']"
} | 0.694791 | Filter_36953 | I | [
"fibonacci_sequence",
"sum_fibonacci_sequence",
"is_prime",
"display_fibonacci_info"
] | 4 | [
[
"display_fibonacci_info",
"fibonacci_sequence"
],
[
"display_fibonacci_info",
"is_prime"
],
[
"display_fibonacci_info",
"sum_fibonacci_sequence"
],
[
"sum_fibonacci_sequence",
"fibonacci_sequence"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | f11e3c3f3f73101f5c26a4b9e0f1d69ffd86bc74 | a85fbe50bdee5fdfc568e1a2e4410830e796fc3b | |||
v1.0 | instruct | Filter | Filter_36972_I | Write a function in Python that takes in a list of positive integers and returns the second smallest unique prime number. If there is no second smallest unique prime number, the function should return None. | def is_prime(n):
"""Helper function to 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 second_smallest_unique_prime(numbers):
"""
Returns the second smallest unique prime number fr... | from solution import second_smallest_unique_prime
def test_no_primes():
assert second_smallest_unique_prime([4, 6, 8, 10]) == None
def test_only_one_prime():
assert second_smallest_unique_prime([5, 10, 15, 20]) == None
def test_normal_case():
assert second_smallest_unique_prime([2, 3, 5, 7, 11, 2, 3]) ==... | [
{
"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 the second smallest unique prime number from the list of positive integers.\nIf there is no second smal... | [
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 \"\"\"Helper function to 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": "00036972",
"row_id": 36972,
"seed_ids": "['Qwen2-72B-Instruct_82319']"
} | 0.704857 | Filter_36972 | I | [
"is_prime",
"second_smallest_unique_prime"
] | 2 | [
[
"second_smallest_unique_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c9ab2685a765db49103f21ae8d2c97ead2b519b1 | cfccc7479bf53921869213aee7cc82d4c96c69f0 | |||
v1.0 | instruct | Filter | Filter_36974_I | Let's write a Python program to implement a basic blockchain algorithm for storing transaction data. I'd like each block to consist of a block ID, the hash of the block's data, the hash of the previous block, a difficulty target, and a nonce for proof-of-work. Additionally, can you include a function that allows genera... | import hashlib
import time
class Block:
def __init__(self, block_id, transactions, previous_hash, difficulty):
self.block_id = block_id
self.timestamp = time.time()
self.transactions = transactions
self.previous_hash = previous_hash
self.difficulty = difficulty
self.... | import pytest
from solution import Block, Blockchain, create_genesis_block, add_transaction_to_blockchain
def test_block_creation():
block = Block(1, "test transactions", "000000", 2)
assert block.block_id == 1
assert block.transactions == "test transactions"
assert block.previous_hash == "000000"
... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import hashlib\nimport time\n\nclass Block:\n def __init__(self, index, previous_hash, transactions, difficulty=2):\n self.index = index\n self.timestamp = time.time()\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00036974",
"row_id": 36974,
"seed_ids": "['Qwen2-72B-Instruct_82321']"
} | 0.371863 | Filter_36974 | I | [
"create_genesis_block",
"create_transaction_data",
"add_transaction_to_blockchain"
] | 3 | [
[
"add_transaction_to_blockchain",
"create_transaction_data"
]
] | 1 | [] | false | [
"Block",
"Blockchain"
] | true | pytest | true | [] | true | d6693bb6d0aa96a0d0c4a4fd2473f578da7c0613 | 2990e1325b0fc9f4a00fb48014ff7f44825d90a2 | |||
v1.0 | instruct | Filter | Filter_37038_I | Implement a function in Python to reverse the contents of a given dictionary, ensuring that all keys and values are of type string. The function should also handle dictionaries nested within the original dictionary and reverse their contents as well. The input dictionary should have at least 5 key-value pairs. The func... | import re
def is_valid_key(key):
"""
Checks if the key is a valid lowercase alphanumeric string with a minimum length of 3 characters.
"""
return isinstance(key, str) and bool(re.match(r'^[a-z0-9]{3,}$', key))
def reverse_dict(d):
"""
Reverses the contents of a dictionary ensuring that all key... | import pytest
from solution import reverse_dict
def test_reverse_dict_simple():
input_dict = {
"foo": "bar",
"baz": "qux",
"abc": "xyz",
"hij": "klm",
"nop": "qrs"
}
expected_output = {
"bar": "foo",
"qux": "baz",
"xyz": "abc",
"klm": ... | [
{
"docstring": "Checks if the key is a valid lowercase alphanumeric string with a minimum length of 3 characters.",
"function_declaration": "def is_valid_key(key):",
"function_name": "is_valid_key",
"parameter_list": "(key)"
},
{
"docstring": "Reverses the contents of a dictionary ensuring t... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_key(key):\n return isinstance(key, str) and bool(re.match(r'^[a-z0-9]{3,}$', key))\n\ndef reverse_dict(d):\n \"\"\"\n Reverses the contents of a dictionary, ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037038",
"row_id": 37038,
"seed_ids": "['Qwen2-72B-Instruct_82425']"
} | 0.667931 | Filter_37038 | I | [
"is_valid_key",
"reverse_dict"
] | 2 | [
[
"reverse_dict",
"is_valid_key"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e956df323d7e1dbd6acf101d496e80a9d989596a | a771355dc1b8673a288a35e57b6834e7cc53adad | |||
v1.0 | instruct | Filter | Filter_37041_I | Create a python function that takes a single integer as an argument and returns the corresponding digit as a string, but only if the digit is prime. The function should also check if the input is within the range of 1 to 10^9, inclusive, and raise an exception if it is outside this range. Additionally, optimize your so... | 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 single_prime_digit, is_prime
def test_prime_digit_within_range():
assert single_prime_digit(2) == "2"
assert single_prime_digit(3) == "3"
assert single_prime_digit(5) == "5"
assert single_prime_digit(7) == "7"
def test_non_prime_single_digits():
assert single_prime_digit(1) is... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given a single integer, returns the corresponding digit as a string if it is prime.\nRaises an exception if the input is outside 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 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_0 | {
"original_instruction": "",
"prompt_id": "00037041",
"row_id": 37041,
"seed_ids": "['Qwen2-72B-Instruct_82428']"
} | 0.667074 | Filter_37041 | I | [
"is_prime",
"single_prime_digit"
] | 2 | [
[
"single_prime_digit",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 75d6de5c2d5fc67e1538c5d8ace39a90ff5428f5 | dd68296dec8cd6629e16d3b17b3c5fd9c5c2573a | |||
v1.0 | instruct | Filter | Filter_37072_I | Write a program to approximate the derivative of a given function using the finite difference method. You can assume the availability of a function for the evaluation of the function at any given point, a function for printing the derivative at any point and an error function to compare the derivative obtained by your ... | def finite_difference_derivative(func, x, h=1e-5):
"""
Approximates the derivative of func at point x using the finite difference method.
Parameters:
func (function): The function for which we want to find the derivative.
x (float): The point at which to evaluate the derivative.
h (float, optio... | from solution import finite_difference_derivative, print_derivative, error
def test_finite_difference_derivative():
func = lambda x: x**2 # The function f(x) = x^2
x = 3
exact_derivative = 2 * x # The exact derivative f'(x) = 2x at x = 3
assert abs(finite_difference_derivative(func, x) - exact_deriva... | [
{
"docstring": "Approximates the derivative of func at point x using the finite difference method.\n\nParameters:\nfunc (function): The function for which we want to find the derivative.\nx (float): The point at which to evaluate the derivative.\nh (float, optional): A small number for the finite difference cal... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def function(x):\n \"\"\"\n Example function for which we want to approximate the derivative.\n For the sake of demonstration, let's use f(x) = x^2.\n \"\"\"\n return x**2\n\nde... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037072",
"row_id": 37072,
"seed_ids": "['Qwen2-72B-Instruct_82476']"
} | 0.511125 | Filter_37072 | I | [
"finite_difference_derivative",
"print_derivative",
"error"
] | 3 | [
[
"error",
"finite_difference_derivative"
],
[
"print_derivative",
"finite_difference_derivative"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 935a61d7b3fa7086cbfb5872c8b4d20f88b7f220 | 633aca4226bb2db1350f4cc7cc27ccb87aec37bc | |||
v1.0 | instruct | Filter | Filter_37091_I | Implement the Caesar Cipher algorithm in a programming language of your choice. The function should accept a string and a shift value as parameters and return the encrypted text. Additionally, create a decryption function that can take the encrypted text and the shift value to return the original message. Also, add fun... | def caesar_cipher_encrypt(text, shift):
"""
Encrypts the given text using Caesar Cipher algorithm with the given shift.
"""
encrypted_text = []
for char in text:
if char.isupper():
encrypted_text.append(chr((ord(char) + shift - 65) % 26 + 65))
elif char.islower():
... | from solution import caesar_cipher_encrypt, caesar_cipher_decrypt
def test_caesar_cipher_encrypt_basic():
assert caesar_cipher_encrypt('abc', 1) == 'bcd'
def test_caesar_cipher_encrypt_with_mixed_case():
assert caesar_cipher_encrypt('aBc', 1) == 'bCd'
def test_caesar_cipher_encrypt_with_wrap():
assert ca... | [
{
"docstring": "Encrypts the given text using Caesar Cipher algorithm with the given shift.",
"function_declaration": "def caesar_cipher_encrypt(text, shift):",
"function_name": "caesar_cipher_encrypt",
"parameter_list": "(text, shift)"
},
{
"docstring": "Decrypts the given text using Caesar... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def caesar_encrypt(text, shift):\n \"\"\"\n Encrypts the text using Caesar Cipher with the given shift.\n Handles both upper and lowercase letters.\n \"\"\"\n result = []\n f... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037091",
"row_id": 37091,
"seed_ids": "['Qwen2-72B-Instruct_82507']"
} | 0.691874 | Filter_37091 | I | [
"caesar_cipher_encrypt",
"caesar_cipher_decrypt"
] | 2 | [
[
"caesar_cipher_decrypt",
"caesar_cipher_encrypt"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b6864045a36704b97184b57c3f78f908e8c4e3a1 | a48ab552fb11c4cd55a4d63f9f4b206ccb2e0fbb | |||
v1.0 | instruct | Filter | Filter_37109_I | Create a Python script to sum up all the elements in a 2-dimensional list, but only consider the elements that are prime numbers. | def is_prime(num):
"""
Check 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 sum_primes(matrix):
"""
Sum up all the prime numbers in a 2-dimensional list (matrix).
"""... | from solution import sum_primes, is_prime
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(1) == False
def test_sum_primes_empty():
assert sum_primes([]) == 0
def test_sum_primes_no_primes():
... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Sum up all the prime numbers in a 2-dimensional list (matrix).",
"function_declaration": "def sum_primes(matrix):",
"f... | [
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 is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037109",
"row_id": 37109,
"seed_ids": "['Qwen2-72B-Instruct_82540']"
} | 0.591211 | Filter_37109 | I | [
"is_prime",
"sum_primes"
] | 2 | [
[
"sum_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2b91a2f64af9e1f08fbb0e9d11cc86749b4d69c4 | ff85f4d283b518cd18f74f8fd10e898b0516ce38 | |||
v1.0 | instruct | Filter | Filter_37124_I | Given is a decimal number: n = 1994. Print out the number in binary format. Then execute the following algorithm: Generate two random decimal numbers a and b within the range of 0 to n. Convert both numbers to binary format, not using any in-built Python functions for conversion. Make sure the function generating binar... | import random
def decimal_to_binary(n):
binary = ""
if n == 0:
return "0"
while n > 0:
binary = str(n % 2) + binary
n = n // 2
return binary
def bitwise_operations(n):
# Step 1: Convert n to binary
n_binary = decimal_to_binary(n)
print(f"Binary of {n}: {n_binary}")
... | from solution import decimal_to_binary
def test_decimal_to_binary():
assert decimal_to_binary(0) == "0"
assert decimal_to_binary(1) == "1"
assert decimal_to_binary(2) == "10"
assert decimal_to_binary(3) == "11"
assert decimal_to_binary(4) == "100"
assert decimal_to_binary(5) == "101"
assert... | [
{
"docstring": null,
"function_declaration": "def decimal_to_binary(n):",
"function_name": "decimal_to_binary",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def bitwise_operations(n):",
"function_name": "bitwise_operations",
"parameter_list": "(n)"
}... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\n\ndef to_binary(n):\n \"\"\"\n Convert a decimal number to binary format.\n \"\"\"\n if n == 0:\n return \"0\"\n binary = \"\"\n while n > 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037124",
"row_id": 37124,
"seed_ids": "['Qwen2-72B-Instruct_82573']"
} | 0.707479 | Filter_37124 | I | [
"decimal_to_binary",
"bitwise_operations"
] | 2 | [
[
"bitwise_operations",
"decimal_to_binary"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ea4d0d2f7fdf4797b226b3ea6e2dc3192249b1b9 | 5792442ebf29883335e6aae48ea9931b237fc135 | |||
v1.0 | instruct | Filter | Filter_37144_I | Write Python code that takes the complement of a DNA strand and then finds the reverse complement. Then, write a function that checks if a DNA strand is palindromic, i.e., reads the same clockwise and anticlockwise in the nucleotide bases adenine, cytosine, guanine, thymine. | def complement_dna(dna):
"""
Returns the complement of a DNA strand.
"""
complement = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
return ''.join(complement[base] for base in dna)
def reverse_complement_dna(dna):
"""
Returns the reverse complement of a DNA strand.
"""
return complement_... | from solution import complement_dna, reverse_complement_dna, is_palindromic_dna
def test_complement_dna():
assert complement_dna("A") == "T"
assert complement_dna("T") == "A"
assert complement_dna("C") == "G"
assert complement_dna("G") == "C"
assert complement_dna("ATCG") == "TAGC"
def test_revers... | [
{
"docstring": "Returns the complement of a DNA strand.",
"function_declaration": "def complement_dna(dna):",
"function_name": "complement_dna",
"parameter_list": "(dna)"
},
{
"docstring": "Returns the reverse complement of a DNA strand.",
"function_declaration": "def reverse_complement_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def complement_dna(dna):\n \"\"\"\n Returns the complement of a DNA strand.\n A <--> T\n C <--> G\n \"\"\"\n complement = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}\n return... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037144",
"row_id": 37144,
"seed_ids": "['Qwen2-72B-Instruct_82603']"
} | 0.62821 | Filter_37144 | I | [
"complement_dna",
"reverse_complement_dna",
"is_palindromic_dna"
] | 3 | [
[
"is_palindromic_dna",
"reverse_complement_dna"
],
[
"reverse_complement_dna",
"complement_dna"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2be0959c3e3ccd04c89cbb21399d5a11f25e9f69 | c872a3ff1c3d682acb7fa40d75b385812e3a652f | |||
v1.0 | instruct | Filter | Filter_37171_I | Given a list of programming terms and jargon, write a program that organizes these terms in increasing alphabetical order, displays them, and also generates a usage example for each term. Also, for an added challenge, ensure that the programming terms are first filtered out from a mixed list of general English words an... | def is_programming_term(word):
"""
Checks if the given word is a programming term by comparing it against a known list of programming terms.
"""
programming_terms = ["algorithm", "array", "function", "loop", "variable", "syntax", "class", "object", "inheritance", "recursion"]
return word.lower() in ... | from solution import is_programming_term, organize_and_display_terms
def test_is_programming_term():
assert is_programming_term("algorithm") == True
assert is_programming_term("apple") == False
assert is_programming_term("loop") == True
assert is_programming_term("banana") == False
assert is_progra... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef filter_and_sort_programming_terms(mixed_list):\n \"\"\"\n Filters programming terms from a mixed list and sorts them alphabetically.\n \n Args:\n mixed_list (li... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00037171",
"row_id": 37171,
"seed_ids": "['Qwen2-72B-Instruct_82648']"
} | 0.471817 | Filter_37171 | I | [
"is_programming_term",
"organize_and_display_terms",
"generate_usage_example"
] | 3 | [
[
"organize_and_display_terms",
"generate_usage_example"
],
[
"organize_and_display_terms",
"is_programming_term"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7cff6cbcf68b4b268429fcdde9072453b99d3f82 | ce99d5baa88b9ae76da23b65c3c9419171ce45f9 | |||
v1.0 | instruct | Filter | Filter_37186_I | Write a python program to display Armstrong numbers till a given limit. | def is_armstrong(number):
"""
Checks if the given number is an Armstrong number.
"""
num_str = str(number)
num_length = len(num_str)
sum_of_powers = sum(int(digit) ** num_length for digit in num_str)
return sum_of_powers == number
def armstrong_numbers_till_limit(limit):
"""
Returns... | from solution import is_armstrong, armstrong_numbers_till_limit
def test_is_armstrong():
assert is_armstrong(0) == True
assert is_armstrong(1) == True
assert is_armstrong(153) == True
assert is_armstrong(370) == True
assert is_armstrong(371) == True
assert is_armstrong(9474) == True
assert ... | [
{
"docstring": "Checks if the given number is an Armstrong number.",
"function_declaration": "def is_armstrong(number):",
"function_name": "is_armstrong",
"parameter_list": "(number)"
},
{
"docstring": "Returns a list of Armstrong numbers up to the specified limit.",
"function_declaratio... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def armstrong_numbers(limit):\n \"\"\"\n Returns a list of Armstrong numbers up to the given limit.\n An Armstrong number for a given number of digits is a number \n that is equal ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00037186",
"row_id": 37186,
"seed_ids": "['Qwen2-72B-Instruct_82678']"
} | 0.470921 | Filter_37186 | I | [
"is_armstrong",
"armstrong_numbers_till_limit"
] | 2 | [
[
"armstrong_numbers_till_limit",
"is_armstrong"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 74a8ce314f7d9123e8ae1d6874d8c189e012043b | bf76319b61236adf5b9319406c5d2694483b5218 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.