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_32524_I | Please implement two Python functions, `sum_proper_divisors(num)` and `is_perfect_number(num)`. The first function, `sum_proper_divisors(num)`, should calculate the sum of all proper divisors of a given number `num`. Proper divisors are numbers less than `num` which divide evenly into `num`. The second function, `is_pe... | def sum_proper_divisors(num):
"""
Returns the sum of all proper divisors of num.
Proper divisors are numbers less than num which divide evenly into num.
"""
if num <= 1:
return 0
total = 1 # 1 is a proper divisor of any number > 1
for i in range(2, int(num**0.5) + 1):
... | from solution import sum_proper_divisors, is_perfect_number
def test_sum_proper_divisors():
assert sum_proper_divisors(1) == 0
assert sum_proper_divisors(6) == 6
assert sum_proper_divisors(28) == 28
assert sum_proper_divisors(12) == 16
assert sum_proper_divisors(25) == 6
def test_is_perfect_number... | [
{
"docstring": "Returns the sum of all proper divisors of num.\nProper divisors are numbers less than num which divide evenly into num.",
"function_declaration": "def sum_proper_divisors(num):",
"function_name": "sum_proper_divisors",
"parameter_list": "(num)"
},
{
"docstring": "Returns True... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_proper_divisors(num):\n \"\"\"\n Returns the sum of all proper divisors of num.\n Proper divisors are numbers less than num which divide evenly into num.\n \"\"\"\n if n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032524",
"row_id": 32524,
"seed_ids": "['Qwen2-72B-Instruct_74570']"
} | 0.712024 | Filter_32524 | I | [
"sum_proper_divisors",
"is_perfect_number"
] | 2 | [
[
"is_perfect_number",
"sum_proper_divisors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9c438fdc0ccff805d67ffed730d14dcda6f17483 | 61c8afa2069141374d9850790853f29f40bd8593 | |||
v1.0 | instruct | Filter | Filter_32525_I | Please write a python script that will send an email with a log file as an attachment and the command to run it as a cron job once a month. Additionally, please include a function that allows the user to input multiple email addresses and choose the frequency of the email (e.g., weekly, bi-weekly, monthly). Finally, pl... | import smtplib
import os
import csv
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from datetime import datetime
log_file = 'logfile.log'
def send_email(smtp_server, smtp_port, sender_email, sender_password, receiver_... | import os
import csv
def setup_module(module):
if not os.path.exists('logfile.log'):
open('logfile.log', 'w').close()
def teardown_module(module):
try:
os.remove('logfile.log')
except OSError:
pass
def test_log_event():
from solution import log_event
log_event('Test event... | [
{
"docstring": "Sends an email with the specified parameters and an attachment.\n\n:param smtp_server: SMTP server address\n:param smtp_port: SMTP server port\n:param sender_email: Email address to send from\n:param sender_password: Password for the sender email\n:param receiver_emails: List of receiver email a... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import smtplib\nimport os\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.base import MIMEBase\nfrom email import encoders\nimport logging\nfrom datetime import datetime\nimpo... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032525",
"row_id": 32525,
"seed_ids": "['Qwen2-72B-Instruct_74571']"
} | 0.450485 | Filter_32525 | I | [
"send_email",
"log_event",
"choose_frequency_and_input_emails",
"generate_cronjob_command",
"display_statistics"
] | 5 | [
[
"send_email",
"log_event"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dbdfd1c6390855ef687555ba6ffc5c3d3b0f1525 | 21cb367292820edf0a827320f3953e188bd4ad12 | |||
v1.0 | instruct | Filter | Filter_32533_I | Write a Python function that generates the Fibonacci sequence up to n and identifies the prime numbers within that sequence. Also, optimize the function to handle large values of n efficiently. In addition, include functionality that allows the user to check if a specific number is within the generated Fibonacci sequen... | def fibonacci_primes_up_to_n(n):
"""
Generates the Fibonacci sequence up to n and identifies the prime numbers within that sequence.
Also allows checking if a specific number is within the generated Fibonacci sequence.
Args:
n (int): The upper bound for generating the Fibonacci sequence.
... | from solution import fibonacci_primes_up_to_n, is_in_fibonacci_sequence, is_prime
def test_fibonacci_primes_up_to_n():
fib_sequence, primes_in_fib = fibonacci_primes_up_to_n(21)
assert fib_sequence == [0, 1, 1, 2, 3, 5, 8, 13, 21]
assert primes_in_fib == [2, 3, 5, 13]
def test_is_prime():
assert is_pr... | [
{
"docstring": "Generates the Fibonacci sequence up to n and identifies the prime numbers within that sequence.\nAlso allows checking if a specific number is within the generated Fibonacci sequence.\n\nArgs:\nn (int): The upper bound for generating the Fibonacci sequence.\n\nReturns:\ntuple: A tuple containing ... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_fibonacci(n):\n \"\"\"\n Generates the Fibonacci sequence up to the nth term.\n \"\"\"\n fib_sequence = []\n a, b = 0, 1\n for _ in range(n):\n fib_sequen... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032533",
"row_id": 32533,
"seed_ids": "['Qwen2-72B-Instruct_74584']"
} | 0.796833 | Filter_32533 | I | [
"fibonacci_primes_up_to_n",
"is_prime",
"is_in_fibonacci_sequence"
] | 3 | [
[
"fibonacci_primes_up_to_n",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5466224f8ef628f9604cd67d9f30bf807a0d3314 | c56251c53a58eade2bff5b19e43ca9e8153be023 | |||
v1.0 | instruct | Filter | Filter_32545_I | Write a python program which will tell if a number is odd or even. If it is an even number, your program should check if the number is a perfect square or not. If it's an odd number, find out if it's a prime number or not. Implement this solution with a time complexity better than O(log n). | import math
def is_even(n):
"""
Check if a number is even.
"""
return n % 2 == 0
def is_perfect_square(n):
"""
Check if a number is a perfect square.
"""
sqrt_n = int(math.sqrt(n))
return sqrt_n * sqrt_n == n
def is_prime(n):
"""
Check if a number is prime.
"""
if ... | from solution import check_number, is_even, is_perfect_square, is_prime
def test_is_even():
assert is_even(2) == True
assert is_even(3) == False
def test_is_perfect_square():
assert is_perfect_square(4) == True
assert is_perfect_square(5) == False
def test_is_prime():
assert is_prime(2) == True
... | [
{
"docstring": "Check if a number is even.",
"function_declaration": "def is_even(n):",
"function_name": "is_even",
"parameter_list": "(n)"
},
{
"docstring": "Check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_sq... | [
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_even(n):\n \"\"\"\n Check if a number is even.\n \"\"\"\n return n % 2 == 0\n\ndef is_perfect_square(n):\n \"\"\"\n Check if a number is a perfect squar... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032545",
"row_id": 32545,
"seed_ids": "['Qwen2-72B-Instruct_74599']"
} | 0.621756 | Filter_32545 | I | [
"is_even",
"is_perfect_square",
"is_prime",
"check_number"
] | 4 | [
[
"check_number",
"is_even"
],
[
"check_number",
"is_perfect_square"
],
[
"check_number",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 5fb2f86236ad369aa6a3267b65ccd0c1ea0a66cd | a39b399e0bb9bb87a3bebc98911c8aea208e9075 | |||
v1.0 | instruct | Filter | Filter_32559_I | Given a URL, write a Python program to extract all the email addresses present in the webpage. Also ensure to check if the email addresses are valid or not. Make sure your program can handle exceptions and errors appropriately. | import requests
import re
from urllib.parse import urlparse
def is_valid_email(email):
"""
Validates the email address using a regex pattern.
"""
email_regex = re.compile(
r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")
return re.match(email_regex, email) is not None
def extract_ema... | from solution import extract_emails, is_valid_email
def test_is_valid_email():
assert is_valid_email("test@example.com")
assert not is_valid_email("test@example")
assert not is_valid_email("test@.com")
assert is_valid_email("user.name+tag+sorting@example.com")
def test_extract_emails(monkeypatch):
... | [
{
"docstring": "Validates the email address using a regex pattern.",
"function_declaration": "def is_valid_email(email):",
"function_name": "is_valid_email",
"parameter_list": "(email)"
},
{
"docstring": "Extracts email addresses from the specified webpage URL and validates them.",
"func... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nimport re\nfrom urllib.parse import urlparse\n\ndef is_valid_email(email):\n \"\"\"\n Validates the email address using a regex pattern.\n \"\"\"\n email_regex = r... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032559",
"row_id": 32559,
"seed_ids": "['Qwen2-72B-Instruct_74621']"
} | 0.60677 | Filter_32559 | I | [
"is_valid_email",
"extract_emails"
] | 2 | [
[
"extract_emails",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [
"requests"
] | false | f78814185b3a1760afc6595f83b3ae5f01fd980a | 755ba60d22a4ffb7685e7bcaf02b9ae54badcae3 | |||
v1.0 | instruct | Filter | Filter_32564_I | Given an array of integers, sort the array in-place using quick sort. | def quick_sort(arr, low, high):
"""
Implements the quick sort algorithm to sort an array of integers in place.
"""
if low < high:
# Partition the array and get the pivot index
pi = partition(arr, low, high)
# Recursively sort elements before and after the partition
... | from solution import quick_sort
def test_quick_sort_single_element():
arr = [1]
quick_sort(arr, 0, len(arr) - 1)
assert arr == [1]
def test_quick_sort_sorted_array():
arr = [1, 2, 3, 4, 5]
quick_sort(arr, 0, len(arr) - 1)
assert arr == [1, 2, 3, 4, 5]
def test_quick_sort_reverse_sorted_array(... | [
{
"docstring": "Implements the quick sort algorithm to sort an array of integers in place.",
"function_declaration": "def quick_sort(arr, low, high):",
"function_name": "quick_sort",
"parameter_list": "(arr, low, high)"
},
{
"docstring": "Helper function to partition the array and find the p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort(arr, low, high):\n \"\"\"\n Sorts the array in place using the quicksort algorithm.\n \"\"\"\n if low < high:\n pi = partition(arr, low, high)\n quickso... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032564",
"row_id": 32564,
"seed_ids": "['Qwen2-72B-Instruct_74627']"
} | 0.575053 | Filter_32564 | I | [
"quick_sort",
"partition"
] | 2 | [
[
"quick_sort",
"partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a0db7dd57b7a984ff4e069aaa25bc45202282fae | 129ce11592b122b7f58eb22519a44b321cf0b4e7 | |||
v1.0 | instruct | Filter | Filter_32587_I | Is there a way to find the count of prime numbers between two given numbers in a programming language? I want to write a function that takes two arguments, let's call them 'start' and 'end', and returns the count of prime numbers within that range. Can you provide a solution in Python? Please include comments to explai... | import math
def is_prime(n):
"""
Checks if a given number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, count_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_count_primes_small_range():
assert count_primes(10, 20) == 4 # primes: 11, 13, 1... | [
{
"docstring": "Checks if a given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the count of prime numbers between start and end (inclusive).",
"function_declaration": "def count_primes(sta... | [
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 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_1 | {
"original_instruction": "",
"prompt_id": "00032587",
"row_id": 32587,
"seed_ids": "['Qwen2-72B-Instruct_74662']"
} | 0.738108 | Filter_32587 | I | [
"is_prime",
"count_primes"
] | 2 | [
[
"count_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9780ff20b76f611dfcaea71e6de014d24b99b39a | 32b27f622cc7505be2a367b268b1ae4df88225c6 | |||
v1.0 | instruct | Filter | Filter_32602_I | Develop a Python program that generates and returns a list of twin primes between 1 and a given number N. Additionally, the program should calculate and print the total number of twin primes found and their average. Note: Twin primes are a pair of primes that differ by 2, such as (3, 5), (5, 7), (11, 13), etc. | def is_prime(n):
"""Check if the number is a 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 twin_primes(N):
"""
Generates ... | from solution import is_prime, twin_primes
def test_is_prime():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert is_prime(29)
assert not is_prime(30)
def test_twin_primes():
assert twin_primes(1) ==... | [
{
"docstring": "Check if the number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates and returns a list of twin primes between 1 and N.\nAlso returns the total number of twin primes and their average."... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Check if the number is a prime.\"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032602",
"row_id": 32602,
"seed_ids": "['Qwen2-72B-Instruct_74685']"
} | 0.612941 | Filter_32602 | I | [
"is_prime",
"twin_primes"
] | 2 | [
[
"twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b12a4ff1cd1d2e8d7c639dd11b76e50bb417d26f | 621ff9dd19d59e803fa878905d60d8f2f928205c | |||
v1.0 | instruct | Filter | Filter_32628_I | Write a function to reverse the contents of a stack without using any additional data structures, and with only constant extra space. | def reverse_stack(stack):
"""
Reverses the contents of the given stack using recursion.
This function uses constant extra space.
"""
if len(stack) == 0:
return
# Pop the top item
top = stack.pop()
# Reverse the remaining stack
reverse_stack(stack)
# Insert ... | from solution import reverse_stack
def test_reverse_stack_single_item():
stack = [1]
reverse_stack(stack)
assert stack == [1]
def test_reverse_stack_two_items():
stack = [1, 2]
reverse_stack(stack)
assert stack == [2, 1]
def test_reverse_stack_multiple_items():
stack = [1, 2, 3]
rever... | [
{
"docstring": "Reverses the contents of the given stack using recursion.\nThis function uses constant extra space.",
"function_declaration": "def reverse_stack(stack):",
"function_name": "reverse_stack",
"parameter_list": "(stack)"
},
{
"docstring": null,
"function_declaration": "def in... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_stack(stack):\n \"\"\"\n Reverses the content of a stack in place.\n \"\"\"\n if not stack:\n return\n \n top = stack.pop()\n reverse_stack(stack)\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032628",
"row_id": 32628,
"seed_ids": "['Qwen2-72B-Instruct_74733']"
} | 0.523342 | Filter_32628 | I | [
"reverse_stack",
"insert_at_bottom"
] | 2 | [
[
"reverse_stack",
"insert_at_bottom"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 65ce9c809c643cbc07e297a3c898d5bac6ba0f73 | bc2a62b0f4fbabe15bf3df9c29e5d2d3b7ec8f67 | |||
v1.0 | instruct | Filter | Filter_32653_I | Given a list of integers, write a function to remove all prime numbers from the list. Additionally, for every number that is removed, insert a comment in the code that explains why that particular number was identified as a prime number and thus, removed. | def is_prime(n):
"""
Helper function to check if a number is prime.
Parameters:
n (int): The number to check for primality.
Returns:
bool: True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
... | from solution import is_prime, remove_primes
def test_is_prime():
assert is_prime(2) == True # 2 is the only even prime number
assert is_prime(3) == True # 3 is a prime number
assert is_prime(4) == False # 4 is not a prime number because it can be divided by 2
assert is_prime(5) == True # 5 is a pr... | [
{
"docstring": "Helper function to check if a number is prime.\nParameters:\n n (int): The number to check for primality.\nReturns:\n bool: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def remove_primes(numbers):\n \"\"\"\n Removes all prime numbers from the list of integers.\n \"\"\"\n def is_prime(n):\n if n <= 1:\n return False\n if n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032653",
"row_id": 32653,
"seed_ids": "['Qwen2-72B-Instruct_74766']"
} | 0.576447 | Filter_32653 | I | [
"is_prime",
"remove_primes"
] | 2 | [
[
"remove_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 21afa3a44d2678588dfd8ef1486ccd717b3a343d | e14f4adf97f27c789ae9889daaedfd3c7757488d | |||
v1.0 | instruct | Filter | Filter_32682_I | Devise a Python web spider program that selectively scrapes only text content from a given web URL, including hidden elements' text but excluding any form of advertisements. The spider should also avoid adult content websites or sections, and should follow and scrape text from up to 2 levels of linked pages deep from t... | import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin
import re
def is_advertisement(element):
"""
Function to check if a BeautifulSoup element is an advertisement.
"""
if element.has_attr('class'):
classes = element.get('class')
for class_ in classes:
... | from solution import is_advertisement, is_adult_content, scrape_text
from bs4 import BeautifulSoup
def test_is_advertisement():
# Simulate BeautifulSoup element with ad-related class
soup = BeautifulSoup('<div class="ad"></div>', 'html.parser')
assert is_advertisement(soup.div)
soup = BeautifulSou... | [
{
"docstring": "Function to check if a BeautifulSoup element is an advertisement.",
"function_declaration": "def is_advertisement(element):",
"function_name": "is_advertisement",
"parameter_list": "(element)"
},
{
"docstring": "Simple function to check if URL might belong to adult content.",... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import requests\nfrom bs4 import BeautifulSoup, Comment\nfrom urllib.parse import urljoin, urlparse\nimport re\n\ndef identify_advertisement(tag):\n \"\"\"Function to identify advertisement... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032682",
"row_id": 32682,
"seed_ids": "['Qwen2-72B-Instruct_74813']"
} | 0.663767 | Filter_32682 | I | [
"is_advertisement",
"is_adult_content",
"scrape_text"
] | 3 | [
[
"scrape_text",
"is_adult_content"
],
[
"scrape_text",
"is_advertisement"
]
] | 2 | [] | false | [] | false | pytest | true | [
"bs4",
"requests"
] | false | 87ed691e0fa6355c0f5b746df8811fb4af2bd6aa | c98c80850c54ec073e0bb91e0b0bd96521f89005 | |||
v1.0 | instruct | Filter | Filter_32683_I | Write a Python script that prints out "Hello, World!" only if the current date is a prime number and the hour is a prime number, using the 24-hour clock format. Additionally, the script should determine if the prime number date and hour are both Fibonacci numbers. If both the date and hour are prime and Fibonacci numbe... | from datetime import datetime
import math
# Helper functions
def is_prime(n):
"""
Determines if the given number n is a prime number.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(math.sqrt(n))+1, 2):
if ... | from solution import is_prime, is_fibonacci
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(-3) == False
def test_is_fibonacci():
assert is_fibonacci(0) == True
... | [
{
"docstring": "Determines if the given number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Determines if the given number n is a Fibonacci number.",
"function_declaration": "def is_fibonacci(n)... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import datetime\n\ndef 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*... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032683",
"row_id": 32683,
"seed_ids": "['Qwen2-72B-Instruct_74814']"
} | 0.595175 | Filter_32683 | I | [
"is_prime",
"is_fibonacci",
"is_perfect_square",
"print_hello_world"
] | 4 | [
[
"is_fibonacci",
"is_perfect_square"
],
[
"print_hello_world",
"is_fibonacci"
],
[
"print_hello_world",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 81a1c40f7df3d344bb17e8eed5f184830d3230c3 | 868831b0423ffbb8d95bce9f07686771c0dc39cb | |||
v1.0 | instruct | Filter | Filter_32687_I | Write a python code to read a large text file and count the frequency of words in it. Also, add functionality to exclude a list of common stop words from your calculation. The code should be efficient for large files and memory-friendly. Below is a python code snippet that reads a large text file, counts the word frequ... | import re
from collections import Counter
def is_stop_word(word, stop_words):
"""
Helper function to check if a word is a stop word.
"""
return word in stop_words
def read_large_file(file_path):
"""
Generator function to read a large file line by line.
"""
with open(file_path, 'r', enc... | import pytest
from solution import count_word_frequency
@pytest.fixture
def sample_text_file(tmp_path):
d = tmp_path / "sub"
d.mkdir()
file_path = d / "sample.txt"
sample_text = """This is a sample text file.
It contains some words for testing.
This sample is u... | [
{
"docstring": "Helper function to check if a word is a stop word.",
"function_declaration": "def is_stop_word(word, stop_words):",
"function_name": "is_stop_word",
"parameter_list": "(word, stop_words)"
},
{
"docstring": "Generator function to read a large file line by line.",
"function... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nfrom collections import defaultdict\n\nSTOP_WORDS = set([\n 'a', 'an', 'the', 'and', 'or', 'but', 'because', 'so', 'if', 'when', 'while', 'of', 'in', 'to', 'with', 'on', 'for'\n]... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032687",
"row_id": 32687,
"seed_ids": "['Qwen2-72B-Instruct_74820']"
} | 0.771666 | Filter_32687 | I | [
"is_stop_word",
"read_large_file",
"count_word_frequency"
] | 3 | [
[
"count_word_frequency",
"is_stop_word"
],
[
"count_word_frequency",
"read_large_file"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | bd7e40574765221367dde26b002c1c6db3a53a3a | 6798630122abddd3622b79a280008ec1daa94709 | |||
v1.0 | instruct | Filter | Filter_32698_I | Write a Python function that finds and returns the largest palindrome number in a given list of integers. The function should raise a ValueError if there are no palindromes in the list. | def is_palindrome(number):
"""
Helper function to determine if a number is a palindrome.
:param number: Integer
:return: Boolean indicating whether the number is a palindrome or not
"""
return str(number) == str(number)[::-1]
def largest_palindrome(numbers):
"""
Returns the largest... | from solution import largest_palindrome
def test_largest_palindrome_with_palindromes():
assert largest_palindrome([121, 232, 34543, 12321, 454]) == 34543
def test_largest_palindrome_single_palindrome():
assert largest_palindrome([101]) == 101
def test_largest_palindrome_with_negative_numbers():
assert la... | [
{
"docstring": "Helper function to determine if a number is a palindrome.\n\n:param number: Integer\n:return: Boolean indicating whether the number is a palindrome or not",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def largest_palindrome(numbers):\n \"\"\"\n Returns the largest palindrome number in the given list of integers.\n Raises a ValueError if there are no palindromes in the list.\n \"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032698",
"row_id": 32698,
"seed_ids": "['Qwen2-72B-Instruct_74833']"
} | 0.790721 | Filter_32698 | I | [
"is_palindrome",
"largest_palindrome"
] | 2 | [
[
"largest_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a7813bfc406e19010b133b7462be1198d710c322 | 53eb562b2017672889be5b09e6408b5175cd28d5 | |||
v1.0 | instruct | Filter | Filter_32723_I | Using whichever programming language is your preference, write a program that generates the first 10,000 prime numbers. Additionally, your program must implement a method for checking the primality of each generated number, and this method should not use any built-in or imported functions for prime number checking. You... | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import is_prime, generate_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(10) == False
assert is_prime(13) == True
assert is_prime(1) == False
assert is_prime(-1) == Fa... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generates the first `limit` prime numbers.",
"function_declaration": "def generate_primes(limit):",
"... | [
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 n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032723",
"row_id": 32723,
"seed_ids": "['Qwen2-72B-Instruct_74874']"
} | 0.538275 | Filter_32723 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5bc05d6cb85fb09760b65586e07685723414123c | 7d7dff166745ee7105bf759cb00049cca30b4895 | |||
v1.0 | instruct | Filter | Filter_32725_I | I need the Python code for a three-level deep lexical decision task. The task should involve selecting a word from a list of options, determining if it is a real word, and then two additional decision steps that are related to the meaning of the word. Can you provide a solution that includes these three levels of decis... | def is_real_word(word, vocabulary):
""" Determine if the word is a real word in the given vocabulary. """
return word in vocabulary
def determine_word_category(word):
"""
Mock function to determine word category for the second level decision.
Let's say we categorize words as 'animal', 'object', o... | from solution import is_real_word, determine_word_category, determine_word_use_case, lexical_decision_task
def test_is_real_word():
vocab = {"cat", "dog", "table", "computer"}
assert is_real_word("cat", vocab) == True
assert is_real_word("bird", vocab) == False
def test_determine_word_category():
... | [
{
"docstring": "Determine if the word is a real word in the given vocabulary. ",
"function_declaration": "def is_real_word(word, vocabulary):",
"function_name": "is_real_word",
"parameter_list": "(word, vocabulary)"
},
{
"docstring": "Mock function to determine word category for the second l... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_real_word(word, word_list):\n \"\"\"\n Returns whether the word is a real word by checking its presence in a predefined word list.\n \"\"\"\n return word.lower() in word_lis... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032725",
"row_id": 32725,
"seed_ids": "['Qwen2-72B-Instruct_74877']"
} | 0.4006 | Filter_32725 | I | [
"is_real_word",
"determine_word_category",
"determine_word_use_case",
"lexical_decision_task"
] | 4 | [
[
"lexical_decision_task",
"determine_word_category"
],
[
"lexical_decision_task",
"determine_word_use_case"
],
[
"lexical_decision_task",
"is_real_word"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 91ed2da9cf6ea3d6b48a0f646298c9faad0b29c4 | 26c8d6c26b810c1bae8bbc35bb05d8a863b56b86 | |||
v1.0 | instruct | Filter | Filter_32743_I | What is the solution for this problem: the Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2), with F(0) = 0 and F(1) = 1. Write a Python code that implements a recursive function to compute the Fibonacci of a given number 'x' which is stored in a CSV file as the first element. Your function should take the filena... | import csv
def read_fibonacci_number_from_csv(filename):
"""
Reads the first element from a CSV file and returns it as an integer.
"""
with open(filename, mode='r') as file:
reader = csv.reader(file)
for row in reader:
return int(row[0])
def fibonacci(n):
"""
Return... | from solution import read_fibonacci_number_from_csv, fibonacci, calculate_fibonacci_from_csv
import tempfile
import csv
def create_temp_csv_file(content):
"""
Helper function to create a temporary CSV file with the given content.
"""
temp_file = tempfile.NamedTemporaryFile(delete=False, mode='w', newli... | [
{
"docstring": "Reads the first element from a CSV file and returns it as an integer.",
"function_declaration": "def read_fibonacci_number_from_csv(filename):",
"function_name": "read_fibonacci_number_from_csv",
"parameter_list": "(filename)"
},
{
"docstring": "Returns the nth Fibonacci numb... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import csv\n\ndef fibonacci(n):\n \"\"\"\n Returns the n-th Fibonacci number using the recursive definition.\n \"\"\"\n if n <= 0:\n return 0\n elif n == 1:\n retu... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032743",
"row_id": 32743,
"seed_ids": "['Qwen2-72B-Instruct_74906']"
} | 0.68645 | Filter_32743 | I | [
"read_fibonacci_number_from_csv",
"fibonacci",
"calculate_fibonacci_from_csv"
] | 3 | [
[
"calculate_fibonacci_from_csv",
"fibonacci"
],
[
"calculate_fibonacci_from_csv",
"read_fibonacci_number_from_csv"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 206b26f0dc4f7df2a1ea367dd31f020dbb994b0f | 87b11102633ab3cd037e1034879bae492484b80a | |||
v1.0 | instruct | Filter | Filter_32773_I | Write me a Python program that combines four CSV files each containing the following fields: filename, category and text. My goal is to create a Dataframe and then split the data into a training set and test set for machine learning purposes. The four CSV files have the following names: train_part1.csv, train_part2.csv... | import pandas as pd
from sklearn.model_selection import train_test_split
import os
def load_csv(file_path):
"""
Loads a CSV file and returns a DataFrame.
If the file is empty, raises a ValueError.
"""
if os.path.getsize(file_path) == 0:
raise ValueError(f"The file '{file_path}' is empty.")
... | import pandas as pd
import pytest
import os
from solution import load_csv, shuffle_dataframe, combine_and_split_csv
@pytest.fixture
def setup_csv_files():
# Create temporary CSV files for testing
data_train1 = {'filename': ['file1', 'file2'], 'category': ['cat1', 'cat2'], 'text': ['text1', 'text2']}
data_... | [
{
"docstring": "Loads a CSV file and returns a DataFrame.\nIf the file is empty, raises a ValueError.",
"function_declaration": "def load_csv(file_path):",
"function_name": "load_csv",
"parameter_list": "(file_path)"
},
{
"docstring": "Shuffles the rows of a DataFrame and returns the shuffle... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import pandas as pd\nimport os\nfrom sklearn.model_selection import train_test_split\n\ndef combine_csv_files(filenames):\n \"\"\"\n Combines multiple CSV files into a single DataFrame i... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032773",
"row_id": 32773,
"seed_ids": "['Qwen2-72B-Instruct_74955']"
} | 0.657202 | Filter_32773 | I | [
"load_csv",
"shuffle_dataframe",
"combine_and_split_csv",
"main"
] | 4 | [
[
"combine_and_split_csv",
"load_csv"
],
[
"combine_and_split_csv",
"shuffle_dataframe"
]
] | 2 | [] | false | [] | false | pytest | true | [
"pandas",
"sklearn"
] | false | 5a2ac24189cfca59cc60a055db79f5a9c13ba0c6 | b5857ebe1f254fad0710e19de56a890b51d4f52e | |||
v1.0 | instruct | Filter | Filter_32775_I | Write a Python program that prompts the user to enter two numbers and then calculates and prints the sum. However, there is a twist: the program should continue prompting the user to enter numbers until they have inputted at least three non-negative integers that sum up to 10 or more. The program should also display an... | def prompt_user_for_number():
while True:
try:
number = float(input("Enter a non-negative number: "))
if number < 0:
print("Error: Negative number entered. Please enter a non-negative number.")
else:
return number
except ValueError:... | from solution import prompt_user_for_number, get_valid_numbers
def test_prompt_user_for_number(monkeypatch):
inputs = iter(['5', '-1', 'abc', '3'])
monkeypatch.setattr('builtins.input', lambda _: next(inputs))
output = prompt_user_for_number()
assert output == 5
output = prompt_user_for_number()
... | [
{
"docstring": null,
"function_declaration": "def prompt_user_for_number():",
"function_name": "prompt_user_for_number",
"parameter_list": "()"
},
{
"docstring": null,
"function_declaration": "def get_valid_numbers():",
"function_name": "get_valid_numbers",
"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 get_positive_number(prompt):\n \"\"\"\n Prompts the user to enter a positive number and returns it.\n If the user enters a negative number or zero, it prompts again.\n \"\"\"\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032775",
"row_id": 32775,
"seed_ids": "['Qwen2-72B-Instruct_74960']"
} | 0.582303 | Filter_32775 | I | [
"prompt_user_for_number",
"get_valid_numbers",
"main"
] | 3 | [
[
"get_valid_numbers",
"prompt_user_for_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | efdc2be48cb3ddc98b0c2efcf3ab3855cc974bd3 | 687b8a471ecbff28459bcce545919246fdb2f3ee | |||
v1.0 | instruct | Filter | Filter_32782_I | Use Python to filter out all the prime numbers from a given list of integers. | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def filter_primes(numbers):
"""
... | from solution import filter_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(18) == False
def test_filter_primes_mixed():
assert filter_primes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == ... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Filter out all prime numbers from the given list of integers.",
"function_declaration": "def filter_primes(numbers):",
"fu... | [
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\n if n % 2 == ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032782",
"row_id": 32782,
"seed_ids": "['Qwen2-72B-Instruct_74972']"
} | 0.656799 | Filter_32782 | I | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 782f8b397af3854aae7873a18d34492ea9f79343 | eb2bd92de680ea7f14a5b81bf0cbdf727c97c4f9 | |||
v1.0 | instruct | Filter | Filter_32795_I | Given a list of strings, write a program to return all strings that are palindromes. However, the solution must have a time complexity of O(n) and a space complexity of O(1), where n is the total number of characters in all the strings combined. Additionally, you are not allowed to use any built-in functions or librari... | def is_palindrome(s):
"""
Checks if a given string s is a palindrome.
"""
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
return False
left += 1
right -= 1
return True
def find_palindromes(strings):
"""
Returns all strings in t... | from solution import find_palindromes
def test_empty_list():
assert find_palindromes([]) == []
def test_no_palindromes():
assert find_palindromes(["apple", "banana", "cherry"]) == []
def test_all_palindromes():
assert find_palindromes(["madonna", "deified", "civic"]) == ["deified", "civic"]
def test_mix... | [
{
"docstring": "Checks if a given string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns all strings in the given list that are palindromes.",
"function_declaration": "def find_pali... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Returns True if the given string s is a palindrome, False otherwise.\n \"\"\"\n i, j = 0, len(s) - 1\n while i < j:\n if s[i] != s[j]:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032795",
"row_id": 32795,
"seed_ids": "['Qwen2-72B-Instruct_74991']"
} | 0.781008 | Filter_32795 | I | [
"is_palindrome",
"find_palindromes"
] | 2 | [
[
"find_palindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 272bf138cbc62162d433cad5fd4db74250d886ac | 399376fd7c462bf5c9ad19e3b2d5a1319d3fd657 | |||
v1.0 | instruct | Filter | Filter_32801_I | Write a Python function that takes a positive integer N as input and returns a list containing the first N prime numbers. Additionally, write a set of test cases to validate your solution. | def is_prime(n):
"""
Helper function to check if a number n is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i... | from solution import first_n_primes
def test_first_prime():
assert first_n_primes(1) == [2]
def test_first_two_primes():
assert first_n_primes(2) == [2, 3]
def test_first_five_primes():
assert first_n_primes(5) == [2, 3, 5, 7, 11]
def test_first_ten_primes():
assert first_n_primes(10) == [2, 3, 5, 7... | [
{
"docstring": "Helper function to check if a number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of the first N prime numbers.",
"function_declaration": "def first_n_primes(N):",
"fun... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number n is 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": "00032801",
"row_id": 32801,
"seed_ids": "['Qwen2-72B-Instruct_75007']"
} | 0.728489 | Filter_32801 | I | [
"is_prime",
"first_n_primes"
] | 2 | [
[
"first_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 313a6924abe850361299743b03a20eeb1a9ee432 | c639613cc7c6a6bb693a77d5c2090d2252abc72f | |||
v1.0 | instruct | Filter | Filter_32810_I | Given the following faulty Python function, identify the issues and fix them. The intended function is to identify and return the integer with the greatest quantity of unique prime divisors from an input list of positive integers. If two numbers have the same greatest amount of unique prime divisors, return the one tha... | def count_prime_factors(n):
"""
Returns the count of unique prime factors of a number `n`.
"""
if n < 2:
return 0
prime_factors = set()
divisor = 2
while n > 1:
while n % divisor == 0:
prime_factors.add(divisor)
n //= divisor
divisor += 1
... | from solution import count_prime_factors, max_prime_divisors
def test_count_prime_factors():
assert count_prime_factors(1) == 0
assert count_prime_factors(2) == 1
assert count_prime_factors(3) == 1
assert count_prime_factors(4) == 1 # 2
assert count_prime_factors(6) == 2 # 2, 3
assert count_p... | [
{
"docstring": "Returns the count of unique prime factors of a number `n`.",
"function_declaration": "def count_prime_factors(n):",
"function_name": "count_prime_factors",
"parameter_list": "(n)"
},
{
"docstring": "Returns the integer with the greatest quantity of unique prime divisors.\nIf ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prime_factors(n):\n \"\"\"\n Returns a set of prime factors of the given number n.\n \"\"\"\n i = 2\n factors = set()\n # Check divisibility starting from smallest prime ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032810",
"row_id": 32810,
"seed_ids": "['Qwen2-72B-Instruct_75017']"
} | 0.661169 | Filter_32810 | I | [
"count_prime_factors",
"max_prime_divisors"
] | 2 | [
[
"max_prime_divisors",
"count_prime_factors"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b1e409d75e8ffad9cc633594763f6368272a1506 | d8bda8c3814f8380b5fd8fdca79d721c42e4d322 | |||
v1.0 | instruct | Filter | Filter_32841_I | Write a code in Python that calculates the product of all prime numbers under 1000. Additionally, write a function that checks if the generated product is a perfect square or not. | import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def product_of_primes_below_1000(... | from solution import is_prime, product_of_primes_below_1000, is_perfect_square
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(97) == True
assert is_prime(1) == False
assert is_prime(0) == Fal... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def product_of_primes_below_1000():",
"function_name": "product_of_primes_below_1000",
"parameter_list": "()"
}... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import isqrt\n\ndef is_prime(n):\n \"\"\"\n Check if a number n is prime.\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": "00032841",
"row_id": 32841,
"seed_ids": "['Qwen2-72B-Instruct_75068']"
} | 0.63928 | Filter_32841 | I | [
"is_prime",
"product_of_primes_below_1000",
"is_perfect_square"
] | 3 | [
[
"product_of_primes_below_1000",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7f921d99bde80edd964f6367078b36870428f82f | ef563edd7a7317c25661d654dd1049e8f9e7224d | |||
v1.0 | instruct | Filter | Filter_32853_I | Create a program in Python that takes a specified file path as input and recursively searches through that directory and all subdirectories to copy files with the .txt extension. The program should then create a new directory within the current working directory named "copied_txt_files" and save the copied files in thi... | import os
import shutil
from pathlib import Path
from filecmp import cmp
def find_and_copy_txt_files(source_directory):
"""
Finds all .txt files in the source_directory and its subdirectories,
copies them to a new directory named "copied_txt_files" in the current working directory.
"""
current_dir... | import os
import shutil
import pytest
from pathlib import Path
from solution import find_and_copy_txt_files
@pytest.fixture
def setup_directories(tmpdir):
"""
Setting up directories and test files
"""
src_dir = tmpdir.mkdir("source_directory")
dest_dir = tmpdir.mkdir("current_working_directory")
... | [
{
"docstring": "Finds all .txt files in the source_directory and its subdirectories, \ncopies them to a new directory named \"copied_txt_files\" in the current working directory.",
"function_declaration": "def find_and_copy_txt_files(source_directory):",
"function_name": "find_and_copy_txt_files",
"... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport shutil\n\ndef create_copied_txt_files_directory():\n \"\"\"\n This function creates the 'copied_txt_files' directory under the current working directory.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032853",
"row_id": 32853,
"seed_ids": "['Qwen2-72B-Instruct_75088']"
} | 0.686619 | Filter_32853 | I | [
"find_and_copy_txt_files",
"remove_duplicate_files"
] | 2 | [
[
"find_and_copy_txt_files",
"remove_duplicate_files"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 80524e1e58d50bbabd7360e091b1fe4205a23cb0 | 8e705c0336c546b6350b37ef720d830e4d754aa9 | |||
v1.0 | instruct | Filter | Filter_32854_I | Write a recursive function to print each letter of a string backwards, with a delay of 1 second between each letter. Make sure to implement proper error checking to prevent crashes when non-string input is entered. Also, your function should reject strings longer than 100 characters due to memory constraints. | import time
def print_string_backwards(s):
"""
Prints each letter of the input string s backwards with a delay of 1 second between each letter.
"""
if not isinstance(s, str):
raise ValueError("Input must be a string")
if len(s) > 100:
raise ValueError("Input string exceeds 100 chara... | import pytest
import time
from solution import print_string_backwards
def test_print_string_backwards_valid_input():
import io
from contextlib import redirect_stdout
s = "hello"
buffer = io.StringIO()
with redirect_stdout(buffer):
print_string_backwards(s)
assert buffer.g... | [
{
"docstring": "Prints each letter of the input string s backwards with a delay of 1 second between each letter.",
"function_declaration": "def print_string_backwards(s):",
"function_name": "print_string_backwards",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\n\ndef print_string_backwards(s):\n \"\"\"\n Recursively prints each letter of a string backwards with 1 second delay.\n \"\"\"\n if not isinstance(s, str):\n ra... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032854",
"row_id": 32854,
"seed_ids": "['Qwen2-72B-Instruct_75092']"
} | 0.593127 | Filter_32854 | I | [
"print_string_backwards",
"_print_helper"
] | 2 | [
[
"print_string_backwards",
"_print_helper"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 51ea9b47d17cc8443c56d03369d36ac543d728d6 | 39944d43617a7c09f39f07b77f267343ec31f431 | |||
v1.0 | instruct | Filter | Filter_32870_I | Generate a process to reverse a string without using any pre-built functions in the programming language of your choice. Additionally, implement a feature to check whether the reversed string is a palindrome or not. | def reverse_string(s):
"""
Reverses the input string without using any pre-built functions.
"""
reversed_str = ""
for char in s:
reversed_str = char + reversed_str
return reversed_str
def is_palindrome(s):
"""
Checks if the input string is a palindrome.
"""
reversed_str ... | from solution import reverse_string, is_palindrome
def test_reverse_string():
assert reverse_string("hello") == "olleh"
assert reverse_string("world") == "dlrow"
assert reverse_string("a") == "a"
assert reverse_string("") == ""
def test_is_palindrome():
assert is_palindrome("radar") == True
as... | [
{
"docstring": "Reverses the input string without using any pre-built functions.",
"function_declaration": "def reverse_string(s):",
"function_name": "reverse_string",
"parameter_list": "(s)"
},
{
"docstring": "Checks if the input string is a palindrome.",
"function_declaration": "def is... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def reverse_string(s):\n \"\"\"\n Reverse the input string without using any pre-built functions.\n \n Parameters:\n s (str): Input string to be reversed\n\n Returns:\n st... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032870",
"row_id": 32870,
"seed_ids": "['Qwen2-72B-Instruct_75121']"
} | 0.713005 | Filter_32870 | I | [
"reverse_string",
"is_palindrome"
] | 2 | [
[
"is_palindrome",
"reverse_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 429c7dbdcc0df9620861ddfafddd94a2432fc2ad | 184940fcb62ac5c042ac79e87dfa97fbbccb733f | |||
v1.0 | instruct | Filter | Filter_32888_I | Write a code to create a 3 x 3 matrix containing all 0s, but the matrix must be initialized using a recursive algorithm instead of a simple loop. Additionally, the recursive algorithm should use a depth-first search approach to populate the matrix, where each element is randomly assigned either 0 or 1. | import random
def initialize_matrix(matrix, i, j, n, m):
"""
Recursively initializes the matrix with random 0s and 1s in a depth-first fashion.
:param matrix: Current matrix
:param i: Current row index
:param j: Current column index
:param n: Total rows in the matrix
:param m: Total co... | import pytest
from solution import create_3x3_matrix
def test_matrix_shape():
matrix = create_3x3_matrix()
assert len(matrix) == 3
for row in matrix:
assert len(row) == 3
def test_matrix_values():
matrix = create_3x3_matrix()
for row in matrix:
for value in row:
assert ... | [
{
"docstring": "Recursively initializes the matrix with random 0s and 1s in a depth-first fashion.\n\n:param matrix: Current matrix\n:param i: Current row index\n:param j: Current column index\n:param n: Total rows in the matrix\n:param m: Total columns in the matrix",
"function_declaration": "def initializ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef initialize_matrix(matrix, i, j, n):\n \"\"\"\n Recursively initializes a 3 x 3 matrix using depth-first search approach\n and randomly assigns either 0 or 1 to ea... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032888",
"row_id": 32888,
"seed_ids": "['Qwen2-72B-Instruct_75153']"
} | 0.480237 | Filter_32888 | I | [
"initialize_matrix",
"create_3x3_matrix"
] | 2 | [
[
"create_3x3_matrix",
"initialize_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 113fc87d25bf3a8a080f62a66b55d213f1a2b3bb | 5c745f72cc46c918db30db2c5459e79f13cf2ba7 | |||
v1.0 | instruct | Filter | Filter_32910_I | Write a code to display all the prime numbers between a given range, but with a twist. Now, instead of taking two integers as input, the program should take a single integer input 'n' and display all the prime numbers between 1 and n. Additionally, the program should also calculate and display the sum of all the prime ... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while (i * i) <= num:
if num % i == 0 or num % (i+2) == 0:
return False
i += 6
return True
def primes_and_sum(n):
... | from solution import primes_and_sum
def test_primes_and_sum_with_small_range():
primes, prime_sum = primes_and_sum(10)
assert primes == [2, 3, 5, 7]
assert prime_sum == 17
def test_primes_and_sum_with_five():
primes, prime_sum = primes_and_sum(5)
assert primes == [2, 3, 5]
assert prime_sum == ... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns all prime numbers between 1 and n (inclusive) and their sum.\n\nParameters:\nn (int): The upper limit to find prime numbers.\n\nReturns:\n(list... | [
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 <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n \n i = 5\n while (i * i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032910",
"row_id": 32910,
"seed_ids": "['Qwen2-72B-Instruct_75189']"
} | 0.582802 | Filter_32910 | I | [
"is_prime",
"primes_and_sum"
] | 2 | [
[
"primes_and_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed201919b4edecf0ae6e46ebd17d1b3c48ea4944 | ae09361c14e08f0e699a448d58a2c879651ec267 | |||
v1.0 | instruct | Filter | Filter_32918_I | Write a recursive function in Python to calculate the least common multiple (LCM) of three numbers without using math library functions for LCM or GCD. Additionally, write unit tests to validate your solution. | def gcd(a, b):
"""
Helper function to calculate the greatest common divisor (GCD) of two numbers using Euclid's algorithm.
"""
if b == 0:
return a
else:
return gcd(b, a % b)
def lcm(a, b):
"""
Helper function to calculate the least common multiple (LCM) of two numbers.
"... | from solution import lcm_of_three
def test_lcm_of_three():
assert lcm_of_three(4, 5, 6) == 60
assert lcm_of_three(12, 15, 20) == 60
assert lcm_of_three(1, 1, 1) == 1
assert lcm_of_three(2, 3, 5) == 30
assert lcm_of_three(3, 6, 9) == 18
assert lcm_of_three(5, 10, 25) == 50
assert lcm_of_thre... | [
{
"docstring": "Helper function to calculate the greatest common divisor (GCD) of two numbers using Euclid's algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Helper function to calculate the least common multiple (LC... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(a, b):\n \"\"\"\n Returns the Greatest Common Divisor (GCD) of a and b.\n \"\"\"\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n\ndef lcm(a, b):\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032918",
"row_id": 32918,
"seed_ids": "['Qwen2-72B-Instruct_75201']"
} | 0.617756 | Filter_32918 | I | [
"gcd",
"lcm",
"lcm_of_three"
] | 3 | [
[
"lcm",
"gcd"
],
[
"lcm_of_three",
"lcm"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3f685f36ac415bcb8942d39717aa5b50a1a0fc85 | eb589fc5bf0b8631f8c209692015705fed39aeaa | |||
v1.0 | instruct | Filter | Filter_32946_I | Develop an algorithm in Python that finds the closest K neighbors of a target point in an array of N points. The algorithm should not use any pre-existing distance functions but should define the Euclidean distance method itself. Moreover, your algorithm should return these neighbors in order of proximity. Remember to ... | import math
def euclidean_distance(point1, point2):
"""
Computes the Euclidean distance between two points in n-dimensional space.
"""
return math.sqrt(sum((a - b) ** 2 for a, b in zip(point1, point2)))
def closest_k_neighbors(points, target, K):
"""
Finds the closest K neighbors to the target... | from solution import closest_k_neighbors
def test_single_point():
points = [(1, 2)]
target = (1, 2)
K = 1
assert closest_k_neighbors(points, target, K) == [(1, 2)]
def test_k_greater_than_n():
points = [(1, 2), (3, 4)]
target = (0, 0)
K = 5
assert closest_k_neighbors(points, target, K)... | [
{
"docstring": "Computes the Euclidean distance between two points in n-dimensional space.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Finds the closest K neighbors to the ... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom heapq import heappush, heappop\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculates the Euclidean distance between two points in 2D space.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032946",
"row_id": 32946,
"seed_ids": "['Qwen2-72B-Instruct_75242']"
} | 0.653729 | Filter_32946 | I | [
"euclidean_distance",
"closest_k_neighbors"
] | 2 | [
[
"closest_k_neighbors",
"euclidean_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84367293dc11c4efff2786820bc4a5e4efc9b635 | 26e3b26879b8aae3a418e61db8b15a1e6ed5484e | |||
v1.0 | instruct | Filter | Filter_32960_I | Create a program to print a table format with 5 rows and 4 columns. Each cell in the table should contain a unique prime number. Additionally, the prime numbers should be generated in a way that they are greater than 100 and less than 1000. | def generate_primes_in_range(start, end, count):
"""
Generate a list of 'count' prime numbers between 'start' and 'end'
"""
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return Tr... | from solution import generate_primes_in_range, print_prime_table
def test_generate_primes_in_range():
primes = generate_primes_in_range(101, 200, 10)
expected_primes = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149]
assert primes == expected_primes
def test_generate_primes_in_large_range():
pr... | [
{
"docstring": "Generate a list of 'count' prime numbers between 'start' and 'end'",
"function_declaration": "def generate_primes_in_range(start, end, count):",
"function_name": "generate_primes_in_range",
"parameter_list": "(start, end, count)"
},
{
"docstring": "Prints a table with 5 rows ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032960",
"row_id": 32960,
"seed_ids": "['Qwen2-72B-Instruct_75264']"
} | 0.481329 | Filter_32960 | I | [
"generate_primes_in_range",
"print_prime_table"
] | 2 | [
[
"print_prime_table",
"generate_primes_in_range"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d8b541beb33debf1f8cb2677b0e10b37a1849658 | 75ce4dc0ef2e703e96eeeddbdd8b669e985dd8a5 | |||
v1.0 | instruct | Filter | Filter_32969_I | Using the heapsort technique, sort the following array of numbers in ascending order. Assume the array can contain up to 10^6 integers and the integers can range from -10^9 to 10^9. Additionally, you are required to implement the heapsort algorithm using a min-heap data structure and the sorting algorithm must have a t... | def heapify(arr, n, i):
"""
Helper function to maintain heap property for a min-heap.
"""
smallest = i
left = 2 * i + 1
right = 2 * i + 2
if left < n and arr[smallest] > arr[left]:
smallest = left
if right < n and arr[smallest] > arr[right]:
smallest = right
if sma... | from solution import heapsort
def test_heapsort_sorted_array():
arr = [1, 2, 3, 4, 5]
heapsort(arr)
assert arr == [1, 2, 3, 4, 5]
def test_heapsort_reverse_sorted_array():
arr = [5, 4, 3, 2, 1]
heapsort(arr)
assert arr == [1, 2, 3, 4, 5]
def test_heapsort_mixed_numbers():
arr = [3, -2, -5... | [
{
"docstring": "Helper function to maintain heap property for a min-heap.",
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"parameter_list": "(arr, n, i)"
},
{
"docstring": "Function to perform heapsort on the given list using min-heap.",
"function_declara... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def heapsort(arr):\n \"\"\"\n Sorts an array using the heapsort algorithm with a min-heap.\n \"\"\"\n \n def heapify(arr, n, i):\n smallest = i\n left = 2 * i + 1 ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00032969",
"row_id": 32969,
"seed_ids": "['Qwen2-72B-Instruct_75283']"
} | 0.669206 | Filter_32969 | I | [
"heapify",
"heapsort"
] | 2 | [
[
"heapsort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 33ad56ee6b4c877ca213a7c763e169436454d102 | 3c6144381668abb37469088da8448714f2bd3e9b | |||
v1.0 | instruct | Filter | Filter_32991_I | Convolution is often used in the context of image processing as filters, and one such filter is edge detection. Write a function in Python using the Numpy library that applies edge detection filters on an input image and plots the resulting image. Additionally, for an increased challenge, write a function that draws a ... | import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import convolve
def edge_detection(image, kernel):
"""
Applies an edge detection filter on an input image using the provided kernel.
Parameters:
- image: 2D numpy array representing the grayscale image.
- kernel: 2D numpy ar... | import numpy as np
import pytest
from solution import edge_detection, compare_edge_detection_filters
# Sample image data (5x5 pixel dummy grayscale image)
sample_image = np.array([
[100, 100, 100, 100, 100],
[100, 255, 255, 255, 100],
[100, 255, 0, 255, 100],
[100, 255, 255, 255, 100],
[100, 100,... | [
{
"docstring": "Applies an edge detection filter on an input image using the provided kernel.\n\nParameters:\n- image: 2D numpy array representing the grayscale image.\n- kernel: 2D numpy array representing the edge detection kernel.\n\nReturns:\n- 2D numpy array with the edge detected image.",
"function_de... | [
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\nimport matplotlib.pyplot as plt\nfrom scipy.ndimage import convolve\n\ndef edge_detection(image, kernel):\n \"\"\"\n Applies an edge detection filter on an input imag... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00032991",
"row_id": 32991,
"seed_ids": "['Qwen2-72B-Instruct_75331']"
} | 0.542468 | Filter_32991 | I | [
"edge_detection",
"compare_edge_detection_filters"
] | 2 | [
[
"compare_edge_detection_filters",
"edge_detection"
]
] | 1 | [] | false | [] | false | pytest | true | [
"matplotlib",
"numpy",
"scipy"
] | false | 8842260b40164e09a5b2d4464ad6778b4ed2604b | f6b6ab22ef750911b9aa5047bf540817892e41ec | |||
v1.0 | instruct | Filter | Filter_32999_I | Please implement a function named "merge_sort" that takes a list of integers as input and returns a new list containing the same integers in ascending order. You should not use any built-in sorting functions or libraries. The function should have a time complexity of O(nlogn) and a space complexity of O(n). | def merge_sort(arr):
"""
Sorts the input list 'arr' using the merge sort algorithm and returns the sorted list.
:param arr: List of integers
:return: A new list of integers in ascending order
"""
if len(arr) <= 1:
return arr
mid = len(arr) // 2
left_half = merge_sort(arr[:mid])... | from solution import merge_sort
def test_merge_sort_sorted():
assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_merge_sort_unsorted():
assert merge_sort([3, 1, 4, 1, 5, 9, 2, 6, 5]) == [1, 1, 2, 3, 4, 5, 5, 6, 9]
def test_merge_sort_negative():
assert merge_sort([-1, -3, -2, 0, 2, 1, -1]... | [
{
"docstring": "Sorts the input list 'arr' using the merge sort algorithm and returns the sorted list.\n\n:param arr: List of integers\n:return: A new list of integers in ascending order",
"function_declaration": "def merge_sort(arr):",
"function_name": "merge_sort",
"parameter_list": "(arr)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts a list of integers in ascending order using the merge sort algorithm.\n \n Args:\n arr (list of int): The list of integers to be sorted.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00032999",
"row_id": 32999,
"seed_ids": "['Qwen2-72B-Instruct_75348']"
} | 0.6248 | Filter_32999 | I | [
"merge_sort",
"merge"
] | 2 | [
[
"merge_sort",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8640fb3a2ae05906f27a9f620ae58090530893e7 | 36a69a9c54f329b8c012e76e579fa5e33f4b7566 | |||
v1.0 | instruct | Filter | Filter_33025_I | You are tasked with implementing a logging function for a system update process. The function should take in input data, log the start of the process, call a service to update information, log the output data along with a debug message, and then log the completion of the process. Your task is to create a Python functio... | import logging
# Setting up the logging configuration
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
def service_update(data):
"""
Simulates an update service which processes the input data and returns some output data.
For demonstration, it may return the dat... | import logging
from io import StringIO
from solution import log_and_update_process
def test_log_and_update_process(caplog):
input_data = {"key": "value"}
with caplog.at_level(logging.DEBUG):
output_data = log_and_update_process(input_data)
assert output_data == input_data
assert "Star... | [
{
"docstring": "Simulates an update service which processes the input data and returns some output data.\nFor demonstration, it may return the data unchanged.",
"function_declaration": "def service_update(data):",
"function_name": "service_update",
"parameter_list": "(data)"
},
{
"docstring"... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import logging\n\ndef update_information_service(data):\n \"\"\"\n Mock function to simulate updating information.\n This should be replaced with actual logic.\n \"\"\"\n # Simu... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033025",
"row_id": 33025,
"seed_ids": "['Qwen2-72B-Instruct_75394']"
} | 0.501742 | Filter_33025 | I | [
"service_update",
"log_and_update_process"
] | 2 | [
[
"log_and_update_process",
"service_update"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6c1be9b352388c0342302bcd4234f7c786fc73bc | 72261f9277eb4a046cd4fe686889f4cb6051efef | |||
v1.0 | instruct | Filter | Filter_33060_I | Rewrite the following variation of quicksort to not use any additional array, meaning an in-place sorting version. Furthermore, enhance the function to work optimally on an array with many duplicate elements. | def quicksort(arr, low, high):
"""
In-place quicksort that sorts an array between the indices low and high inclusively.
This implementation is optimized for arrays with many duplicate elements.
"""
if low < high:
lt, gt = partition(arr, low, high)
quicksort(arr, low, lt - 1)
... | from solution import quicksort
def test_quicksort_empty():
arr = []
quicksort(arr, 0, len(arr) - 1)
assert arr == []
def test_quicksort_single_element():
arr = [1]
quicksort(arr, 0, 0)
assert arr == [1]
def test_quicksort_sorted_array():
arr = [1, 2, 3, 4, 5]
quicksort(arr, 0, len(arr... | [
{
"docstring": "In-place quicksort that sorts an array between the indices low and high inclusively.\nThis implementation is optimized for arrays with many duplicate elements.",
"function_declaration": "def quicksort(arr, low, high):",
"function_name": "quicksort",
"parameter_list": "(arr, low, high... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort(arr, low, high):\n \"\"\"\n In-place quicksort algorithm optimized for arrays with many duplicate elements.\n \"\"\"\n if low < high:\n # Perform the 3-way par... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033060",
"row_id": 33060,
"seed_ids": "['Qwen2-72B-Instruct_75462']"
} | 0.497822 | Filter_33060 | I | [
"quicksort",
"partition"
] | 2 | [
[
"quicksort",
"partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7a32098aea19bae9adf296901651e380b5808401 | ebfdb7cb33a389ab4935e2c66932a1a9df24a5d1 | |||
v1.0 | instruct | Filter | Filter_33061_I | Implement a Monte Carlo simulation of a simple game I will describe. Two players, Player A and Player B are competing in a game that involve a fair 6-sided die. The rules are as follows: Both players roll the die simultaneously. If the sum of the roll is odd, Player A wins that round of the game and scores a point. If ... | import random
def simulate_game(rounds=10000):
"""
Simulate one game consisting of 'rounds' rounds.
- If the sum is odd, Player A gets a point.
- If the sum is even, Player B gets a point.
"""
points_A = 0
points_B = 0
for _ in range(rounds):
roll_A = random.randint(1, 6)
... | from solution import simulate_game, simulate_matches
def test_simulate_game():
points_A, points_B = simulate_game(10000)
assert points_A + points_B == 10000
assert points_A >= 0
assert points_B >= 0
def test_simulate_matches():
match_wins_A, match_wins_B = simulate_matches(100, 10000)
assert m... | [
{
"docstring": "Simulate one game consisting of 'rounds' rounds.\n- If the sum is odd, Player A gets a point.\n- If the sum is even, Player B gets a point.",
"function_declaration": "def simulate_game(rounds=10000):",
"function_name": "simulate_game",
"parameter_list": "(rounds=10000)"
},
{
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef simulate_game_round():\n \"\"\"\n Simulate a single round of the game.\n Returns 1 if Player A wins the round, and 0 if Player B wins the round.\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033061",
"row_id": 33061,
"seed_ids": "['Qwen2-72B-Instruct_75464']"
} | 0.558455 | Filter_33061 | I | [
"simulate_game",
"simulate_matches",
"main"
] | 3 | [
[
"simulate_matches",
"simulate_game"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 500e7bb89009297ec882f0b9440a73c973eacbc2 | d90e8e73be3129f6e6867d8e952a6d95cff93158 | |||
v1.0 | instruct | Filter | Filter_33062_I | Convert the following pseudocode into code that implements an in-place quicksort. | def quicksort(arr, low, high):
"""
Performs in-place quicksort on the list arr from index low to high.
"""
if low < high:
pi = partition(arr, low, high)
quicksort(arr, low, pi - 1)
quicksort(arr, pi + 1, high)
def partition(arr, low, high):
"""
Helper function t... | from solution import quicksort
def test_quicksort_sorted():
arr = [1, 2, 3, 4, 5]
quicksort(arr, 0, len(arr) - 1)
assert arr == [1, 2, 3, 4, 5]
def test_quicksort_reverse_sorted():
arr = [5, 4, 3, 2, 1]
quicksort(arr, 0, len(arr) - 1)
assert arr == [1, 2, 3, 4, 5]
def test_quicksort_unsorted(... | [
{
"docstring": "Performs in-place quicksort on the list arr from index low to high.",
"function_declaration": "def quicksort(arr, low, high):",
"function_name": "quicksort",
"parameter_list": "(arr, low, high)"
},
{
"docstring": "Helper function to find the partition position.",
"functio... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort(arr, low, high):\n if low < high:\n # Partitioning index\n pi = partition(arr, low, high)\n\n # Separately sort elements before partition and after partit... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033062",
"row_id": 33062,
"seed_ids": "['Qwen2-72B-Instruct_75465']"
} | 0.541008 | Filter_33062 | I | [
"quicksort",
"partition"
] | 2 | [
[
"quicksort",
"partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 617afe33dfd24b1e23f46cc38e216c141ffd93e5 | 2fbf024279035579e6ae01a981ec56f69e371f8e | |||
v1.0 | instruct | Filter | Filter_33065_I | Write a Python program that prompts the user to input a list of float numbers, then uses the function to find the mean of these numbers and displays the results. Your program should handle lists of different lengths and should output error messages for any invalid inputs (e.g., non-numeric values). Your program should ... | def compute_mean(numbers):
"""
Returns the mean of the list of numbers.
"""
if not numbers:
return None
return sum(numbers) / len(numbers)
def get_input_and_compute_mean():
"""
Prompts the user to input a list of float numbers and displays the mean.
Handles invalid inputs with e... | import pytest
from solution import compute_mean
def test_compute_mean_with_positive_numbers():
assert compute_mean([1.0, 2.0, 3.0, 4.0, 5.0]) == 3.0
def test_compute_mean_with_negative_numbers():
assert compute_mean([-1.0, -2.0, -3.0, -4.0, -5.0]) == -3.0
def test_compute_mean_with_mixed_numbers():
asser... | [
{
"docstring": "Returns the mean of the list of numbers.",
"function_declaration": "def compute_mean(numbers):",
"function_name": "compute_mean",
"parameter_list": "(numbers)"
},
{
"docstring": "Prompts the user to input a list of float numbers and displays the mean.\nHandles invalid inputs ... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def compute_mean(numbers):\n \"\"\"\n Returns the mean of the list of numbers.\n \"\"\"\n if not numbers:\n return None\n return sum(numbers) / len(numbers)\n\ndef get_in... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033065",
"row_id": 33065,
"seed_ids": "['Qwen2-72B-Instruct_75474']"
} | 0.661157 | Filter_33065 | I | [
"compute_mean",
"get_input_and_compute_mean"
] | 2 | [
[
"get_input_and_compute_mean",
"compute_mean"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2095efd2b671a0f4a0a62704240332fc7b32fe53 | 309fc0812af96350b7a1ba189c0aadd8e192bbe2 | |||
v1.0 | instruct | Filter | Filter_33066_I | Write a Python program that not only checks whether a given number is prime or not, but also handles edge cases like non-integer and negative inputs robustly. Additionally, if the input is valid, the program should also find the smallest prime number larger than the input. | def is_prime(n):
"""
Check if a number is prime.
Returns True if n is a prime number, otherwise False.
"""
if not isinstance(n, int) or 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:
... | from solution import is_prime, find_smallest_prime_greater_than
def test_is_prime_valid_primes():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
def test_is_prime_valid_non_primes():
assert is_prime(1) == False
assert is_prime(4) == ... | [
{
"docstring": "Check if a number is prime.\nReturns True if n is a prime number, otherwise False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Find the smallest prime number greater than the given number.",
"functi... | [
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 Args:\n n (int): The number to check.\n\n Returns:\n bool: True if the number is prime, False otherwise.\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033066",
"row_id": 33066,
"seed_ids": "['Qwen2-72B-Instruct_75475']"
} | 0.747874 | Filter_33066 | I | [
"is_prime",
"find_smallest_prime_greater_than"
] | 2 | [
[
"find_smallest_prime_greater_than",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5d518126969e2ebb68b1fac1ec3f669782609944 | 8ad7fc3cf5dd643acc02ce28d9e255cf0be42df9 | |||
v1.0 | instruct | Filter | Filter_33077_I | How can I sort an array in-place using the quicksort algorithm in Python? | def quicksort(arr, low, high):
"""
Sorts an array in-place using the quicksort algorithm.
"""
if low < high:
# pi is partitioning index, arr[p] is now at the right place
pi = partition(arr, low, high)
# Recursively sort elements before
# partition and after partition
... | from solution import quicksort
def test_quicksort_empty_array():
arr = []
quicksort(arr, 0, len(arr) - 1)
assert arr == []
def test_quicksort_single_element():
arr = [1]
quicksort(arr, 0, len(arr) - 1)
assert arr == [1]
def test_quicksort_already_sorted():
arr = [1, 2, 3, 4, 5]
quicks... | [
{
"docstring": "Sorts an array in-place using the quicksort algorithm.",
"function_declaration": "def quicksort(arr, low, high):",
"function_name": "quicksort",
"parameter_list": "(arr, low, high)"
},
{
"docstring": "Partition the array on the basis of pivot element.",
"function_declarat... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def quicksort(arr, low, high):\n \"\"\"\n Sorts an array in-place using the quicksort algorithm.\n \"\"\"\n if low < high:\n pi = partition(arr, low, high)\n quicksor... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033077",
"row_id": 33077,
"seed_ids": "['Qwen2-72B-Instruct_75495']"
} | 0.59992 | Filter_33077 | I | [
"quicksort",
"partition"
] | 2 | [
[
"quicksort",
"partition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 58e78e8e13dc4bd52974e147e52605191ff8d1d9 | e1c978093c9b8f3e2663d6b300428ce90107f035 | |||
v1.0 | instruct | Filter | Filter_33122_I | Design an algorithm to search for a given element 'x' in a sorted array 'a' with a complexity of O(log n) and without using any built-in search functions or libraries. Additionally, the algorithm should find the first and last occurrence of the element if it exists in the array, and return the number of occurrences. In... | def binary_search(a, x, find_first):
"""
Helper function to perform binary search.
If find_first is True, it finds the first occurrence of x.
Otherwise, it finds the last occurrence of x.
"""
low, high = 0, len(a) - 1
result = -1
while low <= high:
mid = (low + high) // 2
... | def test_element_found():
a = [1, 2, 2, 2, 3, 4, 5]
x = 2
assert search_element(a, x) == 3
def test_element_not_found():
a = [1, 2, 3, 4, 5]
x = 6
assert search_element(a, x) == -1
def test_empty_array():
a = []
x = 3
assert search_element(a, x) == -1
def test_single_occurrence():... | [
{
"docstring": "Helper function to perform binary search.\nIf find_first is True, it finds the first occurrence of x.\nOtherwise, it finds the last occurrence of x.",
"function_declaration": "def binary_search(a, x, find_first):",
"function_name": "binary_search",
"parameter_list": "(a, x, find_firs... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_search_occurrences(a, x):\n \"\"\"\n Searches for the element 'x' in the sorted array 'a', and returns a tuple with two elements:\n - If 'x' is found: (first_index, last_in... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033122",
"row_id": 33122,
"seed_ids": "['Qwen2-72B-Instruct_75571']"
} | 0.629168 | Filter_33122 | I | [
"binary_search",
"search_element"
] | 2 | [
[
"search_element",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4576d318d7537c3455f62412a1d91e90a88e67fa | af525f978aef3abd723054a14f2a537174e1d53e | |||
v1.0 | instruct | Filter | Filter_33131_I | Construct a do-while loop to repeatedly take input from the user until they enter a prime number. | def is_prime(num):
"""
Checks if a number is prime or not.
"""
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def get_prime_number():
"""
Repeatedly takes input from the user until they enter a prime ... | from solution import is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-5) == False
def test_ge... | [
{
"docstring": "Checks if a number is prime or not.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Repeatedly takes input from the user until they enter a prime number.\nReturns the prime number.",
"function_decla... | [
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 or not.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033131",
"row_id": 33131,
"seed_ids": "['Qwen2-72B-Instruct_75593']"
} | 0.545692 | Filter_33131 | I | [
"is_prime",
"get_prime_number"
] | 2 | [
[
"get_prime_number",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f97cf858954ce5b35df6c97f6456f752ce459be0 | f0571c730cafff45dc9892b81ece8048fa6074f6 | |||
v1.0 | instruct | Filter | Filter_33146_I | Update the programming test question to now include 4D vectors and to calculate the angle in both degrees and radians between two 4D vectors. The function should also check if the input vectors have the same length and should return a meaningful error message if they do not. | import math
def dot_product(v1, v2):
"""
Returns the dot product of two vectors v1 and v2.
"""
return sum(x * y for x, y in zip(v1, v2))
def magnitude(v):
"""
Returns the magnitude of a vector v.
"""
return math.sqrt(sum(x**2 for x in v))
def angle_between_4d_vectors(v1, v2):
"""
... | from solution import angle_between_4d_vectors
import pytest
import math
def test_angle_between_4d_vectors_positive_case():
v1 = [1, 0, 0, 0]
v2 = [0, 1, 0, 0]
angle_deg, angle_rad = angle_between_4d_vectors(v1, v2)
assert angle_deg == 90.0
assert math.isclose(angle_rad, math.pi / 2)
def test_a... | [
{
"docstring": "Returns the dot product of two vectors v1 and v2.",
"function_declaration": "def dot_product(v1, v2):",
"function_name": "dot_product",
"parameter_list": "(v1, v2)"
},
{
"docstring": "Returns the magnitude of a vector v.",
"function_declaration": "def magnitude(v):",
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef dot_product(v1, v2):\n \"\"\"\n Returns the dot product of two vectors.\n \"\"\"\n return sum(x*y for x, y in zip(v1, v2))\n\ndef magnitude(v):\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033146",
"row_id": 33146,
"seed_ids": "['Qwen2-72B-Instruct_75618']"
} | 0.443368 | Filter_33146 | I | [
"dot_product",
"magnitude",
"angle_between_4d_vectors"
] | 3 | [
[
"angle_between_4d_vectors",
"dot_product"
],
[
"angle_between_4d_vectors",
"magnitude"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1508255d9d52c4633d7702fffc23cb11337db4ee | 2d1a87d9a3997d78b748843b3ab064a3b510ce1a | |||
v1.0 | instruct | Filter | Filter_33154_I | Write a program that prompts the user to input a date in the format "yyyy-mm-dd" and a time in the format "hh:mm:ss", and then prints the inputted date and time in the format "dd/mm/yyyy hh:mm:ss". Additionally, the program should validate the inputted date and time to ensure that they are valid according to the Gregor... | def is_leap_year(year):
return year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)
def validate_date(date):
if len(date) != 10 or date[4] != '-' or date[7] != '-':
return False
year, month, day = date.split('-')
if not (year.isdigit() and month.isdigit() and day.isdigit()):
return Fa... | from solution import is_leap_year, validate_date, validate_time, validate_timezone_offset, convert_to_output_format, parse_input
def test_leap_year():
assert is_leap_year(2020) == True
assert is_leap_year(1900) == False
assert is_leap_year(2000) == True
assert is_leap_year(2021) == False
def test_vali... | [
{
"docstring": null,
"function_declaration": "def is_leap_year(year):",
"function_name": "is_leap_year",
"parameter_list": "(year)"
},
{
"docstring": null,
"function_declaration": "def validate_date(date):",
"function_name": "validate_date",
"parameter_list": "(date)"
},
{
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_date(date):\n year, month, day = map(int, date.split('-'))\n if month < 1 or month > 12 or day < 1:\n return False\n\n if month in [1, 3, 5, 7, 8, 10, 12]:\n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033154",
"row_id": 33154,
"seed_ids": "['Qwen2-72B-Instruct_75633']"
} | 0.548704 | Filter_33154 | I | [
"is_leap_year",
"validate_date",
"validate_time",
"validate_timezone_offset",
"convert_to_output_format",
"parse_input",
"main"
] | 7 | [
[
"parse_input",
"convert_to_output_format"
],
[
"parse_input",
"validate_date"
],
[
"parse_input",
"validate_time"
],
[
"parse_input",
"validate_timezone_offset"
],
[
"validate_date",
"is_leap_year"
]
] | 5 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 05aa17ea3a4942e768cafbc54c5a3db57e1d166b | 7250e0a8c7c0474da8d686f7d7353d4d38b1baaf | |||
v1.0 | instruct | Filter | Filter_33156_I | Create an iterative function in python that prints all prime numbers between 1 and 100. Additionally, identify and debug an erroneous prime number check algorithm in the function `is_prime(n)` provided below. | def print_primes():
"""
Prints all prime numbers between 1 and 100.
"""
for num in range(2, 101):
if is_prime(num):
print(num)
def is_prime(n):
"""
Checks if a number n is prime.
This function contains a bug that needs to be identified and fixed.
"""
if n <= 1:
... | from solution import print_primes, is_prime
def test_is_prime_for_small_numbers():
assert is_prime(1) == False
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
def test_is_prime_for_larger_primes():
assert is_prime(29) == True
assert is_prime(31) == True
as... | [
{
"docstring": "Prints all prime numbers between 1 and 100.",
"function_declaration": "def print_primes():",
"function_name": "print_primes",
"parameter_list": "()"
},
{
"docstring": "Checks if a number n is prime.\nThis function contains a bug that needs to be identified and fixed.",
"f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033156",
"row_id": 33156,
"seed_ids": "['Qwen2-72B-Instruct_75636']"
} | 0.679123 | Filter_33156 | I | [
"print_primes",
"is_prime"
] | 2 | [
[
"print_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 767170af62876640686ffff61ac84c03eebc899b | 365eac388086257f7e38c73862aad74689077231 | |||
v1.0 | instruct | Filter | Filter_33171_I | Could you generate a Python code that uses a sorting algorithm like the QuickSort to sort a list of random integers then contrast it with the built-in sort function in Python? Additionally, analysis of time complexity and space complexity of both methods should be included. | import time
import random
def quicksort(arr):
"""
Sorts an array using the QuickSort algorithm.
"""
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
retu... | from solution import quicksort, compare_sorts
def test_quicksort_empty():
assert quicksort([]) == []
def test_quicksort_single_element():
assert quicksort([1]) == [1]
def test_quicksort_sorted_list():
assert quicksort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_quicksort_reverse_sorted_list():
asse... | [
{
"docstring": "Sorts an array using the QuickSort algorithm.",
"function_declaration": "def quicksort(arr):",
"function_name": "quicksort",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def compare_sorts(arr):",
"function_name": "compare_sorts",
"par... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport time\n\ndef quicksort(arr):\n \"\"\"\n Implementation of the QuickSort algorithm to sort a list of integers.\n\n :param arr: List of integers to be sorted\n :... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033171",
"row_id": 33171,
"seed_ids": "['Qwen2-72B-Instruct_75662']"
} | 0.56248 | Filter_33171 | I | [
"quicksort",
"compare_sorts"
] | 2 | [
[
"compare_sorts",
"quicksort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3b730e8e07c5c0aa13970f9448120fb4b786c695 | 20e08b8a9fe99ae8974afb3613e6c345d74fc22b | |||
v1.0 | instruct | Filter | Filter_33197_I | Generate a random hexadecimal color in Python that must be displayed in RGB format as well. Incorporate error handling in case of any faulty color conversion and also create a function to generate multiple unique random hexadecimal colors (between 1 to 10) and display them along with their RGB formats. Validate the gen... | import random
import re
def random_hex_color():
"""
Generate a random hexadecimal color.
"""
hex_color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
return hex_color
def hex_to_rgb(hex_color):
"""
Convert a hex color to RGB.
"""
try:
hex_color = hex_color.lstrip('#')
... | from solution import random_hex_color, hex_to_rgb, generate_unique_random_colors, validate_hex_color
def test_random_hex_color():
color = random_hex_color()
assert validate_hex_color(color) is True
def test_hex_to_rgb():
rgb_color = hex_to_rgb("#ffffff")
assert rgb_color == (255, 255, 255)
rgb_col... | [
{
"docstring": "Generate a random hexadecimal color.",
"function_declaration": "def random_hex_color():",
"function_name": "random_hex_color",
"parameter_list": "()"
},
{
"docstring": "Convert a hex color to RGB.",
"function_declaration": "def hex_to_rgb(hex_color):",
"function_name"... | [
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 re\n\ndef generate_random_hex_color():\n \"\"\"\n Generate a random hexadecimal color.\n \"\"\"\n return \"#{:06x}\".format(random.randint(0, 0xFFFFFF))\n\nde... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033197",
"row_id": 33197,
"seed_ids": "['Qwen2-72B-Instruct_75704']"
} | 0.606176 | Filter_33197 | I | [
"random_hex_color",
"hex_to_rgb",
"generate_unique_random_colors",
"validate_hex_color"
] | 4 | [
[
"generate_unique_random_colors",
"hex_to_rgb"
],
[
"generate_unique_random_colors",
"random_hex_color"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2db2a561cca45a019b1f41910a5b70b4f494f03c | ae34fdef24d4624b4e63564448978394e85f2012 | |||
v1.0 | instruct | Filter | Filter_33206_I | Modify the following python program to return the sum of even numbers from the input list that are also prime numbers. | def is_prime(n):
"""
Check 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 sum_of_even_primes(numbers):
"""
Returns the sum of even numbers from the input list that are a... | from solution import sum_of_even_primes
def test_sum_of_even_primes_with_mixed_numbers():
assert sum_of_even_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2
def test_sum_of_even_primes_with_all_even_numbers():
assert sum_of_even_primes([2, 4, 6, 8, 10, 12, 14]) == 2
def test_sum_of_even_primes_with_no_prime_number... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of even numbers from the input list that are also prime numbers.",
"function_declaration": "def sum_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 a prime number.\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": "00033206",
"row_id": 33206,
"seed_ids": "['Qwen2-72B-Instruct_75721']"
} | 0.759361 | Filter_33206 | I | [
"is_prime",
"sum_of_even_primes"
] | 2 | [
[
"sum_of_even_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8d3739c80e838cf39e54d00c27435ee3fbe4df7c | 23c1ee4b7a69897a4b60041fa269366e2bf171ac | |||
v1.0 | instruct | Filter | Filter_33211_I | Write a Python script to simulate a simple dice game between two players where each rolls a six-sided die once. If the result of the roll is even, the player gains points equal to the roll value; if it is odd, the player loses half the roll value in points. The script should include a function to simulate the roll of a... | import random
def roll_die():
"""
Simulates rolling a six-sided die and returns the outcome (1-6).
"""
return random.randint(1, 6)
def calculate_points(roll):
"""
Calculate points based on the roll:
- If roll is even, gain points equal to roll
- If roll is odd, lose half the roll value... | from solution import roll_die, calculate_points, play_game
import pytest
def test_roll_die():
# Since roll_die involves randomness, we'll check if it's within expected bounds
for _ in range(100):
roll = roll_die()
assert 1 <= roll <= 6
def test_calculate_points():
# Test for even rolls
... | [
{
"docstring": "Simulates rolling a six-sided die and returns the outcome (1-6).",
"function_declaration": "def roll_die():",
"function_name": "roll_die",
"parameter_list": "()"
},
{
"docstring": "Calculate points based on the roll:\n- If roll is even, gain points equal to roll\n- If roll is... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef roll_die():\n \"\"\"\n Simulates rolling a six-sided die and returns the outcome (1-6).\n \"\"\"\n return random.randint(1, 6)\n\ndef calculate_points(roll):\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033211",
"row_id": 33211,
"seed_ids": "['Qwen2-72B-Instruct_75733']"
} | 0.498377 | Filter_33211 | I | [
"roll_die",
"calculate_points",
"play_game"
] | 3 | [
[
"play_game",
"calculate_points"
],
[
"play_game",
"roll_die"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c257fb2f8e5be85fcdc3e03fff318dc56334b0f3 | 911417d5af37c6525dd19bdc630be6b8854b08c0 | |||
v1.0 | instruct | Filter | Filter_33224_I | In Python, write a function that accepts an extensive list of IP addresses as input. The function should convert each unique IP address from its decimal representation to a binary representation. The function should then return a dictionary where the key is the binary representation of the IP and the value is the count... | def ip_decimal_to_binary(ip):
"""
Converts a given IP address from decimal to binary representation.
"""
return '.'.join(format(int(octet), '08b') for octet in ip.split('.'))
def count_ip_addresses(ip_list):
"""
Given a list of IP addresses in decimal form, returns a dictionary where
the ke... | from solution import count_ip_addresses, ip_decimal_to_binary
def test_ip_decimal_to_binary():
assert ip_decimal_to_binary("192.168.1.1") == "11000000.10101000.00000001.00000001"
assert ip_decimal_to_binary("0.0.0.0") == "00000000.00000000.00000000.00000000"
assert ip_decimal_to_binary("255.255.255.255") =... | [
{
"docstring": "Converts a given IP address from decimal to binary representation.",
"function_declaration": "def ip_decimal_to_binary(ip):",
"function_name": "ip_decimal_to_binary",
"parameter_list": "(ip)"
},
{
"docstring": "Given a list of IP addresses in decimal form, returns a dictionar... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def decimal_to_binary(ip_decimal):\n \"\"\"\n Converts a decimal IP address to its binary representation.\n \"\"\"\n return '.'.join(format(int(part), '08b') for part in ip_decimal... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033224",
"row_id": 33224,
"seed_ids": "['Qwen2-72B-Instruct_75752']"
} | 0.649866 | Filter_33224 | I | [
"ip_decimal_to_binary",
"count_ip_addresses"
] | 2 | [
[
"count_ip_addresses",
"ip_decimal_to_binary"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 435f1d5a0c96be07acb84da02352cbd350281521 | 9ac50806b1c90f8fc8346056ff58cac84f1d579a | |||
v1.0 | instruct | Filter | Filter_33235_I | Translate the following Python loop into a generator expression, but this time, instead of checking simple divisibility by 2, find all Fibonacci numbers in the data list. A number is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 – 4) is a perfect square. Your generator expression should maintain the ori... | import math
def is_perfect_square(x):
s = int(math.sqrt(x))
return s * s == x
def is_fibonacci(n):
"""Check if a number is a Fibonacci number."""
return is_perfect_square(5 * n * n + 4) or is_perfect_square(5 * n * n - 4)
def even_fibonacci_numbers(data):
return (num for num in data if num % 2 ==... | from solution import even_fibonacci_numbers, is_fibonacci
def test_is_fibonacci():
assert is_fibonacci(1) == True
assert is_fibonacci(2) == True
assert is_fibonacci(3) == True
assert is_fibonacci(4) == False
assert is_fibonacci(5) == True
assert is_fibonacci(6) == False
assert is_fibonacci(... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": "Check if a number is a Fibonacci number.",
"function_declaration": "def is_fibonacci(n):",
"function_name": "is_fibonacci",
"... | [
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_perfect_square(x):\n return int(math.sqrt(x)) ** 2 == x\n\ndef is_fibonacci(n):\n return is_perfect_square(5 * n * n + 4) or is_perfect_square(5 * n * n - 4)\n\ndef... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033235",
"row_id": 33235,
"seed_ids": "['Qwen2-72B-Instruct_75782']"
} | 0.592005 | Filter_33235 | I | [
"is_perfect_square",
"is_fibonacci",
"even_fibonacci_numbers"
] | 3 | [
[
"even_fibonacci_numbers",
"is_fibonacci"
],
[
"is_fibonacci",
"is_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 02931df62968929c18bf9276c5ae4304d5db7271 | bbd197d1ee850680dd9476f32c257984dff370ae | |||
v1.0 | instruct | Filter | Filter_33257_I | Write a concise snippet of Python code to find all the prime numbers from 1 to 100, also ensure that the code snippet includes a function to check if a number is prime. | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def primes_up_to_100():
"""
Returns a list of prime numbers from 1 to 100.
"""
... | from solution import is_prime, primes_up_to_100
def test_is_prime_with_prime_numbers():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(7) == True
def test_is_prime_with_non_prime_numbers():
assert is_prime(1) == False
assert is_prime(4) == Fals... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers from 1 to 100.",
"function_declaration": "def primes_up_to_100():",
"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033257",
"row_id": 33257,
"seed_ids": "['Qwen2-72B-Instruct_75822']"
} | 0.69676 | Filter_33257 | I | [
"is_prime",
"primes_up_to_100"
] | 2 | [
[
"primes_up_to_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | af815a39c1b62685154623753eb71f32954bf2ff | ba95fec74d9fc92eef1a38ca7194ee505b00da77 | |||
v1.0 | instruct | Filter | Filter_33259_I | Create a Python program to check if all items in a list are unique, without using any built-in functions or data structures. Additionally, handle the case where the list contains nested lists. | def flatten_list(nested_list):
"""
Flattens a nested list into a single list.
"""
flat_list = []
for item in nested_list:
if isinstance(item, list):
flat_list.extend(flatten_list(item))
else:
flat_list.append(item)
return flat_list
def all_unique(items):
... | from solution import flatten_list, all_unique
def test_flatten_simple_list():
assert flatten_list([1, 2, 3]) == [1, 2, 3]
def test_flatten_nested_list():
assert flatten_list([[1, 2], [3, 4], 5]) == [1, 2, 3, 4, 5]
def test_flatten_deep_nested_list():
assert flatten_list([1, [2, [3, [4]]]]) == [1, 2, 3, 4... | [
{
"docstring": "Flattens a nested list into a single list.",
"function_declaration": "def flatten_list(nested_list):",
"function_name": "flatten_list",
"parameter_list": "(nested_list)"
},
{
"docstring": "Checks if all items in a list are unique, including nested lists.",
"function_decla... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def are_all_items_unique(lst):\n \"\"\"\n Checks if all items in the list are unique. Handles nested lists.\n\n Args:\n lst (list): The list to check for uniqueness.\n\n Returns... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033259",
"row_id": 33259,
"seed_ids": "['Qwen2-72B-Instruct_75827']"
} | 0.783325 | Filter_33259 | I | [
"flatten_list",
"all_unique"
] | 2 | [
[
"all_unique",
"flatten_list"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b76cd3b6ae22f1911645902201e77ce8b801c992 | f8446e17677cbd6d3b3d352e99f564d5736daf62 | |||
v1.0 | instruct | Filter | Filter_33260_I | In Python, how would you implement a binary search algorithm on a pre-sorted array to find the index of a specific element? If the element does not exist in the array, return -1. Moreover, modify the binary search function to determine the number of occurrences of the specific element in the array and return that numbe... | def binary_search(arr, target):
"""
Performs binary search to find the index of target in arr.
If target is not found, returns -1.
"""
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] ... | from solution import binary_search, count_occurrences
def test_binary_search():
assert binary_search([1, 2, 3, 4, 5], 3) == 2
assert binary_search([1, 2, 3, 4, 5], 1) == 0
assert binary_search([1, 2, 3, 4, 5], 5) == 4
assert binary_search([1, 2, 3, 4, 5], 6) == -1
assert binary_search([], 3) == -1
... | [
{
"docstring": "Performs binary search to find the index of target in arr.\nIf target is not found, returns -1.",
"function_declaration": "def binary_search(arr, target):",
"function_name": "binary_search",
"parameter_list": "(arr, target)"
},
{
"docstring": "Returns the number of occurrence... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def binary_search(arr, target):\n \"\"\"\n Perform binary search on a sorted array to find the index of target.\n If the target does not exist, return -1.\n \"\"\"\n left, right... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033260",
"row_id": 33260,
"seed_ids": "['Qwen2-72B-Instruct_75828']"
} | 0.726545 | Filter_33260 | I | [
"binary_search",
"count_occurrences"
] | 2 | [
[
"count_occurrences",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c4150db43a2b8d7d66692af0227a96d52e23042b | b13c995c370cace822b6a349175309e36579e692 | |||
v1.0 | instruct | Filter | Filter_33288_I | Develop a Python script to find and print the squares of the first 10 prime numbers. Make sure not to use any external libraries for this task and ensure the code is efficient. You may also include a function to verify the correctness of your results. | def is_prime(n):
"""
Check if the 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
i += 6
... | from solution import is_prime, first_10_primes, squares_of_first_10_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(4) == False
assert is_prime(17) == True
def test_first_10_primes():
assert first_10_primes() == [2,... | [
{
"docstring": "Check if the number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return a list of the first 10 prime numbers.",
"function_declaration": "def first_10_primes():",
"function_na... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033288",
"row_id": 33288,
"seed_ids": "['Qwen2-72B-Instruct_75878']"
} | 0.492764 | Filter_33288 | I | [
"is_prime",
"first_10_primes",
"squares_of_first_10_primes"
] | 3 | [
[
"first_10_primes",
"is_prime"
],
[
"squares_of_first_10_primes",
"first_10_primes"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 035467d13ba84ceef228a4afe0cda0ddd64d1ad3 | 5f49841010ae3270f1205141d05cad6a0b365f14 | |||
v1.0 | instruct | Filter | Filter_33290_I | Create a Python script that generates an array of 10,000 random floating point numbers between -100 and 100, and then sort this array in ascending order using a sorting algorithm of your choice (without using built-in sort functions). To make the program more efficient, implement a search algorithm that could find and ... | import random
def generate_random_floats(size, lower_bound, upper_bound):
"""
Generates an array of random floating point numbers.
:param size: The number of float numbers to generate.
:param lower_bound: The lower bound of the random float.
:param upper_bound: The upper bound of the random float.... | from solution import generate_random_floats, quicksort, binary_search, find_number
def test_generate_random_floats():
arr = generate_random_floats(10000, -100, 100)
assert len(arr) == 10000
assert all(-100 <= x <= 100 for x in arr)
def test_quicksort():
unsorted_arr = [3.0, 1.0, 4.0, 1.5]
sorted_a... | [
{
"docstring": "Generates an array of random floating point numbers.\n\n:param size: The number of float numbers to generate.\n:param lower_bound: The lower bound of the random float.\n:param upper_bound: The upper bound of the random float.\n:return: A list of random floating point numbers.",
"function_dec... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_random_floats(count, lower_bound, upper_bound):\n \"\"\"\n Generates an array of random floating point numbers.\n :param count: Number of random floats t... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033290",
"row_id": 33290,
"seed_ids": "['Qwen2-72B-Instruct_75880']"
} | 0.543029 | Filter_33290 | I | [
"generate_random_floats",
"quicksort",
"binary_search",
"find_number"
] | 4 | [
[
"find_number",
"binary_search"
],
[
"find_number",
"quicksort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 02559e402b4f529eded071e2258345525e75e28d | dcbc2619ff39d77e9d5164e9ca75ac203465862d | |||
v1.0 | instruct | Filter | Filter_33292_I | Problem: Given a positive integer N, write a Python program to generate an array representing the first n prime numbers. | def is_prime(num):
"""
Returns True if num is a prime number, otherwise False.
"""
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def generate_primes(n):
"""
Returns a list of the first n prime numbe... | from solution import generate_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(5) == True
assert is_prime(11) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-1) == Fal... | [
{
"docstring": "Returns True if num is a prime number, otherwise False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns a list of the first n prime numbers.",
"function_declaration": "def generate_primes(n)... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a given number is prime.\n \"\"\"\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if num % i == 0:\n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033292",
"row_id": 33292,
"seed_ids": "['Qwen2-72B-Instruct_75882']"
} | 0.674839 | Filter_33292 | I | [
"is_prime",
"generate_primes"
] | 2 | [
[
"generate_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5719d17606cc50a15da38c7d7a83e108a19a87f9 | 005553cf146c2531c883834eb046ec06ccd01692 | |||
v1.0 | instruct | Filter | Filter_33311_I | Write a Python code snippet that uses multiple-step reasoning to determine and display the number of unique numerical elements in a given list which are palindrome numbers. Use this list as your example: [73, 111, 45, 12321, 898, 73, 45]. | def is_palindrome(number):
"""
Check if the given number is a palindrome.
"""
str_num = str(number)
return str_num == str_num[::-1]
def unique_palindromes_count(lst):
"""
Returns the count of unique palindrome numbers in the given list.
"""
unique_elements = set(lst)
palindromes... | from solution import is_palindrome, unique_palindromes_count
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(898) == True
assert is_palindrome(111) == True
assert is_palindrome(73) == False
... | [
{
"docstring": "Check if the given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns the count of unique palindrome numbers in the given list.",
"function_declaration":... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[0]\n\ndef unique_palindromes_count(lst):\n \"\"\"\n Returns the count o... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033311",
"row_id": 33311,
"seed_ids": "['Qwen2-72B-Instruct_75926']"
} | 0.674998 | Filter_33311 | I | [
"is_palindrome",
"unique_palindromes_count"
] | 2 | [
[
"unique_palindromes_count",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 380c6b02b207aa41a95b770838686f50a357bfd9 | bc99327cb477cf9b3c66c478cd6d9d2326e6455e | |||
v1.0 | instruct | Filter | Filter_33319_I | Given a list of numbers, design a function in Python to check if all numbers in the list are prime. The time complexity of your solution should be less than O(n^(1.5)), where n is the length of the input list. | 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
def all_... | from solution import all_primes
def test_all_primes_all_prime_numbers():
assert all_primes([2, 3, 5, 7, 11]) == True
def test_all_primes_some_non_prime_numbers():
assert all_primes([2, 4, 6, 8, 10]) == False
def test_all_primes_single_prime_number():
assert all_primes([3]) == True
def test_all_primes_si... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Check if all numbers in the list are prime.\n\n:param numbers: List of integers.\n:return: Boolean indicating if all numbers are p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"Check if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033319",
"row_id": 33319,
"seed_ids": "['Qwen2-72B-Instruct_75938']"
} | 0.730117 | Filter_33319 | I | [
"is_prime",
"all_primes"
] | 2 | [
[
"all_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4ecdf427eab985d648402c04a3d4a6fc3da0e150 | f2daf66eeebbaab613a6e7b83b96619bf64b8c40 | |||
v1.0 | instruct | Filter | Filter_33335_I | Can you write a python program to generate 5 random english words with at least 5 characters? | import random
import string
def generate_random_word():
"""
Generates a random English word of at least 5 characters length.
"""
length = random.randint(5, 10) # Random word length between 5 and 10 characters
return ''.join(random.choices(string.ascii_lowercase, k=length))
def generate_random_wor... | from solution import generate_random_words
def test_generate_random_words_length():
words = generate_random_words()
assert len(words) == 5 # Check if 5 words are generated
def test_generate_random_words_each_word_length():
words = generate_random_words()
for word in words:
assert len(word) >=... | [
{
"docstring": "Generates a random English word of at least 5 characters length.",
"function_declaration": "def generate_random_word():",
"function_name": "generate_random_word",
"parameter_list": "()"
},
{
"docstring": "Generates n random English words, each of at least 5 characters in leng... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport requests\n\ndef generate_random_words(num_words=5, min_length=5):\n \"\"\"\n Generates a list of random English words with at least the specified minimum length.\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033335",
"row_id": 33335,
"seed_ids": "['Qwen2-72B-Instruct_75968']"
} | 0.661391 | Filter_33335 | I | [
"generate_random_word",
"generate_random_words"
] | 2 | [
[
"generate_random_words",
"generate_random_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9a4015c67b74432566454ba555cab7aa80a28815 | e2a5a8fa126ad839398f44c0a2b37dae19e9f136 | |||
v1.0 | instruct | Filter | Filter_33337_I | Write a Python program that generates a random integer between 1 and 100, then prints whether the number is even or odd. Ensure the program can handle repeated runs without restarting the Python kernel. | import random
def generate_random_number():
"""
Generates a random integer between 1 and 100
"""
return random.randint(1, 100)
def check_even_odd(n):
"""
Returns whether the given number is 'even' or 'odd'
"""
if n % 2 == 0:
return "even"
else:
return "odd"
def ran... | from solution import generate_random_number, check_even_odd, random_even_odd
def test_generate_random_number():
number = generate_random_number()
assert 1 <= number <= 100
def test_check_even_odd():
assert check_even_odd(2) == "even"
assert check_even_odd(3) == "odd"
assert check_even_odd(0) == "e... | [
{
"docstring": "Generates a random integer between 1 and 100",
"function_declaration": "def generate_random_number():",
"function_name": "generate_random_number",
"parameter_list": "()"
},
{
"docstring": "Returns whether the given number is 'even' or 'odd'",
"function_declaration": "def ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef generate_random_even_odd():\n \"\"\"\n Generates a random integer between 1 and 100 and returns a string indicating\n whether the number is even or odd.\n \"\"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033337",
"row_id": 33337,
"seed_ids": "['Qwen2-72B-Instruct_75972']"
} | 0.593317 | Filter_33337 | I | [
"generate_random_number",
"check_even_odd",
"random_even_odd"
] | 3 | [
[
"random_even_odd",
"check_even_odd"
],
[
"random_even_odd",
"generate_random_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 227caf1c1005cf46e6cc2fbf7d6bbd8f26b71332 | ea1ede40cd7656f2781c77c15307956b84ea6077 | |||
v1.0 | instruct | Filter | Filter_33377_I | Can you suggest a Python function that can parse an XML document and generate a JSON representation of it, taking into account attributes and namespace? The function, `xml_to_json`, takes an `xml_string` as input and returns a dictionary with the XML data. It should consider attributes and namespace in the XML structur... | import xml.etree.ElementTree as ET
def parse_element(element):
"""
Recursive function to parse an XML element and convert it to a dictionary.
Handles attributes and namespaces.
"""
parsed_data = {}
# Handle element text
if element.text and element.text.strip():
parsed_data["#te... | from solution import xml_to_json
def test_simple_xml():
xml_string = '<root><child>value</child></root>'
expected_output = {
"root": {
"child": {
"#text": "value"
}
}
}
assert xml_to_json(xml_string) == expected_output
def test_xml_with_attribute... | [
{
"docstring": "Recursive function to parse an XML element and convert it to a dictionary.\nHandles attributes and namespaces.",
"function_declaration": "def parse_element(element):",
"function_name": "parse_element",
"parameter_list": "(element)"
},
{
"docstring": "Converts an XML string to... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import xml.etree.ElementTree as ET\nimport json\n\ndef xml_to_json(xml_string):\n def parse_element(element):\n tag_with_ns = element.tag.split(\"}\")\n if len(tag_with_ns) > ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033377",
"row_id": 33377,
"seed_ids": "['Qwen2-72B-Instruct_76047']"
} | 0.698419 | Filter_33377 | I | [
"parse_element",
"xml_to_json"
] | 2 | [
[
"xml_to_json",
"parse_element"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba000bf68aa45cd7d82d81bdcf879e03a2f9066c | 7e5b8c5c18a127d991d2424810c409a706e11104 | |||
v1.0 | instruct | Filter | Filter_33380_I | Create a function to find the smallest prime number in a given list of positive integers. The function should return -1 if no prime number is present in the list. The function should have a time complexity of O(n√m), where n is the length of the list and m is the largest number in the list. The function should not use ... | def is_prime(n):
"""
Returns True if n is a prime number, else returns False.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import smallest_prime
def test_smallest_prime_with_primes():
assert smallest_prime([10, 3, 5, 7]) == 3
def test_smallest_prime_with_no_primes():
assert smallest_prime([4, 6, 8, 10]) == -1
def test_smallest_prime_with_mixed_values():
assert smallest_prime([15, 11, 14, 22, 17]) == 11
def tes... | [
{
"docstring": "Returns True if n is a prime number, else returns False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the smallest prime number in the given list of positive integers.\nIf no prime number is foun... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number n 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_1 | {
"original_instruction": "",
"prompt_id": "00033380",
"row_id": 33380,
"seed_ids": "['Qwen2-72B-Instruct_76053']"
} | 0.598082 | Filter_33380 | I | [
"is_prime",
"smallest_prime"
] | 2 | [
[
"smallest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 907e9d4aab144f3c85886d58b0df35e56abc710f | 27103d74ef1e37261ed5899bec0dc62beed1730e | |||
v1.0 | instruct | Filter | Filter_33384_I | Devise an algorithm using the Merge Sort procedure to organize special key-value pairs in a dictionary data structure. This algorithm should be adept at handling large dictionaries efficiently and also maintain the integrity of the key-value pair connections after sorting. | def merge_sort_dict(d):
"""
Applies merge sort to a dictionary, sorting it by its keys.
:param d: dictionary to be sorted
:return: sorted dictionary by keys
"""
if len(d) <= 1:
return d
# Split the dictionary into two halves
mid = len(d) // 2
left_dict = dict(list(d.it... | from solution import merge_sort_dict
def test_merge_sort_dict_empty():
assert merge_sort_dict({}) == {}
def test_merge_sort_dict_single_element():
assert merge_sort_dict({2: 'b'}) == {2: 'b'}
def test_merge_sort_dict_multiple_elements():
input_dict = {3: 'c', 1: 'a', 2: 'b'}
expected_output = {1: 'a'... | [
{
"docstring": "Applies merge sort to a dictionary, sorting it by its keys.\n\n:param d: dictionary to be sorted\n:return: sorted dictionary by keys",
"function_declaration": "def merge_sort_dict(d):",
"function_name": "merge_sort_dict",
"parameter_list": "(d)"
},
{
"docstring": "Merges two ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def merge_sort_dict(d):\n \"\"\"\n Sorts a dictionary by its keys using the Merge Sort algorithm.\n \n :param d: Dictionary to be sorted.\n :return: Sorted dictionary.\n \"\"... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033384",
"row_id": 33384,
"seed_ids": "['Qwen2-72B-Instruct_76063']"
} | 0.459294 | Filter_33384 | I | [
"merge_sort_dict",
"merge"
] | 2 | [
[
"merge_sort_dict",
"merge"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 301d0971bf5d3969264aad9717ecacdbf12dc128 | ca31df7b091b4fc8eba46be9bfc34f37ad03c53d | |||
v1.0 | instruct | Filter | Filter_33387_I | Define and implement a function named "mySort" that receives an array of integers and returns the sorted array in ascending order. Also, write a test function named "verifySort" that takes an array of integers as an input, calls the mySort function, and prints the sorted array. Your implementation should not use built-... | def mySort(arr):
"""
Sorts an array of integers in ascending order without using built-in sort functions.
"""
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
def verifySort(arr):
... | from solution import mySort, verifySort
def test_mySort_sorted_array():
assert mySort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5]
def test_mySort_reverse_sorted_array():
assert mySort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
def test_mySort_random_order():
assert mySort([3, 1, 4, 5, 2]) == [1, 2, 3, 4, 5]
def test_m... | [
{
"docstring": "Sorts an array of integers in ascending order without using built-in sort functions.",
"function_declaration": "def mySort(arr):",
"function_name": "mySort",
"parameter_list": "(arr)"
},
{
"docstring": "Takes an array of integers, calls the mySort function,\nand prints the so... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def mySort(array):\n \"\"\"\n This function takes an array of integers and returns the sorted array in ascending order\n without using any built-in sort functions.\n \"\"\"\n n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033387",
"row_id": 33387,
"seed_ids": "['Qwen2-72B-Instruct_76068']"
} | 0.633251 | Filter_33387 | I | [
"mySort",
"verifySort"
] | 2 | [
[
"verifySort",
"mySort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 26a8fa21506c30853374106033c367eee8ed464a | 07ad7216d1a946c1329f0f7844a0b9ee7c3f5d5e | |||
v1.0 | instruct | Filter | Filter_33403_I | How can I detect the number of corrupted files in a directory hierarchy using Python? I am working with MB kmz archive files, and each time I find a corrupted archive, I perform a recovery operation on it. I would appreciate if the solution also integrates this recovery process. | import os
from zipfile import ZipFile, BadZipFile
def is_corrupted(file_path):
"""
Check if a zip file (kmz file) is corrupted.
"""
try:
with ZipFile(file_path, 'r') as zip_ref:
bad_file = zip_ref.testzip()
if bad_file:
return True
return Fals... | import os
import pytest
from solution import is_corrupted, recover_file, detect_and_recover_corrupted_files
def create_test_file(dir_path, file_name, content):
file_path = os.path.join(dir_path, file_name)
with open(file_path, 'w') as f:
f.write(content)
return file_path
@pytest.fixture
def setup_... | [
{
"docstring": "Check if a zip file (kmz file) is corrupted.",
"function_declaration": "def is_corrupted(file_path):",
"function_name": "is_corrupted",
"parameter_list": "(file_path)"
},
{
"docstring": "Perform a recovery operation on the corrupted file.\nThe actual recovery logic depends on... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nfrom zipfile import ZipFile, BadZipFile\n\ndef is_kmz_corrupted(filepath):\n \"\"\"\n Checks if the KMZ file is corrupted.\n\n :param filepath: Path to the KMZ file.\n :... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033403",
"row_id": 33403,
"seed_ids": "['Qwen2-72B-Instruct_76099']"
} | 0.515281 | Filter_33403 | I | [
"is_corrupted",
"recover_file",
"detect_and_recover_corrupted_files"
] | 3 | [
[
"detect_and_recover_corrupted_files",
"is_corrupted"
],
[
"detect_and_recover_corrupted_files",
"recover_file"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0716c1c1a2eab68b6f1bbdfe72dda4de8ba701f6 | aa619a105b26945b596f0852cc97bc84addbd1f1 | |||
v1.0 | instruct | Filter | Filter_33420_I | Given an array of integers, convert the array into a heap and then perform a heapsort to sort the array in ascending order. Your program should be able to handle duplicate elements and negative numbers as well. | def heapify(arr, n, i):
"""
Creates a heap from an array.
"""
largest = i # Initialize largest as root
left = 2 * i + 1 # left child index
right = 2 * i + 2 # right child index
# If left child exists and is greater than root
if left < n and arr[largest] < arr[left]:
largest =... | from solution import heap_sort
def test_heap_sort_with_positive_numbers():
arr = [4, 10, 3, 5, 1]
sorted_arr = heap_sort(arr)
assert sorted_arr == [1, 3, 4, 5, 10]
def test_heap_sort_with_negative_numbers():
arr = [-1, -10, 3, 5, 0]
sorted_arr = heap_sort(arr)
assert sorted_arr == [-10, -1, 0,... | [
{
"docstring": "Creates a heap from an array.",
"function_declaration": "def heapify(arr, n, i):",
"function_name": "heapify",
"parameter_list": "(arr, n, i)"
},
{
"docstring": "Performs in-place heapsort on the input array.",
"function_declaration": "def heap_sort(arr):",
"function_... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def heapsort(arr):\n def heapify(arr, n, i):\n largest = i\n l = 2 * i + 1\n r = 2 * i + 2\n\n if l < n and arr[i] < arr[l]:\n largest = l\n\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033420",
"row_id": 33420,
"seed_ids": "['Qwen2-72B-Instruct_76124']"
} | 0.613851 | Filter_33420 | I | [
"heapify",
"heap_sort"
] | 2 | [
[
"heap_sort",
"heapify"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3744702967de0ab36864b256f160a012a2b9273d | 46e0d7a7b8ca24fd803194d9e451da29416d577f | |||
v1.0 | instruct | Filter | Filter_33457_I | Construct a function that shuffles a list of numbers in place and returns nothing. The function should only use constant extra space and should have a time complexity of O(n) on average, where n is the length of the list. The function should also ensure that each possible permutation of the list is equally likely to oc... | def linear_congruential_generator(seed):
"""
A simple linear congruential generator (LCG) to generate pseudo-random numbers.
"""
a = 1664525
c = 1013904223
m = 2**32
seed = (a * seed + c) % m
return seed
def random_int(seed, a, b):
"""
Generates a pseudo-random integer in the ra... | from solution import shuffle
def test_shuffle_length_remains_same():
nums = [1, 2, 3, 4, 5]
original_length = len(nums)
shuffle(nums, seed=42)
assert len(nums) == original_length
def test_shuffle_different_outcome():
nums = [1, 2, 3, 4, 5]
original_nums = nums[:]
shuffle(nums, seed=42)
... | [
{
"docstring": "A simple linear congruential generator (LCG) to generate pseudo-random numbers.",
"function_declaration": "def linear_congruential_generator(seed):",
"function_name": "linear_congruential_generator",
"parameter_list": "(seed)"
},
{
"docstring": "Generates a pseudo-random inte... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\n\ndef custom_random(seed):\n \"\"\"\n Generate a pseudo-random number using a linear congruential generator (LCG).\n x_{n+1} = (a * x_n + c) % m\n Where a, c, and m ar... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033457",
"row_id": 33457,
"seed_ids": "['Qwen2-72B-Instruct_76199']"
} | 0.580669 | Filter_33457 | I | [
"linear_congruential_generator",
"random_int",
"shuffle"
] | 3 | [
[
"random_int",
"linear_congruential_generator"
],
[
"shuffle",
"random_int"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 108411d3bac512d18305cfb101025eb7f56b1c10 | afc00b6d7d02a3ef827fe73ce1d348ad0949a8d9 | |||
v1.0 | instruct | Filter | Filter_33458_I | debug this code snippet to print a list of all prime numbers under 100 without using the direct prime number checking function or Eratosthenes' sieve method. | 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 get_primes_under_100():
"""
Returns a list of all prime numbers under 100.
"""
primes = []
... | from solution import is_prime, get_primes_under_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(-1) == False
assert is_prime(97) ... | [
{
"docstring": "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 under 100.",
"function_declaration": "def get_primes_under_100():",
"function_name": "... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033458",
"row_id": 33458,
"seed_ids": "['Qwen2-72B-Instruct_76200']"
} | 0.518734 | Filter_33458 | I | [
"is_prime",
"get_primes_under_100"
] | 2 | [
[
"get_primes_under_100",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b84027291aace24ec76b095942c098d5adfc54e6 | c39d7dfedf964a3f67e150c8e5aec86810c833c1 | |||
v1.0 | instruct | Filter | Filter_33488_I | Develop a Python code that cooks up a factorial for every number docked within a list and stashes the outcomes in a separate list. But here's the entree to this puzzle: the final list should not only manage to avoid the inclusion of any previously calculated factorials, but also harmonize with the initial list’s sequen... | def factorial(n):
"""
Helper function to calculate the factorial of a number n.
"""
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
def unique_factorials(numbers):
"""
For a list of numbers, calculates the factorial for ea... | from solution import unique_factorials
def test_unique_factorials_single_occurrences():
assert unique_factorials([3, 4, 5]) == [6, 24, 120]
def test_unique_factorials_with_repeated_numbers():
assert unique_factorials([3, 4, 5, 3, 2]) == [6, 24, 120, 6, 2]
assert unique_factorials([2, 2, 3, 3]) == [2, 2, 6... | [
{
"docstring": "Helper function to calculate the factorial of a number n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "For a list of numbers, calculates the factorial for each number, but avoids\nrecalculating the fac... | [
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 unique_factorials(numbers):\n \"\"\"\n Returns a list of factorials for the given numbers, ensuring that if a \n number appears more than once, its factorial is onl... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033488",
"row_id": 33488,
"seed_ids": "['Qwen2-72B-Instruct_76249']"
} | 0.599323 | Filter_33488 | I | [
"factorial",
"unique_factorials"
] | 2 | [
[
"unique_factorials",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f1d98f35d1685cfea6fd57a5a7ac39f0958ac7d6 | 4e9047a958ba239f7dfd4dda15090b223ec3dffa | |||
v1.0 | instruct | Filter | Filter_33493_I | Devise an optimised computational solution that converts hexadecimal numbers into their binary equivalents. Your solution should not just perform the conversion, but also handle large hexadecimal numbers (like 45FA9B). Also, include a function to validate the entered hexadecimal number to ensure it's accurate and error... | def is_valid_hexadecimal(hex_num):
"""
Validates whether the given string is a valid hexadecimal number.
Returns True if valid, else False.
"""
try:
int(hex_num, 16)
return True
except ValueError:
return False
def hex_to_binary(hex_num):
"""
Converts a hexadecima... | from solution import hex_to_binary, is_valid_hexadecimal
def test_is_valid_hexadecimal():
assert is_valid_hexadecimal("1A3F")
assert not is_valid_hexadecimal("1G3F")
assert is_valid_hexadecimal("abcdef")
assert is_valid_hexadecimal("ABCDEF")
assert not is_valid_hexadecimal("XYZ123")
def test_hex_t... | [
{
"docstring": "Validates whether the given string is a valid hexadecimal number.\nReturns True if valid, else False.",
"function_declaration": "def is_valid_hexadecimal(hex_num):",
"function_name": "is_valid_hexadecimal",
"parameter_list": "(hex_num)"
},
{
"docstring": "Converts a hexadecim... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_hex(hex_num):\n \"\"\"\n Validates whether the given string is a valid hexadecimal number.\n A valid hexadecimal number contains only digits (0-9) and/or letters (A-F, a-... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033493",
"row_id": 33493,
"seed_ids": "['Qwen2-72B-Instruct_76260']"
} | 0.606733 | Filter_33493 | I | [
"is_valid_hexadecimal",
"hex_to_binary"
] | 2 | [
[
"hex_to_binary",
"is_valid_hexadecimal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1789480bc5ed2aa40e1fd1249e907949da57bdd0 | b5c03598e0da1d7186a29c9dee6837a98898fb87 | |||
v1.0 | instruct | Filter | Filter_33510_I | Creating a Flask Python Application for URL Shortening | from flask import Flask, request, redirect, jsonify
import string
import random
app = Flask(__name__)
# Store URL mappings
url_mapping = {}
def generate_short_code(length=6):
"""
Generate a random string of letters and digits.
"""
characters = string.ascii_letters + string.digits
return ''.join(r... | import pytest
from solution import app, generate_short_code, url_mapping
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def test_generate_short_code_length():
code = generate_short_code(6)
assert len(code) == 6
def test_generate_short_code_charset():
code = gener... | [
{
"docstring": "Generate a random string of letters and digits.",
"function_declaration": "def generate_short_code(length=6):",
"function_name": "generate_short_code",
"parameter_list": "(length=6)"
},
{
"docstring": "API Endpoint to shorten a given URL.",
"function_declaration": "def sh... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from flask import Flask, request, redirect, jsonify\nfrom werkzeug.exceptions import NotFound\n\napp = Flask(__name__)\n\n# In-memory storage of shortened URLs\nurl_mapping = {}\n\n@app.route(... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033510",
"row_id": 33510,
"seed_ids": "['Qwen2-72B-Instruct_76283']"
} | 0.510733 | Filter_33510 | I | [
"generate_short_code",
"shorten_url",
"redirect_to_url"
] | 3 | [
[
"shorten_url",
"generate_short_code"
]
] | 1 | [] | false | [] | false | pytest | true | [
"flask"
] | false | 8b989e1565e5277a344bdda357615f73c5a8fdf7 | b88492a6989c3bcdc220e2962103bb8a079f462f | |||
v1.0 | instruct | Filter | Filter_33511_I | Develop a recursive function that calculates the factorial of numbers up to the given number. In addition, have the function return a list of all the factorials of numbers from 1 to the given number. Ensure to implement error checks to maintain that the input is a positive integer. | def factorial_recursive(n):
"""
Calculates the factorial of a given positive integer n.
"""
if not isinstance(n, int) or n <= 0:
raise ValueError("Input must be a positive integer.")
if n == 1:
return 1
else:
return n * factorial_recursive(n-1)
def factorial_list(n)... | from solution import factorial_recursive, factorial_list
def test_factorial_recursive():
assert factorial_recursive(1) == 1
assert factorial_recursive(2) == 2
assert factorial_recursive(3) == 6
assert factorial_recursive(4) == 24
assert factorial_recursive(5) == 120
def test_factorial_recursive_in... | [
{
"docstring": "Calculates the factorial of a given positive integer n.",
"function_declaration": "def factorial_recursive(n):",
"function_name": "factorial_recursive",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of factorials of numbers from 1 to n.",
"function_declaration... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def factorial_recursive(n):\n \"\"\"\n Returns the factorial of the number `n`.\n Also generates a list of factorials for all integers from 1 to `n`.\n \"\"\"\n if not isinstanc... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033511",
"row_id": 33511,
"seed_ids": "['Qwen2-72B-Instruct_76287']"
} | 0.696982 | Filter_33511 | I | [
"factorial_recursive",
"factorial_list"
] | 2 | [
[
"factorial_list",
"factorial_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba4d02da819e5933ab13e57e8262223cedbbe4a0 | 01a3cd7039735ce370cef4bb30ee1d8e2774e399 | |||
v1.0 | instruct | Filter | Filter_33523_I | Create a version of the game rock, paper, scissors against the computer. The game should have a scoring system and a way to keep track of the number of rounds played. The game should also allow the user to quit at any time by typing 'q'. Your program should display the final score after each round, and at the end of th... | import random
def get_computer_choice():
"""
Returns the computer's choice randomly from ['rock', 'paper', 'scissors']
"""
return random.choice(['rock', 'paper', 'scissors'])
def determine_winner(player_choice, computer_choice):
"""
Determines the winner between the player and the computer.
... | from solution import get_computer_choice, determine_winner, play_round
def test_get_computer_choice():
for _ in range(100): # test multiple times due to randomness
choice = get_computer_choice()
assert choice in ['rock', 'paper', 'scissors']
def test_determine_winner():
assert determine_winne... | [
{
"docstring": "Returns the computer's choice randomly from ['rock', 'paper', 'scissors']",
"function_declaration": "def get_computer_choice():",
"function_name": "get_computer_choice",
"parameter_list": "()"
},
{
"docstring": "Determines the winner between the player and the computer.\nRetu... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef get_computer_choice():\n choices = ['rock', 'paper', 'scissors']\n return random.choice(choices)\n\ndef determine_winner(user_choice, computer_choice):\n if user_... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033523",
"row_id": 33523,
"seed_ids": "['Qwen2-72B-Instruct_76309']"
} | 0.487005 | Filter_33523 | I | [
"get_computer_choice",
"determine_winner",
"play_round",
"play_game"
] | 4 | [
[
"play_game",
"get_computer_choice"
],
[
"play_game",
"play_round"
],
[
"play_round",
"determine_winner"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 780f7ff8cb4406b0c20f8293aaaa321ce5ee1034 | a56e56583f27339dd4aec3396cdc276373828929 | |||
v1.0 | instruct | Filter | Filter_33539_I | Construct a Python function that accepts a list of integers as input and returns the sum of all the prime numbers in the input list. While doing this, confirm to the highest standards of legibility, maintainability, and performance. Provide a succinct commentary elucidating the operational mechanics of your function, p... | from typing import List
def is_prime(n: int) -> bool:
"""
Check if a given 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:
... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(1) == False
assert is_prime(-7) == False
def test_sum_of_primes_empty... | [
{
"docstring": "Check if a given number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Return the sum of all prime numbers in the input list.",
"function_declaration": "def sum_of_primes(numbers):... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Check if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033539",
"row_id": 33539,
"seed_ids": "['Qwen2-72B-Instruct_76338']"
} | 0.615218 | Filter_33539 | I | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3b1bb74adb9c1782f976e596b7881e67858f4f17 | 8b508a84ec5a2d6d8cf88eace9ba10064397b1b3 | |||
v1.0 | instruct | Filter | Filter_33548_I | Import the "random" module in Python and generate a random number between 1 and 100, but ensure that the number is prime. | import random
def is_prime(n):
"""Check if a number is prime."""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def random_prime():
"""Gene... | from solution import random_prime, is_prime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(19) == True
assert is_prime(20) == False
def test_random_prime():
for _ in range(100): # Test multi... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Generate a random prime number between 1 and 100.",
"function_declaration": "def random_prime():",
"function_name": "rando... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef is_prime(n):\n \"\"\" Check if a number is prime. \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033548",
"row_id": 33548,
"seed_ids": "['Qwen2-72B-Instruct_76355']"
} | 0.519094 | Filter_33548 | I | [
"is_prime",
"random_prime"
] | 2 | [
[
"random_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c046d0745df734ecf164add42dd3cb780894131e | 3271aa8d047a2e22c85c10459a3e21432e354b1c | |||
v1.0 | instruct | Filter | Filter_33554_I | Given the login information for several users in a format such as "user123:password456:email@email.com", create a code that determines the validity of the email address associated with each login. Additionally, implement conditions to verify that the email domain belongs to a limited set of approved domains (e.g., '@gm... | import re
def is_valid_email(email, approved_domains):
"""
Check if the provided email is valid and belongs to one of the approved domains.
Parameters:
- email: The email address to check.
- approved_domains: A list of approved email domains.
Returns:
- True if the email is valid ... | from solution import is_valid_email, validate_logins
def test_is_valid_email():
approved_domains = ['@gmail.com', '@yahoo.com', '@hotmail.com']
assert is_valid_email('test@gmail.com', approved_domains) == True
assert is_valid_email('test@yahoo.com', approved_domains) == True
assert is_valid_email(... | [
{
"docstring": "Check if the provided email is valid and belongs to one of the approved domains.\n\nParameters:\n- email: The email address to check.\n- approved_domains: A list of approved email domains.\n\nReturns:\n- True if the email is valid and belongs to an approved domain, False otherwise.",
"functi... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef is_valid_email(email, approved_domains):\n \"\"\"\n Validates the email address format and ensures the domain is in the list of approved domains.\n \n Parameters:\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033554",
"row_id": 33554,
"seed_ids": "['Qwen2-72B-Instruct_76368']"
} | 0.400346 | Filter_33554 | I | [
"is_valid_email",
"validate_logins"
] | 2 | [
[
"validate_logins",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 182fdf6771f1e68fa104e6280a3a545e5ac213db | 64c3b612bfb6064217f32dfe1d797ccb457382fd | |||
v1.0 | instruct | Filter | Filter_33560_I | Write a code to delete a node, including its subtrees, from a given Binary Search Tree (BST). Also, after deletion, rearrange the tree to maintain the BST property. The tree must be balanced after every deletion by following AVL (Adelson-Velsky and Landis) tree guidelines. AVL tree is a self-balancing BST where the dif... | class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
self.height = 1
def get_height(node):
if not node:
return 0
return node.height
def update_height(node):
if node:
node.height = 1 + max(get_height(node.left), get_h... | from solution import TreeNode, insert, delete_node, get_height
def in_order_traversal(root, result):
if not root:
return
in_order_traversal(root.left, result)
result.append(root.key)
in_order_traversal(root.right, result)
def test_insert_and_delete_avl_tree():
root = None
keys = [10, 2... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n self.height = 1\n\ndef deleteNode(root, key):\n if not ro... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033560",
"row_id": 33560,
"seed_ids": "['Qwen2-72B-Instruct_76378']"
} | 0.522741 | Filter_33560 | I | [
"get_height",
"update_height",
"get_balance",
"right_rotate",
"left_rotate",
"insert",
"get_min_value_node",
"delete_node"
] | 8 | [
[
"delete_node",
"get_balance"
],
[
"delete_node",
"get_min_value_node"
],
[
"delete_node",
"left_rotate"
],
[
"delete_node",
"right_rotate"
],
[
"delete_node",
"update_height"
],
[
"get_balance",
"get_height"
],
[
"insert",
"get_balanc... | 13 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 5c744c5a956cc0a3474738596d60b403260b7772 | 3e437c8803ad21fd3845b47a3e2369ad98463c67 | |||
v1.0 | instruct | Filter | Filter_33581_I | Devise a script in Python that generates a checkerboard with alternating dark and light squares, using only the characters 'X' for dark squares and 'O' for light squares. You should create this pattern in a way that allows the board size to be easily adjusted to create checkerboards of different sizes. Also, write a fu... | def validate_size(size):
"""
Validates the input size to be an even number.
If the input is odd, decreases the size by 1.
"""
return size if size % 2 == 0 else size - 1
def generate_checkerboard(size):
"""
Generates a checkerboard pattern with 'X' and 'O'.
"""
size = validate_size(... | from solution import validate_size, generate_checkerboard
def test_validate_size_even():
assert validate_size(6) == 6
assert validate_size(8) == 8
def test_validate_size_odd():
assert validate_size(7) == 6
assert validate_size(15) == 14
def test_generate_checkerboard_even_size():
expected_board_4... | [
{
"docstring": "Validates the input size to be an even number. \nIf the input is odd, decreases the size by 1.",
"function_declaration": "def validate_size(size):",
"function_name": "validate_size",
"parameter_list": "(size)"
},
{
"docstring": "Generates a checkerboard pattern with 'X' and '... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def adjust_size(n):\n \"\"\"\n Validate the input size and decrease it by 1 if it's odd.\n \"\"\"\n return n if n % 2 == 0 else n - 1\n\ndef generate_checkerboard(size):\n \"\"\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033581",
"row_id": 33581,
"seed_ids": "['Qwen2-72B-Instruct_76411']"
} | 0.536573 | Filter_33581 | I | [
"validate_size",
"generate_checkerboard"
] | 2 | [
[
"generate_checkerboard",
"validate_size"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fc807e2d14d0cdaa5b410787ccedbb8baeb6b886 | 242bf7ffe4215e11075f905cb5f198d824296d3a | |||
v1.0 | instruct | Filter | Filter_33586_I | You're in a classroom teaching CS. Design a program that solves the maximum subarray problem using a Divide and Conquer approach and allows for interactive input from students. The students should be able to choose the values in the array and see the output on the screen after each execution. | def max_crossing_sum(arr, low, mid, high):
"""
Helper function to calculate the maximum sum of the subarray crossing the midpoint.
"""
left_sum = float('-inf')
sum = 0
for i in range(mid, low - 1, -1):
sum += arr[i]
if sum > left_sum:
left_sum = sum
right_sum = f... | from solution import max_subarray
def test_max_subarray_all_positive():
assert max_subarray([1, 2, 3, 4, 5]) == 15
def test_max_subarray_all_negative():
assert max_subarray([-1, -2, -3, -4, -5]) == -1
def test_max_subarray_mixed():
assert max_subarray([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
def test_max_s... | [
{
"docstring": "Helper function to calculate the maximum sum of the subarray crossing the midpoint.",
"function_declaration": "def max_crossing_sum(arr, low, mid, high):",
"function_name": "max_crossing_sum",
"parameter_list": "(arr, low, mid, high)"
},
{
"docstring": "Function to find the m... | [
0,
1,
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 the sum is made up of elements\n which are contiguous and lie in arr[left..r... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033586",
"row_id": 33586,
"seed_ids": "['Qwen2-72B-Instruct_76419']"
} | 0.585311 | Filter_33586 | I | [
"max_crossing_sum",
"max_subarray_sum",
"max_subarray",
"main"
] | 4 | [
[
"max_subarray",
"max_subarray_sum"
],
[
"max_subarray_sum",
"max_crossing_sum"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 075c0659526f4a1523aa1ac5f4f3751ff2d4b9f5 | 1d341274d6bb9939d32342824bffa2aa4436aa5e | |||
v1.0 | instruct | Filter | Filter_33594_I | Create a python function that evaluates if a given number is a prime number or not. If the number is a prime number, append it to a list. Also, create another function to measure and print the runtime of the first function for a list of number inputs. It should consider scenarios where the input can potentially be a li... | import time
def is_prime(n):
"""
Evaluates if the given number n is a prime number.
If it is, appends to the prime_list.
Parameters:
n (int): The number to check for primality.
Returns:
Boolean: True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
... | from solution import is_prime, evaluate_prime_numbers, measure_runtime
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(0) == False
assert is_prime(1) == False
assert is_prime(-5) == False
def... | [
{
"docstring": "Evaluates if the given number n is a prime number.\nIf it is, appends to the prime_list.\n\nParameters:\nn (int): The number to check for primality.\n\nReturns:\nBoolean: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prim... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import time\n\ndef is_prime(n):\n \"\"\"\n Evaluate if a given number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033594",
"row_id": 33594,
"seed_ids": "['Qwen2-72B-Instruct_76429']"
} | 0.665279 | Filter_33594 | I | [
"is_prime",
"evaluate_prime_numbers",
"measure_runtime"
] | 3 | [
[
"evaluate_prime_numbers",
"is_prime"
],
[
"measure_runtime",
"evaluate_prime_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cc18da68265a7d778d029bc743d72d2faca3928b | 0aabf9fcc661dba9fbebda391ca360c5706d0b34 | |||
v1.0 | instruct | Filter | Filter_33606_I | Can I create something by means of Python that reformats JSON strings so that camelCase keys are changed to snake_case? | import json
import re
def camel_to_snake(name):
"""
Converts camelCase string to snake_case string.
"""
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
def convert_json_keys(data):
"""
Recursively converts all keys in a dictionary fr... | from solution import reformat_json
def test_convert_simple_json():
json_str = '{"firstName": "John", "lastName": "Doe"}'
expected_output = json.dumps({"first_name": "John", "last_name": "Doe"}, indent=4)
assert reformat_json(json_str) == expected_output
def test_convert_nested_json():
json_str = '{"pe... | [
{
"docstring": "Converts camelCase string to snake_case string.",
"function_declaration": "def camel_to_snake(name):",
"function_name": "camel_to_snake",
"parameter_list": "(name)"
},
{
"docstring": "Recursively converts all keys in a dictionary from camelCase to snake_case.",
"function_... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nimport json\n\ndef camel_to_snake(name):\n \"\"\"\n Convert camelCase string to snake_case string.\n \"\"\"\n s1 = re.sub('([a-z0-9])([A-Z])', r'\\1_\\2', name)\n ret... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033606",
"row_id": 33606,
"seed_ids": "['Qwen2-72B-Instruct_76450']"
} | 0.579753 | Filter_33606 | I | [
"camel_to_snake",
"convert_json_keys",
"reformat_json"
] | 3 | [
[
"convert_json_keys",
"camel_to_snake"
],
[
"reformat_json",
"convert_json_keys"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d8413a19cdc540ec89ea436371fcea374aceeaec | 7e527a125555de15a9e039d65959bb6c25b4d93d | |||
v1.0 | instruct | Filter | Filter_33637_I | Develop a Python program that determines and displays all the Fibonacci prime numbers up to a particular input number. The program should identify prime numbers, generate Fibonacci sequences, and manage the memory effectively in large conditions. Also, implement a functionality where it should display enlisted numbers ... | def is_prime(n):
"""
Check if a number is prime or not.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while (i * i) <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | from solution import is_prime, fibonacci_primes
def test_is_prime():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
def test_fibonacci_primes():
result = fibonacci_primes(21)
expected = [
(0, False, ... | [
{
"docstring": "Check if a number is prime or not.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Get all Fibonacci numbers up to 'limit' and identify if they are prime.\nThe result is returned as a list of tuples contain... | [
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 \"\"\" Check if a number is a prime number. \"\"\"\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": "00033637",
"row_id": 33637,
"seed_ids": "['Qwen2-72B-Instruct_76504']"
} | 0.757658 | Filter_33637 | I | [
"is_prime",
"fibonacci_primes"
] | 2 | [
[
"fibonacci_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 473d49c2ca7313f676f91f2cede7f6a6d4285031 | dff318fc11dc9e1db31f4ad5dbe4544e6c5c146c | |||
v1.0 | instruct | Filter | Filter_33642_I | Create a python decorator that times out a function after 5 seconds, returning a default value if the function takes longer. | import signal
class TimeoutException(Exception):
pass
def timeout_handler(signum, frame):
raise TimeoutException()
def timeout(seconds=5, default=None):
"""
A decorator that times out a function after a given number of seconds, returning a default value if it times out.
"""
def decorator(func... | from solution import timeout, TimeoutException, long_running_function, quick_function
def test_function_times_out():
assert long_running_function() == "Timeout"
def test_function_completes():
assert quick_function() == "Success" | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import signal\n\nclass TimeoutException(Exception):\n pass\n\ndef timeout(seconds=5, default_value=None):\n def decorator(func):\n def _handle_timeout(signum, frame):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033642",
"row_id": 33642,
"seed_ids": "['Qwen2-72B-Instruct_76512']"
} | 0.534843 | Filter_33642 | I | [
"timeout_handler",
"timeout",
"long_running_function",
"quick_function"
] | 4 | [
[
"long_running_function",
"timeout"
],
[
"quick_function",
"timeout"
],
[
"timeout",
"timeout_handler"
]
] | 3 | [] | false | [
"TimeoutException"
] | true | pytest | true | [] | true | 431b1e7d778b5ac842a55ee2bcdbcef6f1494e45 | 789ab90e6e98d9825b7bda2c6dea31092c1f5cb8 | |||
v1.0 | instruct | Filter | Filter_33643_I | You are given m long strings. Each string consists of lowercase English letters ('a' - 'z') and question marks ('?'). You are also given the same number of patterns, where each pattern is also a long string of lowercase English letters. Find the count of strings s[i] that match their respective patterns p[i]. '?' can m... | def matches_pattern(s, p):
"""
Checks whether string s matches the pattern p.
'?' in s can be replaced by any character to match p.
"""
if len(s) != len(p):
return False
for sc, pc in zip(s, p):
if sc != '?' and sc != pc:
return False
return True
def count_match... | from solution import matches_pattern, count_matching_strings
def test_single_character_match():
assert matches_pattern('a', 'a') == True
assert matches_pattern('?', 'a') == True
assert matches_pattern('a', 'b') == False
assert matches_pattern('?', 'z') == True
def test_multiple_characters_match():
... | [
{
"docstring": "Checks whether string s matches the pattern p. \n'?' in s can be replaced by any character to match p.",
"function_declaration": "def matches_pattern(s, p):",
"function_name": "matches_pattern",
"parameter_list": "(s, p)"
},
{
"docstring": "Counts the number of strings in str... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def match_strings_with_patterns(strings, patterns):\n \"\"\"\n Given two lists, 'strings' and 'patterns', this function returns the count\n of strings that match their respective patt... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033643",
"row_id": 33643,
"seed_ids": "['Qwen2-72B-Instruct_76513']"
} | 0.668779 | Filter_33643 | I | [
"matches_pattern",
"count_matching_strings"
] | 2 | [
[
"count_matching_strings",
"matches_pattern"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | eb0ad3c8e9cbcc6bcf5a5803db9f6184c563160d | 73dfc9cd32a7f525127aef4acdaa2caf14a91104 | |||
v1.0 | instruct | Filter | Filter_33655_I | Generate the code to find the number of business days (excluding weekends and public holidays) between two dates. Additionally, consider the scenario where the start date could be earlier than the end date. | from datetime import datetime, timedelta
def is_business_day(date, public_holidays):
if date.weekday() >= 5: # Saturday and Sunday
return False
if date in public_holidays:
return False
return True
def business_days_between(start_date, end_date, public_holidays):
"""
Calculate the ... | from datetime import datetime
from solution import business_days_between, is_business_day
def test_is_business_day():
public_holidays = [datetime(2023, 1, 1), datetime(2023, 12, 25)]
assert is_business_day(datetime(2023, 9, 25), public_holidays) == True # Monday
assert is_business_day(datetime(2023, 9, 30... | [
{
"docstring": null,
"function_declaration": "def is_business_day(date, public_holidays):",
"function_name": "is_business_day",
"parameter_list": "(date, public_holidays)"
},
{
"docstring": "Calculate the number of business days between two dates excluding weekends and public holidays.\n\nAr... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import pandas as pd\n\ndef count_business_days(start_date, end_date, holidays=None):\n \"\"\"\n Calculate the number of business days (excluding weekends and public holidays) between two... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033655",
"row_id": 33655,
"seed_ids": "['Qwen2-72B-Instruct_76534']"
} | 0.591344 | Filter_33655 | I | [
"is_business_day",
"business_days_between"
] | 2 | [
[
"business_days_between",
"is_business_day"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3cb11e77b87034e4586707f0d391c9581adb1921 | 9fff4e2c846010f88d2eca7a1d446e5427b81a93 | |||
v1.0 | instruct | Filter | Filter_33658_I | Develop an algorithmic function that can translate not only a single numerical input, but a sequence of numerical inputs into their corresponding hexadecimal notation. Furthermore, let this function allow for error checking to ensure that all input values are valid within the scope of integer numbers.Lastly, implement ... | def int_to_hex(value):
"""
Converts an integer to its hexadecimal representation.
For negative numbers, two's complement form is used.
"""
if not isinstance(value, int):
raise ValueError("Input must be an integer")
if value < 0:
value = (1 << 32) + value
return ... | from solution import int_to_hex, sequence_to_hex
import pytest
# Testing int_to_hex function
def test_int_to_hex_positive():
assert int_to_hex(10) == '0xa'
assert int_to_hex(255) == '0xff'
def test_int_to_hex_negative():
assert int_to_hex(-1) == '0xffffffff'
assert int_to_hex(-15) == '0xfffffff1'
def... | [
{
"docstring": "Converts an integer to its hexadecimal representation.\nFor negative numbers, two's complement form is used.",
"function_declaration": "def int_to_hex(value):",
"function_name": "int_to_hex",
"parameter_list": "(value)"
},
{
"docstring": "Converts a sequence of integers to th... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def to_hexadecimal(numbers):\n \"\"\"\n Converts a list of integers to their corresponding hexadecimal notation.\n Uses two's complement for negative numbers.\n \"\"\"\n if not ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033658",
"row_id": 33658,
"seed_ids": "['Qwen2-72B-Instruct_76542']"
} | 0.55934 | Filter_33658 | I | [
"int_to_hex",
"sequence_to_hex"
] | 2 | [
[
"sequence_to_hex",
"int_to_hex"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e5799c53d533af25ed10898b71f433b6f2bd2f39 | 4569bc1a57a39ba103b1aabf6cabed7d6b1b08db | |||
v1.0 | instruct | Filter | Filter_33665_I | Write a recursive python function to calculate the sum of all numbers in a list. After the function, create another function to check whether the sum is odd or even. Firstly, carry out error checking procedures to make certain that all elements in the list are indeed numbers and not any other data types. If the error c... | def sum_recursive(lst, n=0):
"""
Returns the sum of all numbers in a list recursively.
"""
if n == len(lst):
return 0
else:
return lst[n] + sum_recursive(lst, n + 1)
def is_sum_odd_or_even(lst):
"""
Returns 'odd' or 'even' depending on the sum of all the numbers in the list.... | from solution import sum_recursive, is_sum_odd_or_even
def test_sum_recursive_empty_list():
assert sum_recursive([]) == 0
def test_sum_recursive_single_element():
assert sum_recursive([5]) == 5
assert sum_recursive([-5]) == -5
def test_sum_recursive_multiple_elements():
assert sum_recursive([1, 2, 3,... | [
{
"docstring": "Returns the sum of all numbers in a list recursively.",
"function_declaration": "def sum_recursive(lst, n=0):",
"function_name": "sum_recursive",
"parameter_list": "(lst, n=0)"
},
{
"docstring": "Returns 'odd' or 'even' depending on the sum of all the numbers in the list.",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def sum_of_list(nums):\n \"\"\"\n Returns the sum of all numbers in the list. Raises a ValueError if any element is not a number.\n \"\"\"\n # Error check for non-numeric elements\... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033665",
"row_id": 33665,
"seed_ids": "['Qwen2-72B-Instruct_76558']"
} | 0.766035 | Filter_33665 | I | [
"sum_recursive",
"is_sum_odd_or_even"
] | 2 | [
[
"is_sum_odd_or_even",
"sum_recursive"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d5935393033f15d44f8ccc92e45e359fcbe254ab | b70c2274864b147822b2993ec2f0fcc4b348312e | |||
v1.0 | instruct | Filter | Filter_33674_I | Write a python function to find the product of all elements in a list, but exclude any prime numbers from the product. Additionally, the function should ignore any negative numbers and only consider numbers that are multiples of 3. If the list is empty or contains no valid elements, the function should return 1. | import math
def is_prime(n):
"""Helper function to determine if a number is prime."""
if n <= 1:
return False
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return False
return True
def product_excluding_primes(nums):
"""
Returns the product of all element... | from solution import product_excluding_primes
def test_product_excluding_primes_empty_list():
assert product_excluding_primes([]) == 1
def test_product_excluding_primes_no_valid_elements():
assert product_excluding_primes([2, 5, 7, 11, -3]) == 1
def test_product_excluding_primes_all_primes():
assert ... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the product of all elements in the list excluding the prime numbers,\nconsidering only positive num... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, int(n**0.5) + 1, 2):\n if n ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033674",
"row_id": 33674,
"seed_ids": "['Qwen2-72B-Instruct_76577']"
} | 0.669755 | Filter_33674 | I | [
"is_prime",
"product_excluding_primes"
] | 2 | [
[
"product_excluding_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bfaa710a3b52202e1ae5f63894727ece95bc6dd0 | 17f0ca432cf73b5f38d1f631694bab0816a7a35c | |||
v1.0 | instruct | Filter | Filter_33677_I | Write a code for extracting the last n prime numbers from a list of positive integers and sorting them in descending order. The code should also check for the presence of any duplicate numbers in the list and remove them before performing the extraction and sorting. Additionally, the code should be optimized to have a ... | 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 extract_l... | from solution import extract_last_n_primes
def test_extract_last_n_primes_basic():
assert extract_last_n_primes([2, 3, 5, 7, 11, 13, 17], 3) == [17, 13, 11]
def test_extract_last_n_primes_with_duplicates():
assert extract_last_n_primes([2, 3, 5, 7, 11, 11, 13, 17, 5], 4) == [17, 13, 11, 7]
def test_extract_l... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Extract the last n prime numbers from a list of integers, remove duplicates, and sort them in descending or... | [
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 \"\"\"Helper function to check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033677",
"row_id": 33677,
"seed_ids": "['Qwen2-72B-Instruct_76583']"
} | 0.58572 | Filter_33677 | I | [
"is_prime",
"extract_last_n_primes"
] | 2 | [
[
"extract_last_n_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | acef273a621d8f90161188ef5a22d717aa4f8a68 | e5286ba68118a1e9ec697514d0105dcd0f8a12a4 | |||
v1.0 | instruct | Filter | Filter_33681_I | Devise a do-while loop structure in a programming language to exhibit the initial sextet of twin prime pairs. Moreover, include a simple primality test function that determines whether the numbers within the range are prime. A twin prime pair is a pair of prime numbers that are two apart (example: 3 and 5, or 11 and 13... | def is_prime(n):
"""
Returns True if n is a prime number, False otherwise.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | from solution import is_prime, find_twin_primes
def test_is_prime_basic_cases():
assert not is_prime(0)
assert not is_prime(1)
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
def test_is_prime_larger_cases():
assert is_prime(29)
assert not is_prime(30)
... | [
{
"docstring": "Returns True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the first `count` twin prime pairs.",
"function_declaration": "def find_twin_primes(count=6)... | [
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, False otherwise.\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": "00033681",
"row_id": 33681,
"seed_ids": "['Qwen2-72B-Instruct_76591']"
} | 0.573395 | Filter_33681 | I | [
"is_prime",
"find_twin_primes"
] | 2 | [
[
"find_twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3136a6723373c464f4de45b4dd41405a6860b24d | b5da9680c193861eb5dc735b8d98ada7aca80073 | |||
v1.0 | instruct | Filter | Filter_33696_I | Can_yaml define a fastapi utility in python that is specifically used as an asynchronous function to manage the application environments, and is reusable across various modules? Additionally, can you provide information on implementing security protocols using pydantic models for request and response data validation? | from fastapi import FastAPI, Depends, HTTPException
from pydantic import BaseModel
from typing import Dict, Any
import os
import asyncio
class EnvironmentManager:
_env: Dict[str, Any] = {}
@classmethod
async def load_environment(cls):
cls._env = {
key: value
for key, value ... | from fastapi.testclient import TestClient
from solution import app
client = TestClient(app)
def test_read_environment():
response = client.get("/environment")
assert response.status_code == 200
assert isinstance(response.json(), dict)
def test_read_secure_environment_success():
response = client.get(... | [] | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from fastapi import FastAPI, Depends, HTTPException\nfrom pydantic import BaseModel\nfrom typing import Optional\nfrom functools import lru_cache\nimport os\n\napp = F... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033696",
"row_id": 33696,
"seed_ids": "['Qwen2-72B-Instruct_76616']"
} | 0.382431 | Filter_33696 | I | [
"read_environment",
"verify_credentials",
"read_secure_environment"
] | 3 | [
[
"read_secure_environment",
"verify_credentials"
]
] | 1 | [] | false | [
"EnvironmentManager",
"EnvironmentResponseModel",
"UserCredentials"
] | true | pytest | true | [
"fastapi",
"pydantic"
] | false | a61df7856f9d5912f6f1a375119d7c84bb615734 | 93fee1515a80d56e9e21d093bc3449271a988f86 | |||
v1.0 | instruct | Filter | Filter_33706_I | Craft the quicksort algorithm with a pivotal deviation where the pivot selection is through median-of-three method considering first, middle and last elements in the array. Furthermore, include a functionality where the algorithm can handle not only integer arrays, but also arrays of floating numbers and character stri... | def median_of_three(arr, low, high):
mid = (low + high) // 2
pivot_candidates = [(arr[low], low), (arr[mid], mid), (arr[high], high)]
pivot_candidates.sort(key=lambda x: x[0])
median_value, median_index = pivot_candidates[1]
return median_value, median_index
def quicksort(arr):
if len(arr) <= 1... | from solution import quicksort
def test_quicksort_integers():
assert quicksort([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10]
def test_quicksort_float():
assert quicksort([3.1, 6.5, 8.2, 10.5, 1.1, 2.8, 1.1]) == [1.1, 1.1, 2.8, 3.1, 6.5, 8.2, 10.5]
def test_quicksort_strings():
assert quicksort(["bana... | [
{
"docstring": null,
"function_declaration": "def median_of_three(arr, low, high):",
"function_name": "median_of_three",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quicksort(arr):",
"function_name": "quicksort",
"parameter_list": "(a... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def median_of_three(arr, low, high):\n mid = (low + high) // 2\n pivot_candidates = [(arr[low], low), (arr[mid], mid), (arr[high], high)]\n pivot_candidates.sort(key=lambda x: x[0])\n... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033706",
"row_id": 33706,
"seed_ids": "['Qwen2-72B-Instruct_76632']"
} | 0.485491 | Filter_33706 | I | [
"median_of_three",
"quicksort"
] | 2 | [
[
"quicksort",
"median_of_three"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5628cf4bfb20ffb3c42d535b0bdce235a9d3d5cd | 93e3290d8b14b170ea4388e321e6f52d729467de | |||
v1.0 | instruct | Filter | Filter_33707_I | Write a Python function that takes a list of names and returns a dictionary with each name as a key and a random 8-digit password as its value. The passwords should contain at least one uppercase letter, one lowercase letter, one number, and one special character. Ensure the function contains appropriate error handling... | import random
import string
def generate_password():
"""
Generates a random 8-digit password containing at least one uppercase letter,
one lowercase letter, one number, and one special character.
"""
characters = string.ascii_letters + string.digits + string.punctuation
while True:
pass... | from solution import generate_password, generate_passwords_for_names
import string
def test_generate_password_length():
password = generate_password()
assert len(password) == 8
def test_generate_password_character_requirements():
password = generate_password()
assert any(c.islower() for c in password)... | [
{
"docstring": "Generates a random 8-digit password containing at least one uppercase letter,\none lowercase letter, one number, and one special character.",
"function_declaration": "def generate_password():",
"function_name": "generate_password",
"parameter_list": "()"
},
{
"docstring": "Re... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\nimport string\n\ndef generate_password():\n \"\"\"\n Generate an 8-digit password containing at least one uppercase letter,\n one lowercase letter, one number, and one ... | trial_gpt4o_1 | {
"original_instruction": "",
"prompt_id": "00033707",
"row_id": 33707,
"seed_ids": "['Qwen2-72B-Instruct_76633']"
} | 0.706785 | Filter_33707 | I | [
"generate_password",
"generate_passwords_for_names"
] | 2 | [
[
"generate_passwords_for_names",
"generate_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 825ecca72d65936ed6aefb9a11c724b0c3085a7a | f65f0fd68d6dfdbee5c502dc89675852b0213a57 | |||
v1.0 | instruct | Filter | Filter_33714_I | Write a recursive code for the Fibonacci series which runs in O(log n) time complexity using Matrix Exponentiation method. | def matrix_multiply(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_power(matrix, n):
"""
Exponentia... | from solution import matrix_multiply, matrix_power, fib
def test_matrix_multiply():
A = [[1, 1], [1, 0]]
B = [[1, 1], [1, 0]]
expected = [[2, 1], [1, 1]]
assert matrix_multiply(A, B) == expected
def test_matrix_power():
matrix = [[1, 1], [1, 0]]
n = 5
expected = [[8, 5], [5, 3]] # Because... | [
{
"docstring": "Multiplies two 2x2 matrices A and B.",
"function_declaration": "def matrix_multiply(A, B):",
"function_name": "matrix_multiply",
"parameter_list": "(A, B)"
},
{
"docstring": "Exponentiates a 2x2 matrix to the power n using recursion.\nRuns in O(log n) time.",
"function_de... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def matrix_multiply(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033714",
"row_id": 33714,
"seed_ids": "['Qwen2-72B-Instruct_76640']"
} | 0.558795 | Filter_33714 | I | [
"matrix_multiply",
"matrix_power",
"fib"
] | 3 | [
[
"fib",
"matrix_power"
],
[
"matrix_power",
"matrix_multiply"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f26cca83f273eec4cec06a6ee6684396220e888a | dd14f5934809459cfac3f204d7815348f8a348ac | |||
v1.0 | instruct | Filter | Filter_33750_I | Write a recursive Python function to compute the factorial of the largest prime number less than a given positive integer n. Ensure the function handles error checking and edge conditions properly. | def is_prime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def find_largest_prime_less_than(n):
for num in range(n-1, 1, -1):
if is_prime(num):
return num
return None
def factorial(x)... | from solution import is_prime, find_largest_prime_less_than, factorial, factorial_of_largest_prime_less_than
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_find_largest_prime_l... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def find_largest_prime_less_than(n):",
"function_name": "find_largest_prime_less_than",
"parameter_list": "(n... | [
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 if num < 2:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return False\n return True\n\ndef find_largest_... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033750",
"row_id": 33750,
"seed_ids": "['Qwen2-72B-Instruct_76711']"
} | 0.666386 | Filter_33750 | I | [
"is_prime",
"find_largest_prime_less_than",
"factorial",
"factorial_of_largest_prime_less_than"
] | 4 | [
[
"factorial_of_largest_prime_less_than",
"factorial"
],
[
"factorial_of_largest_prime_less_than",
"find_largest_prime_less_than"
],
[
"find_largest_prime_less_than",
"is_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 0a066d9bfd83b0e6028473ccd2dea16a156180e5 | 16676648f37ce0aca47ddfc6b8fa64f114bc55fc | |||
v1.0 | instruct | Filter | Filter_33761_I | In the realm of genetic algorithms, how can we implement a niching method that maintains a diverse population of solutions by punishing closely related solutions and encouraging those that are more distinct? Please provide a detailed explanation, accompanied by an example and relevant code snippets. | import numpy as np
def calculate_distance(individual1, individual2):
"""
Calculate Euclidean distance between two individuals.
"""
return np.linalg.norm(np.array(individual1) - np.array(individual2))
def sharing_function(distance, sigma_share):
"""
Sharing function to determine the degree of s... | import numpy as np
from solution import calculate_distance, sharing_function, niche_count, fitness_sharing
def test_calculate_distance():
assert np.isclose(calculate_distance([1, 2], [4, 6]), 5.0)
def test_sharing_function():
assert sharing_function(1.5, 2.5) == 1 - (1.5 / 2.5)
assert sharing_function(3.0... | [
{
"docstring": "Calculate Euclidean distance between two individuals.",
"function_declaration": "def calculate_distance(individual1, individual2):",
"function_name": "calculate_distance",
"parameter_list": "(individual1, individual2)"
},
{
"docstring": "Sharing function to determine the degr... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\n\ndef calculate_distance(individual1, individual2):\n \"\"\"\n Calculate Euclidean distance between two individuals.\n \"\"\"\n return np.linalg.norm(np.array(i... | trial_gpt4o_0 | {
"original_instruction": "",
"prompt_id": "00033761",
"row_id": 33761,
"seed_ids": "['Qwen2-72B-Instruct_76726']"
} | 0.363067 | Filter_33761 | I | [
"calculate_distance",
"sharing_function",
"niche_count",
"fitness_sharing"
] | 4 | [
[
"fitness_sharing",
"niche_count"
],
[
"niche_count",
"calculate_distance"
],
[
"niche_count",
"sharing_function"
]
] | 3 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | f25b7666f55f2e5949bf9650adc5ceeae8272300 | 5ca852e53e46915c91622cbeb135463b03c05d61 | |||
v1.0 | instruct | Filter | Filter_33762_I | Develop a Python program that can play random move in the game of 'tic-tac-toe' or 'noughts and crosses'. A 3x3 Tic-Tac-Toe board representation should be used with coordinates (0,0) as the top left of the board. The program should not be strictly against a player but should also be capable of playing a move independ... | import random
def is_position_empty(board, position):
"""
Check if the given position is empty on the board.
"""
return board[position[0]][position[1]] == " "
def get_random_empty_position(board):
"""
Get a random empty position on the board.
"""
empty_positions = [
(i, j) for ... | from solution import is_position_empty, get_random_empty_position, make_random_move
def test_is_position_empty():
board = [
["X", " ", "O"],
["O", "X", " "],
[" ", "O", "X"]
]
assert is_position_empty(board, (0, 1)) == True
assert is_position_empty(board, (0, 0)) == False
def t... | [
{
"docstring": "Check if the given position is empty on the board.",
"function_declaration": "def is_position_empty(board, position):",
"function_name": "is_position_empty",
"parameter_list": "(board, position)"
},
{
"docstring": "Get a random empty position on the board.",
"function_dec... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef init_board():\n \"\"\"\n Initialize an empty 3x3 Tic-Tac-Toe board.\n \"\"\"\n return [[' ' for _ in range(3)] for _ in range(3)]\n\ndef print_board(board):\n ... | trial_gpt4o_2 | {
"original_instruction": "",
"prompt_id": "00033762",
"row_id": 33762,
"seed_ids": "['Qwen2-72B-Instruct_76727']"
} | 0.472837 | Filter_33762 | I | [
"is_position_empty",
"get_random_empty_position",
"make_random_move"
] | 3 | [
[
"get_random_empty_position",
"is_position_empty"
],
[
"make_random_move",
"get_random_empty_position"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 809475215d82074d64b736c4824c2a35bef7a3ad | e2c5bfee2c4a80518757beab3bb70cba50e54c90 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.