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_21282_I
Design a system in Python to allow Peer-to-Peer (P2P) file sharing between two or more peers on the same network.
import socket import threading import os BUFFER_SIZE = 1024 def receive_file(socket, addr, save_path): with socket: print(f"Connection from {addr} has been established!") file_size = int(socket.recv(BUFFER_SIZE).decode()) socket.send("SIZE RECEIVED".encode()) file...
import os import threading import socket from solution import start_server, start_client def test_file_transfer(tmpdir): # Prepare host = '127.0.0.1' port = 65432 save_path = str(tmpdir) original_file = tmpdir.join("testfile.txt") original_file.write("This is a test file content.") ...
[ { "docstring": null, "function_declaration": "def receive_file(socket, addr, save_path):", "function_name": "receive_file", "parameter_list": "(socket, addr, save_path)" }, { "docstring": null, "function_declaration": "def send_file(file_path, host, port):", "function_name": "send_fi...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import socket\nimport threading\nimport os\n\n# Function to handle incoming peer connections\ndef handle_peer_connection(peer_socket, peer_address):\n with peer_socket:\n print(f\"Co...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021282", "row_id": 21282, "seed_ids": "['Llama-3.3-70B-Instruct_53288']" }
0.513473
Filter_21282
I
[ "receive_file", "send_file", "start_server", "start_client" ]
4
[ [ "start_client", "send_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c95cc20edbd3f451cb47237b71e5b2b4b39a3d91
36d1e6aee668ac34e053db7d1868aac27cc338d4
v1.0
instruct
Filter
Filter_21318_I
In this problem, you will develop a well-structured Python program that calculates the Hamming distance between two binary strings of the same length, where the Hamming distance is defined as the number of positions at which two strings are different. Please find the Hamming distance between the two strings provided as...
def read_file(file_path): """ Reads the content of a file and returns it as a string. """ with open(file_path, 'r') as file: return file.read().strip() def hamming_distance(file1, file2): """ Calculates the Hamming distance between two binary strings from files. :param file1: P...
import pytest from solution import hamming_distance def test_hamming_distance_identical(): # Temporary text files with identical content file1 = 'test_identical1.txt' file2 = 'test_identical2.txt' with open(file1, 'w') as f: f.write('101010') with open(file2, 'w') as f: f.write('101...
[ { "docstring": "Reads the content of a file and returns it as a string.", "function_declaration": "def read_file(file_path):", "function_name": "read_file", "parameter_list": "(file_path)" }, { "docstring": "Calculates the Hamming distance between two binary strings from files.\n\n:param fil...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def hamming_distance(file1, file2):\n \"\"\"\n Calculate the Hamming distance between binary strings in two files.\n \n Args:\n file1 (str): Path to the first input file.\n f...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021318", "row_id": 21318, "seed_ids": "['Llama-3.3-70B-Instruct_53370']" }
0.768183
Filter_21318
I
[ "read_file", "hamming_distance" ]
2
[ [ "hamming_distance", "read_file" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d3d7108dc127db2e95f913a5ee62ea2ccab42491
92dc89dae11753816ad88fbbd42259eaaa769f8e
v1.0
instruct
Filter
Filter_21327_I
Can you create a simple script that uses multiprocessing to speed up the generation of 100,000 random numbers?
import random from multiprocessing import Pool def generate_random_number(_): """ Generates a random number between 0 and 1. """ return random.random() def generate_random_numbers(count): """ Generates a specified count of random numbers using multiprocessing. :param count: Number of rand...
from solution import generate_random_numbers def test_generate_random_numbers_length(): result = generate_random_numbers(100) assert len(result) == 100 def test_generate_random_numbers_range(): result = generate_random_numbers(1000) assert all(0 <= number < 1 for number in result) def test_generate_r...
[ { "docstring": "Generates a random number between 0 and 1.", "function_declaration": "def generate_random_number(_):", "function_name": "generate_random_number", "parameter_list": "(_)" }, { "docstring": "Generates a specified count of random numbers using multiprocessing.\n\n:param count: N...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom multiprocessing import Pool\n\ndef generate_random_number(_):\n \"\"\"\n Generates a random number between 0 and 1.\n \"\"\"\n return random.random()\n\ndef gen...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021327", "row_id": 21327, "seed_ids": "['Llama-3.3-70B-Instruct_53390']" }
0.5584
Filter_21327
I
[ "generate_random_number", "generate_random_numbers" ]
2
[ [ "generate_random_numbers", "generate_random_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
602c57be1948e129f2f88a40a286ff8d42dc21af
ed455eec68ae3223a2d769f633332f037ec0d7cb
v1.0
instruct
Filter
Filter_21329_I
### Homework 3 ## Text Analysis You need to manage your time when doing homework to the letter! To that end, first write a script that reads a list of homework files in a directory, then determines the amount of time spent on each file. Assume that the amount of time spent on each file is proportional to the number of ...
import os def get_lines_of_code(file_path): """ Returns the number of lines of code for a given file. """ with open(file_path, 'r', encoding='utf-8') as file: return len(file.readlines()) def time_spent_on_homework(directory): """ Returns a dictionary where the keys are file names and ...
import os import tempfile from solution import get_lines_of_code, time_spent_on_homework def test_get_lines_of_code(): with tempfile.NamedTemporaryFile(delete=False) as temp_file: temp_file.write(b'line1\nline2\nline3\n') temp_file_path = temp_file.name try: assert get_lines_of_co...
[ { "docstring": "Returns the number of lines of code for a given file.", "function_declaration": "def get_lines_of_code(file_path):", "function_name": "get_lines_of_code", "parameter_list": "(file_path)" }, { "docstring": "Returns a dictionary where the keys are file names and the values are ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\n\ndef get_time_spent_per_file(directory):\n \"\"\"\n Given a directory, this function reads each file in the directory,\n counts the number of lines in each file, and then ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021329", "row_id": 21329, "seed_ids": "['Llama-3.3-70B-Instruct_53394']" }
0.460573
Filter_21329
I
[ "get_lines_of_code", "time_spent_on_homework" ]
2
[ [ "time_spent_on_homework", "get_lines_of_code" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c170659a1d365e81f21ae423d08cde00bc16510e
ea9e3c822256a3d172d9ee3170554d13c00c4845
v1.0
instruct
Filter
Filter_21372_I
### Task 3 Given a list of strings, find the common prefix or the empty string if there is no common prefix. ### Task 4 Given a list of strings, write a function that returns True if all strings are the same. ### Task 5 Given a list of strings, write a function that returns True if all strings are unique (no duplicat...
from functools import reduce def common_prefix(strings): """ Returns the common prefix of a list of strings or an empty string if there is none. """ if not strings: return "" return reduce(lambda x, y: common_prefix_two(x, y), strings) def common_prefix_two(a, b): """ Returns the c...
from solution import common_prefix, all_same, all_unique, longest_common_prefix def test_common_prefix_all_same(): assert common_prefix(["flower", "flow", "flight"]) == "fl" def test_common_prefix_no_common(): assert common_prefix(["dog", "racecar", "car"]) == "" def test_common_prefix_empty_list(): asse...
[ { "docstring": "Returns the common prefix of a list of strings or an empty string if there is none.", "function_declaration": "def common_prefix(strings):", "function_name": "common_prefix", "parameter_list": "(strings)" }, { "docstring": "Returns the common prefix between two strings.", ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import reduce\n\ndef common_prefix(strings):\n if not strings:\n return \"\"\n def common_prefix_two(a, b):\n min_len = min(len(a), len(b))\n for i in...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021372", "row_id": 21372, "seed_ids": "['Llama-3.3-70B-Instruct_53514']" }
0.768528
Filter_21372
I
[ "common_prefix", "common_prefix_two", "all_same", "all_unique", "longest_common_prefix" ]
5
[ [ "common_prefix", "common_prefix_two" ], [ "longest_common_prefix", "common_prefix_two" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4c7703e4256df4b5ef8f8bb666498e10a495d4ab
b5cf248b71dbe638a59538a44f410339c43890ec
v1.0
instruct
Filter
Filter_21440_I
I would like to implement an algorithm in Python that is capable of checking whether two given years are leap years or not.
def is_leap_year(year): """ Returns True if the given year is a leap year, False otherwise. A year is a leap year if: - It is divisible by 4, - Except for years that are exactly divisible by 100, - Unless the year is also exactly divisible by 400. """ if (year % 4 == 0 and year % 100 != ...
from solution import check_leap_years, is_leap_year def test_is_leap_year(): assert is_leap_year(2000) == True # Divisible by 400 assert is_leap_year(1900) == False # Divisible by 100 but not 400 assert is_leap_year(2012) == True # Divisible by 4 but not 100 assert is_leap_year(2019) == False # Not d...
[ { "docstring": "Returns True if the given year is a leap year, False otherwise.\nA year is a leap year if:\n- It is divisible by 4,\n- Except for years that are exactly divisible by 100,\n- Unless the year is also exactly divisible by 400.", "function_declaration": "def is_leap_year(year):", "function_n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_leap_year(year):\n \"\"\"\n Returns True if the given year is a leap year, otherwise False.\n \"\"\"\n if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021440", "row_id": 21440, "seed_ids": "['Llama-3.3-70B-Instruct_53696']" }
0.583858
Filter_21440
I
[ "is_leap_year", "check_leap_years" ]
2
[ [ "check_leap_years", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
130ce5d194c54c4d802c7498c4b0e162fc26cda7
edd7770bdb23621d41f07d42851f711ac1f62728
v1.0
instruct
Filter
Filter_21442_I
### Objective Within a hundred lines of code, create a simple Dice Game where two players roll two dice and the player with the higher sum wins. ### Code ```python # We will import the random library, which contains a function called # randint() that can be used to simulate dice rolls import random # Initialize va...
import random def roll_dice(): return random.randint(1, 6) def play_game(player1_name="Player 1", player2_name="Player 2"): player1_roll = roll_dice() player2_roll = roll_dice() player1_roll_second = roll_dice() player2_roll_second = roll_dice() player1_score = player1_roll + player1_roll_sec...
from solution import roll_dice, play_game def test_roll_dice(): for _ in range(100): roll = roll_dice() assert 1 <= roll <= 6 def test_play_game(): results, player1_score, player2_score = play_game("Alice", "Bob") assert results[0].startswith("Alice rolled a ") assert results[1].starts...
[ { "docstring": null, "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def play_game(player1_name='Player 1', player2_name='Player 2'):", "function_name": "play_game", "parameter_list"...
[ 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 roll_dice():\n \"\"\"\n Simulate rolling a single dice.\n Returns an integer between 1 and 6 (inclusive).\n \"\"\"\n return random.randint(1, 6)\n\ndef play...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021442", "row_id": 21442, "seed_ids": "['Llama-3.3-70B-Instruct_53704']" }
0.622505
Filter_21442
I
[ "roll_dice", "play_game" ]
2
[ [ "play_game", "roll_dice" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e58adc56cfd5cfa88a5a9e16ce7308c2fdfeabb
4849a7ad89ca4a05c957cafcf2008f654bae75a9
v1.0
instruct
Filter
Filter_21486_I
I have a list of dictionaries in python where each dictionary represents an event. Each event has an 'event_type', 'start_time', and 'end_time'. Events are sorted by 'start_time'. The task is to write a function that takes this list of events and merges any overlapping events of the same type. For example if there i...
def merge_events(events): if len(events) == 0: return [] # Sort the events by start time events.sort(key=lambda x: x['start_time']) merged_events = [] current_event = events[0] for event in events[1:]: if event['event_type'] == current_event['event_type'] and overlap(current_ev...
from solution import merge_events def test_no_events(): assert merge_events([]) == [] def test_non_overlapping_events(): events = [ {'event_type': 'meeting', 'start_time': 10, 'end_time': 12}, {'event_type': 'meeting', 'start_time': 13, 'end_time': 14}, ] assert merge_events(events) ==...
[ { "docstring": null, "function_declaration": "def merge_events(events):", "function_name": "merge_events", "parameter_list": "(events)" }, { "docstring": null, "function_declaration": "def overlap(event1, event2):", "function_name": "overlap", "parameter_list": "(event1, event2)"...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_events(events):\n if len(events) == 0:\n return []\n\n events.sort(key=lambda x: x['start_time']) # sort the events by start time\n merged_events = []\n current_e...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021486", "row_id": 21486, "seed_ids": "['Llama-3.3-70B-Instruct_53822']" }
0.577674
Filter_21486
I
[ "merge_events", "overlap" ]
2
[ [ "merge_events", "overlap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9906acc76ad001c832a760d33bd60b320ad8009
45fc98b56bbe34a486d9f78caa13cd9f1fa8b316
v1.0
instruct
Filter
Filter_21488_I
I want to build a simple game where the computer makes a random card choice out of a standard 52-card deck, and then I can try to guess the color of the chosen card. Can help me with a basic Python script for this game?
import random def draw_card(): """ Simulates drawing a card from a standard 52-card deck. Returns a tuple (value, suit) representing the drawn card. """ suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'] values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] suit = ...
from solution import draw_card, guess_color def test_draw_card(): """ Tests the draw_card function to ensure it returns a valid card. """ card = draw_card() values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'] assert c...
[ { "docstring": "Simulates drawing a card from a standard 52-card deck.\nReturns a tuple (value, suit) representing the drawn card.", "function_declaration": "def draw_card():", "function_name": "draw_card", "parameter_list": "()" }, { "docstring": "Given a card tuple (value, suit), returns t...
[ 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 draw_card():\n \"\"\"\n Draw a random card from a standard 52-card deck.\n Each card is represented as a tuple with its rank and suit.\n \"\"\"\n ranks = ['...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021488", "row_id": 21488, "seed_ids": "['Llama-3.3-70B-Instruct_53824']" }
0.546039
Filter_21488
I
[ "draw_card", "guess_color", "game" ]
3
[ [ "game", "draw_card" ], [ "game", "guess_color" ] ]
2
[]
false
[]
false
pytest
true
[]
true
def2900dc137fe9fea98a9aa9deb87622221951f
1b11413b4d75c48d01b3c26decc4d868a40f3392
v1.0
instruct
Filter
Filter_21518_I
### Using Python, determine if a year is a leap year. Years divisible by 4 are leap years, but years divisible by 100 are not leap years unless they are also divisible by 400. For example, 1996 is a leap year since it is divisible by 4. 2012 is a leap year since it is divisible by 4. 1900 is not a leap year since i...
def is_leap_year(year): """ Determine if a year is a leap year. A year is a leap year if it is: - Divisible by 4 - Not divisible by 100, unless also divisible by 400 """ return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) def run_leap_year_check(): """ Run a loop that...
from solution import is_leap_year def test_is_leap_year_divisible_by_4_not_100(): assert is_leap_year(1996) == True # Divisible by 4 but not by 100 assert is_leap_year(2012) == True # Divisible by 4 but not by 100 def test_is_leap_year_divisible_by_100_not_400(): assert is_leap_year(1900) == False # Di...
[ { "docstring": "Determine if a year is a leap year.\n\nA year is a leap year if it is:\n- Divisible by 4\n- Not divisible by 100, unless also divisible by 400", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "R...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_leap_year(year):\n \"\"\"\n Determine if a year is a leap year.\n Returns True if the year is a leap year, otherwise False.\n \"\"\"\n return year % 4 == 0 and (year % 10...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021518", "row_id": 21518, "seed_ids": "['Llama-3.3-70B-Instruct_53895']" }
0.592414
Filter_21518
I
[ "is_leap_year", "run_leap_year_check" ]
2
[ [ "run_leap_year_check", "is_leap_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
16ba6852d4b33c247766b7a68b27ebf8d859ff1c
29be1aee669d7dfc900efbb29d553a94725b607b
v1.0
instruct
Filter
Filter_21542_I
Here is a programming task that I need to start: Write a function that takes in a list of vectors where each vector represents a point in n-dimensional space and a point (also in n-dimensional space) to calculate the sigmoid of the dot product of the point and each vector in the list.
import math def sigmoid(x): """ Compute the sigmoid of x. """ return 1 / (1 + math.exp(-x)) def dot_product(vec1, vec2): """ Compute the dot product of two vectors. """ return sum(x * y for x, y in zip(vec1, vec2)) def sigmoid_dot_products(vectors, point): """ Compute the sigm...
from solution import sigmoid_dot_products def test_sigmoid_dot_products_single_vector(): vectors = [[1, 2, 3]] point = [1, 1, 1] result = sigmoid_dot_products(vectors, point) expected = [1 / (1 + math.exp(-(1*1 + 2*1 + 3*1)))] assert result == expected def test_sigmoid_dot_products_multiple_vector...
[ { "docstring": "Compute the sigmoid of x.", "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": "Compute the dot product of two vectors.", "function_declaration": "def dot_product(vec1, vec2):", "function_name": "dot_produc...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef sigmoid(x):\n \"\"\"\n Compute the sigmoid of x.\n \"\"\"\n return 1 / (1 + math.exp(-x))\n\ndef dot_product(vec1, vec2):\n \"\"\"\n Compute the dot produc...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021542", "row_id": 21542, "seed_ids": "['Llama-3.3-70B-Instruct_53943']" }
0.413833
Filter_21542
I
[ "sigmoid", "dot_product", "sigmoid_dot_products" ]
3
[ [ "sigmoid_dot_products", "dot_product" ], [ "sigmoid_dot_products", "sigmoid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
52298e1622f472ab7168d892e3822787e95a1e7c
f66826b06ead7a5c13ec8ac3f2b3dad4a0e7732e
v1.0
instruct
Filter
Filter_21549_I
Given a binary tree where each node has a unique value, find the lowest common ancestor (LCA) of two given nodes. For example, given the binary tree below and the values 3 and 6: 1 / \ 2 3 / \ 4 5 / \ 6 7 The LCA of 3 and 6 is 3. Here is the solution: ```python class TreeNode: def __init__(...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_path_from_root(root, target, path): """ Utility function to find the path from root to a given target node. """ if root is None: return False path.append(root) i...
from solution import TreeNode, lowestCommonAncestor def test_lca_multiple_nodes(): root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) root.left.right.left = TreeNode(6) root.left.right.right = TreeNode(7) p = r...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef lowestCommonAncestorOfNodes(root, nodes):\n \"\"\"\n Finds t...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021549", "row_id": 21549, "seed_ids": "['Llama-3.3-70B-Instruct_53964']" }
0.507909
Filter_21549
I
[ "find_path_from_root", "lowestCommonAncestor" ]
2
[ [ "lowestCommonAncestor", "find_path_from_root" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
ec43c918cfd01050a0bd9c1533b4e933ebb0937e
8bba3ad6da9523fe55875a6c8474f8077ed89aa6
v1.0
instruct
Filter
Filter_21563_I
When we were kids, my brother and I would always argue over who was the biggest fan of our favorite band. It seems silly now, but I think that kind of passion and dedication is important, even for adults. So, I've decided to create a "Fan Meter" to measure people's fandom. I've come up with a simple equation to calcula...
def fan_score(years_as_fan, items_owned, events_attended, years_since_last_event): """ Calculate the fan score based on the given parameters. """ return (years_as_fan + items_owned + events_attended) / (years_since_last_event + 1) def rank_fans(fan_data): """ Rank fans based on their fan score....
from solution import fan_score, rank_fans def test_fan_score(): assert fan_score(10, 20, 15, 2) == (10 + 20 + 15) / (2 + 1) assert fan_score(5, 10, 5, 1) == (5 + 10 + 5) / (1 + 1) assert fan_score(20, 50, 30, 5) == (20 + 50 + 30) / (5 + 1) assert fan_score(15, 30, 10, 3) == (15 + 30 + 10) / (3 + 1) de...
[ { "docstring": "Calculate the fan score based on the given parameters.", "function_declaration": "def fan_score(years_as_fan, items_owned, events_attended, years_since_last_event):", "function_name": "fan_score", "parameter_list": "(years_as_fan, items_owned, events_attended, years_since_last_event)...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_fan_score(years_as_fan, items_owned, events_attended, years_since_last_event):\n \"\"\"\n Calculate the fan score based on the given formula.\n \n Fan Score = (Number...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021563", "row_id": 21563, "seed_ids": "['Llama-3.3-70B-Instruct_53993']" }
0.591466
Filter_21563
I
[ "fan_score", "rank_fans" ]
2
[ [ "rank_fans", "fan_score" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4fe33cbc5204d2a4cbf5c35ab95860da0d2e97b9
287605d76eb36679c2572233783b38aad9dda86d
v1.0
instruct
Filter
Filter_21573_I
I want to create a simple chat system using socket programming in Python. The chat system should be able to handle multiple clients. Can you provide me a basic example of a client-server chat system using Python?
import socket import threading # Server code def handle_client(client_socket): while True: try: message = client_socket.recv(1024).decode('utf-8') if message: print(f"[Client]: {message}") broadcast(message, client_socket) else: ...
import socket import threading import time def mock_server(): server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(("127.0.0.1", 8080)) server_socket.listen(1) print("Mock server listening on port 8080") client_socket, addr = server_socket.accept() print(f"Accept...
[ { "docstring": null, "function_declaration": "def handle_client(client_socket):", "function_name": "handle_client", "parameter_list": "(client_socket)" }, { "docstring": null, "function_declaration": "def broadcast(message, client_socket):", "function_name": "broadcast", "paramet...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import socket\nimport threading\n\n# Server Code\ndef handle_client(client_socket):\n while True:\n message = client_socket.recv(1024).decode('utf-8')\n if not message:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021573", "row_id": 21573, "seed_ids": "['Llama-3.3-70B-Instruct_54022']" }
0.578876
Filter_21573
I
[ "handle_client", "broadcast", "server_program", "client_program" ]
4
[ [ "handle_client", "broadcast" ] ]
1
[]
false
[]
false
pytest
true
[]
true
261c72037d9ea68a947e5360108231a08fce4b1f
7ab3e8b88f55c0de51fe97518423c63532ffc0c0
v1.0
instruct
Filter
Filter_21575_I
I have a plan to count the number of inversions in an array (i.e., the number of pairs of elements that are out of their natural order) using merge sort. My plan is to use the merge step of the merge sort to count inversions while sorting the array. Here is my algorithm: - Split the input array into two halves. - Recu...
def merge_sort_and_count(arr): if len(arr) <= 1: return arr, 0 mid = len(arr) // 2 left_half, left_inversions = merge_sort_and_count(arr[:mid]) right_half, right_inversions = merge_sort_and_count(arr[mid:]) merged, split_inversions = merge_and_count(left_half, right_half) total_invers...
from solution import merge_sort_and_count, merge_and_count def test_merge_sort_and_count_single_element(): arr = [1] sorted_arr, inversions = merge_sort_and_count(arr) assert sorted_arr == [1] assert inversions == 0 def test_merge_sort_and_count_sorted_array(): arr = [1, 2, 3, 4, 5] sorted_arr...
[ { "docstring": null, "function_declaration": "def merge_sort_and_count(arr):", "function_name": "merge_sort_and_count", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge_and_count(left, right):", "function_name": "merge_and_count", "parameter_li...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort_and_count(arr):\n if len(arr) <= 1:\n return arr, 0\n\n mid = len(arr) // 2\n left_half, left_inversions = merge_sort_and_count(arr[:mid])\n right_half, right...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021575", "row_id": 21575, "seed_ids": "['Llama-3.3-70B-Instruct_54032']" }
0.583976
Filter_21575
I
[ "merge_sort_and_count", "merge_and_count" ]
2
[ [ "merge_sort_and_count", "merge_and_count" ] ]
1
[]
false
[]
false
pytest
true
[]
true
26b28ed048b44f4886e6ca172d049e2a45eaf7a4
865a5bc1e68abfeff5de32304d73d115626dc8ee
v1.0
instruct
Filter
Filter_21577_I
I have a numpy array of shape (n, 4) where each row represents a rectangle in a 2D plane. The four columns represent the x and y coordinates of the top-left and bottom-right corners of the rectangle (in that order). I want to check if these rectangles overlap or not. The rectangles are axis-aligned, meaning the sides o...
import numpy as np def do_rectangles_overlap(rectangle1, rectangle2): # Unpack the coordinates x1, y1, x2, y2 = rectangle1 x3, y3, x4, y4 = rectangle2 # Check if the rectangles do not overlap if x2 <= x3 or x1 >= x4 or y2 <= y3 or y1 >= y4: return False # If none of the above ...
import numpy as np from solution import find_overlaps def test_no_overlap(): rectangles = np.array([ [0, 0, 1, 1], [2, 2, 3, 3] ]) result = find_overlaps(rectangles) expected = np.array([ [False, False], [False, False] ]) assert np.array_equal(result, expected) ...
[ { "docstring": null, "function_declaration": "def do_rectangles_overlap(rectangle1, rectangle2):", "function_name": "do_rectangles_overlap", "parameter_list": "(rectangle1, rectangle2)" }, { "docstring": null, "function_declaration": "def find_overlaps(rectangles):", "function_name":...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef do_rectangles_overlap(rectangle1, rectangle2):\n # Unpack the coordinates\n x1, y1, x2, y2 = rectangle1\n x3, y3, x4, y4 = rectangle2\n\n # Check if the r...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021577", "row_id": 21577, "seed_ids": "['Llama-3.3-70B-Instruct_54036']" }
0.608773
Filter_21577
I
[ "do_rectangles_overlap", "find_overlaps" ]
2
[ [ "find_overlaps", "do_rectangles_overlap" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
41aba427322ce3807bba2e1b466ca9952fbba75a
64a86bac637cb7045179e92d89c82cb33f29be9a
v1.0
instruct
Filter
Filter_21578_I
I have a list of integers in Python, and I want to sort this list in ascending order using the quicksort algorithm. However, the list may contain duplicates, and I need to ensure that the final sorted list contains all the unique elements in sorted order.
def quicksort(arr): """ Sorts the input list in ascending order using the quicksort algorithm and returns a list of unique elements in sorted order. """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] less = [x for x in arr if x < pivot] equal = [x for x in arr if x == ...
from solution import unique_sorted def test_unique_sorted_with_duplicates(): assert unique_sorted([4, 2, 2, 3, 1, 3, 4]) == [1, 2, 3, 4] def test_unique_sorted_no_duplicates(): assert unique_sorted([5, 1, 3, 2, 4]) == [1, 2, 3, 4, 5] def test_unique_sorted_all_duplicates(): assert unique_sorted([7, 7, 7,...
[ { "docstring": "Sorts the input list in ascending order using the quicksort algorithm and \nreturns a list of unique elements in sorted order.", "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "parameter_list": "(arr)" }, { "docstring": "Returns a list of unique ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def quicksort(arr):\n \"\"\"\n Sorts the array using the quicksort algorithm and removes duplicates.\n Returns a sorted list with unique elements.\n \"\"\"\n if len(arr) <= 1:\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021578", "row_id": 21578, "seed_ids": "['Llama-3.3-70B-Instruct_54040']" }
0.641351
Filter_21578
I
[ "quicksort", "unique_sorted" ]
2
[ [ "unique_sorted", "quicksort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
deca40a82e423c3a01f5c5d59b2fbde04ccbb609
7432aea732bb05b84879ce6d3140c5c555b767ac
v1.0
instruct
Filter
Filter_21584_I
### Task 1: Build a Hangman Game You are given a word to guess. The word has 6 letters. You can make 6 guesses. After each guess, you will be told if your guess appears in the word or not. If you guess a letter correctly, the correctly guessed letters will be revealed. If you guess incorrectly, a part of a hangman's g...
import random HANGMAN_PICS = [''' +---+ | | | | | | =========''', ''' +---+ | | O | | | | =========''', ''' +---+ | | O | | | | | =========''', ''' +---+ | | O | /| | | | =========''', ''' +---+ | | O ...
from solution import get_display_blanks def test_get_display_blanks_all_correct(): assert get_display_blanks('python', 'python') == 'python' def test_get_display_blanks_one_correct(): assert get_display_blanks('python', 'p') == 'p_____' def test_get_display_blanks_some_correct(): assert get_display_blank...
[ { "docstring": null, "function_declaration": "def get_display_blanks(secretWord, correctLetters):", "function_name": "get_display_blanks", "parameter_list": "(secretWord, correctLetters)" }, { "docstring": null, "function_declaration": "def hangman(secretWord):", "function_name": "ha...
[ 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\nHANGMAN_PICS = ['''\n +---+\n | |\n |\n |\n |\n |\n=========''', '''\n +---+\n | |\n O |\n |\n |\n |\n=========''', '''\n +---+\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021584", "row_id": 21584, "seed_ids": "['Llama-3.3-70B-Instruct_54051']" }
0.502911
Filter_21584
I
[ "get_display_blanks", "hangman", "displayBoard", "getGuess" ]
4
[ [ "displayBoard", "get_display_blanks" ], [ "hangman", "displayBoard" ], [ "hangman", "getGuess" ] ]
3
[]
false
[]
false
pytest
true
[]
true
79f7049b5716af71613e333e7a4e0c90fd868c5d
917293941be6489099e4872b5deb59a4cc8911ee
v1.0
instruct
Filter
Filter_21590_I
Assume this code is a Mastermind game where the secret code is a 4-digit number and each digit can be between 0-9. The goal is to guess the code in as few attempts as possible. ```python def mastermind(code, guess): black = 0 white = 0 for i in range(4): if guess[i] == code[i]: black += ...
import pandas as pd import random # Function to generate the secret code def generate_secret_code(): return [random.randint(0, 9) for _ in range(4)] # Function to generate a random guess def random_guess(): return [random.randint(0, 9) for _ in range(4)] # Function to generate a guess that always increments ...
import pytest from solution import ( generate_secret_code, random_guess, incrementing_guess, mastermind, play_mastermind, compare_strategies ) def test_generate_secret_code(): code = generate_secret_code() assert len(code) == 4 assert all(0 <= digit <= 9 for digit in code) def test...
[ { "docstring": null, "function_declaration": "def generate_secret_code():", "function_name": "generate_secret_code", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def random_guess():", "function_name": "random_guess", "parameter_list": "()" }, { ...
[ 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 random\n\ndef mastermind(code, guess):\n \"\"\"\n Function to compare a guess against the secret code based on Mastermind rules.\n \"\"\"\n black, white...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021590", "row_id": 21590, "seed_ids": "['Llama-3.3-70B-Instruct_54067']" }
0.568452
Filter_21590
I
[ "generate_secret_code", "random_guess", "incrementing_guess", "mastermind", "play_mastermind", "compare_strategies" ]
6
[ [ "compare_strategies", "generate_secret_code" ], [ "compare_strategies", "play_mastermind" ], [ "play_mastermind", "mastermind" ] ]
3
[]
false
[]
false
pytest
true
[ "pandas" ]
false
1ca535c314401afad75dd71146e2744caff00074
5bcc68a2f76e98649f382b6c01cb3f19a8472f91
v1.0
instruct
Filter
Filter_21614_I
Here's a problem: given an array of strings, where each string contains only uppercase English letters, return the minimum length of the longest common prefix among all pairs of strings. Example 1: Input: ["ABCD", "AAEF", "AKLD"] Output: 1 Explanation: The longest common prefix among all pairs of strings is 1. Examp...
def is_common_prefix(strs, length): """ Helper function to determine if all strings in the list have the same prefix of a given length. """ if not strs or length == 0: return True prefix = strs[0][:length] for string in strs: if not string.startswith(prefix): ret...
from solution import min_common_prefix def test_example_1(): assert min_common_prefix(["ABCD", "AAEF", "AKLD"]) == 1 def test_example_2(): assert min_common_prefix(["EFGHI", "EFGHA", "EFOLM"]) == 2 def test_no_common_prefix(): assert min_common_prefix(["ABC", "DEF", "GHI"]) == 0 def test_all_strings_are...
[ { "docstring": "Helper function to determine if all strings in the list have the same prefix of a given length.", "function_declaration": "def is_common_prefix(strs, length):", "function_name": "is_common_prefix", "parameter_list": "(strs, length)" }, { "docstring": "Returns the minimum leng...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_common_prefix(strs):\n if not strs:\n return 0\n \n min_len = float('inf')\n \n for i in range(len(strs)):\n for j in range(i + 1, len(strs)):\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021614", "row_id": 21614, "seed_ids": "['Llama-3.3-70B-Instruct_54129']" }
0.725275
Filter_21614
I
[ "is_common_prefix", "min_common_prefix" ]
2
[ [ "min_common_prefix", "is_common_prefix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae3a443fedc0e95845b339f9ac1ea20963852bf6
7011150dd5be889dd5c4f5578a8b33412f25113c
v1.0
instruct
Filter
Filter_21621_I
### Introduction to Project Euler Project Euler is a series of mathematical and computational programming challenges and a great resource to improve your coding skills. The problems range from very simple to extremely difficult and require the use of algorithms, data structures, number theory, and efficiency techniques...
def sum_of_multiples_3_or_5(n): """ Return the sum of all the multiples of 3 or 5 below n. :param n: int, upper limit (exclusive) :return: int, sum of multiples of 3 or 5 below n """ return sum(i for i in range(n) if i % 3 == 0 or i % 5 == 0) def fibonacci_sequence_up_to(max_value): ""...
from solution import sum_of_multiples_3_or_5, fibonacci_sequence_up_to, sum_of_even_fibonacci def test_sum_of_multiples_3_or_5_below_10(): assert sum_of_multiples_3_or_5(10) == 23 def test_sum_of_multiples_3_or_5_below_1000(): assert sum_of_multiples_3_or_5(1000) == 233168 def test_fibonacci_sequence_up_to_1...
[ { "docstring": "Return the sum of all the multiples of 3 or 5 below n.\n\n:param n: int, upper limit (exclusive)\n:return: int, sum of multiples of 3 or 5 below n", "function_declaration": "def sum_of_multiples_3_or_5(n):", "function_name": "sum_of_multiples_3_or_5", "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 sum_of_multiples_3_or_5(n):\n \"\"\"\n Return the sum of all the multiples of 3 or 5 below n.\n \n :param n: int, upper limit (exclusive)\n :return: int, sum of multiples of...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021621", "row_id": 21621, "seed_ids": "['Llama-3.3-70B-Instruct_54143']" }
0.560189
Filter_21621
I
[ "sum_of_multiples_3_or_5", "fibonacci_sequence_up_to", "sum_of_even_fibonacci" ]
3
[ [ "sum_of_even_fibonacci", "fibonacci_sequence_up_to" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5ffa1d6855c6fa54d5d690012528075015a56f76
79641b055e30aa96a1e5d1a69d63dbf9a0dff8c3
v1.0
instruct
Filter
Filter_21635_I
I've got a Python list of tuples, where each tuple contains a character and an integer. I want to create a new list that contains only those tuples where the integer value is a power of 2 (e.g. 1, 2, 4, 8, 16, etc.). How would I go about doing that?
def is_power_of_two(n): """ Check if a given integer n is a power of two. """ if n <= 0: return False return (n & (n - 1)) == 0 def filter_power_of_two_tuples(lst): """ Filter a list of tuples to only include those tuples where the integer is a power of two. Parameters: ...
from solution import is_power_of_two, filter_power_of_two_tuples def test_is_power_of_two(): assert is_power_of_two(1) == True assert is_power_of_two(2) == True assert is_power_of_two(4) == True assert is_power_of_two(8) == True assert is_power_of_two(16) == True assert is_power_of_two(3) == Fa...
[ { "docstring": "Check if a given integer n is a power of two.", "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": "Filter a list of tuples to only include those tuples where the integer is a power of two.\n\nParam...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_power_of_2(n):\n \"\"\"\n Check if a number is a power of 2.\n\n :param n: Integer to check.\n :return: True if n is a power of 2, False otherwise.\n \"\"\"\n return n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021635", "row_id": 21635, "seed_ids": "['Llama-3.3-70B-Instruct_54168']" }
0.554845
Filter_21635
I
[ "is_power_of_two", "filter_power_of_two_tuples" ]
2
[ [ "filter_power_of_two_tuples", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
478a539a05ad44b9ecb9ff4e018550974c999e7a
1c7a41e7240c3bb077f7176cda27bacb6a575fbf
v1.0
instruct
Filter
Filter_21637_I
### Developing Software with Python in Jupyter Notebooks Develop a Python script to estimate the area and perimeter of a rectangle. Derive two more scripts to estimate the area and perimeter of a circle and a triangle respectively. Also, derive a script that can calculate the area and perimeter for all the three shape...
import math # Function to estimate area and perimeter of a rectangle def rectangle_area_perimeter(length, width): area = length * width perimeter = 2 * (length + width) return area, perimeter # Function to estimate area and perimeter of a circle def circle_area_perimeter(radius): area = math.pi * radi...
from solution import rectangle_area_perimeter, circle_area_perimeter, triangle_area_perimeter, all_shapes_area_perimeter def test_rectangle_area_perimeter(): area, perimeter = rectangle_area_perimeter(5, 3) assert area == 15 assert perimeter == 16 def test_circle_area_perimeter(): area, perimeter = ci...
[ { "docstring": null, "function_declaration": "def rectangle_area_perimeter(length, width):", "function_name": "rectangle_area_perimeter", "parameter_list": "(length, width)" }, { "docstring": null, "function_declaration": "def circle_area_perimeter(radius):", "function_name": "circle...
[ 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 rectangle_area(length, width):\n return length * width\n\ndef rectangle_perimeter(length, width):\n return 2 * (length + width)\n\ndef circle_area(radius):\n return...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021637", "row_id": 21637, "seed_ids": "['Llama-3.3-70B-Instruct_54171']" }
0.547748
Filter_21637
I
[ "rectangle_area_perimeter", "circle_area_perimeter", "triangle_area_perimeter", "all_shapes_area_perimeter" ]
4
[ [ "all_shapes_area_perimeter", "circle_area_perimeter" ], [ "all_shapes_area_perimeter", "rectangle_area_perimeter" ], [ "all_shapes_area_perimeter", "triangle_area_perimeter" ] ]
3
[]
false
[]
false
pytest
true
[]
true
c3048d9f33681fb62bdd51fd26735c0c15661ac0
1cf8041b2e7a0025299d9d9865e9f0be257defcb
v1.0
instruct
Filter
Filter_21641_I
### Introduction to Programming **Lab 1: Introduction to Python** **Objective:** To get familiar with basic syntax and data types in Python. **Task:** Create a Python program that asks for the user's name, age and location, then prints a welcome message including this information. **Constraints:** - The user sh...
def get_user_info(): """ Asks for the user's name, age, and location and returns them as a tuple. Ensures that the age input is a positive integer. """ name = input("Enter your name: ") while True: age_input = input("Enter your age: ") try: age = int(age_input) ...
from solution import get_user_info, welcome_message import pytest from unittest.mock import patch # Testing get_user_info function def test_get_user_info_valid_input(): user_inputs = ['John', '25', 'New York'] with patch('builtins.input', side_effect=user_inputs): assert get_user_info() == ('John', 25...
[ { "docstring": "Asks for the user's name, age, and location and returns them as a tuple.\nEnsures that the age input is a positive integer.", "function_declaration": "def get_user_info():", "function_name": "get_user_info", "parameter_list": "()" }, { "docstring": "Generates and prints a wel...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_user_info():\n \"\"\"\n Prompts the user for their name, age, and location.\n Returns a tuple containing (name, age, location).\n \"\"\"\n while True:\n name = in...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021641", "row_id": 21641, "seed_ids": "['Llama-3.3-70B-Instruct_54182']" }
0.472883
Filter_21641
I
[ "get_user_info", "welcome_message" ]
2
[ [ "welcome_message", "get_user_info" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9762373acf9ce1ce8d6db3e9335d94125cd1966f
1e76b81cadc0c21086d6c5978c9e6dc7cb86ccce
v1.0
instruct
Filter
Filter_21655_I
### Idea: A Prime Number Game #### Objective: Design an interactive game where the player has to find prime numbers within a specified range. The range will be given as input by the user. #### Game Rules: 1. The game starts with a range of numbers from 1 to n, where n is provided by the user. 2. The game will display a...
def get_user_range(): """ This function will get the range from the user. Returns: int: The upper limit of the range. """ while True: try: n = int(input("Please enter the upper limit of the range: ")) if n <= 1: print("The upper limit should b...
from solution import get_user_range, is_prime def test_is_prime(): # Test known primes assert is_prime(2) == True assert is_prime(3) == True assert is_prime(5) == True assert is_prime(7) == True # Test known non-primes assert is_prime(1) == False assert is_prime(4) == False ass...
[ { "docstring": "This function will get the range from the user.\n\nReturns:\nint: The upper limit of the range.", "function_declaration": "def get_user_range():", "function_name": "get_user_range", "parameter_list": "()" }, { "docstring": "This function checks if a number is prime.\n\nArgs:\...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "def get_user_range():\n \"\"\"\n This function will get the range from the user.\n \n Returns:\n int: The upper limit of the range.\n \"\"\"\n whi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021655", "row_id": 21655, "seed_ids": "['Llama-3.3-70B-Instruct_54211']" }
0.656087
Filter_21655
I
[ "get_user_range", "is_prime", "game" ]
3
[ [ "game", "get_user_range" ], [ "game", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
67a0bb0edf9df8705bcf255ab9b56fb4e1b0590c
d7858be183b1d6368b2b119709d3099747928138
v1.0
instruct
Filter
Filter_21659_I
Here's a scenario. You have a limited number of dice in your role-playing game world. However, the GM (game master) wants to introduce a minigame where players roll dice for stats. Stat rolling is done by rolling 4 six-sided dice, discarding the lowest die, and taking the sum of the remaining 3 dice. How would you wr...
import random from typing import List def roll_dice() -> List[int]: """ Rolls 4 six-sided dice and returns the list of the outcomes. """ return [random.randint(1, 6) for _ in range(4)] def calculate_stat(dice_rolls: List[int]) -> int: """ Takes a list of 4 dice rolls, discards the lowest one a...
from solution import calculate_stat, roll_dice, get_player_stats def test_calculate_stat_with_sample_rolls(): assert calculate_stat([1, 2, 3, 4]) == 9 # 2+3+4 = 9 assert calculate_stat([4, 4, 4, 4]) == 12 # 4+4+4 = 12 assert calculate_stat([6, 1, 5, 3]) == 14 # 6+5+3 = 14 def test_roll_dice_returns_4_d...
[ { "docstring": "Rolls 4 six-sided dice and returns the list of the outcomes.", "function_declaration": "def roll_dice():", "function_name": "roll_dice", "parameter_list": "()" }, { "docstring": "Takes a list of 4 dice rolls, discards the lowest one and returns the sum of the remaining 3.", ...
[ 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_stat():\n \"\"\"\n Rolls 4 six-sided dice, discards the lowest roll, and returns the sum of the remaining 3 dice.\n \"\"\"\n rolls = [random.randint(1, 6)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021659", "row_id": 21659, "seed_ids": "['Llama-3.3-70B-Instruct_54218']" }
0.606094
Filter_21659
I
[ "roll_dice", "calculate_stat", "get_player_stats" ]
3
[ [ "get_player_stats", "calculate_stat" ], [ "get_player_stats", "roll_dice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7b927c4a770b0ee8c8bbe280da214314ac3f84f8
541d98153739d388600fa535049a5cbc909c76d3
v1.0
instruct
Filter
Filter_21680_I
### How to Train a Deep Neural Network with Batch Gradient Descent # Step-by-step explanation of the algorithm 1. **Initialization**: Initialize the weights of the network with some random values and initialize the learning rate. 2. **Forward Propagation**: Propagate the training data through the network to compute the...
import numpy as np # Sigmoid function def sigmoid(x): return 1 / (1 + np.exp(-x)) # Derivative of sigmoid function def sigmoid_derivative(x): return x * (1 - x) # Train a neural network using batch gradient descent def train_nn(X, y, num_epochs=15000, learning_rate=1, num_hidden=2): # Number of inputs an...
import numpy as np from solution import sigmoid, sigmoid_derivative, train_nn def test_sigmoid(): assert np.isclose(sigmoid(0), 0.5) assert np.isclose(sigmoid(10), 0.9999546, atol=1e-5) assert np.isclose(sigmoid(-10), 4.5398e-05, atol=1e-5) def test_sigmoid_derivative(): assert np.isclose(sigmoid_deri...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def sigmoid_derivative(x):", "function_name": "sigmoid_derivative", "parameter_list": "(x)" }, { "docstring...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef sigmoid(x):\n \"\"\"\n Sigmoid activation function.\n \"\"\"\n return 1 / (1 + np.exp(-x))\n\ndef sigmoid_derivative(x):\n \"\"\"\n Derivative of th...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021680", "row_id": 21680, "seed_ids": "['Llama-3.3-70B-Instruct_54259']" }
0.611921
Filter_21680
I
[ "sigmoid", "sigmoid_derivative", "train_nn" ]
3
[ [ "train_nn", "sigmoid" ], [ "train_nn", "sigmoid_derivative" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy" ]
false
bb5673e5464f68c447465acae9c1073dd872327a
6130cc5844ef5a9bf2bc604404dd16b71dfb6ba7
v1.0
instruct
Filter
Filter_21682_I
Here's a code snippet that checks if a given string is in alphabetical order: ```python def is_alphabetical_order(input_str): return input_str == ''.join(sorted(input_str)) ``` How can I implement the code so that the script can take in an array of string inputs and verify that the characters within each string a...
def is_alphabetical_order(input_str): """ Check if the given string is in alphabetical order. """ return input_str == ''.join(sorted(input_str)) def are_all_strings_in_alphabetical_order(strings): """ Given an array of strings, check if all strings are in alphabetical order. """ for s i...
from solution import is_alphabetical_order, are_all_strings_in_alphabetical_order def test_is_alphabetical_order(): assert is_alphabetical_order("abc") == True assert is_alphabetical_order("bca") == False assert is_alphabetical_order("xyz") == True assert is_alphabetical_order("zyx") == False def test...
[ { "docstring": "Check if the given string is in alphabetical order.", "function_declaration": "def is_alphabetical_order(input_str):", "function_name": "is_alphabetical_order", "parameter_list": "(input_str)" }, { "docstring": "Given an array of strings, check if all strings are in alphabeti...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def are_strings_in_alphabetical_order(strings):\n \"\"\"\n Takes in an array of strings and verifies that the characters within each \n string are in alphabetical order.\n \n Ar...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021682", "row_id": 21682, "seed_ids": "['Llama-3.3-70B-Instruct_54265']" }
0.61706
Filter_21682
I
[ "is_alphabetical_order", "are_all_strings_in_alphabetical_order" ]
2
[ [ "are_all_strings_in_alphabetical_order", "is_alphabetical_order" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ab0e624a6a8c094d145602b0d5aa756b4209389e
ee2e91e6b057e671663d260c9cc4b8925382a760
v1.0
instruct
Filter
Filter_21709_I
Here's a challenge: write a code that checks whether a given number is a palindrome or not. A palindrome is a number which remains the same when its digits are reversed. For example, 12321 is a palindrome but 123456 is not. To make it more interesting, you can ask the user to input the number and also include an error...
def get_valid_number(): while True: user_input = input("Enter a number: ") if user_input.lower() == 'q': return None try: num = int(user_input) return num except ValueError: print("That's not a valid number. Please try again.") def is_...
import pytest from solution import get_valid_number, is_palindrome def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(12321) == True assert is_palindrome(123456) == False assert is_palindrome(0) == True assert is_palindrome(12) == False assert is_palindrome(-121) =...
[ { "docstring": null, "function_declaration": "def get_valid_number():", "function_name": "get_valid_number", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def is_palindrome(num):", "function_name": "is_palindrome", "parameter_list": "(num)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_valid_number():\n while True:\n user_input = input(\"Enter a number: \")\n if user_input.lower() == 'q':\n return None\n try:\n num = int(...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021709", "row_id": 21709, "seed_ids": "['Llama-3.3-70B-Instruct_54335']" }
0.773497
Filter_21709
I
[ "get_valid_number", "is_palindrome", "palindrome_checker" ]
3
[ [ "palindrome_checker", "get_valid_number" ], [ "palindrome_checker", "is_palindrome" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7c781cd13e3d42b1c8e450f5015365431c3e8bc4
09d116fd5f66c3ae85ecaec9293f71d292216fad
v1.0
instruct
Filter
Filter_21723_I
I have 6 rectangles on my screen with their vertex coordinates, and I would like to run an algorithm that detects whether there is any overlap between two or more rectangles. Here is a simple example with coordinates (x, y, width, height): Rectangle 1: (0, 0, 100, 100) Rectangle 2: (50, 50, 150, 150) Rectangle 3: (200...
def is_overlap(rect1, rect2): """ Checks if two rectangles overlap. Each rectangle is represented as a tuple (x, y, width, height). Returns True if the rectangles overlap, otherwise False. """ x1, y1, w1, h1 = rect1 x2, y2, w2, h2 = rect2 # Check if one rectangle is on the left side of the ...
import pytest from solution import is_overlap, detect_overlaps def test_is_overlap_no_overlap(): # No overlap - rect2 is to the right of rect1 rect1 = (0, 0, 100, 100) rect2 = (150, 0, 100, 100) assert not is_overlap(rect1, rect2) # No overlap - rect2 is above rect1 rect1 = (0, 0, 100, 100) ...
[ { "docstring": "Checks if two rectangles overlap. Each rectangle is represented as a tuple (x, y, width, height).\nReturns True if the rectangles overlap, otherwise False.", "function_declaration": "def is_overlap(rect1, rect2):", "function_name": "is_overlap", "parameter_list": "(rect1, rect2)" }...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_overlap(rect1, rect2):\n \"\"\"\n Checks if two rectangles overlap. Rectangles are provided as tuples:\n (x, y, width, height)\n \"\"\"\n x1_min, y1_min, w1, h1 = rect1\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021723", "row_id": 21723, "seed_ids": "['Llama-3.3-70B-Instruct_54369']" }
0.603493
Filter_21723
I
[ "is_overlap", "detect_overlaps" ]
2
[ [ "detect_overlaps", "is_overlap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d420327d8bed36fe0cdf2dbaaf996ec64cd71984
16b8ad7fa15e543c6b08baa29043f7886dfe6b52
v1.0
instruct
Filter
Filter_21768_I
I would like to create a button that changes the state of a compound object when clicked. I have a variety of compound objects (all of the same type) and I want each button press to toggle the state of a different object. How can I create the buttons dynamically and assign them to the different objects?
class CompoundObject: def __init__(self, identifier): self.identifier = identifier self.state = False # Initial state is False def toggle_state(self): self.state = not self.state # Toggle the state def create_buttons_for_objects(objects): buttons = [] for obj in objects: ...
from solution import CompoundObject, create_buttons_for_objects def test_initial_state(): obj = CompoundObject(1) assert obj.state == False def test_toggle_state(): obj = CompoundObject(1) obj.toggle_state() assert obj.state == True obj.toggle_state() assert obj.state == False def test_cr...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class CompoundObject:\n def __init__(self, identifier):\n self.identifier = identifier\n self.state = False # Initial state is False\n\n def toggle_state(self):\n s...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021768", "row_id": 21768, "seed_ids": "['Llama-3.3-70B-Instruct_54498']" }
0.214941
Filter_21768
I
[ "create_buttons_for_objects", "create_button" ]
2
[ [ "create_buttons_for_objects", "create_button" ] ]
1
[]
false
[ "CompoundObject" ]
true
pytest
true
[]
true
b7117213dadeaf341fe74461b5d1177ced1bb113
03cd1d633d98e4c256a0a41b24d29fec44de7d11
v1.0
instruct
Filter
Filter_21773_I
Given an array of strings where each string can be considered as a sequence of characters. Implement a solution that will find the longest common prefix that can be a valid prefix for all strings in the given array. If there is no common prefix then print an empty string. Example: Input: arr = ["flower","flow","flig...
def is_common_prefix(arr, length): """ Checks if the first length characters are common prefix. """ prefix = arr[0][:length] for string in arr: if not string.startswith(prefix): return False return True def longest_common_prefix(arr): """ Finds the longest common pre...
from solution import longest_common_prefix def test_longest_common_prefix_single_string(): assert longest_common_prefix(["flower"]) == "flower" def test_longest_common_prefix_common_prefix(): assert longest_common_prefix(["flower","flow","flight"]) == "fl" def test_longest_common_prefix_no_common_prefix(): ...
[ { "docstring": "Checks if the first length characters are common prefix.", "function_declaration": "def is_common_prefix(arr, length):", "function_name": "is_common_prefix", "parameter_list": "(arr, length)" }, { "docstring": "Finds the longest common prefix string amongst an array of string...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_common_prefix(arr):\n \"\"\"\n Finds the longest common prefix string amongst an array of strings.\n If there is no common prefix, returns an empty string.\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021773", "row_id": 21773, "seed_ids": "['Llama-3.3-70B-Instruct_54508']" }
0.746282
Filter_21773
I
[ "is_common_prefix", "longest_common_prefix" ]
2
[ [ "longest_common_prefix", "is_common_prefix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
408720288285936d61ee56e0202ca9983602f74a
b501702e4291233c317b384eedab9371ae290288
v1.0
instruct
Filter
Filter_21780_I
I have a set of nested, recursive XML elements that I want to parse. How can I use Python with the ElementTree module to do this?
import xml.etree.ElementTree as ET def parse_xml_element(element): """ Recursively parse an XML element. """ parsed_data = { "tag": element.tag, "attributes": element.attrib, "text": element.text.strip() if element.text else None, "children": [] } for child in e...
import xml.etree.ElementTree as ET from solution import parse_xml_string def test_parse_simple_xml(): xml_string = '<root><child1>Text1</child1><child2>Text2</child2></root>' expected = { 'tag': 'root', 'attributes': {}, 'text': None, 'children': [ {'tag': 'child1', ...
[ { "docstring": "Recursively parse an XML element.", "function_declaration": "def parse_xml_element(element):", "function_name": "parse_xml_element", "parameter_list": "(element)" }, { "docstring": "Parse an XML string into a nested dictionary structure.", "function_declaration": "def par...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import xml.etree.ElementTree as ET\n\ndef parse_xml(xml_string):\n \"\"\"\n Parses an XML string and returns a dictionary representation of the XML structure.\n \"\"\"\n root = ET....
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021780", "row_id": 21780, "seed_ids": "['Llama-3.3-70B-Instruct_54530']" }
0.583492
Filter_21780
I
[ "parse_xml_element", "parse_xml_string" ]
2
[ [ "parse_xml_string", "parse_xml_element" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0bc52922514d3db65330fec678d42b2bb060a449
63662b0f8c1f11d72ed1e4c6690a723b81cd1e1f
v1.0
instruct
Filter
Filter_21784_I
### Using MapReduce to Solve Sudoku Sudoku is a popular puzzle where you have a 9x9 grid, and each cell can have a number from 1 to 9. Some numbers are already filled in, and some are blank. The objective is to fill in all the blank cells such that each row, column, and 3x3 sub-grid contains each number from 1 to 9 ex...
from collections import defaultdict def parse_sudoku_grid(grid_str): grid = [] rows = grid_str.split(';') for row in rows: grid.append(list(map(int, row.split(',')))) return grid def is_valid_move(grid, row, col, num): # Check the row if num in grid[row]: return False # Che...
from solution import solve_sudoku_mapreduce, parse_sudoku_grid, format_sudoku_grid def test_solve_sudoku_easy(): sudoku_str = "5,3,0,0,7,0,0,0,0;6,0,0,1,9,5,0,0,0;0,9,8,0,0,0,0,6,0;" \ "8,0,0,0,6,0,0,0,3;4,0,0,8,0,3,0,0,1;7,0,0,0,2,0,0,0,6;" \ "0,6,0,0,0,0,2,8,0;0,0,0,4,1,9,0,0,5;...
[ { "docstring": null, "function_declaration": "def parse_sudoku_grid(grid_str):", "function_name": "parse_sudoku_grid", "parameter_list": "(grid_str)" }, { "docstring": null, "function_declaration": "def is_valid_move(grid, row, col, num):", "function_name": "is_valid_move", "para...
[ 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(board, row, col, num):\n \"\"\"\n Check if it's valid to place the number num in the given row and column.\n \"\"\"\n subgrid_row_start = (row // 3) * 3\n subgrid_c...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021784", "row_id": 21784, "seed_ids": "['Llama-3.3-70B-Instruct_54541']" }
0.54461
Filter_21784
I
[ "parse_sudoku_grid", "is_valid_move", "solve_sudoku_mapreduce", "format_sudoku_grid" ]
4
[ [ "solve_sudoku_mapreduce", "is_valid_move" ], [ "solve_sudoku_mapreduce", "parse_sudoku_grid" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b9e5bb24667948906a829abec30ff49a18a78454
fe7292e8b87d4946a89cb023fc166cad206cf0ae
v1.0
instruct
Filter
Filter_21813_I
I have written a script to simulate a lottery draw. I would like to extend it to include an excess of numbers, more prize tiers and real-time (or at least faster) random number generation. My current script is: ```python import random import time def generate_numbers(): """Generate a list of 6 unique random numbe...
import random def generate_numbers(): """Generate a list of 7 unique random numbers between 1 and 52, where the first 6 are main numbers and the 7th is a bonus ball.""" numbers = random.sample(range(1, 53), 7) main_numbers = numbers[:6] bonus_ball = numbers[6] return main_numbers, bonus_ball def d...
from solution import generate_numbers, check_ticket, draw_lotto def test_generate_numbers(): main_numbers, bonus_ball = generate_numbers() assert len(main_numbers) == 6 assert len(set(main_numbers)) == 6 assert bonus_ball not in main_numbers assert 1 <= bonus_ball <= 52 def test_check_ticket(): ...
[ { "docstring": "Generate a list of 7 unique random numbers between 1 and 52, where the first 6 are main numbers and the 7th is a bonus ball.", "function_declaration": "def generate_numbers():", "function_name": "generate_numbers", "parameter_list": "()" }, { "docstring": "Simulate a lottery ...
[ 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 tkinter as tk\nfrom tkinter import messagebox\n\ndef generate_numbers():\n \"\"\"Generate a list of 6 unique random numbers between 1 and 52 and a bonus ball\"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021813", "row_id": 21813, "seed_ids": "['Llama-3.3-70B-Instruct_54636']" }
0.490473
Filter_21813
I
[ "generate_numbers", "draw_lotto", "check_ticket", "input_ticket", "run_simulation" ]
5
[ [ "draw_lotto", "generate_numbers" ], [ "run_simulation", "check_ticket" ], [ "run_simulation", "draw_lotto" ], [ "run_simulation", "input_ticket" ] ]
4
[]
false
[]
false
pytest
true
[]
true
0cb0d5ea25c758135800d1e25087bb0bf4c7ec85
e7d9aa311823dbee6a6be00ee0386992a418ff81
v1.0
instruct
Filter
Filter_21819_I
### Basic 21 Game Implementation #### Overview The 21 game is a simplified version of the casino banking game, Blackjack. The objective of the game is to have a hand value that is closer to 21 than the dealer's hand without exceeding 21. #### Rules: 1. Numbered cards are worth their face value. 2. Face cards (Jack, Qu...
import random # Initialize deck suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades'] ranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'] deck = [(rank, suit) for suit in suits for rank in ranks] # Function to calculate the value of a hand def calculate_hand_value(hand): values = {'...
from solution import calculate_hand_value, deal_card, deal_initial_cards, game_flow def test_calculate_hand_value(): assert calculate_hand_value([('2', 'Spades'), ('3', 'Hearts')]) == 5 assert calculate_hand_value([('10', 'Diamonds'), ('Jack', 'Clubs')]) == 20 assert calculate_hand_value([('Ace', 'Spades')...
[ { "docstring": null, "function_declaration": "def calculate_hand_value(hand):", "function_name": "calculate_hand_value", "parameter_list": "(hand)" }, { "docstring": null, "function_declaration": "def deal_card(deck):", "function_name": "deal_card", "parameter_list": "(deck)" }...
[ 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\n# Initialize deck\nsuits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']\nranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace']\ndeck = [(rank, su...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021819", "row_id": 21819, "seed_ids": "['Llama-3.3-70B-Instruct_54647']" }
0.575279
Filter_21819
I
[ "calculate_hand_value", "deal_card", "deal_initial_cards", "game_flow" ]
4
[ [ "deal_initial_cards", "deal_card" ], [ "game_flow", "calculate_hand_value" ], [ "game_flow", "deal_card" ], [ "game_flow", "deal_initial_cards" ] ]
4
[]
false
[]
false
pytest
true
[]
true
2e6fd7a40ce990ef6373e24d234e7e3830429bbc
d47335058d89386be0dcca080f585616dad105bf
v1.0
instruct
Filter
Filter_21821_I
### Building a Game of Hangman #### Overview The classic game of hangman involves one player thinking of a word, and the other player trying to guess the word by suggesting letters. For each letter that is not in the word, the first player draws a part of a hangman's gallows. The game continues until the word is guesse...
import random def select_word(word_list): """ Randomly selects a word from a list of words. """ return random.choice(word_list) def draw_gallows(incorrect_guesses): """ Returns the current state of the gallows based on the number of incorrect guesses. """ stages = [ "", ...
import pytest from solution import select_word, draw_gallows, display_word, guess_letter def test_select_word(): word_list = ["python", "hangman", "challenge", "programming", "random"] word = select_word(word_list) assert word in word_list def test_draw_gallows(): assert draw_gallows(0) == "" asse...
[ { "docstring": "Randomly selects a word from a list of words.", "function_declaration": "def select_word(word_list):", "function_name": "select_word", "parameter_list": "(word_list)" }, { "docstring": "Returns the current state of the gallows based on the number of incorrect guesses.", "...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef select_random_word(word_list):\n return random.choice(word_list)\n\ndef draw_gallows(incorrect_guesses):\n stages = [\n \"\"\"\n ------\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021821", "row_id": 21821, "seed_ids": "['Llama-3.3-70B-Instruct_54651']" }
0.547769
Filter_21821
I
[ "select_word", "draw_gallows", "display_word", "guess_letter", "play_hangman" ]
5
[ [ "play_hangman", "display_word" ], [ "play_hangman", "draw_gallows" ], [ "play_hangman", "guess_letter" ], [ "play_hangman", "select_word" ] ]
4
[]
false
[]
false
pytest
true
[]
true
d6da45b818f289ebd078e56e34fdf282927e1cd1
e8081aa7879a439e05a03f05372799587b2a0434
v1.0
instruct
Filter
Filter_21858_I
I have a shape, and I know which points are connected, but I need to know what angle each line of the shape makes with the origin. Calculating the angles is becoming tedious. Can I write some code to do this for me? You can write the code in any programming language of this task, but it might be helpful to note that I...
import math def calculate_angle_with_origin(x, y): """ Returns the angle (in degrees) between the line connecting the origin to the point (x, y) and the positive x-axis. """ angle_radians = math.atan2(y, x) angle_degrees = math.degrees(angle_radians) return angle_degrees def shape_angles(p...
from solution import calculate_angle_with_origin, shape_angles def test_calculate_angle_with_origin(): assert calculate_angle_with_origin(1, 0) == 0 assert calculate_angle_with_origin(0, 1) == 90 assert calculate_angle_with_origin(-1, 0) == 180 assert calculate_angle_with_origin(0, -1) == -90 asser...
[ { "docstring": "Returns the angle (in degrees) between the line connecting the origin to the point (x, y)\nand the positive x-axis.", "function_declaration": "def calculate_angle_with_origin(x, y):", "function_name": "calculate_angle_with_origin", "parameter_list": "(x, y)" }, { "docstring":...
[ 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 calculate_angle_with_origin(x, y):\n \"\"\"\n Returns the angle (in degrees) between the line connecting the origin to the point (x, y)\n and the positive x-axis.\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021858", "row_id": 21858, "seed_ids": "['Llama-3.3-70B-Instruct_54770']" }
0.479051
Filter_21858
I
[ "calculate_angle_with_origin", "shape_angles" ]
2
[ [ "shape_angles", "calculate_angle_with_origin" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d8a4747f50e5eba0facc995d8e9c730b80455f7
679d90a02b02aa454d85e27942991859d2597760
v1.0
instruct
Filter
Filter_21870_I
Based on the data provided below, write a program in Python to solve the correct patent citations based on the data. Data: 1. list of patents: ['US1234567', 'US7654321', 'US1654321'] 2. list of cited patents: ['US7654321', 'US1234567'] The task is to check if the cited patent is indeed a patent and hence a valid ci...
def binary_search(arr, val): """ Performs binary search on the sorted array to find the value. Returns True if found, False otherwise. """ low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == val: return True elif arr[mid]...
from solution import valid_citations def test_valid_citations_all_cited_are_valid(): patents = ['US1234567', 'US7654321', 'US1654321'] cited_patents = ['US7654321', 'US1234567'] assert valid_citations(patents, cited_patents) == ['US7654321', 'US1234567'] def test_valid_citations_some_cited_are_valid(): ...
[ { "docstring": "Performs binary search on the sorted array to find the value.\nReturns True if found, False otherwise.", "function_declaration": "def binary_search(arr, val):", "function_name": "binary_search", "parameter_list": "(arr, val)" }, { "docstring": "Returns a list of valid citatio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search(sorted_list, val):\n \"\"\"\n Perform binary search on a sorted list and return the index of the value if found, else -1.\n \"\"\"\n low, high = 0, len(sorted_lis...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021870", "row_id": 21870, "seed_ids": "['Llama-3.3-70B-Instruct_54790']" }
0.505557
Filter_21870
I
[ "binary_search", "valid_citations" ]
2
[ [ "valid_citations", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19b83d0590505d688fd52c09fc027dc46714d12e
a127b7de11baf7aef38d71e977b2e5d07b9f6f9a
v1.0
instruct
Filter
Filter_21932_I
# File Explorer Three As part of a software development project, you are given an FTP server with thousands of files. You need to determine the most recently modified files. The files are stored in a hierarchical directory. Each file is represented as a string in the format `["dir1/dir2/../file1.txt", "dir1/dir2/./f...
def resolve_path(path): """ Resolves relative paths to absolute paths. """ parts = path.split("/") stack = [] for part in parts: if part == "..": if stack: stack.pop() elif part == ".": continue else: stack.append(part) ...
from solution import mostRecentlyModified, resolve_path def test_resolve_path(): assert resolve_path("dir1/dir2/../file1.txt") == "dir1/file1.txt" assert resolve_path("dir1/dir2/./file2.txt") == "dir1/dir2/file2.txt" assert resolve_path("dir1/./file3.txt") == "dir1/file3.txt" assert resolve_path("fileN...
[ { "docstring": "Resolves relative paths to absolute paths.", "function_declaration": "def resolve_path(path):", "function_name": "resolve_path", "parameter_list": "(path)" }, { "docstring": "Returns the most recently modified files given a list of file paths.", "function_declaration": "d...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def resolve_path(path):\n \"\"\"\n Resolves relative paths to absolute paths.\n \"\"\"\n parts = path.split(\"/\")\n stack = []\n for part in parts:\n if part == \"..\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021932", "row_id": 21932, "seed_ids": "['Llama-3.3-70B-Instruct_54927']" }
0.558194
Filter_21932
I
[ "resolve_path", "mostRecentlyModified" ]
2
[ [ "mostRecentlyModified", "resolve_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a6ee045b290caa001211cf4f913f7f94c7141115
e5b2b04d35e444eedada4e60f0673aff93a774d0
v1.0
instruct
Filter
Filter_21938_I
Here's an example of a problem that would be perfect for solving with code: "The Ice Cream Shop sells the most popular 15 ice cream flavors in cones with three different sizes: Small (1 scoop), Medium (2 scoops) and Large (3 scoops). For each size, the price is: * Small: $3 * Medium: $5 * Large: $7 Additionally, there ...
# Constants for ice cream prices PRICE_SMALL = 3 PRICE_MEDIUM = 5 PRICE_LARGE = 7 SIGNATURE_FEE = 1 # List of signature flavors SIGNATURE_FLAVORS = ["Flavor1", "Flavor2", "Flavor3", "Flavor4", "Flavor5"] def get_ice_cream_price(size, flavor): """ Calculate the price of ice cream based on its size and flavor. ...
from solution import get_ice_cream_price, total_price_for_order def test_get_ice_cream_price_small(): assert get_ice_cream_price("Small", "Vanilla") == 3 def test_get_ice_cream_price_medium(): assert get_ice_cream_price("Medium", "Chocolate") == 5 def test_get_ice_cream_price_large(): assert get_ice_crea...
[ { "docstring": "Calculate the price of ice cream based on its size and flavor.\n\nParameters:\n- size (str): The size of the ice cream (\"Small\", \"Medium\", \"Large\")\n- flavor (str): The flavor of the ice cream\n\nReturns:\n- int: The total price of the ice cream", "function_declaration": "def get_ice_c...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def ice_cream_price(flavor, size):\n \"\"\"\n Calculate the price of an ice cream cone given the flavor and size.\n \"\"\"\n SIZE_PRICES = {'Small': 3, 'Medium': 5, 'Large': 7}\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021938", "row_id": 21938, "seed_ids": "['Llama-3.3-70B-Instruct_54942']" }
0.555838
Filter_21938
I
[ "get_ice_cream_price", "total_price_for_order" ]
2
[ [ "total_price_for_order", "get_ice_cream_price" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5a131c637923d0e29c4f5e1244786b4fc766569f
a445cafec483d21a95954f0052636539adaa841f
v1.0
instruct
Filter
Filter_22009_I
Here are the instructions I have to make a chatbot: In this task, you are going to create a simple chatbot for asking the user for their favorite food and store the previous conversations. 1. Define how the chatbot will ask the user for their name and favorite food. 2. Define how the chatbot will store the conversati...
import re conversations = {} def get_conversation_history(): history = "Conversations:\n" for name, food in conversations.items(): history += f"- {name}: {food}\n" return history.strip() def chatbot(input_fn=input): """ Chatbot function that interacts with the user. :param input_fn: F...
from solution import chatbot, conversations, get_conversation_history def mock_input_generator(inputs): """ Generate a mock input function for testing """ def input_fn(prompt): return next(inputs) return input_fn def test_chatbot(): inputs = iter([ "John, Pizza", "history", ...
[ { "docstring": null, "function_declaration": "def get_conversation_history():", "function_name": "get_conversation_history", "parameter_list": "()" }, { "docstring": "Chatbot function that interacts with the user.\n:param input_fn: Function to get input from the user, default is the built-in...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\nconversations = {}\n\ndef get_conversation_history(): \n history = \"Conversations: \\n\"\n for name, food in conversations.items(): \n history += f\"- {name}: {food}...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022009", "row_id": 22009, "seed_ids": "['Llama-3.3-70B-Instruct_55122']" }
0.4541
Filter_22009
I
[ "get_conversation_history", "chatbot" ]
2
[ [ "chatbot", "get_conversation_history" ] ]
1
[]
false
[]
false
pytest
true
[]
true
df3b9ed2f06028270cf31c24540ff70e30844346
785ab18e794447b8ddb6b0fb3f8c98ca9e6ad587
v1.0
instruct
Filter
Filter_22014_I
### Basic Calculator Program #### Overview A basic calculator program will be developed to perform simple arithmetic operations such as addition, subtraction, multiplication, and division. #### Requirements - The calculator program will ask the user to input two numbers. - The calculator program will ask the user to in...
def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): if y == 0: return "Error: Division by zero is not allowed" return x / y def perform_operation(num1, num2, operator): if operator == '+': return add(num1, num2) ...
from solution import add, subtract, multiply, divide, perform_operation def test_add(): assert add(2, 3) == 5 assert add(-1, 1) == 0 assert add(-1, -1) == -2 def test_subtract(): assert subtract(10, 5) == 5 assert subtract(-1, 1) == -2 assert subtract(-1, -1) == 0 def test_multiply(): ass...
[ { "docstring": null, "function_declaration": "def add(x, y):", "function_name": "add", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def subtract(x, y):", "function_name": "subtract", "parameter_list": "(x, y)" }, { "docstring": null, "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(x, y):\n return x + y\n\ndef subtract(x, y):\n return x - y\n\ndef multiply(x, y):\n return x * y\n\ndef divide(x, y):\n if y == 0:\n return \"Error: Division by zer...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022014", "row_id": 22014, "seed_ids": "['Llama-3.3-70B-Instruct_55136']" }
0.68555
Filter_22014
I
[ "add", "subtract", "multiply", "divide", "perform_operation" ]
5
[ [ "perform_operation", "add" ], [ "perform_operation", "divide" ], [ "perform_operation", "multiply" ], [ "perform_operation", "subtract" ] ]
4
[]
false
[]
false
pytest
true
[]
true
89c6b95bf4347cf86692b0678bbeede5b1d04c6e
8c622b08898030f616e318337eb539386b2f2dce
v1.0
instruct
Filter
Filter_22029_I
Here is the code for computing the Voronoi diagram of a set of points in 2-dimensions: ```python import numpy as np def voronoi(x, y): points = np.column_stack((x, y)) vor = scipy.spatial.Voronoi(points) return vor def compute_voronoi(): x = np.random.rand(10) y = np.random.rand(10) voronoi_di...
import numpy as np import scipy.spatial def voronoi(x, y): """ Computes the Voronoi diagram of a set of points given by x, y coordinates. Parameters: x (array-like): The x-coordinates of the points. y (array-like): The y-coordinates of the points. Returns: scipy.spatial.Voronoi: The compu...
import numpy as np import scipy.spatial from solution import voronoi, compute_voronoi def test_voronoi_shape(): x = np.random.rand(10) y = np.random.rand(10) vor = voronoi(x, y) assert isinstance(vor, scipy.spatial.Voronoi) assert len(vor.points) == 10 def test_voronoi_computation(): x = np.ar...
[ { "docstring": "Computes the Voronoi diagram of a set of points given by x, y coordinates.\n\nParameters:\nx (array-like): The x-coordinates of the points.\ny (array-like): The y-coordinates of the points.\n\nReturns:\nscipy.spatial.Voronoi: The computed Voronoi diagram.", "function_declaration": "def voron...
[ 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\nimport scipy.spatial\n\ndef voronoi(x, y):\n \"\"\"\n Computes the Voronoi diagram of a set of points given by x, y coordinates.\n\n Parameters:\n x (array-like...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022029", "row_id": 22029, "seed_ids": "['Llama-3.3-70B-Instruct_55171']" }
0.852429
Filter_22029
I
[ "voronoi", "compute_voronoi" ]
2
[ [ "compute_voronoi", "voronoi" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
bca95a008a85810356bac761ab84497626d24189
947a3f435da39b605ea2b16de7a515680c26a067
v1.0
instruct
Filter
Filter_22043_I
I am trying to encode a message and for the receiver to decode the encoded message using the same method. Would you be able to provide a simple example in Python of a Caesar Cipher?
def caesar_cipher_encode(message, shift): """ Encodes the given message using Caesar cipher with the given shift. Args: message (str): the message to encode. shift (int): the amount by which to shift each letter. Returns: str: the encoded message. """ encoded_message = [] ...
from solution import caesar_cipher_encode, caesar_cipher_decode def test_caesar_cipher_encode(): assert caesar_cipher_encode("hello", 3) == "khoor" assert caesar_cipher_encode("HELLO", 3) == "KHOOR" assert caesar_cipher_encode("hello, world!", 3) == "khoor, zruog!" assert caesar_cipher_encode("xyz", 3)...
[ { "docstring": "Encodes the given message using Caesar cipher with the given shift.\n\nArgs:\nmessage (str): the message to encode.\nshift (int): the amount by which to shift each letter.\n\nReturns:\nstr: the encoded message.", "function_declaration": "def caesar_cipher_encode(message, shift):", "funct...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def caesar_cipher_encode(message, shift):\n \"\"\"\n Encodes a message using a Caesar Cipher with the given shift.\n Args:\n message (str): The message to encode.\n shif...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022043", "row_id": 22043, "seed_ids": "['Llama-3.3-70B-Instruct_55208']" }
0.583434
Filter_22043
I
[ "caesar_cipher_encode", "caesar_cipher_decode" ]
2
[ [ "caesar_cipher_decode", "caesar_cipher_encode" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a39eaf2bee454dc031d2cfca2b8ccbe01643be54
af38d7a8984677226c44a076c66064912fc37ba0
v1.0
instruct
Filter
Filter_22047_I
Here is a variation of the word ladder problem. Given a start word and an end word and a file containing a dictionary of valid English words, implement a solution to find the shortest transformation (word ladder) between the start word and end word by changing one letter at a time with each resulting word being a valid...
from collections import deque def load_word_list(file_path): with open(file_path, 'r') as file: words = set(file.read().splitlines()) return words def get_neighbors(word, word_list): neighbors = [] word_chars = list(word) for i in range(len(word_chars)): original_char = word_chars[...
from solution import word_ladder, create_temp_word_list, delete_temp_word_list def test_word_ladder_basic(): words = ["hit", "hot", "dot", "dog", "cog", "log"] path = create_temp_word_list(words) result = word_ladder("hit", "cog", path) assert result == ["hit", "hot", "dot", "dog", "cog"] delete_te...
[ { "docstring": null, "function_declaration": "def load_word_list(file_path):", "function_name": "load_word_list", "parameter_list": "(file_path)" }, { "docstring": null, "function_declaration": "def get_neighbors(word, word_list):", "function_name": "get_neighbors", "parameter_li...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef word_ladder(start, end, word_list):\n \"\"\"\n Finds the shortest transformation from start to end by changing one letter at a time.\n Each interm...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022047", "row_id": 22047, "seed_ids": "['Llama-3.3-70B-Instruct_55221']" }
0.602417
Filter_22047
I
[ "load_word_list", "get_neighbors", "word_ladder", "create_temp_word_list", "delete_temp_word_list" ]
5
[ [ "word_ladder", "get_neighbors" ], [ "word_ladder", "load_word_list" ] ]
2
[]
false
[]
false
pytest
true
[]
true
629703a5c683d861caf8c02985a1801627167e54
e2e3d6ef171968c90622208a9537f71e2b91d355
v1.0
instruct
Filter
Filter_22048_I
Code to delete a node with a given key from a binary search tree.
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def deleteNode(root, key): """ Delete a node with the given `key` from the Binary Search Tree and return the new root. """ if not root: return root if key < root.val: ...
from solution import TreeNode, deleteNode, inorderTraversal def test_delete_leaf_node(): root = TreeNode(5) root.left = TreeNode(3) root.right = TreeNode(6) root.left.left = TreeNode(2) root.left.right = TreeNode(4) root = deleteNode(root, 2) assert inorderTraversal(root) == [3, 4, 5, ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef deleteNode(root, key):\n \"\"\"\n Delete a node with the...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022048", "row_id": 22048, "seed_ids": "['Llama-3.3-70B-Instruct_55223']" }
0.527852
Filter_22048
I
[ "deleteNode", "getMinValueNode", "inorderTraversal" ]
3
[ [ "deleteNode", "getMinValueNode" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
66e8f25147f25ca9efc414aed65589b998f9f06c
45f68ef8a8fb3d7f3450f8d226a70ca436dd78e0
v1.0
instruct
Filter
Filter_22064_I
### Adding Alignments Most newer text editors and word processors have paragraph alignment features. Among other things, these features allow you to align a block of text to the left or right margin, or to center the text. When aligning text to the left or right, you are creating a flush alignment. In centering text, y...
def longest_string(strings): """ Returns the length of the longest string in the list of strings. """ max_len = 0 for s in strings: if len(s) > max_len: max_len = len(s) return max_len def align_text(strings, alignment): """ Aligns a list of strings based on the spe...
import pytest from solution import align_text def test_align_text_left(): strings = ["left", "right", "center"] expected = ["left ", "right ", "center"] assert align_text(strings, 'left') == expected def test_align_text_right(): strings = ["left", "right", "center"] expected = [" left", " right"...
[ { "docstring": "Returns the length of the longest string in the list of strings.", "function_declaration": "def longest_string(strings):", "function_name": "longest_string", "parameter_list": "(strings)" }, { "docstring": "Aligns a list of strings based on the specified alignment: 'left', 'r...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_string(strings):\n \"\"\"\n Returns the length of the longest string in the list of strings.\n \"\"\"\n max_len = 0\n for s in strings:\n if len(s) > max_len:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022064", "row_id": 22064, "seed_ids": "['Llama-3.3-70B-Instruct_55260']" }
0.540281
Filter_22064
I
[ "longest_string", "align_text" ]
2
[ [ "align_text", "longest_string" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bfcf35c5b8264514eb1c8c4d2cc0f54c5bb4d25f
ddc1a46c6f7b35a28413203f11a8097027d27009
v1.0
instruct
Filter
Filter_22083_I
Here is a list of 25 musicians/bands. Using the following procedure, find a pair of musicians/bands with the maximum number of mutual followers on last.fm: 1. Write code to scrape the last.fm user pages of the given musicians/bands to find the number of plays, number of listeners etc. 2. To find the number of mutual fo...
def mutual_followers(artists_data, artist1, artist2): """ Calculate the number of mutual followers between two artists. Parameters: artists_data (dict): A dictionary where keys are artist names and values are sets of user ids following them artist1 (str): Name of the first artist artist2 (s...
from solution import mutual_followers, find_max_mutual_followers def test_mutual_followers(): data = { "ArtistA": {"user1", "user2", "user3"}, "ArtistB": {"user2", "user3", "user4"}, "ArtistC": {"user5"} } assert mutual_followers(data, "ArtistA", "ArtistB") == 2 assert mutual_fo...
[ { "docstring": "Calculate the number of mutual followers between two artists.\n\nParameters:\nartists_data (dict): A dictionary where keys are artist names and values are sets of user ids following them\nartist1 (str): Name of the first artist\nartist2 (str): Name of the second artist\n\nReturns:\nint: Number o...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_mutual_followers(artist1, artist2, data):\n \"\"\"\n Returns the number of mutual followers between two artists based on mock data.\n \n Parameters:\n artist1 (str): The...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022083", "row_id": 22083, "seed_ids": "['Llama-3.3-70B-Instruct_55319']" }
0.447402
Filter_22083
I
[ "mutual_followers", "find_max_mutual_followers" ]
2
[ [ "find_max_mutual_followers", "mutual_followers" ] ]
1
[]
false
[]
false
pytest
true
[]
true
487bf05687736c223ccc65224d3c2f3a0b91e3d6
600fb9a066baba4301e6584bcc019b751e9e3f54
v1.0
instruct
Filter
Filter_22115_I
Here is the complete code implementation for the merge sort algorithm, as well as the auxiliary functions: ```python def merge(left, right): merged = [] left_index = 0 right_index = 0 while left_index < len(left) and right_index < len(right): if left[left_index] < right[right_index]: ...
def merge(left, right): """ Merge two sorted lists into one sorted list. """ merged = [] left_index = 0 right_index = 0 while left_index < len(left) and right_index < len(right): if left[left_index] < right[right_index]: merged.append(left[left_index]) le...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_array(): assert me...
[ { "docstring": "Merge two sorted lists into one sorted list.", "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" }, { "docstring": "Recursively split and merge the input array.", "function_declaration": "def merge_sort_helper(a...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge(left, right):\n \"\"\"\n Merges two sorted lists into one sorted list.\n \n Parameters:\n left (list): The first sorted list.\n right (list): The second sorted list...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022115", "row_id": 22115, "seed_ids": "['Llama-3.3-70B-Instruct_55391']" }
0.615117
Filter_22115
I
[ "merge", "merge_sort_helper", "merge_sort" ]
3
[ [ "merge_sort", "merge_sort_helper" ], [ "merge_sort_helper", "merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
355541eac1d82ef1de267923a7ff95a1fda19c65
3878d0d6e9d5ab31064b395d63ef08953a62a879
v1.0
instruct
Filter
Filter_22117_I
Here is a Python code that generates a random integer between 1 and 10: ``` import random def generate_random_integer(): return random.randint(1,10) print(generate_random_integer()) ``` Here is another code that generates all the permutations of a string: ``` import itertools def generate_permutations(s): r...
import random import itertools def generate_random_integer(): """ Returns a random integer between 1 and 10. """ return random.randint(1, 10) def generate_permutations(s): """ Returns a list of permutations of the input string s. """ return list(itertools.permutations(s)) def print_pe...
from solution import generate_permutations, generate_random_integer, print_permutations_with_random_numbers import itertools import random def test_generate_permutations(): assert generate_permutations("abc") == list(itertools.permutations("abc")) assert generate_permutations("") == list(itertools.permutations...
[ { "docstring": "Returns a random integer between 1 and 10.", "function_declaration": "def generate_random_integer():", "function_name": "generate_random_integer", "parameter_list": "()" }, { "docstring": "Returns a list of permutations of the input string s.", "function_declaration": "de...
[ 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 itertools\n\ndef generate_random_integer():\n \"\"\"\n Generates a random integer between 1 and 10.\n \"\"\"\n return random.randint(1, 10)\n\ndef generate_pe...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022117", "row_id": 22117, "seed_ids": "['Llama-3.3-70B-Instruct_55396']" }
0.536632
Filter_22117
I
[ "generate_random_integer", "generate_permutations", "print_permutations_with_random_numbers" ]
3
[ [ "print_permutations_with_random_numbers", "generate_permutations" ], [ "print_permutations_with_random_numbers", "generate_random_integer" ] ]
2
[]
false
[]
false
pytest
true
[]
true
59bbfc0d79081bc12de5a61aa8f2f473b8173c6f
f25529cad1fc2b81d8a515563ac5a48c637106cf
v1.0
instruct
Filter
Filter_22129_I
### Magic 8 Ball Create a Magic 8 Ball game using Python. The computer acts as the Magic 8 Ball. The program should randomly select an answer to the user's question and print it out. ### Step-by-Step Solution 1. **Import necessary modules**: Import the `random` module which will be used to select a random answer from...
import random def get_user_question(): """ Simulates getting a user question. This would normally be an input prompt. """ # For simplicity in testing, returning a preset question return "Will I get a promotion?" def get_random_answer(): """ Selects a random answer from the predefined set o...
from solution import get_random_answer def test_random_answer_within_possible_answers(): possible_answers = [ "It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it", "As I see it, yes", "Most likely", "Outlook...
[ { "docstring": "Simulates getting a user question. This would normally be an input prompt.", "function_declaration": "def get_user_question():", "function_name": "get_user_question", "parameter_list": "()" }, { "docstring": "Selects a random answer from the predefined set of possible answers...
[ 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_user_question():\n \"\"\"\n Asks the user for their question (for interactive mode).\n \"\"\"\n question = input(\"Please ask a question: \")\n return q...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022129", "row_id": 22129, "seed_ids": "['Llama-3.3-70B-Instruct_55419']" }
0.5168
Filter_22129
I
[ "get_user_question", "get_random_answer", "play_game" ]
3
[ [ "play_game", "get_random_answer" ], [ "play_game", "get_user_question" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d701aa611e5d73d73988a619c5f449fa5cd235c3
a30fe551982eabce63bbcf8d4d0aa29abfdef716
v1.0
instruct
Filter
Filter_22132_I
Given a fixed $n \times n$ grid, where n = 5, and a set of candidate points, write a program to apply the nearest neighbor algorithm on a given set of points to find the shortest path that visits each point exactly once and returns to the starting point.
import math def distance(point1, point2): """ Calculate the Euclidean distance between two points. :param point1: A tuple (x, y) representing the coordinates of the first point. :param point2: A tuple (x, y) representing the coordinates of the second point. :return: The Euclidean distance betw...
from solution import nearest_neighbor def test_nearest_neighbor_square_grid(): points = [(0, 0), (0, 4), (4, 0), (4, 4)] path = nearest_neighbor(points) expected_points_set = set(points) assert set(path[:-1]) == expected_points_set, "The path did not visit all points exactly once." def test_nearest_ne...
[ { "docstring": "Calculate the Euclidean distance between two points.\n\n:param point1: A tuple (x, y) representing the coordinates of the first point.\n:param point2: A tuple (x, y) representing the coordinates of the second point.\n:return: The Euclidean distance between the two points.", "function_declara...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef euclidean_distance(p1, p2):\n return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5\n\ndef nearest_neighbor_algorithm(points):\n \"\"\"\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022132", "row_id": 22132, "seed_ids": "['Llama-3.3-70B-Instruct_55427']" }
0.562454
Filter_22132
I
[ "distance", "nearest_neighbor" ]
2
[ [ "nearest_neighbor", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
416786e893bf63c0e081735664fa3750ccc0d3a2
b0e0758a4a9de195aebbb34aa97c38d913e52d15
v1.0
instruct
Filter
Filter_22137_I
I would like to create a program in Python that can read in a directory of image files and output the average hue of each image to a CSV file. Would someone be able to provide me with code to accomplish this?
import os import cv2 import numpy as np import csv def calculate_average_hue(image_path): """ Calculate the average hue of an image. """ # Read image image = cv2.imread(image_path) # Convert image to HSV color space hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # Extract the hue ch...
from solution import calculate_average_hue, process_images_in_directory import os import csv def test_calculate_average_hue(): # Test an image with known average hue # Setup a test image with known hue. test_image = np.zeros((100, 100, 3), dtype=np.uint8) test_image[:] = [30, 255, 255] # HSV: Hue=30 ...
[ { "docstring": "Calculate the average hue of an image.", "function_declaration": "def calculate_average_hue(image_path):", "function_name": "calculate_average_hue", "parameter_list": "(image_path)" }, { "docstring": "Process all images in the specified directory and output their average hue ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import os\nimport cv2\nimport numpy as np\nimport pandas as pd\n\ndef calculate_average_hue(image_path):\n \"\"\"\n Calculate the average hue of an image.\n \"\"\"\n image = cv2.im...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022137", "row_id": 22137, "seed_ids": "['Llama-3.3-70B-Instruct_55438']" }
0.54862
Filter_22137
I
[ "calculate_average_hue", "process_images_in_directory" ]
2
[ [ "process_images_in_directory", "calculate_average_hue" ] ]
1
[]
false
[]
false
pytest
true
[ "cv2", "numpy" ]
false
1c4d7b5e33724acc0e6617963c733f3fbb018c79
d7a1d190ac336a0c17ef129b2394dabf0356b080
v1.0
instruct
Filter
Filter_22145_I
This code is to generate the next 6 lottery numbers. These numbers use a system called cardano and if a number has been picked it cannot be reused, however if it is a power of 2 (ie 2, 4, 8, 16), then it can be reused even if it has been picked before. Here I have a code but I cant seem to work out how to do it ```py...
import random def is_power_of_two(n): if n == 0: return False return (n & (n - 1)) == 0 def cardano(): max_numbers = 49 picked_numbers = [] used_numbers = set() while len(picked_numbers) < 6: new_number = random.randint(1, max_numbers) if is_power_of_two(new_number) or...
import pytest from solution import cardano, is_power_of_two def test_is_power_of_two(): assert is_power_of_two(0) == False assert is_power_of_two(1) == True assert is_power_of_two(2) == True assert is_power_of_two(3) == False assert is_power_of_two(4) == True assert is_power_of_two(5) == False ...
[ { "docstring": null, "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def cardano():", "function_name": "cardano", "parameter_list": "()" } ]
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_power_of_two(n):\n if n == 0:\n return False\n return (n & (n - 1) == 0)\n\ndef cardano():\n max_numbers = 49\n picked_numbers = []\n used_powers_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022145", "row_id": 22145, "seed_ids": "['Llama-3.3-70B-Instruct_55454']" }
0.47867
Filter_22145
I
[ "is_power_of_two", "cardano" ]
2
[ [ "cardano", "is_power_of_two" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0173d64356ed1f751d8ff1e9f2fe3b6fafe05491
166f3a73a0a5ffeea7c1e5deee77728da47b34f0
v1.0
instruct
Filter
Filter_22162_I
Create a Word Guessing Game in Python ===================================== Below is a Python program that guesses a word from a predefined list based on the user's input. ```python import random def get_word_list(): # returns list of words word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig...
import random from collections import Counter def get_word_list(): # returns list of words word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] return word_list def get_user_input(prompt): # get user input with prompt user_input = input(prompt) return user_input def...
from solution import get_filtered_word_list, generate_guess def test_get_filtered_word_list(): word_list = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"] assert get_filtered_word_list(word_list, 5) == ["apple", "grape"] assert get_filtered_word_list(word_list, 4) == ["date"] assert...
[ { "docstring": null, "function_declaration": "def get_word_list():", "function_name": "get_word_list", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def get_user_input(prompt):", "function_name": "get_user_input", "parameter_list": "(prompt)" }, { ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_word_list():\n # returns list of words\n word_list = [\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\", \"fig\", \"grape\"]\n return word_list\n\nd...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022162", "row_id": 22162, "seed_ids": "['Llama-3.3-70B-Instruct_55493']" }
0.589773
Filter_22162
I
[ "get_word_list", "get_user_input", "get_filtered_word_list", "generate_guess", "play_game", "main" ]
6
[ [ "play_game", "generate_guess" ], [ "play_game", "get_filtered_word_list" ], [ "play_game", "get_user_input" ] ]
3
[]
false
[]
false
pytest
true
[]
true
3b5d10be05945d15193a81466dc3f89e0216a28d
0e9a04f7e6db80556d7244be8df59cb25c4b8f01
v1.0
instruct
Filter
Filter_22171_I
You have been tasked with writing a game in which players roll a six-sided die to determine how many spaces to move on a game board. The board has a special space that is the "snake pit." If a player lands on this space, they will move backwards to the space that is 7 spaces before the snake pit. Write a code that simu...
import random def roll_die(): """Simulates rolling a six-sided die.""" return random.randint(1, 6) def play_game(): """Simulates a player rolling a die and moving on the board.""" current_space = 0 snake_pit = 20 while current_space < 50: roll = roll_die() print(f"Rolled a...
import pytest from solution import roll_die, play_game def test_roll_die(): """Test that roll_die() returns a value between 1 and 6 inclusive.""" roll = roll_die() assert 1 <= roll <= 6 def test_play_game_snake_pit(monkeypatch): responses = iter(['n']) def mock_input(prompt): return n...
[ { "docstring": "Simulates rolling a six-sided die.", "function_declaration": "def roll_die():", "function_name": "roll_die", "parameter_list": "()" }, { "docstring": "Simulates a player rolling a die and moving on the board.", "function_declaration": "def play_game():", "function_nam...
[ 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 roll_die():\n \"\"\"Simulates rolling a six-sided die.\"\"\"\n return random.randint(1, 6)\n\ndef play_game(mock_input=None):\n \"\"\"Simulates a player rolling a...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022171", "row_id": 22171, "seed_ids": "['Llama-3.3-70B-Instruct_55513']" }
0.549589
Filter_22171
I
[ "roll_die", "play_game" ]
2
[ [ "play_game", "roll_die" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a7c5292cd415dd4047e324f3adfb320a2d198366
a1ef74a5d1318025d16ad72a38414cb9e772bbc3
v1.0
instruct
Filter
Filter_22177_I
### Question 1: Introduction to Python # You are given the following Python code snippet: ```python def process_list(input_list): result = [] for item in input_list: # processing code here result.append(item) return result def process_item(item): # processing code here return item ...
# Solution for Question 1 def process_list(input_list): result = [] for item in input_list: processed_item = process_item(item) result.append(processed_item) return result def process_item(item): return item * 2 # Call the functions input_list = [1, 2, 3, 4, 5] result_list = process_li...
from solution import process_list, process_item, preprocess_text def test_process_list(): assert process_list([1, 2, 3, 4, 5]) == [2, 4, 6, 8, 10] def test_process_item(): assert process_item(1) == 2 assert process_item(2) == 4 assert process_item(3) == 6 def test_preprocess_text(): assert prepro...
[ { "docstring": null, "function_declaration": "def process_list(input_list):", "function_name": "process_list", "parameter_list": "(input_list)" }, { "docstring": null, "function_declaration": "def process_item(item):", "function_name": "process_item", "parameter_list": "(item)" ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_list(input_list):\n result = []\n for item in input_list:\n processed_item = process_item(item)\n result.append(processed_item)\n return result\n\ndef proces...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022177", "row_id": 22177, "seed_ids": "['Llama-3.3-70B-Instruct_55530']" }
0.543999
Filter_22177
I
[ "process_list", "process_item", "preprocess_text" ]
3
[ [ "process_list", "process_item" ] ]
1
[]
false
[]
false
pytest
true
[]
true
693cd5881fab05d2946a1a5c81148b31345b961d
a434982e2b5c157045f5854ed9869a7a6a8924db
v1.0
instruct
Filter
Filter_22178_I
Here's some code I wrote that finds the sum of all the values in a particular JSON object. I'd like to iterate over a list of lists where each inner list contains two items: the json data and the key to look for. I'd like to add the elements of each inner list together and store that sum, along with the original json ...
def calculate_sum(json_obj, key): def try_parse_int(value): try: return int(value) except ValueError: return 0 total_sum = 0 if key in json_obj: if isinstance(json_obj[key], list): total_sum = sum([try_parse_int(i) for i in json_obj[key]]) ...
from solution import calculate_sum, process_data_list def test_calculate_sum_scores(): assert calculate_sum({"name": "John", "age": 30, "scores": [90, 95, 85]}, "scores") == 270 def test_calculate_sum_pets(): assert calculate_sum({"pets": ["dog", "cat", 1, 2, "3"]}, "pets") == 6 def test_calculate_sum_name()...
[ { "docstring": null, "function_declaration": "def calculate_sum(json_obj, key):", "function_name": "calculate_sum", "parameter_list": "(json_obj, key)" }, { "docstring": null, "function_declaration": "def process_data_list(data_list):", "function_name": "process_data_list", "para...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_sum(json_obj, key):\n def try_parse_int(value):\n try:\n return int(value)\n except ValueError:\n return 0\n\n total_sum = 0\n if key...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022178", "row_id": 22178, "seed_ids": "['Llama-3.3-70B-Instruct_55531']" }
0.54416
Filter_22178
I
[ "calculate_sum", "process_data_list" ]
2
[ [ "process_data_list", "calculate_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4a7bc8a177c5769a7e874110e0986016b3a52a05
3e189616e95aa1944accacfc5a9ac2914149c46d
v1.0
instruct
Filter
Filter_22183_I
Given a positive number N, write a program to find all the prime factors of the number. A prime factor is a prime number which divides the number evenly, i.e., it leaves no remainder. The program should list all the prime factors and calculate the sum of all distinct prime factors of the number. ### Example For the n...
def is_prime(n): """Check if a number is prime.""" if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def get_prime_factors(n): """Get all prime factors of a number.""" prime_factors = [] i = 2 while n > 1: ...
from solution import is_prime, get_prime_factors, sum_of_distinct_prime_factors 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(30) == False def test_get_prime_factors(): assert get_prime_factors...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Get all prime factors of a number.", "function_declaration": "def get_prime_factors(n):", "function_name": "get_prime_fact...
[ 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 < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022183", "row_id": 22183, "seed_ids": "['Llama-3.3-70B-Instruct_55546']" }
0.763794
Filter_22183
I
[ "is_prime", "get_prime_factors", "sum_of_distinct_prime_factors", "main" ]
4
[ [ "get_prime_factors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c8d4f222615d95602d3a3ea6ee27148974135a8
1cb45b1f486656f1a71f3fe7729649cb04d2cba1
v1.0
instruct
Filter
Filter_22192_I
Knowing that a binary search tree is a type of binary tree where each node has a comparable value, and for each node, all elements in the left subtree are less than the node's value, and all elements in the right subtree are greater than the node's value. Write a python function to delete a node, given the node's value...
class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def delete_node(root, key): """ Deletes a node with the given key from the binary search tree and returns the new root. """ if not root: return ...
from solution import TreeNode, delete_node, find_min def tree_to_list(root): """ Helper function to convert a binary search tree to a list in order. """ if not root: return [] return tree_to_list(root.left) + [root.value] + tree_to_list(root.right) def test_delete_leaf_node(): root = T...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.key = key\n self.left = None\n self.right = None\n\ndef delete_node(root, key):\n if not root:\n return root...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022192", "row_id": 22192, "seed_ids": "['Llama-3.3-70B-Instruct_55564']" }
0.523996
Filter_22192
I
[ "delete_node", "find_min" ]
2
[ [ "delete_node", "find_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
3a2e511f94318295d1b7951579f829f6f9742df8
860c0d24846b6d701cfa64ab84244992fd55db10
v1.0
instruct
Filter
Filter_22227_I
I've been trying to optimize one of my functions to be more a dynamic input. Here's what I have so far ```python def create_task(item): # solve task pass # Known types VEHICLE_TYPES = ["van", "suv", "car", "bike"] NAMES = ["task1", "task2"] for name in NAMES: for vehicle_type in VEHICLE_TYPES: g...
def create_task(item): """ Dummy function to simulate task creation. """ return f"Task created with item {item}" def generate_dynamic_functions(names, vehicle_types): """ Generates dynamic functions based on provided names and vehicle types. """ for name in names: for vehicle_ty...
import pytest from solution import generate_dynamic_functions, create_task def test_create_task(): assert create_task("example_item") == "Task created with item example_item" def test_dynamic_functions(): VEHICLE_TYPES = ["van", "suv", "car", "bike"] NAMES = ["task1", "task2"] generate_dynamic_functio...
[ { "docstring": "Dummy function to simulate task creation.", "function_declaration": "def create_task(item):", "function_name": "create_task", "parameter_list": "(item)" }, { "docstring": "Generates dynamic functions based on provided names and vehicle types.", "function_declaration": "de...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import types\n\ndef create_task(item):\n \"\"\"\n Placeholder function to simulate task handling.\n \"\"\"\n return f\"Task created with item: {item}\"\n\ndef create_dynamic_functi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022227", "row_id": 22227, "seed_ids": "['Llama-3.3-70B-Instruct_55643']" }
0.47038
Filter_22227
I
[ "create_task", "generate_dynamic_functions" ]
2
[ [ "generate_dynamic_functions", "create_task" ] ]
1
[]
false
[]
false
pytest
true
[]
true
359be2f47299c239db80905e679790c0715b253e
0d307663e1ddde410276ae7166534a3a649ef110
v1.0
instruct
Filter
Filter_22246_I
i am working on a text game i have made two dictionaries that contains lists of words. each word is a key in the first dictionary and a value in the second dictionary i try to move words from one dictionary to another, when the word is not present in the keys of the second dictionary, and vice versa. can you please p...
def move_to_dict1(key, dictionary1, dictionary2): """ Move a key and its value from dictionary2 to dictionary1 if the key is not in dictionary1. """ if key not in dictionary1: # Move the key-value pair from dictionary2 to dictionary1 dictionary1[key] = dictionary2.pop(key) def move_to_d...
from solution import manage_dictionaries def test_manage_dictionaries(): dict1 = {"apple": ["list", "of", "words"], "banana": ["list", "of", "other", "words"]} dict2 = {"pear": ["some", "text"], "cherry": ["other", "text"]} manage_dictionaries(dict1, dict2) assert "banana" in dict2 and "apple" not in...
[ { "docstring": "Move a key and its value from dictionary2 to dictionary1 if the key is not in dictionary1.", "function_declaration": "def move_to_dict1(key, dictionary1, dictionary2):", "function_name": "move_to_dict1", "parameter_list": "(key, dictionary1, dictionary2)" }, { "docstring": "M...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def move_word_between_dicts(dict1, dict2):\n \"\"\"\n Moves words between two dictionaries based on their presence.\n If a word from dict1 is not in dict2, it gets moved to dict2.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022246", "row_id": 22246, "seed_ids": "['Llama-3.3-70B-Instruct_55709']" }
0.50792
Filter_22246
I
[ "move_to_dict1", "move_to_dict2", "manage_dictionaries", "main" ]
4
[ [ "manage_dictionaries", "move_to_dict1" ], [ "manage_dictionaries", "move_to_dict2" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ef21b9d724949f7d2ee0567cb96765618d157d32
cf340917c813fe475b25731f4c34189feae129b4
v1.0
instruct
Filter
Filter_22253_I
Given an adjacency matrix A representing a simple, undirected graph G, give an algorithm to check whether G contains a Hamiltonian Cycle. A Hamiltonian Cycle is a cycle in a graph that visits each vertex exactly once, except for the starting vertex which is visited twice (once at the start and once at the end). The a...
def is_hamiltonian_cycle(matrix): if len(matrix) == 0: return False num_vertices = len(matrix) # Start from vertex 0 and try to find a Hamiltonian cycle path = [0] visited = [False] * num_vertices def is_hamiltonian_cycle_helper(path, visited): current_vertex = path[-1] ...
from solution import is_hamiltonian_cycle def test_hamiltonian_cycle_exists(): matrix = [ [0, 1, 1, 0], [1, 0, 1, 1], [1, 1, 0, 1], [0, 1, 1, 0] ] assert is_hamiltonian_cycle(matrix) == True def test_hamiltonian_cycle_does_not_exist(): matrix = [ [0, 1, 0, 0], ...
[ { "docstring": null, "function_declaration": "def is_hamiltonian_cycle(matrix):", "function_name": "is_hamiltonian_cycle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def get_neighbors(matrix, vertex):", "function_name": "get_neighbors", "paramet...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_hamiltonian_cycle(matrix):\n if len(matrix) == 0:\n return False\n num_vertices = len(matrix)\n # start from node 0 and try to find a cycle\n path = [0]\n visited ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022253", "row_id": 22253, "seed_ids": "['Llama-3.3-70B-Instruct_55725']" }
0.487652
Filter_22253
I
[ "is_hamiltonian_cycle", "get_neighbors" ]
2
[ [ "is_hamiltonian_cycle", "get_neighbors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
38b8ec6be90aa04b727ea3463e9cf8ba8bcc67f1
5f06a02147605ca2939f9c57eae147cb77cd6d44
v1.0
instruct
Filter
Filter_22255_I
I would like to generate all possible Treap variations for the given size n using the "dynamic programming" approach. Could you please provide me with a Python implementation using the dynamic programming approach to generate all possible Treap variations for the given size n? Also, I have been told that you can gen...
import itertools def all_subsets(ss): """ Generates all non-empty subsets of a set. """ subsets = [] for r in range(1, len(ss)+1): subsets.extend(itertools.combinations(ss, r)) return [set(subset) for subset in subsets] def treap_variations(n): """ Generates all possible Treap ...
from solution import treap_variations def test_treap_variations_n_3(): result = treap_variations(3) expected = [{'1'}, {'2'}, {'3'}, {'1', '2'}, {'1', '3'}, {'2', '3'}, {'1', '2', '3'}] assert result == expected def test_treap_variations_n_4(): result = treap_variations(4) expected = [{'1'}, {'2'}...
[ { "docstring": "Generates all non-empty subsets of a set.", "function_declaration": "def all_subsets(ss):", "function_name": "all_subsets", "parameter_list": "(ss)" }, { "docstring": "Generates all possible Treap variations for the given size n.", "function_declaration": "def treap_varia...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\ndef all_subsets(ss):\n subsets = []\n for r in range(1, len(ss)+1):\n subsets.extend(itertools.combinations(ss, r))\n return [set(subset) for subset in subs...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022255", "row_id": 22255, "seed_ids": "['Llama-3.3-70B-Instruct_55733']" }
0.441385
Filter_22255
I
[ "all_subsets", "treap_variations" ]
2
[ [ "treap_variations", "all_subsets" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a6b057274b53d39cec707389418736c3d821225b
210d3fe21ce3548e44a033070ebcef6f8944f097
v1.0
instruct
Filter
Filter_22258_I
### Importing Necessary Modules and Defining a Function to Calculate LCM ```python from math import gcd def lcm(x, y): return x * y // gcd(x, y) ``` ### Define a Function to Calculate the Result ```python def calculate_result(): numbers = [i for i in range(1, 21)] # Generate a list of numbers from 1 to 20 result = nu...
from math import gcd def lcm(x, y): """ Calculate the Least Common Multiple (LCM) of two numbers x and y. Args: x (int): The first number. y (int): The second number. Returns: int: The LCM of x and y. """ return x * y // gcd(x, y) def calculate_result(): """ Calculate the ...
from solution import lcm, calculate_result def test_lcm(): assert lcm(4, 5) == 20 assert lcm(6, 8) == 24 assert lcm(7, 3) == 21 assert lcm(1, 20) == 20 assert lcm(21, 6) == 42 def test_calculate_result(): assert calculate_result() == 232792560
[ { "docstring": "Calculate the Least Common Multiple (LCM) of two numbers x and y.\nArgs:\nx (int): The first number.\ny (int): The second number.\n\nReturns:\nint: The LCM of x and y.", "function_declaration": "def lcm(x, y):", "function_name": "lcm", "parameter_list": "(x, y)" }, { "docstri...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\n\ndef lcm(x, y):\n \"\"\"\n Calculate the Least Common Multiple (LCM) of two numbers x and y.\n Args:\n x (int): The first number.\n y (int): The second nu...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022258", "row_id": 22258, "seed_ids": "['Llama-3.3-70B-Instruct_55739']" }
0.600559
Filter_22258
I
[ "lcm", "calculate_result", "main" ]
3
[ [ "calculate_result", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
816c65f6370e71855116e7458e9988bed171637f
30eba88ae4451b3dea736fd14e8436ade6c4bd9f
v1.0
instruct
Filter
Filter_22284_I
### Triggering Multiple Actions with a Single Event You have a method `log_and_notify` that logs a message and then notifies a user. You now want to add an additional action after the notification, which is to update a database. However, you want to ensure that the update happens only if the notification was successful...
def log_and_notify(message): """ Logs a message and then notifies a user. If the notification is successful, it updates the database. """ log_message(message) notification_successful = notify_user(message) if notification_successful: update_database(message) def l...
from solution import log_and_notify, log_message, notify_user, update_database def test_log_message(capfd): log_message("Test log") captured = capfd.readouterr() assert "Log: Test log" in captured.out def test_notify_user(capfd): result = notify_user("Test notification") assert result is True ...
[ { "docstring": "Logs a message and then notifies a user. If the notification is successful, \nit updates the database.", "function_declaration": "def log_and_notify(message):", "function_name": "log_and_notify", "parameter_list": "(message)" }, { "docstring": "Simulates logging a message.", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def log_and_notify(message):\n \"\"\"\n Logs a message and then notifies a user. If the notification is successful, \n it updates the database.\n \"\"\"\n log_message(message)\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022284", "row_id": 22284, "seed_ids": "['Llama-3.3-70B-Instruct_55802']" }
0.387427
Filter_22284
I
[ "log_and_notify", "log_message", "notify_user", "update_database" ]
4
[ [ "log_and_notify", "log_message" ], [ "log_and_notify", "notify_user" ], [ "log_and_notify", "update_database" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d30f0fde78891886d988ebfc90be4b4ad7bf30b3
fb3edd4fa7d67901dfe68de6d6adba87def391a6
v1.0
instruct
Filter
Filter_22286_I
I have a predefined set of coordinates in my program, and for each pair of coordinates, I need to compare them with every other pair of coordinates and calculate the distance between them using the Euclidean distance formula. Here is an example of the coordinates I have: ```python coordinates = [ [0.0, 0.0], ...
import math def calculate_distance(coord1, coord2): return math.sqrt((coord1[0] - coord2[0])**2 + (coord1[1] - coord2[1])**2) def calculate_distances(coordinates): distances = {} for i in range(len(coordinates)): for j in range(i + 1, len(coordinates)): distance = calculate_distance(co...
import pytest from solution import calculate_distance, calculate_distances def test_calculate_distance(): assert calculate_distance([0.0, 0.0], [0.0, 3.0]) == 3.0 assert calculate_distance([2.0, 0.0], [1.0, 1.0]) == pytest.approx(1.41421356237, 0.00001) assert calculate_distance([3.0, 4.0], [6.0, 8.0]) == ...
[ { "docstring": null, "function_declaration": "def calculate_distance(coord1, coord2):", "function_name": "calculate_distance", "parameter_list": "(coord1, coord2)" }, { "docstring": null, "function_declaration": "def calculate_distances(coordinates):", "function_name": "calculate_dis...
[ 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 calculate_distance(coord1, coord2):\n return math.sqrt((coord1[0] - coord2[0])**2 + (coord1[1] - coord2[1])**2)\n\ndef calculate_distances(coordinates):\n distances = ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022286", "row_id": 22286, "seed_ids": "['Llama-3.3-70B-Instruct_55806']" }
0.715395
Filter_22286
I
[ "calculate_distance", "calculate_distances" ]
2
[ [ "calculate_distances", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
43c49b2bee142552bfc0f8d77b5e0984b49aac6a
436a4d7d1cc05808e815ee4b0ea62da0999ff92c
v1.0
instruct
Filter
Filter_22289_I
I have a collection of images and I want to augment it by adding random rotations, scaling and flipping to each image. I can write the code to perform these operations but I'm not having trouble understanding the proper range to use for each of the transformations. What ranges would be suitable for a real-world image a...
import random from PIL import Image, ImageOps def random_rotate(image, angle_range=(-45, 45)): """ Rotates the image by a random angle within the specified range. """ angle = random.uniform(*angle_range) return image.rotate(angle) def random_scale(image, scale_range=(0.8, 1.2)): """ Scales...
from PIL import Image import tempfile import os from solution import random_rotate, random_scale, random_flip, augment_image def create_temp_image(): """ Create a temporary image for testing. """ image = Image.new('RGB', (100, 100), color='red') temp_file = tempfile.NamedTemporaryFile(delete=False,...
[ { "docstring": "Rotates the image by a random angle within the specified range.", "function_declaration": "def random_rotate(image, angle_range=(-45, 45)):", "function_name": "random_rotate", "parameter_list": "(image, angle_range=(-45, 45))" }, { "docstring": "Scales the image by a random f...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nimport cv2\nimport random\n\ndef augment_image(image):\n \"\"\"\n Augment an image by applying random rotation, scaling, and flipping.\n \n Parameters:\n ima...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022289", "row_id": 22289, "seed_ids": "['Llama-3.3-70B-Instruct_55811']" }
0.26593
Filter_22289
I
[ "random_rotate", "random_scale", "random_flip", "augment_image" ]
4
[ [ "augment_image", "random_flip" ], [ "augment_image", "random_rotate" ], [ "augment_image", "random_scale" ] ]
3
[]
false
[]
false
pytest
true
[ "PIL" ]
false
81da6fb4251771aa2d1eaab16fd0ec430200cf19
4621433274e7492152e22533a29227d1fd79d772
v1.0
instruct
Filter
Filter_22302_I
I have design specifications that require the presence of a minimum of three identical contour lines in the output. To achieve this, I've experimented with a few different approaches. One viable method involves the use of epoch and learning rate combinations for the Generative Adversarial Network (GAN) used in image sy...
# importing necessary modules import numpy as np import itertools def get_learning_rate_epoch_combinations(): # define learning rates and epochs learning_rates = [0.01, 0.005, 0.001, 0.0005, 0.0001] epochs = [10, 20, 30] # Generate combinations using Cartesian product combinations = list(itertoo...
from solution import train_gan_for_combinations, get_learning_rate_epoch_combinations def test_get_learning_rate_epoch_combinations(): combinations = get_learning_rate_epoch_combinations() expected_combinations = [ (10, 0.01), (10, 0.005), (10, 0.001), (10, 0.0005), (10, 0.0001), (20, 0.01), (2...
[ { "docstring": null, "function_declaration": "def get_learning_rate_epoch_combinations():", "function_name": "get_learning_rate_epoch_combinations", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def train_gan_for_combinations():", "function_name": "train_gan...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\n\n# Dummy GAN model for illustration purposes\nclass GAN:\n def __init__(self, learning_rate, epochs):\n self.learning_rate = learning_rate\n self.epochs = e...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022302", "row_id": 22302, "seed_ids": "['Llama-3.3-70B-Instruct_55850']" }
0.450539
Filter_22302
I
[ "get_learning_rate_epoch_combinations", "train_gan_for_combinations", "initialize_gan_model", "train_gan_model", "synthesize_images" ]
5
[ [ "train_gan_for_combinations", "get_learning_rate_epoch_combinations" ], [ "train_gan_for_combinations", "initialize_gan_model" ], [ "train_gan_for_combinations", "synthesize_images" ], [ "train_gan_for_combinations", "train_gan_model" ] ]
4
[]
false
[]
false
pytest
true
[ "numpy" ]
false
c965f00b06321e1a34b3643ee48e34af2eba6fa5
e8916f6fa7b6c56d89c29e3364f52a5a1fcc8e22
v1.0
instruct
Filter
Filter_22307_I
I'm looking to solve a second-order differential equation of the form y'' + Ay' + By = 0, where A and B are constants, using Python. Can you provide me with an example code snippet to get started?
import numpy as np from scipy.integrate import solve_ivp # Define the second-order differential equation as a system of first-order equations def second_order_ode(t, y, A, B): # y[0] is y and y[1] is y' return [y[1], -A * y[1] - B * y[0]] def solve_second_order_ode(A, B, y0, y1, t_span, t_eval): """ S...
from solution import solve_second_order_ode import numpy as np def test_homogeneous_solution(): A = 1.0 B = 1.0 y0 = 1.0 # Initial condition for y y1 = 0.0 # Initial condition for y' t_span = (0, 10) t_eval = np.linspace(t_span[0], t_span[1], 100) solution = solve_second_order_ode(A, B, ...
[ { "docstring": null, "function_declaration": "def second_order_ode(t, y, A, B):", "function_name": "second_order_ode", "parameter_list": "(t, y, A, B)" }, { "docstring": "Solves the second-order differential equation y'' + Ay' + By = 0\n\nParameters:\n- A (float): Coefficient of y'\n- B (flo...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from scipy.integrate import solve_ivp\nimport numpy as np\n\ndef second_order_ode(t, y, A, B):\n \"\"\"\n Defines the second-order differential equation y'' + Ay' + By = 0 \n as a sys...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022307", "row_id": 22307, "seed_ids": "['Llama-3.3-70B-Instruct_55859']" }
0.272541
Filter_22307
I
[ "second_order_ode", "solve_second_order_ode" ]
2
[ [ "solve_second_order_ode", "second_order_ode" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy", "scipy" ]
false
8e463826241715b5536e66e39c2e5086032c3851
1127a07c1575547532903832eb66b104cfe19d0f
v1.0
instruct
Filter
Filter_22314_I
Here is a Python function to determine whether a sequence of transactions can result from a given initial bank balance: ``` def is_possible_balance(bank_balance, transactions): """ Determines whether a sequence of transactions can result from a given initial bank balance. Args: bank_balance (fl...
def validate_inputs(bank_balance, transactions): """ Validates the inputs for the is_possible_balance function. Args: bank_balance (float): the initial bank balance transactions (list): a list of transaction amounts (positive for deposit, negative for withdrawal) Returns: ...
from solution import is_possible_balance, validate_inputs def test_validate_inputs_valid(): assert validate_inputs(100, [10, -20, 30]) == True assert validate_inputs(0, []) == True assert validate_inputs(-100, [-10, 20, -30, 0]) == True def test_validate_inputs_invalid(): assert validate_inputs(100, "...
[ { "docstring": "Validates the inputs for the is_possible_balance function.\n\nArgs:\n bank_balance (float): the initial bank balance\n transactions (list): a list of transaction amounts (positive for deposit, negative for withdrawal)\n \nReturns:\n bool: True if inputs are valid, False if inputs are...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_possible_balance(bank_balance, transactions):\n \"\"\"\n Determines whether a sequence of transactions can result from a given initial bank balance.\n \n Args:\n bank...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022314", "row_id": 22314, "seed_ids": "['Llama-3.3-70B-Instruct_55878']" }
0.68135
Filter_22314
I
[ "validate_inputs", "is_possible_balance" ]
2
[ [ "is_possible_balance", "validate_inputs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7ec4b9d722b757f6b3b44ff616e8f9a183ff158b
54f5b3ce217f724bbc81ec6685fa8b14861b867c
v1.0
instruct
Filter
Filter_22321_I
Here's an overview of my project: I have a bunch of songs, and each song has a list of attributes (like genre, tempo, mood, etc...). The goal is to play a song that is as similar as possible to the one that was just played. To determine how similar two songs are, I need to use a function that takes two lists, each re...
def similarity(song1, song2): """ Calculates the similarity between two songs. Returns a value between 0 and 1 indicating similarity. """ if len(song1) != len(song2): raise ValueError("Songs must have the same number of attributes") total_attributes = len(song1) matching_attribu...
from solution import similarity, find_next_song def test_similarity_identical_songs(): song1 = [1, 2, 3, 4] song2 = [1, 2, 3, 4] assert similarity(song1, song2) == 1.0 def test_similarity_completely_different_songs(): song1 = [1, 2, 3, 4] song2 = [5, 6, 7, 8] assert similarity(song1, song2) ==...
[ { "docstring": "Calculates the similarity between two songs.\nReturns a value between 0 and 1 indicating similarity.", "function_declaration": "def similarity(song1, song2):", "function_name": "similarity", "parameter_list": "(song1, song2)" }, { "docstring": "Given a current song and a list...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def song_similarity(song1, song2):\n \"\"\"\n Calculates the similarity between two songs.\n \n Each song is represented as a list of attributes. The function should return a\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022321", "row_id": 22321, "seed_ids": "['Llama-3.3-70B-Instruct_55892']" }
0.484401
Filter_22321
I
[ "similarity", "find_next_song" ]
2
[ [ "find_next_song", "similarity" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22e7531d8bc4aa16f36549e5d4c7bfa9638bcf12
3b6a56332596cfec3e17e03f8eb459ac58d4b8cb
v1.0
instruct
Filter
Filter_22330_I
### Programming Challenge: Mastermind #### Game Overview Mastermind is a popular code-breaking game where a player attempts to guess a hidden sequence of colored pegs. The game consists of a code maker (the computer) and a code breaker (the player). The code maker thinks of a secret sequence of four colored pegs and th...
import random def generate_secret_sequence(): colors = ["Red", "Green", "Blue", "Yellow", "White", "Black"] return random.sample(colors, 4) def get_feedback(secret_sequence, guess): black_pegs = 0 white_pegs = 0 temp_secret = list(secret_sequence) temp_guess = list(guess) # First pass: Ch...
from solution import generate_secret_sequence, get_feedback def test_generate_secret_sequence(): secret_sequence = generate_secret_sequence() assert len(secret_sequence) == 4 assert all(color in ["Red", "Green", "Blue", "Yellow", "White", "Black"] for color in secret_sequence) def test_get_feedback_all_co...
[ { "docstring": null, "function_declaration": "def generate_secret_sequence():", "function_name": "generate_secret_sequence", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def get_feedback(secret_sequence, guess):", "function_name": "get_feedback", "param...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\nclass Mastermind:\n def __init__(self):\n self.colors = [\"Red\", \"Green\", \"Blue\", \"Yellow\", \"White\", \"Black\"]\n self.secret_sequence = random.sampl...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022330", "row_id": 22330, "seed_ids": "['Llama-3.3-70B-Instruct_55923']" }
0.495225
Filter_22330
I
[ "generate_secret_sequence", "get_feedback", "mastermind_game" ]
3
[ [ "mastermind_game", "generate_secret_sequence" ], [ "mastermind_game", "get_feedback" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8751c835136261d5501af1ad3ba0d62dac67c2d9
9bcc197bfabf022ce6176d0944e2f9b2e4af25eb
v1.0
instruct
Filter
Filter_22333_I
I'm working on a neural network project and need to calculate the output of each neuron. Can you help me implement the calculation of the weighted sum of inputs for each neuron? Here's an example code snippet that calculates the output: ``` import numpy as np def sigmoid(x): return 1 / (1 + np.exp(-x)) def calcu...
import numpy as np def sigmoid(x): return 1 / (1 + np.exp(-x)) def calculate_neuron_output(weights, inputs, bias): """ Calculate the output of a neuron given the weights, inputs, and bias. Parameters: weights (numpy array): Array of weights inputs (numpy array): Array of input values ...
from solution import calculate_neuron_output, sigmoid import numpy as np def test_sigmoid(): assert np.isclose(sigmoid(0), 0.5) assert np.isclose(sigmoid(1), 1 / (1 + np.exp(-1))) assert np.isclose(sigmoid(-1), 1 / (1 + np.exp(1))) def test_calculate_neuron_output_no_bias(): weights = np.array([0.2, 0...
[ { "docstring": null, "function_declaration": "def sigmoid(x):", "function_name": "sigmoid", "parameter_list": "(x)" }, { "docstring": "Calculate the output of a neuron given the weights, inputs, and bias.\n\nParameters:\nweights (numpy array): Array of weights\ninputs (numpy array): Array of...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\ndef sigmoid(x):\n return 1 / (1 + np.exp(-x))\n\ndef calculate_neuron_output(weights, inputs, bias):\n weighted_sum = np.sum(weights * inputs) + bias\n output = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022333", "row_id": 22333, "seed_ids": "['Llama-3.3-70B-Instruct_55927']" }
0.40802
Filter_22333
I
[ "sigmoid", "calculate_neuron_output" ]
2
[ [ "calculate_neuron_output", "sigmoid" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
a902e30c34113c0831682ae10aa491c9c69b11ac
c95889039f356a6f3a41edd021c63195f0dcb4e6
v1.0
instruct
Filter
Filter_22337_I
In this problem, you'll implement the basic structure of a neural network using NumPy. You're given a dataset with three features and the corresponding labels. The task is to create a simple neural network that classifies the data into 2 classes. Here's the data: Features: | X1 | X2 | X3 | |------|------|----...
import numpy as np # Features X = np.array([ [40, 10, 12], [23, 50, 70], [11, 30, 90], [80, 5, 4], [90, 2, 3], [70, 15, 20], [75, 80, 85], [34, 60, 40], [110, 10, 5], [95, 15, 10], ]) # Labels y = np.array([0, 1, 1, 0, 0, 1, 1, 1, 0, 0]) # Number of features n_features = X.sha...
from solution import model, loss_fn, train import numpy as np def test_model_output_shape(): X = np.random.rand(5, 3) weights = np.random.rand(3, 2) bias = np.random.rand(1, 2) output = model(X) assert output.shape == (5, 2) def test_loss_fn(): y_true = np.array([0, 1, 1, 0, 0]) y_pred = n...
[ { "docstring": null, "function_declaration": "def model(X):", "function_name": "model", "parameter_list": "(X)" }, { "docstring": null, "function_declaration": "def loss_fn(y_true, y_pred, weights, lambda_l1):", "function_name": "loss_fn", "parameter_list": "(y_true, y_pred, weig...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\n\n# Features\nX = np.array([\n [40, 10, 12],\n [23, 50, 70],\n [11, 30, 90],\n [80, 5, 4],\n [90, 2, 3],\n [70, 15, 20],\n [75, 80, 85],\n [34, 60, ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022337", "row_id": 22337, "seed_ids": "['Llama-3.3-70B-Instruct_55936']" }
0.532184
Filter_22337
I
[ "model", "loss_fn", "train" ]
3
[ [ "train", "loss_fn" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
67dec1fa38ac75813b04aa884f0589bfa0d3fc7e
5715f411b648c04664c91891694d2a30d7ce355a
v1.0
instruct
Filter
Filter_22348_I
### Golden Random Library Implement a simple random library following the rules of the golden ratio (phi = 1.61803398875). The golden ratio is an irrational number believed to possess unique properties that make it a fundamental element in mathematics, art, and design. In a sequence where each term is the sum of the t...
import random phi = 1.61803398875 def golden_random(): """ Generates a random float number between 0 and 1 adjusted by the Golden Ratio. """ return random.random() * phi % 1 def golden_choice(sequence): """ Returns a random element from the given sequence based on the Golden Ratio random. ...
from solution import golden_random, golden_choice, golden_sample def test_golden_random_range(): random_value = golden_random() assert 0 <= random_value < 1 def test_golden_choice(): sequence = [1, 2, 3, 4, 5] choice = golden_choice(sequence) assert choice in sequence def test_golden_sample_lengt...
[ { "docstring": "Generates a random float number between 0 and 1 adjusted by the Golden Ratio.", "function_declaration": "def golden_random():", "function_name": "golden_random", "parameter_list": "()" }, { "docstring": "Returns a random element from the given sequence based on the Golden Rat...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\nPHI = 1.61803398875\n\ndef golden_random():\n \"\"\"\n Generates a random float number between 0 and 1 following the Golden Random Distribution.\n This is achieved by...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022348", "row_id": 22348, "seed_ids": "['Llama-3.3-70B-Instruct_55965']" }
0.578692
Filter_22348
I
[ "golden_random", "golden_choice", "golden_sample" ]
3
[ [ "golden_choice", "golden_random" ], [ "golden_sample", "golden_choice" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0788388f1c6dda13c412491e13d56832ae5a6069
6004eee882c1e8429785ee0f46e8af1cc5028108
v1.0
instruct
Filter
Filter_22362_I
I have a CSV file named "books.csv" containing a list of books, each row representing a book with the following columns: - "title", a string representing the title of the book - "author", a string representing the author of the book - "pages", an integer representing the number of pages in the book - "genre", a string ...
import csv import operator def calculate_cost_of_book(pages, genre): """ Calculates the cost of a book based on number of pages and genre. Parameters: pages (int): The number of pages in the book. genre (str): The genre of the book. Returns: float: The cost of the book. """ base_c...
from solution import calculate_cost_of_book, read_books_and_calculate_costs def test_calculate_cost_of_book(): assert calculate_cost_of_book(200, 'Science Fiction') == 18.0 # 10% discount assert calculate_cost_of_book(300, 'Fantasy') == 28.5 # 5% discount assert calculate_cost_of_book(150, 'Mystery') == ...
[ { "docstring": "Calculates the cost of a book based on number of pages and genre.\n\nParameters:\npages (int): The number of pages in the book.\ngenre (str): The genre of the book.\n\nReturns:\nfloat: The cost of the book.", "function_declaration": "def calculate_cost_of_book(pages, genre):", "function_...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "Magpie-Filter-89K_sanitized_prepared1_results_combined.jsonl", "solution_code": "import csv\nimport operator\n\ndef calculate_cost_of_book(pages, genre):\n \"\"\"\n Calculates the cost of a book based on number of pages and genre.\n\n Para...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022362", "row_id": 22362, "seed_ids": "['Llama-3.3-70B-Instruct_56006']" }
0.605673
Filter_22362
I
[ "calculate_cost_of_book", "read_books_and_calculate_costs", "print_book_costs" ]
3
[ [ "read_books_and_calculate_costs", "calculate_cost_of_book" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1e2046c8bfdae124cdf0bf3b015ce64398b9f4cd
690634e595a3702f5e68e54d5e6dc598eb7e5193
v1.0
instruct
Filter
Filter_22375_I
Your company has created a Python script that simulates a 3D random walk. Using this script, you would like to estimate the average distance that a random walker travels over a certain number of steps. You want to repeat this experiment many times to get a reliable estimate. Here is your Python script: ``` import rando...
import random import math def random_walk_3d(steps): """ Simulates a 3D random walk of a given number of steps. Returns the final coordinates (x, y, z) of the random walker. """ x, y, z = 0, 0, 0 for _ in range(steps): step = random.random() if step < 1/6: x += 1 ...
from solution import random_walk_3d, average_distance def test_random_walk_3d_returns_tuple(): result = random_walk_3d(10) assert isinstance(result, tuple) assert len(result) == 3 def test_random_walk_3d_single_step(): for _ in range(100): # run the test multiple times to check consistency x, ...
[ { "docstring": "Simulates a 3D random walk of a given number of steps.\nReturns the final coordinates (x, y, z) of the random walker.", "function_declaration": "def random_walk_3d(steps):", "function_name": "random_walk_3d", "parameter_list": "(steps)" }, { "docstring": "Estimates the averag...
[ 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 math\n\ndef random_walk_3d(steps):\n x, y, z = 0, 0, 0\n for _ in range(steps):\n step = random.random()\n if step < 0.25:\n x += 1\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022375", "row_id": 22375, "seed_ids": "['Llama-3.3-70B-Instruct_56046']" }
0.570971
Filter_22375
I
[ "random_walk_3d", "average_distance" ]
2
[ [ "average_distance", "random_walk_3d" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa2a70ac84a369c96126a1635f7a158895a1adef
b2444e80b6b762c2066ec62a0a6c9826bd37a03a
v1.0
instruct
Filter
Filter_22404_I
You've been tasked with writing a function `find_closest_job`: this function will take two parameters: `jobs` and `target_location`. The `jobs` is a list of dictionaries where each dictionary contains information about a job such as the `id`, `title`, `location` etc. The `target_location` is the location where you want...
import math def calculate_distance(loc1, loc2): """ Calculate the Euclidean distance between two geographical locations. Parameters: loc1, loc2: Tuples representing locations (latitude, longitude) Returns: float: Euclidean distance between loc1 and loc2 """ return math.sqrt((l...
from solution import find_closest_job def test_find_closest_job_basic(): jobs = [ {'id': 1, 'title': 'Engineer', 'location': (37.7749, -122.4194)}, {'id': 2, 'title': 'Teacher', 'location': (34.0522, -118.2437)}, {'id': 3, 'title': 'Artist', 'location': (40.7128, -74.0060)} ] target...
[ { "docstring": "Calculate the Euclidean distance between two geographical locations.\n\nParameters:\nloc1, loc2: Tuples representing locations (latitude, longitude)\n\nReturns:\nfloat: Euclidean distance between loc1 and loc2", "function_declaration": "def calculate_distance(loc1, loc2):", "function_nam...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef calculate_distance(loc1, loc2):\n \"\"\"\n Calculate the Euclidean distance between two geographical locations.\n \n Parameters:\n loc1, loc2: Tuples represen...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022404", "row_id": 22404, "seed_ids": "['Llama-3.3-70B-Instruct_56131']" }
0.680421
Filter_22404
I
[ "calculate_distance", "find_closest_job" ]
2
[ [ "find_closest_job", "calculate_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1395fe06c11b0f0da0180af264d641b55d7c6f5
f2a6166b95680ed8a1d3c78afab4d58015a765eb
v1.0
instruct
Filter
Filter_22409_I
Here is the Python code for the standard Euclidean algorithm to compute the gcd of 2 numbers: ```python def gcd(a, b): while b != 0: a, b = b, a % b return a ``` This function takes two arguments and returns their greatest common divisor. How would you extend this function so that it can compute the g...
def gcd(a, b): """ Returns the greatest common divisor of a and b using the Euclidean Algorithm. """ while b != 0: a, b = b, a % b return a def gcd_multiple(*args): """ Returns the greatest common divisor of multiple numbers by applying the gcd function recursively. """ if l...
from solution import gcd, gcd_multiple def test_gcd_two_numbers(): assert gcd(12, 15) == 3 assert gcd(100, 10) == 10 assert gcd(7, 13) == 1 assert gcd(16, 24) == 8 def test_gcd_multiple_numbers(): assert gcd_multiple(12, 15, 21) == 3 assert gcd_multiple(48, 64, 80) == 16 assert gcd_multipl...
[ { "docstring": "Returns the greatest common divisor of a and b using the Euclidean Algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the greatest common divisor of multiple numbers by applying the gcd function...
[ 0, 1, 1 ]
2
easy
0.667
{ "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 of a and b using the Euclidean algorithm.\n \"\"\"\n while b != 0:\n a, b = b, a % b\n return a\n\ndef gcd_m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022409", "row_id": 22409, "seed_ids": "['Llama-3.3-70B-Instruct_56148']" }
0.680906
Filter_22409
I
[ "gcd", "gcd_multiple" ]
2
[ [ "gcd_multiple", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0729214f177b48bee95581ebf7a9dcfc8d97604b
359816ae08a3fecc7f1b0b830e7f4e4649c7efdf
v1.0
instruct
Filter
Filter_22442_I
### UDP Pinger Here is a high level overview of how you can create a UDP Pinger: 1. Create a UDP socket. 2. Set up the client and server hosts and ports. 3. Send ping messages from the client to the server at regular intervals. 4. The server should receive the ping message, record the time it was received, and send a ...
import socket import time import threading # Server side def start_server(port): server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server_socket.bind(('localhost', port)) print(f"Server listening on port {port}") while True: message, client_address = server_socket.recvfrom(1024)...
import time import threading from solution import start_server, start_client def test_udp_pinger(): server_port = 12345 server_thread = threading.Thread(target=start_server, args=(server_port,)) server_thread.daemon = True server_thread.start() time.sleep(1) # Give the server a second to start ...
[ { "docstring": null, "function_declaration": "def start_server(port):", "function_name": "start_server", "parameter_list": "(port)" }, { "docstring": null, "function_declaration": "def start_client(port, ping_count=5):", "function_name": "start_client", "parameter_list": "(port, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import socket\nimport time\n\ndef start_server(port):\n \"\"\"\n Starts the UDP server on the provided port.\n \"\"\"\n with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as ser...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022442", "row_id": 22442, "seed_ids": "['Llama-3.3-70B-Instruct_56226']" }
0.618477
Filter_22442
I
[ "start_server", "start_client", "run_udp_pinger" ]
3
[ [ "run_udp_pinger", "start_client" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aeae6aa0b5e082bb9c10e0e43ae2da5399fdbfc1
4a25bf7af8a3af4b40fba59c6052dd1dd4a20c4c
v1.0
instruct
Filter
Filter_22455_I
In this problem, you will write a Python program that reads a list of students' names from the user and their corresponding test scores, then stores them in a dictionary. The program must be able to input this data, display it, update it, and delete any student. ### Program Requirements 1. Create an empty dictionary...
from typing import Dict # Define an empty dictionary to store the student information students: Dict[str, int] = {} def display_students() -> None: """Display the current list of students.""" if not students: print("No students in the list.") else: print("Students:") for student, s...
from solution import add_student, update_student, delete_student, display_students, students def test_add_student(): # Clear the students dictionary before the test students.clear() add_student("John Doe", 85) assert students["John Doe"] == 85 def test_update_student(): students.clear() s...
[ { "docstring": "Display the current list of students.", "function_declaration": "def display_students():", "function_name": "display_students", "parameter_list": "()" }, { "docstring": "Add a student to the dictionary.", "function_declaration": "def add_student(name, score):", "funct...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import Dict\n\nstudents: Dict[str, int] = {}\n\ndef display_students() -> None:\n \"\"\"Display the current list of students.\"\"\"\n if not students:\n print(\"No stu...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022455", "row_id": 22455, "seed_ids": "['Llama-3.3-70B-Instruct_56255']" }
0.530304
Filter_22455
I
[ "display_students", "add_student", "update_student", "delete_student", "main_menu" ]
5
[ [ "main_menu", "add_student" ], [ "main_menu", "delete_student" ], [ "main_menu", "display_students" ], [ "main_menu", "update_student" ] ]
4
[]
false
[]
false
pytest
true
[]
true
bbb5b32b722bb12523c51c5f49582f87b0309991
5670afa735af8be9b7596a66cb8a4385a0d47281
v1.0
instruct
Filter
Filter_22471_I
Given a string of digits, write a function that returns all possible unique palindromes that can be formed using all the digits.
from itertools import permutations def is_palindrome(s): """ Check if a given string is a palindrome. """ return s == s[::-1] def all_unique_palindromes(s): """ Given a string of digits, returns all unique palindromes that can be formed using all the digits. """ # Generate all possible...
from solution import all_unique_palindromes def test_all_unique_palindromes_single_digit(): assert all_unique_palindromes('1') == ['1'] def test_all_unique_palindromes_two_digits_palindrome(): assert sorted(all_unique_palindromes('11')) == ['11'] def test_all_unique_palindromes_two_digits_non_palindrome(): ...
[ { "docstring": "Check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Given a string of digits, returns all unique palindromes that can be formed using all the digits.", "fu...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import permutations\n\ndef is_palindrome(s):\n \"\"\"\n Helper function to check if a string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef unique_palindrome...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022471", "row_id": 22471, "seed_ids": "['Llama-3.3-70B-Instruct_56287']" }
0.626545
Filter_22471
I
[ "is_palindrome", "all_unique_palindromes" ]
2
[ [ "all_unique_palindromes", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6c75c7a3a9347a78f0fda2037a9ce9d9346bfcac
5e47f7d30776595fe294223b52ae4337ec05acf7
v1.0
instruct
Filter
Filter_22484_I
Given a function that simulates a coin toss, which is a server-side function and is inaccessible, we want to write a client-side function that can make use of this server-side function, as well as other useful functions. Here are the conditions and methods we will be using: Server-side Function (Inaccessible): - The c...
import random # Assuming the server-side function; here we'll simulate it for the client-side design. def coin_toss(): return random.choice(["Heads", "Tails"]) # Assuming the accessible function to retrieve server-side coin toss result. def get_server_coin_toss_result(): # This function would interact with th...
from solution import CoinTossSimulator def test_initial_toss_count(): simulator = CoinTossSimulator() assert simulator.get_toss_count() == 0 def test_toss_coin_increases_count(): simulator = CoinTossSimulator() result = simulator.toss_coin() assert result in ["Heads", "Tails"] assert simulator...
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_server_coin_toss_result():\n \"\"\"\n Simulate the behavior of the server-side function which retrieves the last coin toss result.\n This is a placeholder for the actual serve...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022484", "row_id": 22484, "seed_ids": "['Llama-3.3-70B-Instruct_56312']" }
0.395433
Filter_22484
I
[ "coin_toss", "get_server_coin_toss_result" ]
2
[ [ "get_server_coin_toss_result", "coin_toss" ] ]
1
[]
false
[ "CoinTossSimulator" ]
true
pytest
true
[]
true
4058b4b85a7810dd61e140e0c3471c63c42e0114
e64c2f7d29da27b08d9b4902a11c36576c4d6e66
v1.0
instruct
Filter
Filter_22509_I
Given an array of strings, determine if there is a pair of strings where one string is a rotation of the other. For example: 'abc' and 'cab' are rotations of each other. Write a function that returns True if there is a pair of strings that are rotations of each other and False otherwise. Here is an example: Input: ['a...
def are_rotations(s1, s2): """ Determines if s1 and s2 are rotations of each other. """ if len(s1) != len(s2): return False return s2 in (s1 + s1) def check_rotation(lst): """ Determines if there is a pair of strings in the list where one is a rotation of the other. Args: ...
from solution import check_rotation def test_check_rotation_pair_found(): assert check_rotation(['abc', 'def', 'cab']) == True def test_check_rotation_no_pair_found(): assert check_rotation(['abc', 'def', 'xyz']) == False def test_check_rotation_same_string(): assert check_rotation(['a', 'a']) == True d...
[ { "docstring": "Determines if s1 and s2 are rotations of each other.", "function_declaration": "def are_rotations(s1, s2):", "function_name": "are_rotations", "parameter_list": "(s1, s2)" }, { "docstring": "Determines if there is a pair of strings in the list where one is a rotation of the o...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_rotation(s1, s2):\n \"\"\"\n Helper function to check if s2 is a rotation of s1.\n \"\"\"\n if len(s1) != len(s2):\n return False\n return s2 in (s1 + s1)\n\ndef c...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022509", "row_id": 22509, "seed_ids": "['Llama-3.3-70B-Instruct_56372']" }
0.678352
Filter_22509
I
[ "are_rotations", "check_rotation" ]
2
[ [ "check_rotation", "are_rotations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a4daeb04274813f05602da99239bcb8781e0fe67
c869414217a7f29b416d8a3767cbb5a17b768ad5
v1.0
instruct
Filter
Filter_22537_I
I am trying to programatically store data into the language package for a given profile in a system which supports multiple languages. I want to keep everything as simple as as possible so I want to use a system were I can store an organize the data in a simple key-value format. Using the system profiles with differnet...
import locale import os def detect_user_language(): """ Detects the language code of the user's device. """ return locale.getdefaultlocale()[0] def find_user_directory(username): """ Finds and returns the user's profile directory path. """ base_directory = "/home" user_directory = ...
from solution import detect_user_language, find_user_directory, change_to_directory, setup_user_profile import os import pytest def test_detect_user_language(monkeypatch): # Mocking locale.getdefaultlocale to return a specific language code monkeypatch.setattr(locale, 'getdefaultlocale', lambda: ('en_US', 'UTF...
[ { "docstring": "Detects the language code of the user's device.", "function_declaration": "def detect_user_language():", "function_name": "detect_user_language", "parameter_list": "()" }, { "docstring": "Finds and returns the user's profile directory path.", "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 locale\nimport os\n\ndef get_user_language():\n \"\"\"\n Retrieves the default locale's language code.\n \"\"\"\n language_code = locale.getdefaultlocale()[0]\n return la...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022537", "row_id": 22537, "seed_ids": "['Llama-3.3-70B-Instruct_56436']" }
0.390852
Filter_22537
I
[ "detect_user_language", "find_user_directory", "change_to_directory", "setup_user_profile" ]
4
[ [ "setup_user_profile", "change_to_directory" ], [ "setup_user_profile", "detect_user_language" ], [ "setup_user_profile", "find_user_directory" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ea5c3b8c05764dbe339fcee0dc94a934f3628be6
87bb27e09d254437ff822f223995273e7bfe8811
v1.0
instruct
Filter
Filter_22543_I
I have to write a program that simulates a game. The game has the following rules: - There are 3 players. - Every player starts with a number of biscuits, a number of cookies, and a number of chocolates. - The players are placed in a line. - The first player always goes first. - In every turn, a player's turn star...
import random class Player: def __init__(self, biscuits, cookies, chocolates): self.biscuits = biscuits self.cookies = cookies self.chocolates = chocolates def draw(self, item): if item == "biscuits": self.biscuits += 1 elif item == "cookies": se...
from solution import Player, game_round, simulate_game, determine_winner, create_initial_pool def test_player_initialization(): player = Player(5, 3, 2) assert player.biscuits == 5 assert player.cookies == 3 assert player.chocolates == 2 def test_player_draw(): player = Player(0, 0, 0) player....
[]
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\nclass Player:\n def __init__(self, biscuits, cookies, chocolates):\n self.biscuits = biscuits\n self.cookies = cookies\n self.chocolates = chocolates\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022543", "row_id": 22543, "seed_ids": "['Llama-3.3-70B-Instruct_56447']" }
0.524366
Filter_22543
I
[ "game_round", "simulate_game", "determine_winner", "create_initial_pool" ]
4
[ [ "simulate_game", "game_round" ] ]
1
[]
false
[ "Player" ]
true
pytest
true
[]
true
2ea147ebcb9fbd57149a3e481401cc0b72f15a9a
45e8cf572a524a5cf515f35fe0f7fa3f4508df06
v1.0
instruct
Filter
Filter_22545_I
Based on the snippet of code below, I have a sequence of elements that should be inserted into an ordered list. The elements to be inserted are designated by the non-canonical base "N". Can you assist in providing a common solution for this task using Python?
def insert_ordered(seq, element): """ Inserts an element into a sequence while maintaining order. Args: seq (list): The ordered list of elements. element: The element to be inserted. Returns: list: The new ordered list with the element inserted. """ for i in range(len(seq))...
from solution import insert_ordered, insert_N def test_insert_ordered_empty(): assert insert_ordered([], 'N') == ['N'] def test_insert_ordered_beginning(): assert insert_ordered(['A', 'C', 'G', 'T'], 'A') == ['A', 'A', 'C', 'G', 'T'] def test_insert_ordered_middle(): assert insert_ordered(['A', 'C', 'G',...
[ { "docstring": "Inserts an element into a sequence while maintaining order.\n\nArgs:\nseq (list): The ordered list of elements.\nelement: The element to be inserted.\n\nReturns:\nlist: The new ordered list with the element inserted.", "function_declaration": "def insert_ordered(seq, element):", "functio...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def insert_elements(sequence, elements):\n \"\"\"\n Inserts elements into the sequence at the position of 'N' and returns the ordered list.\n \n :param sequence: List of sorted ele...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022545", "row_id": 22545, "seed_ids": "['Llama-3.3-70B-Instruct_56456']" }
0.572427
Filter_22545
I
[ "insert_ordered", "insert_N" ]
2
[ [ "insert_N", "insert_ordered" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a8f694525e06681916ad28cb4045f073e677b608
20927e6d00c468c614a04f658a1d92bd4ecf8c68
v1.0
instruct
Filter
Filter_22548_I
A decorator is a function that takes another function as an argument and returns a function that "wraps" the given function. Here is an example of a logging decorator: ```python def logging_decorator(func): def wrapper(*args, **kwargs): print(f"{func.__name__} was called") return func(*args, **kwar...
import logging import functools # Set up basic configuration for logging logging.basicConfig(level=logging.DEBUG) def advanced_logging_decorator(log_level=logging.INFO): def decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): logger = logging.getLogger(func.__name__) ...
from solution import add, advanced_logging_decorator import logging # Test cases for the add function with the advanced logging decorator def test_add_positive_numbers(caplog): with caplog.at_level(logging.DEBUG): result = add(2, 3) assert result == 5 assert 'Called with args: (2, 3)' in c...
[ { "docstring": null, "function_declaration": "def advanced_logging_decorator(log_level=logging.INFO):", "function_name": "advanced_logging_decorator", "parameter_list": "(log_level=logging.INFO)" }, { "docstring": null, "function_declaration": "def add(a, b):", "function_name": "add"...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import logging\nimport functools\n\n# Set up basic configuration for logging\nlogging.basicConfig(level=logging.DEBUG)\n\ndef advanced_logging_decorator(log_level=logging.INFO):\n def decor...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022548", "row_id": 22548, "seed_ids": "['Llama-3.3-70B-Instruct_56461']" }
0.410371
Filter_22548
I
[ "advanced_logging_decorator", "add" ]
2
[ [ "add", "advanced_logging_decorator" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a3b155777cc93f9d8c806ec096673cee04728f29
8cc5552593f03a089611af44877acb616be99266
v1.0
instruct
Filter
Filter_22552_I
Create a simple rock, paper, scissors game in python. Player 1 and player 2 can be either a human or a computer. The game features a normal game mode and a tournament mode.
import random def get_computer_choice(): choices = ['rock', 'paper', 'scissors'] return random.choice(choices) def get_winner(choice1, choice2): if choice1 == choice2: return 'tie' elif (choice1 == 'rock' and choice2 == 'scissors') or \ (choice1 == 'scissors' and choice2 == 'paper') o...
from solution import play_round, play_game, play_tournament def test_play_round(): assert play_round('rock', 'scissors') == 'player1' assert play_round('scissors', 'rock') == 'player2' assert play_round('rock', 'rock') == 'tie' assert play_round('paper', 'rock') == 'player1' assert play_round('scis...
[ { "docstring": null, "function_declaration": "def get_computer_choice():", "function_name": "get_computer_choice", "parameter_list": "()" }, { "docstring": null, "function_declaration": "def get_winner(choice1, choice2):", "function_name": "get_winner", "parameter_list": "(choice...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef get_computer_choice():\n return random.choice(['rock', 'paper', 'scissors'])\n\ndef determine_winner(player1_choice, player2_choice):\n if player1_choice == player2_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022552", "row_id": 22552, "seed_ids": "['Llama-3.3-70B-Instruct_56471']" }
0.422122
Filter_22552
I
[ "get_computer_choice", "get_winner", "play_round", "play_game", "play_tournament" ]
5
[ [ "play_game", "play_round" ], [ "play_round", "get_winner" ], [ "play_tournament", "play_game" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a09eee638703dbdd532ea11889e157c9c12f8545
7c309ce29d3f00a74ed6017f105814f6c85d51bb
v1.0
instruct
Filter
Filter_22570_I
I have fetched some images and would like to create a new image by combining 4 of the images. The goal is to create a new image that has the top left of the first image, the top right of the second, the bottom left of the third image and the bottom right of the fourth image. Here is the code I have so far: ```python...
from PIL import Image def resize_image(img, size): """ Resizes the image to the given size. """ return img.resize(size) def split_image(img, size): """ Splits the image into four parts and resizes each part. """ half_width = img.size[0] // 2 half_height = img.size[1] // 2 top_...
from solution import resize_image, split_image, combine_images from PIL import Image def test_resize_image(): img = Image.new("RGB", (200, 200)) resized_img = resize_image(img, (100, 100)) assert resized_img.size == (100, 100) def test_split_image(): img = Image.new("RGB", (200, 200)) size = (100,...
[ { "docstring": "Resizes the image to the given size.", "function_declaration": "def resize_image(img, size):", "function_name": "resize_image", "parameter_list": "(img, size)" }, { "docstring": "Splits the image into four parts and resizes each part.", "function_declaration": "def split_...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "from PIL import Image\n\ndef resize_image(img, size):\n \"\"\"\n Resizes the image to the given size.\n \"\"\"\n return img.resize(size)\n\ndef split_image(img, size):\n \"\"\"\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022570", "row_id": 22570, "seed_ids": "['Llama-3.3-70B-Instruct_56508']" }
0.515147
Filter_22570
I
[ "resize_image", "split_image", "combine_images", "main" ]
4
[ [ "split_image", "resize_image" ] ]
1
[]
false
[]
false
pytest
true
[ "PIL" ]
false
3cce61359e40a57c4be6d5c389ccac82c9073c33
f799cf51bc7d8efa2521581dcffb326d34a95dd6
v1.0
instruct
Filter
Filter_22586_I
I am a professor, and I have decided to assign a task to my students to write a Python script that implements a simple banking system. The system should allow users to log in, create new accounts, deposit and withdraw money, and view their account balances. The information should be stored in a SQLite database, and t...
import sqlite3 from sqlite3 import Error def create_connection(): """Create a database connection to the SQLite database specified by the db_file Returns: conn (object): Connection object or None """ conn = None try: conn = sqlite3.connect('banking.db') return conn ...
import pytest from solution import create_connection, create_table, create_account, login, deposit, withdraw, view_balance @pytest.fixture(scope='module') def setup_db(): """Fixture to set up the database for testing.""" conn = create_connection() with conn: conn.execute("DROP TABLE IF EXISTS accou...
[ { "docstring": "Create a database connection to the SQLite database\n specified by the db_file\n\nReturns:\n conn (object): Connection object or None", "function_declaration": "def create_connection():", "function_name": "create_connection", "parameter_list": "()" }, { "docstring": "Cr...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sqlite3\nfrom sqlite3 import Error\n\ndef create_connection():\n \"\"\"Create a database connection to the SQLite database\n specified by the db_file\n\n Returns:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022586", "row_id": 22586, "seed_ids": "['Llama-3.3-70B-Instruct_56549']" }
0.498194
Filter_22586
I
[ "create_connection", "create_table", "create_account", "login", "deposit", "withdraw", "view_balance", "main" ]
8
[ [ "create_account", "create_connection" ], [ "create_table", "create_connection" ], [ "deposit", "create_connection" ], [ "login", "create_connection" ], [ "view_balance", "create_connection" ], [ "withdraw", "create_connection" ] ]
6
[]
false
[]
false
pytest
true
[]
true
baaada1b0953b0280c5f451f432bfff2b9988e18
7bb622896203fb29fa0ab081c35d054080160cf4
v1.0
instruct
Filter
Filter_22606_I
I wrote a function to check if a number is prime or not. I want to create a function that generates the first 10 (or n) prime numbers starting from 1, and then test the function by generating the first 10 primes. Please provide a solution with example code in Python. Here is my current prime-checking function: ```p...
def is_prime(n): """ Checks if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return Fals...
from solution import generate_primes, is_prime def test_generate_primes(): primes = generate_primes(10) expected_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] assert primes == expected_primes def test_primes_are_prime(): primes = generate_primes(10) for prime in primes: assert is_prime(pri...
[ { "docstring": "Checks if a number is prime.\n\nArgs:\n n (int): The number to check.\n\nReturns:\n bool: True if the number is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generates the fi...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n\n Args:\n n (int): The number to check.\n\n Returns:\n bool: True if the number is prime, False otherwise.\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022606", "row_id": 22606, "seed_ids": "['Llama-3.3-70B-Instruct_56590']" }
0.665688
Filter_22606
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
10ae403fa86db18070195031469edd309afa4443
b52e8c9aae1872d643d6c5e776b021ca5c8d4ce5
v1.0
instruct
Filter
Filter_22620_I
Here is a code that converts a temperature from Fahrenheit to Celsius: ```python def fahrenheit_to_celsius(fahrenheit): """Converts a temperature in Fahrenheit to Celsius.""" celsius = (fahrenheit - 32) * 5.0/9.0 return celsius ``` Using this function, write a program to prompt the user for a Fahrenheit tem...
def fahrenheit_to_celsius(fahrenheit): """ Converts a temperature in Fahrenheit to Celsius. """ celsius = (fahrenheit - 32) * 5.0 / 9.0 return celsius def convert_and_print_temperature(): """ Prompts the user for a Fahrenheit temperature, converts it to Celsius, and prints out the resul...
from solution import fahrenheit_to_celsius, convert_and_print_temperature import pytest from unittest.mock import patch def test_fahrenheit_to_celsius(): assert fahrenheit_to_celsius(32) == 0 assert fahrenheit_to_celsius(212) == 100 assert fahrenheit_to_celsius(98.6) == pytest.approx(37, 0.001) assert ...
[ { "docstring": "Converts a temperature in Fahrenheit to Celsius.", "function_declaration": "def fahrenheit_to_celsius(fahrenheit):", "function_name": "fahrenheit_to_celsius", "parameter_list": "(fahrenheit)" }, { "docstring": "Prompts the user for a Fahrenheit temperature, converts it to Cel...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def fahrenheit_to_celsius(fahrenheit):\n \"\"\"\n Converts a temperature in Fahrenheit to Celsius.\n \"\"\"\n celsius = (fahrenheit - 32) * 5.0 / 9.0\n return celsius\n\ndef con...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022620", "row_id": 22620, "seed_ids": "['Llama-3.3-70B-Instruct_56641']" }
0.464249
Filter_22620
I
[ "fahrenheit_to_celsius", "convert_and_print_temperature" ]
2
[ [ "convert_and_print_temperature", "fahrenheit_to_celsius" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b6e203b67976939b71dd8d0eabd702fc6d7c41f5
5d38310f901ee5993bc34946bd36652bda37fa50
v1.0
instruct
Filter
Filter_22623_I
How to sort the elements of an array in ascending order without using the built-in sorting functionality? ### Example ```markdown | Input | Output | | --- | --- | | [4, 2, 9, 6, 3, 1] | [1, 2, 3, 4, 6, 9] | ``` ### Hint To solve this problem, you can use the **Merge Sort** algorithm.
def merge_sort(arr): """ Sorts an array in ascending order using the merge sort algorithm. Parameters: arr (list): The array to be sorted. Returns: list: A new list that is sorted in ascending order. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left...
from solution import merge_sort def test_merge_sort_unsorted_list(): assert merge_sort([4, 2, 9, 6, 3, 1]) == [1, 2, 3, 4, 6, 9] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert merge_sort([5, 4, 3, 2, 1]) == [1, 2,...
[ { "docstring": "Sorts an array in ascending order using the merge sort algorithm.\n\nParameters:\narr (list): The array to be sorted.\n\nReturns:\nlist: A new list that is sorted in ascending order.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(...
[ 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 an array in ascending order using the merge sort algorithm.\n \"\"\"\n if len(arr) > 1:\n mid = len(arr) // 2 # Finding the mid of the...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022623", "row_id": 22623, "seed_ids": "['Llama-3.3-70B-Instruct_56649']" }
0.662652
Filter_22623
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73b62a4d210b18575968aa89762ca1839860ece3
8fc24b6922c0611ee6a27b18ca1e7103c9ff8083
v1.0
instruct
Filter
Filter_22630_I
**131. Palindrome Partitioning** Given a string s, partition s into all possible palindrome partitions. Return all possible palindrome partitions of s. Example 1: Input: s = "aab" Output: [["a","a","b"],["aa","b"]] Example 2: Input: s = "abba" Output: [["a","a","b","b"],["b","a","a","b"],["b","bb","a"],["bab","a"],["a"...
def is_palindrome(s): """ Helper function to check if the given string is a palindrome. """ return s == s[::-1] def partition(s): """ Returns all possible palindrome partitioning of s. """ def backtrack(start, path): if start == len(s): result.append(path.copy()) ...
from solution import is_palindrome, partition def test_is_palindrome(): assert is_palindrome("a") assert is_palindrome("aa") assert is_palindrome("aba") assert not is_palindrome("abc") def test_partition_example1(): result = partition("aab") expected = [["a", "a", "b"], ["aa", "b"]] assert...
[ { "docstring": "Helper function to check if the given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Returns all possible palindrome partitioning of s.", "function_declaration": "def ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s):\n \"\"\"\n Helper function to determine if a string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef partition(s):\n \"\"\"\n Returns all possible...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022630", "row_id": 22630, "seed_ids": "['Llama-3.3-70B-Instruct_56663']" }
0.745691
Filter_22630
I
[ "is_palindrome", "partition" ]
2
[ [ "partition", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
18eeb8ee43111cd51a270c0b8d1edbd1866fb62f
c09fd7b2004b25ccc24d08e6e9a83aa56948c627
v1.0
instruct
Filter
Filter_22632_I
In Python, how can I allow a user to start a new game or load a previous game from a list of save files?
def start_new_game(): """ Starts a new game. """ print("Starting a new game...") return "new_game_started" def load_game(save_files, save_file_name): """ Loads a game from the list of save files if the save_file_name exists. Parameters: save_files (list): List of available save...
import pytest from solution import start_new_game, load_game, user_choice def test_start_new_game(): assert start_new_game() == "new_game_started" def test_load_game_file_exists(): save_files = ["save1", "save2", "save3"] assert load_game(save_files, "save2") == "game_loaded" def test_load_game_file_not_...
[ { "docstring": "Starts a new game.", "function_declaration": "def start_new_game():", "function_name": "start_new_game", "parameter_list": "()" }, { "docstring": "Loads a game from the list of save files if the save_file_name exists.\n\nParameters:\nsave_files (list): List of available save ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def start_new_game():\n \"\"\"\n Starts a new game.\n \"\"\"\n print(\"Starting a new game...\")\n return \"new_game_started\"\n\ndef load_game(save_files, save_file_name):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022632", "row_id": 22632, "seed_ids": "['Llama-3.3-70B-Instruct_56665']" }
0.359212
Filter_22632
I
[ "start_new_game", "load_game", "user_choice" ]
3
[ [ "user_choice", "load_game" ], [ "user_choice", "start_new_game" ] ]
2
[]
false
[]
false
pytest
true
[]
true
34a533e8427ba0d63ffa1236291b54c32c6e074b
292b0b9e84201adcb997200012b35265ebdbdd57
v1.0
instruct
Filter
Filter_22634_I
Yesterday, a cable system failed and you need to restore from a backup file named `backups(decimal2hex).txt`. You're unsure of the backup filename but you know that it's a decimal number converted to hexadecimal, followed by the `.txt` file extension. This is a problem where you can start from 0 and keep trying numbe...
import os def decimal_to_hex(decimal_number): """ Converts a decimal number to its hexadecimal string representation. """ return f"{decimal_number:x}" def generate_backup_filename(decimal_number): """ Generates a backup filename from the given decimal number. """ hex_str = decimal_to_h...
import os from solution import decimal_to_hex, generate_backup_filename, restore_from_backup def test_decimal_to_hex(): assert decimal_to_hex(0) == "0" assert decimal_to_hex(10) == "a" assert decimal_to_hex(255) == "ff" assert decimal_to_hex(4096) == "1000" def test_generate_backup_filename(): ass...
[ { "docstring": "Converts a decimal number to its hexadecimal string representation.", "function_declaration": "def decimal_to_hex(decimal_number):", "function_name": "decimal_to_hex", "parameter_list": "(decimal_number)" }, { "docstring": "Generates a backup filename from the given decimal n...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_backup_filename(target_filename):\n \"\"\"\n Finds the decimal number corresponding to the target hexadecimal filename with .txt extension.\n \n Parameters:\n targe...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022634", "row_id": 22634, "seed_ids": "['Llama-3.3-70B-Instruct_56674']" }
0.435732
Filter_22634
I
[ "decimal_to_hex", "generate_backup_filename", "restore_from_backup" ]
3
[ [ "generate_backup_filename", "decimal_to_hex" ], [ "restore_from_backup", "generate_backup_filename" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5ed5a1b23d5ed1b2149859ab667b029ed152e37f
734d737be70508c0c2a50871499fe2bd3e14d6d9
v1.0
instruct
Filter
Filter_22635_I
Here is the Python code for getting multiple sequential inputs from the user: ```python def get_input(prompt): """Get a single input from the user.""" while True: try: return input(prompt) except KeyboardInterrupt: print('\nKeyboard interrupt detected. Exiting.') ...
def get_input(prompt): """Get a single input from the user.""" try: return input(prompt) except KeyboardInterrupt: print('\nKeyboard interrupt detected. Exiting.') exit() def get_inputs(num_requested_inputs, max_allowed_inputs): """Get multiple sequential inputs from the user wi...
import pytest from solution import get_input, get_inputs def test_get_inputs_within_limits(monkeypatch): inputs = iter(['input1', 'input2', 'input3']) monkeypatch.setattr('builtins.input', lambda _: next(inputs)) assert get_inputs(3, 5) == ['input1', 'input2', 'input3'] def test_get_inputs_exceeds_limits(...
[ { "docstring": "Get a single input from the user.", "function_declaration": "def get_input(prompt):", "function_name": "get_input", "parameter_list": "(prompt)" }, { "docstring": "Get multiple sequential inputs from the user with validation for max allowed inputs.", "function_declaration...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "Magpie-Filter-89K_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_input(prompt):\n \"\"\"Get a single input from the user.\"\"\"\n while True:\n try:\n return input(prompt)\n except KeyboardInterrupt:\n print...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022635", "row_id": 22635, "seed_ids": "['Llama-3.3-70B-Instruct_56676']" }
0.412384
Filter_22635
I
[ "get_input", "get_inputs" ]
2
[ [ "get_inputs", "get_input" ] ]
1
[]
false
[]
false
pytest
true
[]
true
29b7f28c7564205982bb0137d01d442b9b4b62a2
0f9cfc0fc943fdca0e81da384997f43ea169b0c3