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
Apps
Apps_17012_I
You are given a list of strings. A string is considered "unique" if it does not have any repeated characters. Your task is to find the longest unique string from the given list. If there are multiple strings with the same length, return the one that appears first in the list. -----Input:----- - The first line contains...
def is_unique(s): """ Check if all characters in the string are unique. """ return len(s) == len(set(s)) def longest_unique_string(test_cases): """ For each test case, return the longest string with all unique characters. If no such string exists, return 'NONE'. """ results = [] ...
from solution import is_unique, longest_unique_string def test_is_unique(): assert is_unique("abcdef") == True assert is_unique("aabbcc") == False assert is_unique("abcdeff") == False assert is_unique("qwerty") == True def test_longest_unique_string(): assert longest_unique_string([["abcdef", "abb...
[ { "docstring": "Check if all characters in the string are unique.", "function_declaration": "def is_unique(s):", "function_name": "is_unique", "parameter_list": "(s)" }, { "docstring": "For each test case, return the longest string with all unique characters.\nIf no such string exists, retur...
[ 1, 1, 1, 0, 1, 0, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_unique_string(T, test_cases):\n \"\"\"\n Finds the longest unique string from the given test cases.\n \n Parameters:\n - T (int): number ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00017012", "row_id": 17012, "seed_ids": "[1490]" }
0.721663
Apps_17012
I
[ "is_unique", "longest_unique_string" ]
2
[ [ "longest_unique_string", "is_unique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7647096847e9f95c12ed9ccc4f4838843884c1e
0409402f1fc04cd30dfdbf1cea0e3718b27c113b
v1.0
instruct
Apps
Apps_17090_I
You are given a network of pipes represented as an undirected graph with `n` nodes and `m` edges. Each edge has a weight representing the capacity of the pipe. Water flows from node `a` to node `b` through the network. Your task is to determine the maximum flow from node `a` to node `b` using the Edmonds-Karp algorith...
from collections import deque, defaultdict def bfs(capacity, source, sink, parent): visited = set() queue = deque([source]) visited.add(source) while queue: current = queue.popleft() for neighbor in capacity[current]: if neighbor not in visited and capacity[cur...
def test_max_flow_simple_case(): edges = [ (1, 2, 100), (1, 3, 100), (2, 3, 1), (2, 4, 100), (3, 4, 100) ] assert max_flow(4, 5, edges, 1, 4) == 200 def test_max_flow_single_edge(): edges = [(1, 2, 50)] assert max_flow(2, 1, edges, 1, 2) == 50 def test_max_f...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "edmonds...
[ 0, 0, 1, 0, 0, 0, 0, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(capacity, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(source)\n \n whil...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017090", "row_id": 17090, "seed_ids": "[1501]" }
0.551746
Apps_17090
I
[ "bfs", "edmonds_karp", "max_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "max_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
false
[]
true
136b02013413c705c20b7351d0c15f1e4665bc68
6999e4b87a13c891c411f16966c02de22c885c5e
v1.0
instruct
Apps
Apps_17097_I
# Task **_Given_** a number, **_Find if it is Palindromic Prime or not_**. ____ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers) ___ # Notes * **_Number_** *passed is always* **_Positive_**. * **_Return_** *the result as* **_String_** ___ ...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import palindromicPrime def test_palindromic_prime(): assert palindromicPrime(131) == "Palindromic Prime !!" assert palindromicPrime(373) == "Palindromic Prime !!" def test_not_palindromic(): assert palindromicPrime(133) == "Not !!" assert palindromicPrime(12321) == "Not !!" # Palindro...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns \"Palindromic Prime !!\" if n is both palindromic and prime,\notherwise returns \"Not !!\".", "func...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Check if a given number is prime.\n\n :param num: int\n :return: bool\n \"\"\"\n if num <= 1:\n return False\...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017097", "row_id": 17097, "seed_ids": "[3455]" }
0.674428
Apps_17097
I
[ "is_prime", "palindromicPrime" ]
2
[ [ "palindromicPrime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b27259f456091107e2cda16fdf04e71a18952db2
5f66d353a4f23d0a409a8352ff3e0b88ae1781ab
v1.0
instruct
Apps
Apps_17101_I
`Prime Selection` You're given multiple requests for selecting prime numbers from a given list, and your task is to respond to each request efficiently. ---Input--- The input consists of multiple lines: - The first line contains two integers `n` and `q` (1 ≤ n, q ≤ 10^5) — the number of elements in the list and the ...
import bisect def sieve_of_eratosthenes(max_num): is_prime = [True] * (max_num + 1) is_prime[0] = is_prime[1] = False p = 2 while p * p <= max_num: if is_prime[p]: for i in range(p * p, max_num + 1, p): is_prime[i] = False p += 1 return is_prime def prim...
from solution import prime_selection def test_prime_selection_example_1(): n = 6 q = 3 elements = [2, 17, 11, 4, 7, 20] queries = [1, 3, 5] assert prime_selection(n, q, elements, queries) == [2, 11, -1] def test_prime_selection_example_2(): n = 5 q = 2 elements = [1, 5, 3, 9, 6] qu...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def prime_selection(n, q, elements, queries):", "function_name": "prime_selecti...
[ 1, 1, 1, 1, 0, 1, 0, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017101", "row_id": 17101, "seed_ids": "[2027]" }
0.64426
Apps_17101
I
[ "sieve_of_eratosthenes", "prime_selection" ]
2
[ [ "prime_selection", "sieve_of_eratosthenes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8c3e883bfad2affb6dd40d8e402181d25e03d29
ce745e9caf1213a390d60e92d121b99e1f5af193
v1.0
instruct
Apps
Apps_17102_I
A mysterious traveler has stumbled upon a magical garden. Amidst the verdant foliage and vibrant flowers, surreal voices echo with enigmatic math problems. One such voice whispers: "In this realm lies a special type of number known as the 'Frond Number'. A Frond Number is defined by a unique property: the sum of the f...
import math def is_frond_number(n): """ Check if a number is a Frond Number. A Frond Number is defined as a number for which the sum of the factorials of its digits equals the number itself. """ return n == sum(math.factorial(int(digit)) for digit in str(n)) def find_frond_numbers(start, end): ...
from solution import find_frond_numbers, is_frond_number def test_is_frond_number(): assert is_frond_number(1) == True assert is_frond_number(2) == True assert is_frond_number(145) == True assert is_frond_number(40585) == True assert is_frond_number(123) == False def test_find_frond_numbers_in_sma...
[ { "docstring": "Check if a number is a Frond Number.\nA Frond Number is defined as a number for which the sum of the factorials of its digits equals the number itself.", "function_declaration": "def is_frond_number(n):", "function_name": "is_frond_number", "parameter_list": "(n)" }, { "docst...
[ 1, 0, 1, 0, 0, 0, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_frond_number(number):\n \"\"\"\n Check if a given number is a Frond Number.\n \"\"\"\n return number == sum(math.factorial(int(dig...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017102", "row_id": 17102, "seed_ids": "[4779]" }
0.529436
Apps_17102
I
[ "is_frond_number", "find_frond_numbers" ]
2
[ [ "find_frond_numbers", "is_frond_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a0cd653fb919bc09ec2762d887ec7b59b2c0663
f5b348ef2206f91d1bc6ff32db59fa7abda567d8
v1.0
instruct
Apps
Apps_17154_I
Given two strings representing simplified polynomials, your task is to create a function that sums them up and returns the result as a string of a simplified polynomial in descending order of powers. Each polynomial will contain: - Only positive integer coefficients. - Only non-negative powers (including zero). - Vari...
import re from collections import defaultdict def parse_polynomial(poly): """ Parses a polynomial string into a dictionary with keys as (variable, power) and values as coefficients. """ if not poly: return defaultdict(int) terms = poly.split('+') poly_dict = defaultdict(int) ...
from solution import sum_polynomials def test_sum_polynomials(): assert sum_polynomials("3x^2+4x+1", "2x^2+5") == "5x^2+4x+6" assert sum_polynomials("6a", "7a^2+2a+3") == "7a^2+8a+3" assert sum_polynomials("5z^3+2z^1+1", "") == "5z^3+2z+1" assert sum_polynomials("", "3x^2+4z+1") == "3x^2+4z+1" asse...
[ { "docstring": "Parses a polynomial string into a dictionary with keys as (variable, power) and values as coefficients.", "function_declaration": "def parse_polynomial(poly):", "function_name": "parse_polynomial", "parameter_list": "(poly)" }, { "docstring": "Sums up two polynomial strings a...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_polynomials(poly1, poly2):\n def parse_polynomial(poly):\n terms = {}\n if not poly:\n return terms\n\n poly = poly.repla...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00017154", "row_id": 17154, "seed_ids": "[4409]" }
0.522622
Apps_17154
I
[ "parse_polynomial", "sum_polynomials" ]
2
[ [ "sum_polynomials", "parse_polynomial" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fcadba901936b99ef0971cffc0c662b7ec8b6a84
e824fc7c921f0134d90cb937ad74cd505f4b04ae
v1.0
instruct
Apps
Apps_17182_I
Given an array of integers, write a function that returns a new array containing only the elements that are prime numbers. Examples: ``` [2, 3, 4, 5, 6, 7] => [2, 3, 5, 7] [10, 12, 15, 17, 19, 20] => [17, 19] [1, 13, 22, 29] => [13, 29] ```
def is_prime(n): """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([2, 3, 4, 5, 6, 7]) == [2, 3, 5, 7] assert filter_primes([10, 12, 15, 17, 19, 20]) == [17, 19] assert filter_primes([1, 13, 22, 29]) == [13, 29] def test_filter_primes_with_no_primes(): assert filter_p...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the prime numbers from the given list 'numbers'.", "function_decl...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return T...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00017182", "row_id": 17182, "seed_ids": "[3424]" }
0.663605
Apps_17182
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e9cc95fd5b54064a486e341f7bc4bf0fafcc02c0
2a4a6c1430f3bf2f508498f0a1541cf764e3d764
v1.0
instruct
Apps
Apps_17195_I
Implement a function that takes a list of integer pairs as input and returns a list of their greatest common divisors (GCD). Each pair will consist of two positive integers. The order in the output list should correspond to the order of pairs in the input list. Write the function `find_gcds(pairs: List[Tuple[int, int]...
from typing import List, Tuple def gcd(a: int, b: int) -> int: """ Computes the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. """ while b: a, b = b, a % b return a def find_gcds(pairs: List[Tuple[int, int]]) -> List[int]: """ Takes a list of integer p...
from solution import find_gcds def test_find_gcds(): assert find_gcds([(8, 12), (9, 27), (20, 30)]) == [4, 9, 10] assert find_gcds([(14, 35), (18, 24)]) == [7, 6] assert find_gcds([(42, 56), (100, 200)]) == [14, 100] assert find_gcds([(81, 27), (49, 21)]) == [27, 7] assert find_gcds([]) == [] def ...
[ { "docstring": "Computes the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Takes a list of integer pairs and returns a list of their greatest commo...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef gcd(a: int, b: int) -> int:\n \"\"\"\n Returns the greatest common divisor of a and b using the Euclidean algorithm.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017195", "row_id": 17195, "seed_ids": "[3294]" }
0.760576
Apps_17195
I
[ "gcd", "find_gcds" ]
2
[ [ "find_gcds", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f4612425e71256929d915fc11ad2ffa788d104c2
32334e2973fca5aba3e21752aa07429711c889fa
v1.0
instruct
Apps
Apps_17215_I
Given a 2D array of integers representing a grid, determine if there exists a path from the top-left corner to the bottom-right corner such that you can only move right or down, and the sum of the numbers on the path is a prime number. -----Input----- First line of the input contains a single integer T denoting the nu...
import math def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def path_sums(grid, n, m): # ...
def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert is_prime(13) assert not is_prime(15) def test_path_sums(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] assert path_sums(grid,...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def path_sums(grid, n, m):", "function_name": "path_sums", "parameter_list": "(grid, n, m)" }, { "docstri...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00017215", "row_id": 17215, "seed_ids": "[1415]" }
0.657024
Apps_17215
I
[ "is_prime", "path_sums", "solve", "read_input", "main" ]
5
[ [ "solve", "is_prime" ], [ "solve", "path_sums" ] ]
2
[ "read_input" ]
false
[]
false
pytest
false
[]
true
1fd81a4e7f352b4bf77b49a23c61746e86795d42
2a5dc2718b3deed33af46d4f1cb055cd1f6863b2
v1.0
instruct
Apps
Apps_17237_I
Your task is to implement a function that sorts an array, but with a twist: the sorting should be done based on the sum of the divisors for each element. If two elements have the same sum of divisors, maintain their relative order from the original array. You will receive an array of distinct positive integers, and yo...
from typing import List def sum_of_divisors(n: int) -> int: """ Calculate the sum of all divisors of a given number n. """ total = 0 for i in range(1, n + 1): if n % i == 0: total += i return total def divisor_sort(arr: List[int]) -> List[int]: """ Sort array based ...
from solution import divisor_sort def test_divisor_sort_example(): assert divisor_sort([10, 6, 8]) == [6, 8, 10] def test_divisor_sort_single_element(): assert divisor_sort([5]) == [5] def test_divisor_sort_two_elements(): assert divisor_sort([28, 12]) == [12, 28] def test_divisor_sort_multiple_elements...
[ { "docstring": "Calculate the sum of all divisors of a given number n.", "function_declaration": "def sum_of_divisors(n):", "function_name": "sum_of_divisors", "parameter_list": "(n)" }, { "docstring": "Sort array based on the sum of divisors of each element.", "function_declaration": "d...
[ 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef sum_of_divisors(n: int) -> int:\n \"\"\"\n Returns the sum of all divisors of a number including 1 and the number itself.\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00017237", "row_id": 17237, "seed_ids": "[4891]" }
0.677155
Apps_17237
I
[ "sum_of_divisors", "divisor_sort" ]
2
[ [ "divisor_sort", "sum_of_divisors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c01d48640e8e9a5a44e19134d59aaaa97a71e78d
66c8e5b0c5099339f9d1db1aeb8382c13834fea9
v1.0
instruct
Apps
Apps_17289_I
Binary Search Trees - Find Minimum and Maximum Write a function, findMinAndMax(), which finds and returns the minimum and maximum values in a Binary Search Tree (BST). The function takes the root of a BST as its argument and should return a tuple containing the minimum and maximum values respectively. You may assume t...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.value = key def findMin(root): current = root while current.left is not None: current = current.left return current.value def findMax(root): current = root while current.right is no...
from solution import TreeNode, findMinAndMax def test_find_min_and_max_single_node(): root = TreeNode(10) assert findMinAndMax(root) == (10, 10) def test_find_min_and_max_left_skewed(): root = TreeNode(10) root.left = TreeNode(5) root.left.left = TreeNode(2) assert findMinAndMax(root) == (2, 1...
[]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef fi...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00017289", "row_id": 17289, "seed_ids": "[4971]" }
0.555816
Apps_17289
I
[ "findMin", "findMax", "findMinAndMax" ]
3
[ [ "findMinAndMax", "findMax" ], [ "findMinAndMax", "findMin" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6af3737007f49bbd62d937f2fd6701c3f0a4bf40
5b06c8ff2ff1da1b32dff34ea702dc78287c5ee7
v1.0
instruct
Apps
Apps_17401_I
Write a function that takes a string and a dictionary of words, and returns the longest word from the dictionary that can be formed by deleting some of the letters from the given string without reordering the remaining letters. If there are ties, return the longest word that appears first in the dictionary. If no words...
def is_subsequence(s, t): """ Helper function to check if s is a subsequence of t. """ t_iter = iter(t) return all(char in t_iter for char in s) def longestWordFromDict(s, dictionary): """ Returns the longest word from the dictionary that can be formed by deleting some of the letters f...
from solution import longestWordFromDict, is_subsequence def test_is_subsequence(): assert is_subsequence("abc", "ahbgdc") == True assert is_subsequence("axc", "ahbgdc") == False assert is_subsequence("apple", "abpcplea") == True assert is_subsequence("plea", "abpcplea") == True def test_longestWordFr...
[ { "docstring": "Helper function to check if s is a subsequence of t.", "function_declaration": "def is_subsequence(s, t):", "function_name": "is_subsequence", "parameter_list": "(s, t)" }, { "docstring": "Returns the longest word from the dictionary that can be formed by deleting some of the...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_subsequence(s, t):\n \"\"\"\n Helper function to check if s is a subsequence of t.\n \"\"\"\n t_iter = iter(t)\n return all(char in t_iter for...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00017401", "row_id": 17401, "seed_ids": "[4335]" }
0.734221
Apps_17401
I
[ "is_subsequence", "longestWordFromDict" ]
2
[ [ "longestWordFromDict", "is_subsequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5f700665ede1bf94fb421858a3a63cd9fb74e412
677e6206e62c0269d1c62aac1bfab910ce2e017a
v1.0
instruct
Apps
Apps_17436_I
A city wants to develop a new navigation system to aid drivers. The road network is represented as a graph where intersections are nodes and roads are edges. Each road has a travel time associated with it (an integer). The city wants to implement a system that can answer multiple queries efficiently. Each query consis...
import heapq def dijkstra(n, graph, start): """ Use Dijkstra's algorithm to find the shortest paths from start to all other nodes. """ distances = {node: float('infinity') for node in range(1, n+1)} distances[start] = 0 pq = [(0, start)] while pq: current_distance, current_node...
def test_navigation_system_simple_case(): n = 5 m = 6 edges = [ (1, 2, 10), (1, 3, 3), (2, 3, 1), (3, 4, 2), (4, 5, 5), (2, 5, 9) ] q = 3 queries = [ (1, 5), (2, 4), (1, 4) ] assert navigation_system(n, m, edges, q,...
[ { "docstring": "Use Dijkstra's algorithm to find the shortest paths from start to all other nodes.", "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def navigatio...
[ 1, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, adj, src):\n distances = [float('inf')] * (n + 1)\n distances[src] = 0\n pq = [(0, src)] # (distance, node)\n while pq:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017436", "row_id": 17436, "seed_ids": "[1060]" }
0.790437
Apps_17436
I
[ "dijkstra", "navigation_system" ]
2
[ [ "navigation_system", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
a7212ad615f646079115131b02c8385bedecf478
0d6761e6aa8c0652f923415f556f4b0b3cb864cc
v1.0
instruct
Apps
Apps_17532_I
Given an undirected, weighted graph with $N$ nodes and $M$ edges, you are required to find the shortest distance from the starting node to a given destination node using Dijkstra's algorithm. The graph is represented using an adjacency list. -----Input----- - The first line contains two integers $N$ and $M$ denoting t...
import heapq from collections import defaultdict import sys def dijkstra_shortest_path(N, M, edges, S, D): # Prepare the graph graph = defaultdict(list) for u, v, w in edges: graph[u].append((w, v)) graph[v].append((w, u)) # Dijkstra's algorithm pq = [(0, S)] # (distance, node) ...
from solution import find_shortest_path def test_example_case(): N = 5 M = 6 edge_list = [ "1 2 2", "1 3 4", "2 3 1", "2 4 7", "3 5 3", "4 5 1" ] S = 1 D = 5 assert find_shortest_path(N, M, edge_list, S, D) == 6 def test_no_path_case(): N...
[ { "docstring": null, "function_declaration": "def dijkstra_shortest_path(N, M, edges, S, D):", "function_name": "dijkstra_shortest_path", "parameter_list": "(N, M, edges, S, D)" }, { "docstring": null, "function_declaration": "def find_shortest_path(N, M, edge_list, S, D):", "functio...
[ 1, 1, 1, 1, 1, 0, 1, 0, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(N, edges, S, D):\n \"\"\"\n Returns the shortest distance from S to D using Dijkstra's algorithm.\n :param N: Number of nodes....
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017532", "row_id": 17532, "seed_ids": "[1402]" }
0.715209
Apps_17532
I
[ "dijkstra_shortest_path", "find_shortest_path" ]
2
[ [ "find_shortest_path", "dijkstra_shortest_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b82add84309040489c8f01348b795b17032f17c7
e061db84b6582c82a3eb49d40cedaa49f572db77
v1.0
instruct
Apps
Apps_17551_I
Given a list of integers, determine whether the sum of the integers at prime indices is even or odd. For example, consider the list `[5, 3, 8, 7, 1, 2]`: - At index 2 (a prime number), the value is 8. - At index 3 (a prime number), the value is 7. - At index 5 (a prime number), the value is 2. The sum of these value...
def is_prime(num): """ Returns True if num is a prime number, else False. """ if num < 2: return False for i in range(2, int(num**0.5) + 1): if num % i == 0: return False return True def sum_at_prime_indices(lst): """ Given a list of integers, determine wheth...
from solution import sum_at_prime_indices def test_example_case(): assert sum_at_prime_indices([5, 3, 8, 7, 1, 2]) == 'odd' def test_empty_list(): assert sum_at_prime_indices([]) == 'even' def test_single_element(): assert sum_at_prime_indices([10]) == 'even' def test_no_prime_indices(): assert sum_...
[ { "docstring": "Returns True if num is a prime number, else False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Given a list of integers, determine whether the sum of the integers at prime indices is even or odd.\nR...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n i...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00017551", "row_id": 17551, "seed_ids": "[4577]" }
0.71201
Apps_17551
I
[ "is_prime", "sum_at_prime_indices" ]
2
[ [ "sum_at_prime_indices", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
514ef02547d4050401cf4428d9005cda79981f5b
2d9f1806f067934c2d23c9645ff63c600ecc1f20
v1.0
instruct
Apps
Apps_17585_I
You are given a string s of length n consisting of uppercase and lowercase English letters. Construct a new string t by rearranging the characters of s such that no two adjacent characters in t are the same. If it is not possible to construct such string t, output "Impossible". -----Input----- The first line contains...
from collections import Counter import heapq def rearrange_string(s): char_count = Counter(s) max_heap = [(-count, char) for char, count in char_count.items()] heapq.heapify(max_heap) previous_char = None previous_freq = 0 result = [] while max_heap: current_freq, current_...
def test_rearrange_string(): assert solve("aabbcc") == "abcabc" or solve("aabbcc") == "acbacb" assert solve("aaa") == "Impossible" assert solve("a") == "a" assert solve("ab") == "ab" or solve("ab") == "ba" assert solve("aaabbbc") == "abababc" or solve("aaabbbc") == "ababacb" or solve("aaabbbc") == "...
[ { "docstring": null, "function_declaration": "def rearrange_string(s):", "function_name": "rearrange_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def solve(s):", "function_name": "solve", "parameter_list": "(s)" } ]
[ 1, 0, 0, 0, 0, 1, 1, 1, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\nimport heapq\n\ndef rearrange_string(s):\n \"\"\"\n Rearranges string s such that no two adjacent characters are the same.\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017585", "row_id": 17585, "seed_ids": "[2353]" }
0.818301
Apps_17585
I
[ "rearrange_string", "solve" ]
2
[ [ "solve", "rearrange_string" ] ]
1
[]
false
[]
false
pytest
false
[]
true
524323df2f3d32da6cc069ba346c33cc9cfef4b5
c5f137ff126a551201809e0798d4f39f176cbda6
v1.0
instruct
Apps
Apps_17589_I
You are given an array of N$N$ integers. Your task is to determine if there exists a subset of this array whose sum is a prime number and if such a subset exists, find the smallest length of such a subset. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. T...
from itertools import combinations import math def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(math.sqrt(num)) + 1, 2): if num % i == 0: return False return True def smallest_prime...
from solution import prime_sum_subsets def test_example_case(): input_data = '1\n5\n1 2 3 4 5' assert prime_sum_subsets(input_data) == [1] def test_no_prime_subsets(): input_data = '1\n4\n4 6 8 10' assert prime_sum_subsets(input_data) == [-1] def test_prime_subset_lengths(): input_data = '2\n3\n1...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def smallest_prime_subset_length(test_cases):", "function_name": "smallest_prime_subset_length", "parameter_l...
[ 1, 1, 1, 0, 1, 0, 0, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\nfrom math import isqrt\n\ndef is_prime(number):\n if number < 2:\n return False\n for i in range(2, isqrt(number) +...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00017589", "row_id": 17589, "seed_ids": "[701]" }
0.71775
Apps_17589
I
[ "is_prime", "smallest_prime_subset_length", "parse_input", "prime_sum_subsets" ]
4
[ [ "prime_sum_subsets", "parse_input" ], [ "prime_sum_subsets", "smallest_prime_subset_length" ], [ "smallest_prime_subset_length", "is_prime" ] ]
3
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
ab86640fee2cc0d425bf37ea6aec6d8ca754faa6
4a8c50a92d20daf026cfcfa009a9622da44ca6ed
v1.0
instruct
Apps
Apps_17628_I
Evelyn is planning a birthday party and wants to arrange games for the kids. One of the games involves arranging the kids in a circle. Evelyn wants the arrangement to have the maximum number of "happy pairs." A "happy pair" is defined as two adjacent kids who have the same preference for a toy. Evelyn has n kids, and e...
def max_happy_pairs(n, m, preferences): from collections import Counter counts = Counter(preferences) pairs = 0 remaining = [] for toy in counts: pairs += counts[toy] // 2 if counts[toy] % 2: remaining.append(toy) arrangement = [] for toy, count in counts.i...
from solution import format_solution def test_example1(): n = 6 m = 3 preferences = [1, 1, 3, 2, 2, 3] expected_pairs = 3 result_pairs, result_arrangement = format_solution(n, m, preferences) assert result_pairs == expected_pairs assert len(result_arrangement) == n + 1 assert result_arr...
[ { "docstring": null, "function_declaration": "def max_happy_pairs(n, m, preferences):", "function_name": "max_happy_pairs", "parameter_list": "(n, m, preferences)" }, { "docstring": null, "function_declaration": "def format_solution(n, m, preferences):", "function_name": "format_solu...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import Counter\n\ndef max_happy_pairs(n, m, preferences):\n \"\"\"\n Determines the maximum number of happy pairs and gives an example arrang...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00017628", "row_id": 17628, "seed_ids": "[2020]" }
0.645884
Apps_17628
I
[ "max_happy_pairs", "format_solution" ]
2
[ [ "format_solution", "max_happy_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0a41861f6ff65f05b2189f79f25df374bc27f0b
b41e45a6bd299b4b8437211fad8611e6afc410c0
v1.0
instruct
Apps
Apps_17723_I
Aditi loves playing with prime numbers. One day, she came up with an intriguing puzzle involving prime numbers and arrays. She has an array of integers and wants to find the sum of all prime numbers in the array. However, to make it more interesting, she performs this operation multiple times with different arrays and ...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
from solution import solve def test_case_1(): assert solve([[2, 3, 4, 5, 6], [8, 10, 12], [7, 11, 13, 17]]) == [10, 0, 48] def test_case_2(): # All elements are prime assert solve([[2, 3, 5, 7], [11, 13, 17, 19], [23, 29, 31]]) == [17, 60, 83] def test_case_3(): # No prime numbers in the array as...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of all prime numbers in the array arr.", "function_declaration": "def sum_of_primes(...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n r...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00017723", "row_id": 17723, "seed_ids": "[1010]" }
0.66126
Apps_17723
I
[ "is_prime", "sum_of_primes", "solve" ]
3
[ [ "solve", "sum_of_primes" ], [ "sum_of_primes", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
936beffcd8389196fbfc056ba8749102f3b00cfd
f11e53c3786936cdbc68cf2a2cb19021cb5f7975
v1.0
instruct
Apps
Apps_17757_I
Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. Ensure the function performs the prime-checking efficiently for large lists.
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 re...
from solution import filter_primes def test_filter_primes_empty_list(): assert filter_primes([]) == [] def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 10, 12]) == [] def test_filter_primes_with_primes(): assert filter_primes([2, 3, 4, 5, 10, 13, 17]) == [2, 3, 5, 13, 17] def test_filt...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the prime numbers from the original list.", "function_declaration": "def filter_pr...
[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017757", "row_id": 17757, "seed_ids": "[3067]" }
0.617318
Apps_17757
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1625bdcb82500c31c77525c9ddb400996046f14a
5167b369b132ca0a89cd05f7a79f2cd4c45a528d
v1.0
instruct
Apps
Apps_17768_I
Given a list of integers, your task is to implement a function that returns the list of all prime numbers present in the initial list. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Ensure the function efficiently determines whether a number is prime before adding it to...
def is_prime(n): "Check if a number is a prime number." if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_primes(nums): "Return a li...
from solution import filter_primes def test_filter_primes_normal_case(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_with_larger_numbers(): assert filter_primes([15, 21, 22, 23, 25, 29]) == [23, 29] def test_filter_primes_no_primes(): assert filter_primes([1,...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return a list of prime numbers from the given list of integers.", "function_declaration": "def filter_primes(nums):",...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <=...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017768", "row_id": 17768, "seed_ids": "[2692]" }
0.683625
Apps_17768
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ac65f70964d357418538ec2147dac55a3ea34b19
715c55cdf2c8ed93ccb64ba404b5b96b0e7ecac2
v1.0
instruct
Apps
Apps_17791_I
The residents of Smalltown have recently implemented a new delivery system for their postal service. Each house is represented as a point on a 2D grid, and each point has coordinates (x, y). The postman starts at the origin point (0, 0) and has a list of house coordinates he needs to deliver mail to. However, given th...
from itertools import permutations from math import sqrt def euclidean_distance(point1, point2): return sqrt((point2[0] - point1[0])**2 + (point2[1] - point1[1])**2) def total_distance(path): # Path includes return to the origin distance = 0 for i in range(len(path) - 1): distance += euclidean...
from solution import minimum_travel_distance def test_minimum_travel_distance_with_houses(): assert minimum_travel_distance([(1, 2), (3, 4), (6, 8), (2, 1)]) > 20 # Depends on optimal calculation assert minimum_travel_distance([(0, 1), (0, 2)]) == 4 # Optimal path is (0,0) -> (0,1) -> (0,2) -> (0,0) asse...
[ { "docstring": null, "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": null, "function_declaration": "def total_distance(path):", "function_name": "total_distance", "par...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\nimport math\n\ndef euclidean_distance(p1, p2):\n \"\"\"\n Calculate the Euclidean distance between two points p1 and p2.\n \"\"\"\n re...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00017791", "row_id": 17791, "seed_ids": "[4378]" }
0.690179
Apps_17791
I
[ "euclidean_distance", "total_distance", "minimum_travel_distance" ]
3
[ [ "minimum_travel_distance", "total_distance" ], [ "total_distance", "euclidean_distance" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c64ade3dc47773ca16317b0c12441df70f820bad
678a0b98cd01138d7012fac7685996c45695e9e8
v1.0
instruct
Apps
Apps_17804_I
Kakashi is a fan of prime numbers and Fibonacci sequences. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A Fibonacci sequence is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. Kakashi has two int...
def is_prime(n): """ Check if a number is prime. """ if n < 2: return False if n in (2, 3): return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return ...
def test_smallest_prime_fibonacci(): assert smallest_prime_fibonacci(10, 100) == 13 assert smallest_prime_fibonacci(50, 60) == -1 assert smallest_prime_fibonacci(1, 1) == -1 assert smallest_prime_fibonacci(1, 2) == 2 assert smallest_prime_fibonacci(60, 1000) == 89 assert smallest_prime_fibonacci...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find the smallest prime number that is also a Fibonacci number in the range [a, b].", "function_declaration": "def smallest_pr...
[ 0, 0, 0, 0, 1, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00017804", "row_id": 17804, "seed_ids": "[2001]" }
0.605348
Apps_17804
I
[ "is_prime", "smallest_prime_fibonacci" ]
2
[ [ "smallest_prime_fibonacci", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
032e568dbf8fb78fbec69f9ef624dc9cebfcd51c
71ad0d9e100449b568f42262a9660899b69d704a
v1.0
instruct
Apps
Apps_17805_I
In a distant future, a race of intelligent creatures known as the Xyloids is engaged in a game of resource allocation. There are $M$ territories on their planet, each with its own unique resource. The Xyloids have $P$ packets of resources that they wish to distribute among these $M$ territories such that the distributi...
def maximum_packets(M, P): """ Given M territories and P packets, return the maximum number of packets a territory can have such that no two territories differ by more than 1 packet. """ # Each territory will have at least P // M packets base_packets = P // M # Calculate the number of terri...
from solution import maximum_packets, solve, process_input def test_maximum_packets(): assert maximum_packets(4, 10) == 3 assert maximum_packets(3, 7) == 3 assert maximum_packets(5, 14) == 3 assert maximum_packets(6, 18) == 3 assert maximum_packets(1, 1000000000) == 1000000000 assert maximum_pa...
[ { "docstring": "Given M territories and P packets, return the maximum number of packets \na territory can have such that no two territories differ by more than 1 packet.", "function_declaration": "def maximum_packets(M, P):", "function_name": "maximum_packets", "parameter_list": "(M, P)" }, { ...
[ 1, 1, 0, 1, 1, 1, 0, 0, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_packets_per_territory(M, P):\n \"\"\"\n Given M territories and P packets, returns the maximum number of resource packets that a territory can have.\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00017805", "row_id": 17805, "seed_ids": "[536]" }
0.616407
Apps_17805
I
[ "maximum_packets", "solve", "process_input" ]
3
[ [ "solve", "maximum_packets" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
6af151d35592d0a588a4f9ce3d0f00cdb3ac09b8
3e762817050ad1468869155733fd5873af7ba09c
v1.0
instruct
Apps
Apps_17821_I
Write a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list, preserving their order. ``` input: [4, 6, 7, 9, 11, 13, 15] output: [7, 11, 13] example: When the function is called with the above input, it should return a list containing [7,...
def is_prime(n): """ Checks if a number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_primes(number...
from solution import filter_primes def test_filter_primes_no_primes(): assert filter_primes([4, 6, 8, 9, 10]) == [] def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_mixed(): assert filter_primes([4, 6, 7, 9, 11, 13, 15]) == [7, 11, 13]...
[ { "docstring": "Checks if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list of integers.", "function_declaration": "def filter_primes(numb...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00017821", "row_id": 17821, "seed_ids": "[3334]" }
0.642342
Apps_17821
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d246bd52cb93a2c4620b143673f2360f0a1f77c1
6b2cf1241d6ac412461f96c1e03ecd791a2fe227
v1.0
instruct
Apps
Apps_17826_I
Given an array of integers, you need to process multiple queries to find the sum of a given subarray. Each query will ask for the sum of elements between two indices, inclusive. -----Input----- The first line of the input contains two integers N and Q, where N is the number of elements in the array and Q is the number...
def prefix_sum(arr): """ Compute the prefix sums of the given array. """ n = len(arr) prefix = [0] * (n + 1) for i in range(n): prefix[i + 1] = prefix[i] + arr[i] return prefix def subarray_sum_query(arr, queries): """ Compute the sum of elements for each query range [L, R]....
from solution import subarray_sum_query def test_subarray_sum_query_basic(): arr = [1, 2, 3, 4, 5] queries = [(1, 3), (0, 4), (2, 4)] assert subarray_sum_query(arr, queries) == [9, 15, 12] def test_subarray_sum_query_single_element(): arr = [10] queries = [(0, 0)] assert subarray_sum_query(arr...
[ { "docstring": "Compute the prefix sums of the given array.", "function_declaration": "def prefix_sum(arr):", "function_name": "prefix_sum", "parameter_list": "(arr)" }, { "docstring": "Compute the sum of elements for each query range [L, R].", "function_declaration": "def subarray_sum_q...
[ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def process_queries(array, queries):\n \"\"\"\n Given an array of integers, this function will process multiple queries to find the sum of a given subarray.\n...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017826", "row_id": 17826, "seed_ids": "[529]" }
0.681279
Apps_17826
I
[ "prefix_sum", "subarray_sum_query" ]
2
[ [ "subarray_sum_query", "prefix_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
941106daf570afe4b7046839d6831aefbfc47d3e
411cefeb4709bdf7fc456455b116bbe39b9dce84
v1.0
instruct
Apps
Apps_17894_I
Given an integer array ```arr```, write a function ```untangle_list()``` that returns a new array containing the prime numbers from the input array followed by the non-prime numbers, both groups sorted in ascending order. The function signature is: ```python def untangle_list(arr: List[int]) -> List[int]: # Your ...
from typing import List def is_prime(n: int) -> bool: """ Returns True if n is a prime number, False otherwise. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + ...
from solution import untangle_list def test_untangle_list_primes_and_non_primes(): assert untangle_list([11, 4, 6, 7, 9, 10, 5]) == [5, 7, 11, 4, 6, 9, 10] def test_untangle_list_primes_and_non_primes_2(): assert untangle_list([29, 15, 14, 23, 8, 3]) == [3, 23, 29, 8, 14, 15] def test_untangle_list_empty():...
[ { "docstring": "Returns True if n is a prime number, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new array containing the prime numbers from the input array followed by\nthe non-prime numbers...
[ 1, 0, 0, 1, 1, 0, 1, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00017894", "row_id": 17894, "seed_ids": "[3079]" }
0.672732
Apps_17894
I
[ "is_prime", "untangle_list" ]
2
[ [ "untangle_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7bf5b9a4fda96e48fe0e0952a9f39a7e5be37ec5
38f1303bd11674e72c65b78ec843021327fc25d9
v1.0
instruct
Apps
Apps_17935_I
Ravi, a computer science student, accidentally deleted some important academic files from his computer and was very worried. However, he remembered that he had sent a backup of the files to his friend via email. The problem is that the backup files were named following a complex pattern, and Ravi has a list of patterns...
import fnmatch def matches_patterns(filenames, patterns): results = [] for pattern in patterns: matched = any(fnmatch.fnmatch(filename, pattern) for filename in filenames) results.append("YES" if matched else "NO") return results def solve(test_cases): results = [] for case in test...
import pytest from solution import matches_patterns def test_matches_patterns_all_yes(): filenames = ["file1.txt", "backup.docx", "report2023.pdf"] patterns = ["*.txt", "f?le?.*"] assert matches_patterns(filenames, patterns) == ["YES", "YES"] def test_matches_patterns_some_no(): filenames = ["file1.tx...
[ { "docstring": null, "function_declaration": "def matches_patterns(filenames, patterns):", "function_name": "matches_patterns", "parameter_list": "(filenames, patterns)" }, { "docstring": null, "function_declaration": "def solve(test_cases):", "function_name": "solve", "parameter...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import fnmatch\n\ndef match_patterns(filenames, patterns):\n results = []\n for pattern in patterns:\n matched = any(fnmatch.fnmatch(filename, pattern)...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00017935", "row_id": 17935, "seed_ids": "[1043]" }
0.594941
Apps_17935
I
[ "matches_patterns", "solve", "process_input" ]
3
[ [ "process_input", "solve" ], [ "solve", "matches_patterns" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
3b98bb69f6cf386980bbb4b2b7faeb538bfec058
0a2a7b064fa82506b898994a879df92be4e68e9c
v1.0
instruct
Apps
Apps_17956_I
The Mysterious Cave Guild is planning an expedition to collect valuable gems in a cave. The cave can be represented as a grid with `n` rows and `m` columns, where each cell either contains a gem (represented by a 1) or is empty (represented by a 0). To make their journey efficient, they want to maximize the number of g...
def bfs(grid, x, y, visited): from collections import deque queue = deque([(x, y)]) directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] count = 0 while queue: cx, cy = queue.popleft() if visited[cx][cy]: continue visited[cx][cy] = True count += 1 ...
from solution import max_gems_in_cave def test_case_1(): t = 2 test_cases = [ (3, 3, [[1, 0, 1], [0, 1, 0], [1, 0, 1]]), (4, 4, [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 0, 1]]), ] assert max_gems_in_cave(t, test_cases) == [1, 4] def test_case_2(): t = 1 test_case = [ ...
[ { "docstring": null, "function_declaration": "def bfs(grid, x, y, visited):", "function_name": "bfs", "parameter_list": "(grid, x, y, visited)" }, { "docstring": null, "function_declaration": "def max_gems_in_cave(t, test_cases):", "function_name": "max_gems_in_cave", "parameter_...
[ 0, 1, 0, 1, 0, 1, 1, 1, 0 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_max_gems(n, m, grid):\n def dfs(x, y):\n if x < 0 or x >= n or y < 0 or y >= m or grid[x][y] == 0:\n return 0\n grid[x][y] = 0 ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00017956", "row_id": 17956, "seed_ids": "[66]" }
0.72905
Apps_17956
I
[ "bfs", "max_gems_in_cave" ]
2
[ [ "max_gems_in_cave", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
408b80e1f7942f0f35fa8c71f670b35089cb6365
e79857f5b09116642ab26df876d42ab916a71f31
v1.0
instruct
Apps
Apps_17968_I
Harry is a wildlife photographer and loves capturing birds in flight. He has recently taken a sequence of photographs of birds flying at different altitudes. Harry wants to analyze the sequence to find the longest subsequence of birds that are strictly ascending in altitude. Help Harry by writing a program that finds t...
def longest_strictly_ascending_subsequence(test_cases): """ Finds the longest strictly ascending subsequence for each test case. Args: test_cases (list): A list of tuples, where each tuple contains two elements: - an integer N representing the number of photographs. ...
from solution import longest_strictly_ascending_subsequence, parse_input, run_solution def test_longest_strictly_ascending_subsequence(): assert longest_strictly_ascending_subsequence([(5, [1, 3, 2, 4, 6])]) == [4] assert longest_strictly_ascending_subsequence([(4, [5, 4, 3, 2])]) == [1] assert longest_str...
[ { "docstring": "Finds the longest strictly ascending subsequence for each test case.\n\nArgs:\ntest_cases (list): A list of tuples, where each tuple contains two elements:\n - an integer N representing the number of photographs.\n - a list of integers representing the altitud...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_ascending_subsequence(T, test_cases):\n def length_of_lis(sequence):\n if not sequence:\n return 0\n lis_lengths = [1] * len...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00017968", "row_id": 17968, "seed_ids": "[1031]" }
0.714549
Apps_17968
I
[ "longest_strictly_ascending_subsequence", "parse_input", "run_solution" ]
3
[ [ "run_solution", "longest_strictly_ascending_subsequence" ], [ "run_solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
af0491532a8f001d9fdc920773d211e7222592a1
b8f57c60e992c42a95ef393758225eeaf3fe9232
v1.0
instruct
Apps
Apps_17972_I
Chef has started a new game called "Magical Forest". In this game, each player needs to collect magical orbs scattered in the forest. Each player has a separate bag to store these orbs and the player with the most magical power wins the game. Each orb has a magical power associated with it, and the players can gain a...
def calculate_magical_power(orbs): unique_orbs = len(set(orbs)) additional_power = 0 if unique_orbs >= 5: additional_power += 20 unique_orbs -= 5 if unique_orbs >= 4: additional_power += 10 unique_orbs -= 4 if unique_orbs >= 3: additional_power += 5 ...
import pytest from solution import magical_forest_game def test_single_player_multiple_orb_types(): assert magical_forest_game(1, [[[1, 2, 3, 4, 5]]]) == ["chef"] def test_multiple_players_with_different_powers(): assert magical_forest_game(1, [[[1, 2, 3], [1, 1, 2, 2, 3, 3], [1, 2, 3, 4, 5, 6]]]) == ["3"] d...
[ { "docstring": null, "function_declaration": "def calculate_magical_power(orbs):", "function_name": "calculate_magical_power", "parameter_list": "(orbs)" }, { "docstring": null, "function_declaration": "def find_winner(test_cases):", "function_name": "find_winner", "parameter_lis...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_magical_power(m, orbs):\n from collections import Counter\n orb_types = list(set(orbs))\n orb_count = len(orb_types)\n\n power = m\n\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00017972", "row_id": 17972, "seed_ids": "[730]" }
0.664385
Apps_17972
I
[ "calculate_magical_power", "find_winner", "magical_forest_game" ]
3
[ [ "find_winner", "calculate_magical_power" ], [ "magical_forest_game", "find_winner" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c952c48398324951bc98c02e2943da71dc9563b4
93ebe1c657ef70f6cb07c9a8700f596c39b6359d
v1.0
instruct
Apps
Apps_18022_I
Write a function that takes in a list of integers and returns a new list containing only the integers that are prime numbers. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. > Note: You may assume the list contains only positive integers. Here's a small example...
def is_prime(n): """ Checks if a number is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def filter_primes(number...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(20) == False assert is_prime(1) == False def test_filter_primes(): assert filter_primes([10, 11, 1...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list containing only the prime numbers from the input list of integers.", "function_declaration": "def fil...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018022", "row_id": 18022, "seed_ids": "[3896]" }
0.687175
Apps_18022
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
816818533a119bac33f5eb0d1e207b2a68753e3b
30179b674eebd9894c4a100615b3092c494e23a4
v1.0
instruct
Apps
Apps_18063_I
=====Problem Statement===== You are given a positive integer N. Write a Python program to generate a list of all prime numbers less than N. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. For example, 2, 3, 5, 7, and 11 are primes. =====Input Format===== A singl...
def is_prime(num): """ Helper function to check if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def p...
from solution import primes_less_than_n, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(13) == True assert is_prime(1) == False def test_primes_less_than_n(): assert primes_less_than_n(10) == [2, 3, 5, 7] asse...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers less than N.", "function_declaration": "def primes_less_than_n(N):"...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, in...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018063", "row_id": 18063, "seed_ids": "[2599]" }
0.730455
Apps_18063
I
[ "is_prime", "primes_less_than_n" ]
2
[ [ "primes_less_than_n", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c734ca9912ef916767ea68ed501c11e7870e5c12
e6933ade6c77a026305713e673196910a679185f
v1.0
instruct
Apps
Apps_18214_I
During an archaeological expedition, scientists have discovered an ancient construct consisting of a sequence of stones with each stone numbered with an integer ranging from 1 to n. Each stone has a unique identifier. The identifier of the i-th stone is represented by the integer s_i. The archaeologists noticed a pecu...
def length_of_lis(nums): """ Returns the length of the longest increasing subsequence in the list of integers nums. """ if not nums: return 0 dp = [] for num in nums: idx = binary_search(dp, num) if idx == len(dp): dp.append(num) else: ...
from solution import length_of_lis def test_example_1(): assert length_of_lis([10, 9, 2, 5, 3]) == 2 def test_example_2(): assert length_of_lis([0, 8, 4, 12, 2, 50]) == 4 def test_empty_list(): assert length_of_lis([]) == 0 def test_single_element(): assert length_of_lis([5]) == 1 def test_all_incr...
[ { "docstring": "Returns the length of the longest increasing subsequence in the list of integers nums.", "function_declaration": "def length_of_lis(nums):", "function_name": "length_of_lis", "parameter_list": "(nums)" }, { "docstring": "Helper function to perform binary search and return the...
[ 1, 1, 1, 0, 1, 1, 1, 1, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def length_of_lis(n, stones):\n \"\"\"\n Returns the length of the longest increasing subsequence of the given sequence of stone identifiers.\n \n Args:...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00018214", "row_id": 18214, "seed_ids": "[2123]" }
0.751977
Apps_18214
I
[ "length_of_lis", "binary_search" ]
2
[ [ "length_of_lis", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee1c3579089add406b01477d980a9b13c910c51c
e23ac58010f9be1ed7e29a1d2d4ef855e378f996
v1.0
instruct
Apps
Apps_18218_I
Given an array of integers, write a function `merge_sort` that implements the merge sort algorithm to sort the array in ascending order. The function should accept one argument, the array, and return the sorted array. Merge sort is a divide-and-conquer algorithm that works as follows: 1. Divide the array into two halv...
def merge_sort(array): """ Sorts an array in ascending order using the merge sort algorithm. """ if len(array) <= 1: return array mid = len(array) // 2 left = merge_sort(array[:mid]) right = merge_sort(array[mid:]) return merge(left, right) def merge(left, right): ...
from solution import merge_sort def test_merge_sort(): assert merge_sort([4, 2, 6, 5, 1, 3]) == [1, 2, 3, 4, 5, 6] assert merge_sort([10, -1, 2, 5, 0, 6, 4, -5]) == [-5, -1, 0, 2, 4, 5, 6, 10] assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] ...
[ { "docstring": "Sorts an array in ascending order using the merge sort algorithm.", "function_declaration": "def merge_sort(array):", "function_name": "merge_sort", "parameter_list": "(array)" }, { "docstring": "Merges two sorted arrays into one sorted array.", "function_declaration": "d...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(array):\n \"\"\"\n Implements merge sort algorithm to sort the input array in ascending order.\n \n :param array: List of integers to be ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018218", "row_id": 18218, "seed_ids": "[3045]" }
0.689222
Apps_18218
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0fb201a6e60f1d8b0710a3b6ba1229c966d52439
b78c308bf48a900e460ae729f452604349e2ce5b
v1.0
instruct
Apps
Apps_18246_I
## Task Write a function that accepts a list of integers and returns a new list containing only the integers that are prime numbers. ### Definition: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Examples of prime numbers are 2, 3, 5, 7, 11, etc. ### Input: ...
def is_prime(n): """ Returns True if n is a prime number, else False. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return Fa...
from solution import filter_primes def test_filter_primes_with_mixed_numbers(): assert filter_primes([10, 15, 2, 3, 4, 7, 8]) == [2, 3, 7] def test_filter_primes_with_all_primes(): assert filter_primes([2, 3, 5, 7, 11]) == [2, 3, 5, 7, 11] def test_filter_primes_with_no_primes(): assert filter_primes([4,...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of all prime numbers in the given list of integers.", "function_declaration": "def filter_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018246", "row_id": 18246, "seed_ids": "[3150]" }
0.721444
Apps_18246
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e868b5f7a5c1a3ad64a46367e74b00de2926d26a
340eb5f9f69ffc4bf8b418b0180cbe084f2bfa29
v1.0
instruct
Apps
Apps_18500_I
Alex wants to send a package from city A to city B in the shortest possible time. There are N cities and M roads connecting them. Each road connects two cities and takes a certain amount of time to traverse. Additionally, certain roads are toll roads, which means Alex needs to pay a certain amount of money to use them....
import heapq import sys from collections import defaultdict def shortest_path_with_budget(N, M, A, B, K, roads): graph = defaultdict(list) for u, v, t, l in roads: graph[u].append((v, t, l)) graph[v].append((u, t, l)) # Using a tuple (time, current_city, money_spent) for heapq pq =...
from solution import find_shortest_path def test_case_1(): N, M, A, B, K = 5, 6, 1, 5, 10 edges = [ "1 2 3 2", "2 3 4 5", "2 4 2 1", "4 5 6 2", "3 5 3 8", "1 3 7 10" ] assert find_shortest_path(N, M, A, B, K, edges) == 11 def test_case_2(): N, M, A, ...
[ { "docstring": null, "function_declaration": "def shortest_path_with_budget(N, M, A, B, K, roads):", "function_name": "shortest_path_with_budget", "parameter_list": "(N, M, A, B, K, roads)" }, { "docstring": null, "function_declaration": "def find_shortest_path(N, M, A, B, K, edges):", ...
[ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\n\ndef shortest_path(N, M, A, B, K, roads):\n graph = [[] for _ in range(N + 1)]\n \n for u, v, t, l in roads:\n graph[u].a...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00018500", "row_id": 18500, "seed_ids": "[2303]" }
0.807375
Apps_18500
I
[ "shortest_path_with_budget", "find_shortest_path" ]
2
[ [ "find_shortest_path", "shortest_path_with_budget" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b2c485baac8f44fc8880856247ba02347e274b2f
9dfb84307ad47efb6f592b030f4182bf3c875d34
v1.0
instruct
Apps
Apps_18513_I
In a dystopian future, a large matrix represents a battle grid where various factions are preparing for combat. Each cell in the matrix contains a positive integer representing the strength of a particular faction's unit. Two factions are allies if they have a common divisor greater than 1. Your task is to find out the...
from math import gcd from collections import deque def get_neighbors(r, c, R, C): """ Return valid neighbors (up, down, left, right) for cell (r, c) """ neighbors = [] if r - 1 >= 0: neighbors.append((r - 1, c)) if r + 1 < R: neighbors.append((r + 1, c)) if c - 1 >= 0: ...
from solution import largest_allied_group def test_largest_allied_group(): R = 4 C = 4 matrix = [ [2, 3, 4, 5], [6, 4, 3, 8], [6, 9, 2, 7], [1, 8, 9, 2] ] assert largest_allied_group(R, C, matrix) == 5 def test_largest_allied_group_single_cell(): R = 1 C = 1...
[ { "docstring": "Return valid neighbors (up, down, left, right) for cell (r, c)", "function_declaration": "def get_neighbors(r, c, R, C):", "function_name": "get_neighbors", "parameter_list": "(r, c, R, C)" }, { "docstring": "Return whether two cell values are allied.", "function_declarat...
[ 1, 1, 0, 0, 0, 1, 0, 0, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\nfrom math import gcd\n\ndef find_factors(n):\n \"\"\"\n Returns set of factors of a number n.\n \"\"\"\n if n < 2:\n ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00018513", "row_id": 18513, "seed_ids": "[1590]" }
0.622727
Apps_18513
I
[ "get_neighbors", "are_allies", "bfs", "largest_allied_group" ]
4
[ [ "bfs", "are_allies" ], [ "bfs", "get_neighbors" ], [ "largest_allied_group", "bfs" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8d8cb3c02980300509dc1b98ac5cc61d972ecc10
85f88f197912f583550317afab40b229ebad4686
v1.0
instruct
Apps
Apps_18569_I
In a magical forest, there are several kinds of magical fruits. Each fruit type can be collected multiple times and each fruit has a certain magic power value associated with it. The magical properties of the fruits allow you to perform a special operation when you collect two of the same type of fruit, which is to mer...
def total_magic_power_value(batches): """ This function takes a list of batches where each batch is a list of integer values representing the magic power of fruits. It returns a list of total magic power values after merging the fruits in each batch. """ results = [] for batch in batches: ...
from solution import merge_fruit_batches def test_single_batch_all_same(): input_data = "1\n5\n3 3 3 3 3" assert merge_fruit_batches(input_data) == [15] def test_single_batch_two_types(): input_data = "1\n4\n5 10 5 10" assert merge_fruit_batches(input_data) == [30] def test_single_batch_repeated_smal...
[ { "docstring": "This function takes a list of batches where each batch is a list of integer values\nrepresenting the magic power of fruits.\nIt returns a list of total magic power values after merging the fruits in each batch.", "function_declaration": "def total_magic_power_value(batches):", "function_...
[ 0, 0, 0, 1, 1, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_and_sum_fruits(batches):\n \"\"\"\n Given a list of batches where each batch consists of fruit power values,\n return a list of total magic power...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00018569", "row_id": 18569, "seed_ids": "[1019]" }
0.601148
Apps_18569
I
[ "total_magic_power_value", "read_input", "merge_fruit_batches" ]
3
[ [ "merge_fruit_batches", "read_input" ], [ "merge_fruit_batches", "total_magic_power_value" ] ]
2
[ "read_input" ]
false
[]
false
pytest
true
[]
true
37519028e0db85d20a73bf87f5f9e57d9547fa0a
e6649d1f10dea8ffdd63588dd159449574a705ba
v1.0
instruct
Apps
Apps_18598_I
You are tasked to help a team of archaeologists who have found a sequence of ancient artifacts. The artifacts are arranged in a line and each artifact has a unique identifier, represented by an integer. The archaeologists are interested in finding out if there is a beautiful segment in the sequence. A beautiful segment...
def is_beautiful_segment(artifact_ids): seen = set() for artifact_id in artifact_ids: if artifact_id in seen: return "Not Beautiful" seen.add(artifact_id) return "Beautiful" def evaluate_cases(test_cases): results = [] for i in range(0, len(test_cases), 2): # Ski...
from solution import process_input def test_single_beautiful(): input_str = '1\n5\n1 2 3 4 5' expected_output = ['Beautiful'] assert process_input(input_str) == expected_output def test_single_not_beautiful(): input_str = '1\n5\n1 2 2 3 4' expected_output = ['Not Beautiful'] assert process_inp...
[ { "docstring": null, "function_declaration": "def is_beautiful_segment(artifact_ids):", "function_name": "is_beautiful_segment", "parameter_list": "(artifact_ids)" }, { "docstring": null, "function_declaration": "def evaluate_cases(test_cases):", "function_name": "evaluate_cases", ...
[ 0, 0, 0, 1, 1, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_beautiful_segment(num_cases, cases):\n \"\"\"\n Determines if there's at least one beautiful segment in the sequence for each test case.\n \"\"\"\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018598", "row_id": 18598, "seed_ids": "[684]" }
0.683831
Apps_18598
I
[ "is_beautiful_segment", "evaluate_cases", "process_input" ]
3
[ [ "evaluate_cases", "is_beautiful_segment" ], [ "process_input", "evaluate_cases" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
2bf6c9cae566978edecefb089b1b339a70b9b900
a02b63fd23fef1f56c9651d9e19b48020c611eb7
v1.0
instruct
Apps
Apps_18621_I
You are given a list of integers `tasks` where each integer represents the amount of time a task takes to complete, and an integer `T` which represents the total number of time slots available. Each time slot can accommodate one or more tasks, but the total duration of tasks assigned to any single time slot should not ...
def canComplete(tasks, T, maxTime): current_slot_time = 0 slots_used = 1 for task in tasks: if current_slot_time + task <= maxTime: current_slot_time += task else: slots_used += 1 current_slot_time = task if slots_used > T: ...
from solution import minRequiredMaxTime def test_example1(): tasks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] T = 5 assert minRequiredMaxTime(tasks, T) == 15 def test_example2(): tasks = [3, 2, 2, 4, 1, 4] T = 3 assert minRequiredMaxTime(tasks, T) == 6 def test_example3(): tasks = [1, 2, 3, 1, 1] ...
[ { "docstring": null, "function_declaration": "def canComplete(tasks, T, maxTime):", "function_name": "canComplete", "parameter_list": "(tasks, T, maxTime)" }, { "docstring": null, "function_declaration": "def minRequiredMaxTime(tasks, T):", "function_name": "minRequiredMaxTime", ...
[ 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_complete(tasks, T, maxTime):\n time_slots = 1\n current_time_in_slot = 0\n \n for task in tasks:\n if current_time_in_slot + task <= maxT...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018621", "row_id": 18621, "seed_ids": "[360]" }
0.698087
Apps_18621
I
[ "canComplete", "minRequiredMaxTime" ]
2
[ [ "minRequiredMaxTime", "canComplete" ] ]
1
[]
false
[]
false
pytest
true
[]
true
af5d3564fb21f5b73788790e8bc7c195dc16f776
dfd202b56ebec4c56d842598b8f4e530f77c8200
v1.0
instruct
Apps
Apps_18658_I
Riya loves prime numbers and she is fascinated by their properties. Her latest interest is in twin primes. Twin primes are pairs of prime numbers that have a gap of two between them (for example, (3, 5), (11, 13), etc.). She comes up with a task where you are given a list of numbers and need to find out if it contains ...
def is_prime(n): """ Check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def find_twin_primes(numbers): ...
def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-5) == False assert is_prime(19) == True def test_find_twin_primes(): assert fin...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find and return all pairs of twin primes in the given list of numbers.", "function_declaration": "def find_twin_primes(numbers...
[ 1, 0, 0, 0, 1, 0, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018658", "row_id": 18658, "seed_ids": "[682]" }
0.740632
Apps_18658
I
[ "is_prime", "find_twin_primes", "process_twin_primes_output" ]
3
[ [ "find_twin_primes", "is_prime" ], [ "process_twin_primes_output", "find_twin_primes" ] ]
2
[]
false
[]
false
pytest
false
[]
true
dfda69c98fad172dd060264056bb257bb2148331
0d5fa93623c1b06d9b3cca6566a95ee515a5caab
v1.0
instruct
Apps
Apps_18709_I
Mark is participating in a driving simulation challenge where he has to drive through a grid of size NxM. Each cell in this grid contains a certain fuel cost. He starts at the top-left corner of the grid and must reach the bottom-right corner. However, he's only allowed to move right or down at each step. If he starts ...
def min_fuel_needed(grid, N, M): """ Returns the minimum fuel needed to reach the bottom-right corner of the grid. If it's impossible, returns -1. """ dp = [[float('inf')] * M for _ in range(N)] dp[0][0] = grid[0][0] for i in range(N): for j in range(M): if i > 0: ...
def test_min_fuel_needed(): grid = [ [3, 4, 1], [2, 8, 3], [6, 2, 1] ] assert min_fuel_needed(grid, 3, 3) == 12 def test_driving_simulation_possible(): grid = [ [3, 4, 1], [2, 8, 3], [6, 2, 1] ] assert driving_simulation(3, 3, 15, grid) == 12 def...
[ { "docstring": "Returns the minimum fuel needed to reach the bottom-right corner of the grid.\nIf it's impossible, returns -1.", "function_declaration": "def min_fuel_needed(grid, N, M):", "function_name": "min_fuel_needed", "parameter_list": "(grid, N, M)" }, { "docstring": null, "funct...
[ 0, 0, 0, 1, 0, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_fuel_cost_to_reach_destination(N, M, F, grid):\n \"\"\"\n Finds the minimum fuel cost to reach the bottom-right corner of the grid.\n If the minimu...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018709", "row_id": 18709, "seed_ids": "[811]" }
0.653967
Apps_18709
I
[ "min_fuel_needed", "driving_simulation" ]
2
[ [ "driving_simulation", "min_fuel_needed" ] ]
1
[]
false
[]
false
pytest
false
[]
true
ad6c40f14d34a2d306a341e33ffee3b159ffd4ee
465a17f9b765744c032606ccee75a0f87852e423
v1.0
instruct
Apps
Apps_18751_I
Given a list of positive integers, write a function that returns a list of the integers that are prime numbers. A prime number is defined as a positive integer greater than 1 that has no positive integer divisors other than 1 and itself. ### Input - An integer `n` (1 <= n <= 10000), representing the number of elemen...
from typing import List def is_prime(num: int) -> bool: """ Returns True if num is a prime number, otherwise False. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num ** 0.5) + 1, 2): if num % i == 0...
from solution import find_prime_numbers def test_find_prime_numbers_with_example_data(): assert find_prime_numbers(5, [2, 4, 6, 5, 7]) == [2, 5, 7] assert find_prime_numbers(3, [4, 6, 8]) == [] def test_find_prime_numbers_all_primes(): assert find_prime_numbers(4, [2, 3, 5, 7]) == [2, 3, 5, 7] def test_f...
[ { "docstring": "Returns True if num is a prime number, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime numbers from the given list of numbers.", "function_declaration": "def...
[ 0, 0, 0, 1, 1, 1, 0, 1, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(number: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if number <= 1:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018751", "row_id": 18751, "seed_ids": "[3182]" }
0.73726
Apps_18751
I
[ "is_prime", "find_prime_numbers" ]
2
[ [ "find_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92002f31bcd36f7e4bb33d2d9ee34843a6f91145
9d4e11c3a69434336708d8236d00af6613fe855b
v1.0
instruct
Apps
Apps_18769_I
In a city, there are m landmarks and n roads connecting them. Each landmark has a unique positive integer ID. The roads are bidirectional and each has a specific travel time associated with it. You are given the IDs of K landmarks that are considered special. A special landmark is defined as one that is of significant ...
import heapq from itertools import permutations def dijkstra(graph, start): """ Returns the shortest distance from start to all other nodes using Dijkstra's algorithm. """ min_heap = [(0, start)] # (distance, vertex) distances = {node: float('inf') for node in graph} distances[start] = 0 w...
def test_shortest_travel_time(): m, n = 5, 7 roads = [ (1, 2, 3), (1, 3, 1), (1, 4, 6), (2, 3, 1), (2, 5, 2), (3, 5, 5), (4, 5, 2), ] K = 3 special_landmarks = [1, 3, 5] assert shortest_travel_time(m, n, roads, K, special_landmarks) == 8 d...
[ { "docstring": "Returns the shortest distance from start to all other nodes using Dijkstra's algorithm.", "function_declaration": "def dijkstra(graph, start):", "function_name": "dijkstra", "parameter_list": "(graph, start)" }, { "docstring": null, "function_declaration": "def shortest_t...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nimport sys\nfrom itertools import permutations\n\ndef shortest_travel_time(m, n, roads, K, special_landmarks):\n # Build graph (Adjacency list) wit...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00018769", "row_id": 18769, "seed_ids": "[4162]" }
0.771201
Apps_18769
I
[ "dijkstra", "shortest_travel_time" ]
2
[ [ "shortest_travel_time", "dijkstra" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c978ede0f1f928a6193b70ffd1c3c0a25019ede8
89167d6abe33512c692bf3f3999508b6dd4943e3
v1.0
instruct
Apps
Apps_18815_I
Given an integer array nums, return the largest number you can form by concatenating its elements. The result should be in string format. Example 1: Input: [10, 2] Output: "210" Explanation: Concatenating all the numbers in the array in different orders will yield: "102", "210". The largest number is "210". Example...
from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_number(nums): """ Returns the largest number that can be formed by concatenating the elements of nums. """ # Convert numbers to st...
from solution import largest_number def test_example_1(): assert largest_number([10, 2]) == "210" def test_example_2(): assert largest_number([3, 30, 34, 5, 9]) == "9534330" def test_single_element(): assert largest_number([1]) == "1" assert largest_number([10]) == "10" def test_repeated_elements():...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Returns the largest number that can be formed by concatenating the elements of nums.", "function_declaration": "def largest_number(nums):", "fu...
[ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef largestNumber(nums):\n \"\"\"\n Returns the largest number that can be formed by concatenating the elements of the arr...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00018815", "row_id": 18815, "seed_ids": "[1822]" }
0.680325
Apps_18815
I
[ "compare", "largest_number" ]
2
[ [ "largest_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ec488b6a84516a93e1469c29f004f23261fb961c
700e09c201a20c08dd468a5b4097a4afdeb39345
v1.0
instruct
Apps
Apps_18820_I
In a zoo, there are `n` cages arranged in a line, each containing a different species of animal. You have been tasked with determining the maximum possible number of pairs of adjacent animals that can be of the same species after performing the following operation: - You can swap any two animals, but only once. Writ...
from typing import List def count_adjacent_pairs(animals: List[int]) -> int: count = 0 for i in range(1, len(animals)): if animals[i] == animals[i - 1]: count += 1 return count def max_adjacent_pairs(animals: List[int]) -> int: n = len(animals) if n < 2: return 0 ...
from solution import max_adjacent_pairs def test_example_1(): assert max_adjacent_pairs([1, 2, 3, 3, 2, 1]) == 3 def test_all_same_species(): assert max_adjacent_pairs([1, 1, 1, 1]) == 3 def test_no_pair_possible(): assert max_adjacent_pairs([1, 2, 3, 4]) == 0 def test_two_elements(): assert max_adj...
[ { "docstring": null, "function_declaration": "def count_adjacent_pairs(animals):", "function_name": "count_adjacent_pairs", "parameter_list": "(animals)" }, { "docstring": null, "function_declaration": "def max_adjacent_pairs(animals):", "function_name": "max_adjacent_pairs", "pa...
[ 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_adjacent_pairs(animals):\n \"\"\"\n Returns the maximum number of pairs of adjacent animals that can be of the same species after \n performing at ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00018820", "row_id": 18820, "seed_ids": "[4162]" }
0.607202
Apps_18820
I
[ "count_adjacent_pairs", "max_adjacent_pairs" ]
2
[ [ "max_adjacent_pairs", "count_adjacent_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
419372eef545083bc8dadefe4f636e1df6614627
7abea06e5e91f6c60a8125ac89d03ff0c6af6b11
v1.0
instruct
Apps
Apps_18843_I
Write a function to generate all possible valid IP addresses from a given string of digits. A valid IP address consists of exactly four integers (each ranging from 0 to 255) separated by periods. The integers cannot have leading zeros. For example, "25525511135" can be interpreted as the IP addresses "255.255.11.135" a...
from typing import List def is_valid(segment: str) -> bool: """ Check if the given string segment is a valid IP address segment. """ if len(segment) == 0 or len(segment) > 3: return False if segment[0] == '0' and len(segment) > 1: return False if int(segment) > 255: retu...
from solution import generate_ip_addresses def test_generate_ip_addresses_example_1(): assert generate_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"] def test_generate_ip_addresses_example_2(): assert generate_ip_addresses("0000") == ["0.0.0.0"] def test_generate_ip_addresses_example_3()...
[ { "docstring": "Check if the given string segment is a valid IP address segment.", "function_declaration": "def is_valid(segment):", "function_name": "is_valid", "parameter_list": "(segment)" }, { "docstring": "Generate all possible valid IP addresses from a given string.", "function_dec...
[ 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef generate_ip_addresses(s: str) -> List[str]:\n def is_valid(segment):\n return int(segment) <= 255 if segment[0] != '0' else...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018843", "row_id": 18843, "seed_ids": "[3073]" }
0.618323
Apps_18843
I
[ "is_valid", "generate_ip_addresses" ]
2
[ [ "generate_ip_addresses", "is_valid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
453a37eb906b96118b4d6ff333ba144e71e79a24
08724856463b820f02d34196608efb9de4894a7b
v1.0
instruct
Apps
Apps_18857_I
## Task Write a function that takes a positive integer `n` and returns a list of all its divisors that are also prime numbers. The list should be sorted in ascending order. ## Example ```python divisors(28) -> [2, 7] divisors(30) -> [2, 3, 5] divisors(17) -> [17] divisors(1) -> [] divisors(77) -> [7, 11] ``` ## Const...
def is_prime(num): """ Helper function to check if a number is prime """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True def di...
from solution import divisors def test_divisors_case1(): assert divisors(28) == [2, 7] def test_divisors_case2(): assert divisors(30) == [2, 3, 5] def test_divisors_case3(): assert divisors(17) == [17] def test_divisors_case4(): assert divisors(1) == [] def test_divisors_case5(): assert divisor...
[ { "docstring": "Helper function to check if a number is prime", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of prime divisors of the given number n.", "function_declaration": "def divisors(n):", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(num: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num < 2:\n ret...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00018857", "row_id": 18857, "seed_ids": "[3815]" }
0.718349
Apps_18857
I
[ "is_prime", "divisors" ]
2
[ [ "divisors", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
46963efd686f8a5ca0bc95000254c31267558249
de94dfe678cc8e973c593053800c2db5dcaf1c78
v1.0
instruct
Apps
Apps_18899_I
George is trying to understand the concept of prime numbers and their product. He came up with a challenge to find the product of all prime numbers less than or equal to a given number $N$. Since the product can be very large, the result should be given modulo 1000000007 ($10^9+7$). Can you help George with this challe...
def sieve_of_eratosthenes(max_num): """Generate a list of primes up to max_num using the Sieve of Eratosthenes.""" is_prime = [True] * (max_num + 1) p = 2 while (p * p <= max_num): if is_prime[p]: for i in range(p * p, max_num + 1, p): is_prime[i] = False p +=...
from solution import product_of_primes, sieve_of_eratosthenes, solve def test_sieve_of_eratosthenes(): assert sieve_of_eratosthenes(10) == [2, 3, 5, 7] assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19] def test_product_of_primes(): assert product_of_primes(10) == 210 # 2 * 3 * 5 * 7 = 210 ...
[ { "docstring": "Generate a list of primes up to max_num using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(max_num):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_num)" }, { "docstring": null, "function_declaration": "def product_o...
[ 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve(limit):\n primes = []\n is_prime = [True] * (limit + 1)\n is_prime[0] = is_prime[1] = False\n \n for num in range(2, limit + 1):\n i...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00018899", "row_id": 18899, "seed_ids": "[1555]" }
0.610804
Apps_18899
I
[ "sieve_of_eratosthenes", "product_of_primes", "solve" ]
3
[ [ "product_of_primes", "sieve_of_eratosthenes" ], [ "solve", "product_of_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7f1498b4cf390808b18f538b2c4fb9dc21256788
96be6e7330c231c40c9385551b58c9122da11ff3
v1.0
instruct
Apps
Apps_18942_I
=====Problem Statement===== XYZ University is conducting an online examination for its students. As part of the test system, the university needs to validate the submission timestamps of the test answers. Each submission timestamp must follow the rules below: It should be exactly 19 characters long. It must follow th...
import datetime def is_leap_year(year): """ Returns True if the given year is a leap year, otherwise False. """ return (year % 4 == 0) and (year % 100 != 0 or year % 400 == 0) def validate_timestamp(timestamp): """ Validates the format and values of the given timestamp. """ if len(time...
from solution import validate_timestamps def test_valid_timestamps(): timestamps = [ "2020-02-29 12:45:59", # Valid leap year and date "2016-12-31 23:59:59", # Valid date and time "2000-02-29 00:00:00" # Valid leap year ] results = validate_timestamps(timestamps) assert resu...
[ { "docstring": "Returns True if the given year is a leap year, otherwise False.", "function_declaration": "def is_leap_year(year):", "function_name": "is_leap_year", "parameter_list": "(year)" }, { "docstring": "Validates the format and values of the given timestamp.", "function_declarat...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\nfrom datetime import datetime\n\ndef is_leap_year(year):\n return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)\n\ndef validate_timestamp(t...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00018942", "row_id": 18942, "seed_ids": "[2618]" }
0.608344
Apps_18942
I
[ "is_leap_year", "validate_timestamp", "validate_timestamps" ]
3
[ [ "validate_timestamp", "is_leap_year" ], [ "validate_timestamps", "validate_timestamp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3a975765feb96434b08ffc27a0129fc02e421f6b
b8f954f832a834875bdb28f83c8f2cbcbed5c947
v1.0
instruct
Apps
Apps_19018_I
A well-known problem in competitive programming is to partition an array into `k` contiguous subarrays such that the max sum of the subarrays is minimized. Let's define a problem around this concept. You are given an array `A` of `N` integers. You are also given an integer `k`. Your task is to partition the array int...
def can_partition(nums, max_sum, k): subarray_sum, subarray_count = 0, 1 for num in nums: if subarray_sum + num > max_sum: subarray_sum = num subarray_count += 1 if subarray_count > k: return False else: subarray_sum += num retu...
from solution import partition_and_find_min_max_sum def test_single_case(): T = 1 test_cases = [ [(7, 3), [7, 2, 5, 10, 8]], ] assert partition_and_find_min_max_sum(T, test_cases) == [14] def test_multiple_cases(): T = 2 test_cases = [ [(7, 3), [7, 2, 5, 10, 8]], [(5, 2...
[ { "docstring": null, "function_declaration": "def can_partition(nums, max_sum, k):", "function_name": "can_partition", "parameter_list": "(nums, max_sum, k)" }, { "docstring": null, "function_declaration": "def min_max_subarray_sum(nums, k):", "function_name": "min_max_subarray_sum",...
[ 0, 1, 1, 0, 0, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimize_max_sum(A, k):\n def can_partition(max_sum):\n current_sum = 0\n required_subarrays = 1\n for num in A:\n if current...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019018", "row_id": 19018, "seed_ids": "[901]" }
0.745701
Apps_19018
I
[ "can_partition", "min_max_subarray_sum", "partition_and_find_min_max_sum" ]
3
[ [ "min_max_subarray_sum", "can_partition" ], [ "partition_and_find_min_max_sum", "min_max_subarray_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6558c295e937003a476262c90c5597e0ae5525c8
6fed2d4017e013c1195c91bf05a17efc99d2919c
v1.0
instruct
Apps
Apps_19077_I
A fraudulent activity detection system is being created to detect anomalies in a sequence of transactions. Given an array of integers representing the daily expenditures for a client, the system needs to find out how many notifications were sent for a potential fraudulent activity. A notification is sent if the current...
from bisect import insort, bisect_left def median(data, d): k = d // 2 if d % 2 == 0: return (data[k-1] + data[k]) / 2 else: return data[k] def count_notifications(exp, d): cnt = 0 trailing = sorted(exp[:d]) for i in range(d, len(exp)): med = median(trailing, d...
from solution import solve def test_single_case(): T = 1 test_cases = [ (9, 5, [2, 3, 4, 2, 3, 6, 8, 4, 5]) ] assert solve(T, test_cases) == [2] def test_multiple_cases(): T = 2 test_cases = [ (9, 5, [2, 3, 4, 2, 3, 6, 8, 4, 5]), (5, 2, [1, 2, 3, 4, 5]) ] assert...
[ { "docstring": null, "function_declaration": "def median(data, d):", "function_name": "median", "parameter_list": "(data, d)" }, { "docstring": null, "function_declaration": "def count_notifications(exp, d):", "function_name": "count_notifications", "parameter_list": "(exp, d)" ...
[ 0, 1, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from bisect import insort, bisect_left\n\ndef find_median(trailing, d):\n if d % 2 == 1:\n return trailing[d // 2]\n else:\n return (trailing[d ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019077", "row_id": 19077, "seed_ids": "[550]" }
0.59124
Apps_19077
I
[ "median", "count_notifications", "solve" ]
3
[ [ "count_notifications", "median" ], [ "solve", "count_notifications" ] ]
2
[]
false
[]
false
pytest
true
[]
true
53b3f42b70a699b40640ba405809d079f51fc51b
fe5ca5a5b65e1cc0d87419d738e3820af6fd854b
v1.0
instruct
Apps
Apps_19208_I
You are given two linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. Each number does not contain any leading zero, except the number 0 itself. For example, consider the n...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def add_two_numbers(l1, l2): dummy = ListNode() current = dummy carry = 0 while l1 or l2 or carry: val1 = l1.val if l1 else 0 val2 = l2.val if l2 else 0 carry, out = di...
from solution import add_two_numbers, list_to_linkedlist, linkedlist_to_list, sum_linkedlists_linkedlist_format def test_add_two_numbers(): l1 = list_to_linkedlist([2, 4, 3]) l2 = list_to_linkedlist([5, 6, 4]) result = add_two_numbers(l1, l2) assert linkedlist_to_list(result) == [7, 0, 8] l1 = lis...
[]
[ 1, 0, 1, 1, 1, 1, 1, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, x):\n self.val = x\n self.next = None\n\ndef addTwoNumbers(l1, l2):\n \"\"\"\n Returns the sum of two li...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019208", "row_id": 19208, "seed_ids": "[2397]" }
0.580455
Apps_19208
I
[ "add_two_numbers", "list_to_linkedlist", "linkedlist_to_list", "sum_linkedlists_linkedlist_format" ]
4
[ [ "sum_linkedlists_linkedlist_format", "add_two_numbers" ], [ "sum_linkedlists_linkedlist_format", "linkedlist_to_list" ], [ "sum_linkedlists_linkedlist_format", "list_to_linkedlist" ] ]
3
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
12ca1560643e801725d94016834d3dfa46b93698
962e7ec40e274146d58594d83d18cc0f6a1a5875
v1.0
instruct
Apps
Apps_19251_I
You are given a binary tree consisting of N nodes numbered from 1 to N. Each node has a value associated with it. You need to determine the maximum sum of values that can be obtained from a path that starts at any node and ends at any node. You must not revisit any node along this path. -----Input----- - The first lin...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def max_path_sum(root): def helper(node): nonlocal max_sum if not node: return 0 left_max = max(helper(node.left), 0) right_ma...
from solution import max_sum_on_path def test_case_1(): T = 1 test_cases = [ (5, [-10, 20, -30, 40, -50], [(1, 2), (1, 3), (2, 4), (2, 5)]) ] assert max_sum_on_path(T, test_cases) == [60] def test_case_2(): T = 1 test_cases = [ (3, [1, 2, 3], [(1, 2), (1, 3)]) ] assert ...
[]
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\n\ndef max_path_sum(tree_values, tree_edges):\n def dfs(node, parent):\n nonlocal max_sum\n max_child_sum = 0\n...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019251", "row_id": 19251, "seed_ids": "[701]" }
0.720754
Apps_19251
I
[ "max_path_sum", "build_tree", "max_sum_on_path" ]
3
[ [ "max_sum_on_path", "build_tree" ], [ "max_sum_on_path", "max_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e9ab65a697d469644325dd78264252ddcaa67859
ad9cdb038de9fb35371172cb872ecd262c67a73f
v1.0
instruct
Apps
Apps_19334_I
----- PERFECT BALANCE ----- Anna loves collecting weights. She has a collection of weights and she's always interested in balancing them perfectly on a scale. A weight collection is balanced if the sum of weights on the left side of the scale is equal to the sum on the right. Anna can put any number of weights on each...
def can_be_balanced(weights): """ Determines if a collection of weights can be split into two groups with equal sum. """ total_sum = sum(weights) # If total sum is odd, it can't be split into two equal parts if total_sum % 2 != 0: return False target = total_sum // 2 n = len(wei...
from solution import perfect_balance def test_case_1(): input_data = "2\n4\n1 5 11 5\n3\n1 2 5" assert perfect_balance(input_data) == ["YES", "NO"] def test_case_2(): input_data = "1\n5\n3 1 4 2 2" assert perfect_balance(input_data) == ["YES"] def test_case_3(): input_data = "1\n3\n1 2 4" ass...
[ { "docstring": "Determines if a collection of weights can be split into two groups with equal sum.", "function_declaration": "def can_be_balanced(weights):", "function_name": "can_be_balanced", "parameter_list": "(weights)" }, { "docstring": null, "function_declaration": "def process_tes...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_be_perfectly_balanced(weights):\n total_sum = sum(weights)\n # If the total sum is odd, it can't be perfectly balanced\n if total_sum % 2 != 0:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019334", "row_id": 19334, "seed_ids": "[1066]" }
0.625296
Apps_19334
I
[ "can_be_balanced", "process_test_cases", "perfect_balance" ]
3
[ [ "perfect_balance", "process_test_cases" ], [ "process_test_cases", "can_be_balanced" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
fbeca8070f03faae13455cea4f4daf3570467fda
99268c281fbab25b48cb16ab1f9d4837707b2434
v1.0
instruct
Apps
Apps_19393_I
In a card game, each card has a numerical value from 1 to 13 and belongs to one of four suits: Spades, Hearts, Diamonds, Clubs. You are given a deck of cards as a list of tuples where each tuple represents a card with a value and a suit. For example: ```python deck = [(3, "Hearts"), (12, "Spades"), (7, "Diamonds"), (1...
from collections import defaultdict from typing import List, Tuple def can_form_straight_flush(deck: List[Tuple[int, str]]) -> str: # Organize cards by suit suits = defaultdict(list) for value, suit in deck: suits[suit].append(value) # Check each suit for possible straight flush for ca...
from solution import can_form_straight_flush def test_can_form_straight_flush_found(): deck = [(3, "Hearts"), (4, "Hearts"), (5, "Hearts"), (6, "Hearts"), (7, "Hearts"), (9, "Diamonds"), (12, "Spades")] assert can_form_straight_flush(deck) == "Straight Flush Found!" def test_can_form_straight_flush_not_found(...
[ { "docstring": null, "function_declaration": "def can_form_straight_flush(deck):", "function_name": "can_form_straight_flush", "parameter_list": "(deck)" }, { "docstring": null, "function_declaration": "def has_straight(cards):", "function_name": "has_straight", "parameter_list":...
[ 0, 0, 1, 0, 0, 1, 1, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\nfrom collections import defaultdict\n\ndef can_form_straight_flush(deck):\n def is_straight(cards):\n sorted_cards = s...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019393", "row_id": 19393, "seed_ids": "[3060]" }
0.651846
Apps_19393
I
[ "can_form_straight_flush", "has_straight" ]
2
[ [ "can_form_straight_flush", "has_straight" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1248dc73b73c4945d92a5baa63cd56b01ddfaaec
fcba4126ee5ae1dcb75f4f9ec3fd501a7e148e94
v1.0
instruct
Apps
Apps_19406_I
In a binary tree, each node contains an integer value. You are to determine the maximum sum of node values from any leaf node to the root node. Given such a binary tree, the path must start at a leaf node and end at the root node. A leaf node is defined as a node with no children. -----Input----- - The first line cont...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nodes): tree_nodes = [None] + [TreeNode(val=x[0]) for x in nodes] # create a list of nodes for i, (v, l, r) in enumerate(nodes, start=1): if l...
import pytest from solution import max_sum_path def test_max_sum_path(): nodes = [ (1, 2, 3), # Node 1 with children 2 and 3 (2, -1, -1), # Node 2 is a leaf (3, 4, -1), # Node 3 with left child 4 (4, 5, -1), # Node 4 with left child 5 (5, -1, -1) # Node 5 is a leaf...
[]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(node_descriptions...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019406", "row_id": 19406, "seed_ids": "[1414]" }
0.718515
Apps_19406
I
[ "build_tree", "max_sum_leaf_to_root", "max_sum_path" ]
3
[ [ "max_sum_path", "build_tree" ], [ "max_sum_path", "max_sum_leaf_to_root" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
d8a4e79d9bb258ccac60176cc1e3a8f9507fe9e3
1550e9f8bff89104ac1be02645f00ec56e538564
v1.0
instruct
Apps
Apps_19438_I
## Overview Palindromes are numbers or phrases that read the same backward as forward (ignoring spaces, punctuation, and capitalization). This task focuses on palindromic numbers. ## Palindromic Primes A palindromic prime is a prime number that is also a palindrome. For example, 131 is a palindromic prime because it ...
def is_prime(num): """ Check if a number is a prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
from solution import is_prime, is_palindrome, smallest_palindromic_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(11) == True def test_is_palindrome(): assert is_palindrome(121) == True ...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Check if a number is a palindrome.", "function_declaration": "def is_palindrome(num):", "function_name": "is_palindr...
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num < 2:\n return False\n if num == 2 or num == 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return F...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019438", "row_id": 19438, "seed_ids": "[3498]" }
0.752033
Apps_19438
I
[ "is_prime", "is_palindrome", "smallest_palindromic_prime" ]
3
[ [ "smallest_palindromic_prime", "is_palindrome" ], [ "smallest_palindromic_prime", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ea091bb7ea2c601ac6e36f695f3a45e56f68215b
161e8adea0b6ede7ce497fcd3d4cef051196d4cf
v1.0
instruct
Apps
Apps_19500_I
----- PRIME POSITION ----- Chef is intrigued by prime numbers and their positions. He considers a number to be interesting if it lies in a position which is a prime number and the number itself is also a prime number in a given array. You are given an array, and your task is to find whether each number in the array ...
def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False max_divisor = int(num ** 0.5) + 1 for divisor in range(3, max_divisor, 2): if num % divisor == 0: return False return True def prime_positions_are_prim...
from solution import main def test_example(): input_str = "1\n6\n2 3 5 7 11 13\n" assert main(input_str) == "YES" def test_no_prime_positions_are_prime(): input_str = "1\n6\n4 6 8 12 18 22\n" assert main(input_str) == "NO" def test_some_prime_positions_are_not_prime(): input_str = "1\n6\n2 3 4 7 ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def prime_positions_are_primes(arr):", "function_name": "prime_positions_are_primes", "parameter_list": "(arr...
[ 0, 0, 0, 1, 0, 1, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n p = 3\n while p * p <=...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00019500", "row_id": 19500, "seed_ids": "[1066]" }
0.653401
Apps_19500
I
[ "is_prime", "prime_positions_are_primes", "process_test_cases", "main" ]
4
[ [ "prime_positions_are_primes", "is_prime" ], [ "process_test_cases", "prime_positions_are_primes" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
9b7386f99ecce73a2da135e59587f2a3b1bc455c
806e390814e92d17754c2ec0896886609f94e270
v1.0
instruct
Apps
Apps_19573_I
A secret missionary mission requires decoding a sequence of shield activation codes embedded within a specific number pattern. The codes are generated by a numerical sequence that follows a special property: every even-indexed number (starting from index 1) in the sequence is the sum of the number in the previous odd i...
def digital_root(n): """ Returns the digital root of a number. """ while n >= 10: n = sum(int(digit) for digit in str(n)) return n def shield_activation_code(N, K): """ Returns the K-th number in the sequence starting from N. """ sequence = [N] for i in range(1, K):...
from solution import digital_root, shield_activation_code, format_shield_activation_code def test_digital_root(): assert digital_root(678) == 3 assert digital_root(12345) == 6 assert digital_root(9) == 9 assert digital_root(99999) == 9 def test_shield_activation_code(): assert shield_activation_co...
[ { "docstring": "Returns the digital root of a number.", "function_declaration": "def digital_root(n):", "function_name": "digital_root", "parameter_list": "(n)" }, { "docstring": "Returns the K-th number in the sequence starting from N.", "function_declaration": "def shield_activation_co...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def digital_root(num):\n while num >= 10:\n num = sum(int(digit) for digit in str(num))\n return num\n\ndef shield_activation_code(N, K):\n sequence...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00019573", "row_id": 19573, "seed_ids": "[1475]" }
0.579847
Apps_19573
I
[ "digital_root", "shield_activation_code", "format_shield_activation_code" ]
3
[ [ "format_shield_activation_code", "shield_activation_code" ], [ "shield_activation_code", "digital_root" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d9d499873cf71c041ca2406880f6250bc6e02d8d
406625e09bae01bc568843c69364106661383e19
v1.0
instruct
Apps
Apps_19585_I
## **Instructions** You are tasked to write a function that takes in an array of positive integers and returns an object (or dictionary) that categorizes each input number into `prime`, `composite`, or `neither`. 1. **Prime numbers:** Numbers greater than 1 that have only two divisors: 1 and themselves. 2. **Composit...
from math import isqrt def is_prime(n): """ Helper function to determine if a number is prime. Returns True if the number is prime, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i...
from solution import categorize_numbers def test_numbers_mixed_categories(): result = categorize_numbers([2, 3, 4, 5, 1, 0, 15, 23, 25]) assert result == { 'prime': [2, 3, 5, 23], 'composite': [4, 15, 25], 'neither': [1, 0] } def test_composite_only(): result = categorize_numbe...
[ { "docstring": "Helper function to determine if a number is prime.\nReturns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Categorizes numbers into prime, composite, or neithe...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import isqrt\n\ndef is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n Returns True if the number is prime, otherwise F...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00019585", "row_id": 19585, "seed_ids": "[4996]" }
0.587662
Apps_19585
I
[ "is_prime", "categorize_numbers" ]
2
[ [ "categorize_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ca105921ff4cb8d6df07353d1a3e83905f7fce4e
78ae8ce2a82a6c6a0b7e0988f66c3d83cbe2c953
v1.0
instruct
Apps
Apps_19607_I
A city has a system of one-way roads connecting various junctions. Your task is to determine the shortest path from a specific starting junction to a specific destination junction. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The first line of each test case cont...
import heapq def dijkstra(n, graph, start): distances = {i: float("inf") for i in range(1, n + 1)} distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if current_distance > distances[curren...
def test_example_case(): input_data = """1 5 6 3 1 2 10 2 3 5 3 4 3 4 5 2 1 3 20 2 5 15 1 5 2 4 4 2""" expected_output = [20, 8, -1] assert solve_city_roads(input_data) == expected_output def test_no_path(): input_data = """1 3 2 1 1 2 5 2 3 10 1 3""" expected_output = [15] assert solve_city_ro...
[ { "docstring": null, "function_declaration": "def dijkstra(n, graph, start):", "function_name": "dijkstra", "parameter_list": "(n, graph, start)" }, { "docstring": null, "function_declaration": "def shortest_paths(test_cases):", "function_name": "shortest_paths", "parameter_list"...
[ 0, 1, 1, 0, 0, 1, 1, 1, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef dijkstra(n, adj, start):\n \"\"\"\n Function to perform Dijkstra's algorithm to find shortest paths from the start node.\n \"\"\"\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00019607", "row_id": 19607, "seed_ids": "[1275]" }
0.795715
Apps_19607
I
[ "dijkstra", "shortest_paths", "solve_city_roads" ]
3
[ [ "shortest_paths", "dijkstra" ], [ "solve_city_roads", "shortest_paths" ] ]
2
[]
false
[]
false
pytest
false
[]
true
6e1c45f4dad6d55be81ca8ec76299e4ae2307bc3
34ead6804e902338ed95c931d5e2739dd6fd7b0d
v1.0
instruct
Apps
Apps_19644_I
A tech company has a new method for password validation. A password is considered valid if it satisfies the following conditions: - It must contain at least one uppercase letter (A to Z). - It must contain at least one lowercase letter (a to z). - It must contain at least one digit (0 to 9). - It must contain at least...
def is_valid_password(password): """ Returns "VALID" if the password meets the given criteria, otherwise "INVALID". """ if len(password) < 8: return "INVALID" has_upper = False has_lower = False has_digit = False has_special = False special_characters = {'$', '!', '#', '%', ...
import pytest from solution import is_valid_password, validate_passwords def test_is_valid_password(): assert is_valid_password("StrongPass1!") == "VALID" assert is_valid_password("weakpass") == "INVALID" assert is_valid_password("12345678!") == "INVALID" assert is_valid_password("Valid_One1") == "VALI...
[ { "docstring": "Returns \"VALID\" if the password meets the given criteria, otherwise \"INVALID\".", "function_declaration": "def is_valid_password(password):", "function_name": "is_valid_password", "parameter_list": "(password)" }, { "docstring": null, "function_declaration": "def valid...
[ 0, 1, 1, 1, 0, 0, 1, 1, 1, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_password(password):\n \"\"\"\n Check if a password is valid based on the given criteria.\n \"\"\"\n if len(password) < 8:\n return '...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019644", "row_id": 19644, "seed_ids": "[2311]" }
0.633302
Apps_19644
I
[ "is_valid_password", "validate_passwords" ]
2
[ [ "validate_passwords", "is_valid_password" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7db87b5911641c55259ff69caf2242401cb6fc91
c75b9fc4baa24da02e00b1e6494a148746d50de7
v1.0
instruct
Apps
Apps_19727_I
Your task is to write a function named `map_letters_to_primes` that receives a single string argument. This string will consist of multiple words separated by spaces. Each word contains only alphabetical characters and no punctuation. The function should map each letter in the alphabet to a unique prime number, starti...
def map_letters_to_primes(text): """ Maps each letter in the input text to a unique prime number and computes the product for each word. Parameters: text (str): A string consisting of words separated by spaces. Returns: List[int]: A list of products for each word in the input string. ...
from solution import map_letters_to_primes def test_map_letters_to_primes_single_word(): assert map_letters_to_primes("cat") == [710] def test_map_letters_to_primes_multiple_words(): assert map_letters_to_primes("bat cat dog") == [426, 710, 5593] def test_map_letters_to_primes_with_repeated_letters(): as...
[ { "docstring": "Maps each letter in the input text to a unique prime number and computes the product for each word.\n\nParameters:\ntext (str): A string consisting of words separated by spaces.\n\nReturns:\nList[int]: A list of products for each word in the input string.", "function_declaration": "def map_l...
[ 0, 0, 1, 0, 0, 1, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def map_letters_to_primes(sentence):\n \"\"\"\n Maps each letter in the alphabet to a unique prime number and computes\n the product for each word in the g...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019727", "row_id": 19727, "seed_ids": "[4274]" }
0.607862
Apps_19727
I
[ "map_letters_to_primes", "product" ]
2
[ [ "map_letters_to_primes", "product" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d370bbfd8f2eb207f6121f59209faa70058e4f53
277fce40ec038ff591f20e1b7abd2c9891176720
v1.0
instruct
Apps
Apps_19789_I
Emily is a crossword puzzle enthusiast and is designing a custom crossword puzzle. She has a grid of letters and wants to identify how many specific words can be found within it. The words can be present horizontally, vertically, or diagonally in any direction (top-left to bottom-right, top-right to bottom-left, bottom...
def find_word_in_grid(grid, word): N, M = len(grid), len(grid[0]) len_word = len(word) # Direction vectors for 8 possible directions directions = [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (-1, 1), (1, -1), (1, 1)] def is_valid(x, y): return 0 <= x < N and 0 <= y < M ...
from solution import count_words_in_grid def test_single_word_found_horizontally(): T = 1 test_cases = [ { "dimensions": (5, 5), "grid": [ "ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY" ], ...
[ { "docstring": null, "function_declaration": "def find_word_in_grid(grid, word):", "function_name": "find_word_in_grid", "parameter_list": "(grid, word)" }, { "docstring": null, "function_declaration": "def count_words_in_grid(T, test_cases):", "function_name": "count_words_in_grid",...
[ 1, 0, 0, 1, 1, 0, 0, 0, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_words_in_grid(T, test_cases):\n \"\"\"\n Finds and counts the occurrence of words in the provided grids for each test case.\n \"\"\"\n def sear...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019789", "row_id": 19789, "seed_ids": "[1097]" }
0.623605
Apps_19789
I
[ "find_word_in_grid", "count_words_in_grid" ]
2
[ [ "count_words_in_grid", "find_word_in_grid" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cce575019ddcebf75dd92cff4ee5439192f1d847
0fcf180bce55b7b4f860c85db598a1fc11f7d830
v1.0
instruct
Apps
Apps_19794_I
Write a program that takes a year as input and determines if it is a 'Beautiful Year'. A year is considered beautiful if no two digits in it are the same. Your program should read a single year from the standard input, process it, and print the next beautiful year that is strictly greater than the given one. For examp...
def is_beautiful_year(year): """ Checks if the year has all unique digits. """ year_str = str(year) return len(year_str) == len(set(year_str)) def next_beautiful_year(year): """ Finds the next beautiful year greater than the given year. """ year += 1 while not is_beautiful_year(...
from solution import next_beautiful_year def test_next_beautiful_year(): assert next_beautiful_year(1987) == 2013 assert next_beautiful_year(2013) == 2014 assert next_beautiful_year(999) == 1023 assert next_beautiful_year(1000) == 1023 assert next_beautiful_year(2019) == 2031 assert next_beauti...
[ { "docstring": "Checks if the year has all unique digits.", "function_declaration": "def is_beautiful_year(year):", "function_name": "is_beautiful_year", "parameter_list": "(year)" }, { "docstring": "Finds the next beautiful year greater than the given year.", "function_declaration": "de...
[ 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_beautiful(year):\n \"\"\"\n Checks if a year has all unique digits.\n \"\"\"\n year_str = str(year)\n return len(set(year_str)) == len(year_st...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00019794", "row_id": 19794, "seed_ids": "[4955]" }
0.619209
Apps_19794
I
[ "is_beautiful_year", "next_beautiful_year" ]
2
[ [ "next_beautiful_year", "is_beautiful_year" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c662ba25bfc42c92b5fc23c8a43d07f9cfb8f51d
81bfad7dd785d9f88d94a521d23157826e4d6a94
v1.0
instruct
Apps
Apps_19800_I
# Task Write a function that takes a list of integers and returns a new list containing only the numbers that have exactly three divisors (1, the number itself, and one other divisor). # Notes * The input list contains integers greater than 1. * The list should maintain the original order of the numbers that qualify...
def has_exactly_three_divisors(n): """ Helper function to check if a number has exactly three divisors. """ if n < 2: return False root = int(n**0.5) return root * root == n and all(n % i != 0 for i in range(2, root)) def filter_three_divisors(nums): """ Returns a list of number...
from solution import filter_three_divisors def test_has_three_divisors(): assert filter_three_divisors([2, 3, 4, 7, 9, 10, 16, 25, 36]) == [4, 9, 25] assert filter_three_divisors([1, 5, 8, 11, 12, 13]) == [] assert filter_three_divisors([4, 9, 25, 49]) == [4, 9, 25, 49] assert filter_three_divisors([3,...
[ { "docstring": "Helper function to check if a number has exactly three divisors.", "function_declaration": "def has_exactly_three_divisors(n):", "function_name": "has_exactly_three_divisors", "parameter_list": "(n)" }, { "docstring": "Returns a list of numbers from the input list that have e...
[ 1, 1, 1, 0, 1, 0, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef has_exactly_three_divisors(n):\n \"\"\"\n Helper function to check if n has exactly three divisors.\n Returns True if n has exactly thre...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019800", "row_id": 19800, "seed_ids": "[4107]" }
0.698795
Apps_19800
I
[ "has_exactly_three_divisors", "filter_three_divisors" ]
2
[ [ "filter_three_divisors", "has_exactly_three_divisors" ] ]
1
[]
false
[]
false
pytest
true
[]
true
100fdd8857657e948c8db600b1cddbff8cda241a
4811f16ca3b7438c7d2ffe0760a275c214cc005a
v1.0
instruct
Apps
Apps_19819_I
Implement a function to calculate the maximum sum subarray using the divide and conquer approach. ##### Inputs: A list of integers `arr` which could contain both positive and negative numbers. ##### Outputs: A tuple with two elements: 1. An integer representing the maximum sum of the subarray. 2. A list of integers w...
def max_crossing_sum(arr, left, mid, right): """ Helper function to find the maximum sum of the subarray crossing the midpoint. """ # Initialize variables to store the maximum sums on the left and right of the midpoint left_sum = float('-inf') right_sum = float('-inf') # Calculate the maxim...
from solution import find_maximum_subarray def test_find_maximum_subarray(): # Example test case assert find_maximum_subarray([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == (6, [4, -1, 2, 1]) # All positive numbers assert find_maximum_subarray([1, 2, 3, 4, 5]) == (15, [1, 2, 3, 4, 5]) # All negative...
[ { "docstring": "Helper function to find the maximum sum of the subarray crossing the midpoint.", "function_declaration": "def max_crossing_sum(arr, left, mid, right):", "function_name": "max_crossing_sum", "parameter_list": "(arr, left, mid, right)" }, { "docstring": "Helper function to find...
[ 1, 1, 1, 0, 0, 0, 1, 1, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_crossing_sum(arr, left, mid, right):\n # Include elements on left of mid\n left_sum = float('-inf')\n sum = 0\n max_left = mid\n for i in ran...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019819", "row_id": 19819, "seed_ids": "[3898]" }
0.793948
Apps_19819
I
[ "max_crossing_sum", "max_subarray_sum", "find_maximum_subarray" ]
3
[ [ "find_maximum_subarray", "max_subarray_sum" ], [ "max_subarray_sum", "max_crossing_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
18c82797dd494b214aa0463a1faffc62dec6f107
2f4fdddbdfa3b81c3e792c96184a3b98cd730c73
v1.0
instruct
Apps
Apps_19920_I
A positive integer is called a $palindrome$ if its decimal representation reads the same backward as forward. For example, $121$, $545$, and $1221$ are palindromes, whereas $123$, $4321$, and $1213$ are not palindromes. You are given a positive integer $N$. Your task is to find the count of palindromic numbers less th...
def is_palindrome(number): """ Check if a given number is a palindrome. """ str_number = str(number) return str_number == str_number[::-1] def count_palindromes_up_to_n(n): """ Counts the number of palindromic numbers up to and including n. """ count = 0 for i in range(1, n + 1)...
from solution import is_palindrome, count_palindromes_up_to_n, count_palindromic_numbers def test_is_palindrome(): assert is_palindrome(121) == True assert is_palindrome(123) == False assert is_palindrome(1) == True assert is_palindrome(22) == True assert is_palindrome(10) == False def test_count_...
[ { "docstring": "Check if a given number is a palindrome.", "function_declaration": "def is_palindrome(number):", "function_name": "is_palindrome", "parameter_list": "(number)" }, { "docstring": "Counts the number of palindromic numbers up to and including n.", "function_declaration": "de...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_palindromes(t, test_cases):\n def is_palindrome(num):\n return str(num) == str(num)[::-1]\n\n results = []\n for n in test_cases:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00019920", "row_id": 19920, "seed_ids": "[1420]" }
0.795506
Apps_19920
I
[ "is_palindrome", "count_palindromes_up_to_n", "count_palindromic_numbers" ]
3
[ [ "count_palindromes_up_to_n", "is_palindrome" ], [ "count_palindromic_numbers", "count_palindromes_up_to_n" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4922cfefc0fabdc0f1289d88ed4e00f7e14e17d0
7f88efc6d89dabb39959d1ce2feaa8440238332f
v1.0
instruct
Apps
Apps_19925_I
## Task You are given an integer array `arr` and a positive integer `k`. Your goal is to partition the array into `k` subsets such that the maximum subset sum is minimized. Your task is to complete the function which returns the minimized maximum subset sum. ### Notes: - The number of elements in `arr` does not exce...
def can_partition(arr, k, max_sum): """ Helper function to check whether we can partition the array into k subsets with each subset's sum not exceeding max_sum. """ current_sum = 0 count = 1 for num in arr: if current_sum + num > max_sum: count += 1 current_su...
from solution import minimize_max_partition_sum def test_example_1(): arr = [1, 2, 3, 4, 5] k = 2 assert minimize_max_partition_sum(arr, k) == 9 def test_example_2(): arr = [7, 2, 5, 10, 8] k = 2 assert minimize_max_partition_sum(arr, k) == 18 def test_example_3(): arr = [1, 2, 3, 4] ...
[ { "docstring": "Helper function to check whether we can partition the array into k subsets\nwith each subset's sum not exceeding max_sum.", "function_declaration": "def can_partition(arr, k, max_sum):", "function_name": "can_partition", "parameter_list": "(arr, k, max_sum)" }, { "docstring":...
[ 0, 1, 0, 1, 0, 0, 1, 0, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_partition(arr, k, max_sum):\n def _can_partition(start, k, current_sum, subsets):\n if k == 0:\n return True\n if current_sum > ...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00019925", "row_id": 19925, "seed_ids": "[4585]" }
0.700629
Apps_19925
I
[ "can_partition", "minimize_max_partition_sum" ]
2
[ [ "minimize_max_partition_sum", "can_partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f67130a89e5e327baec2dcf518f4c3bdaca70a5
728b2f830a03514306b577bfba3c28045b95dd60
v1.0
instruct
Apps
Apps_19940_I
In a small town, there is a unique vending machine that dispenses items based on a specific pattern. The vending machine is filled with N items, each having a certain weight. You need to determine whether it's possible to select a subset of these items such that their combined weight is exactly W. Write a function to ...
def can_sum_to_weight(N, W, weights): """ Determines whether there is a subset of the weights that sum to exactly W. """ dp = [False] * (W + 1) dp[0] = True for weight in weights: for j in range(W, weight - 1, -1): if dp[j - weight]: dp[j] = True return ...
from solution import vending_machine_subset_sum def test_case_1(): input_data = "5 9\n3 34 4 12 5" assert vending_machine_subset_sum(input_data) == "YES" def test_case_2(): input_data = "5 30\n3 34 4 12 5" assert vending_machine_subset_sum(input_data) == "NO" def test_case_3(): input_data = "1 10...
[ { "docstring": "Determines whether there is a subset of the weights that sum to exactly W.", "function_declaration": "def can_sum_to_weight(N, W, weights):", "function_name": "can_sum_to_weight", "parameter_list": "(N, W, weights)" }, { "docstring": null, "function_declaration": "def ven...
[ 1, 0, 1, 0, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_required_weight(N, W, weights):\n # Initialize a DP table where dp[i] will be True if a subset with sum i can be formed from the given weights.\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00019940", "row_id": 19940, "seed_ids": "[2650]" }
0.661766
Apps_19940
I
[ "can_sum_to_weight", "vending_machine_subset_sum" ]
2
[ [ "vending_machine_subset_sum", "can_sum_to_weight" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4da56fbda38ab868b641a471f033741a09401b05
4b72b80d1984f34503762a778beb107d00c9c5fc
v1.0
instruct
Taco
Taco_30_I
You have been hired by a delivery company that transports packages between different waypoints in a city. The company uses a fleet of drones that can carry packages from one waypoint to another autonomously. A drone can carry a package from one waypoint to another if there exists a direct route and the carrying capacit...
import heapq import sys def dijkstra(W, adj, start, end, weight): INF = sys.maxsize distances = [INF] * W distances[start] = 0 priority_queue = [(0, start)] while priority_queue: current_distance, current_node = heapq.heappop(priority_queue) if current_distance > distances[current_n...
from solution import minimum_delivery_times def test_example_case(): W = 3 R = 3 P = 1 routes = [ (0, 1, 5, 10), (1, 2, 5, 15), (0, 2, 2, 50) ] packages = [ (0, 2, 5) ] assert minimum_delivery_times(W, R, P, routes, packages) == ["25"] def test_unreachab...
[ { "docstring": null, "function_declaration": "def dijkstra(W, adj, start, end, weight):", "function_name": "dijkstra", "parameter_list": "(W, adj, start, end, weight)" }, { "docstring": null, "function_declaration": "def minimum_delivery_times(W, R, P, routes, packages):", "function_...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef deliver_packages(W, R, P, routes, packages):\n # Creating adjacency list for graph\n graph = [[] for _ in range(W)]\n for a, b, c, t i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000030", "row_id": 30, "seed_ids": "[24280]" }
0.683379
Taco_30
I
[ "dijkstra", "minimum_delivery_times" ]
2
[ [ "minimum_delivery_times", "dijkstra" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ffdd6335ebe844c2bcddca6bd0b40c430278eb70
56467f2c4c7eaa64d93c0d9a3a15cde4c2b46c87
v1.0
instruct
Taco
Taco_39_I
You are given an array of integers and a list of queries. Each query consists of a starting index and an ending index. For each query, determine the sum of the integers within that range, inclusive. Input: First line contains two integers N and Q, where N is the number of integers in the array and Q is the number of q...
def range_sum_queries(n, arr, queries): """ Returns a list of sums for each query. :param n: int - The number of integers in the array :param arr: list - The array of integers :param queries: list of tuples - Each tuple contains starting and ending indices (L, R) for the query :return: list...
import pytest from solution import solve, parse_input, range_sum_queries def test_parse_input(): input_str = "5 3\n1 2 3 4 5\n0 2\n1 3\n2 4" n, arr, queries = parse_input(input_str) assert n == 5 assert arr == [1, 2, 3, 4, 5] assert queries == [(0, 2), (1, 3), (2, 4)] def test_range_sum_queries():...
[ { "docstring": "Returns a list of sums for each query.\n\n:param n: int - The number of integers in the array\n:param arr: list - The array of integers\n:param queries: list of tuples - Each tuple contains starting and ending indices (L, R) for the query\n:return: list - Sums for each query", "function_decl...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef range_sum_queries(N: int, Q: int, array: List[int], queries: List[Tuple[int, int]]) -> List[int]:\n \"\"\"\n Given an a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000039", "row_id": 39, "seed_ids": "[11969]" }
0.713739
Taco_39
I
[ "range_sum_queries", "parse_input", "solve" ]
3
[ [ "solve", "parse_input" ], [ "solve", "range_sum_queries" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
922c9cd13f75a6b01ca62a479f20ed85ac49fd90
9922a44d79f095f1708f6e1835d54d01a7fc66dc
v1.0
instruct
Taco
Taco_58_I
You are given a list of integers, and you need to determine if the sum of the digits of each integer in the list is an even or an odd number. Write a program that processes the list and outputs "Even" if the sum of the digits is even, and "Odd" if the sum of the digits is odd for each integer. -----Constraints----- -...
def is_even_or_odd(sum_of_digits): """ Determines if the sum of digits is even or odd. Args: - sum_of_digits (int): The sum of the digits. Returns: - A string "Even" if the sum is even, "Odd" if the sum is odd. """ return "Even" if sum_of_digits % 2 == 0 else "Odd" def sum_of_...
def test_is_even_or_odd(): assert is_even_or_odd(6) == "Even" assert is_even_or_odd(15) == "Odd" assert is_even_or_odd(24) == "Even" assert is_even_or_odd(1) == "Odd" def test_sum_of_digits(): assert sum_of_digits(123) == 6 assert sum_of_digits(456) == 15 assert sum_of_digits(789) == 24 ...
[ { "docstring": "Determines if the sum of digits is even or odd.\n\nArgs:\n- sum_of_digits (int): The sum of the digits.\n\nReturns:\n- A string \"Even\" if the sum is even, \"Odd\" if the sum is odd.", "function_declaration": "def is_even_or_odd(sum_of_digits):", "function_name": "is_even_or_odd", "...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_of_digits(n):\n \"\"\"\n Returns the sum of digits of an integer n.\n \"\"\"\n return sum(int(digit) for digit in str(n))\n\ndef even_or_odd_su...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000058", "row_id": 58, "seed_ids": "[5483]" }
0.730731
Taco_58
I
[ "is_even_or_odd", "sum_of_digits", "process_numbers" ]
3
[ [ "process_numbers", "is_even_or_odd" ], [ "process_numbers", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
false
[]
true
77fb5db73fbcc556fb0feb990439a2d9dbb58f34
a7e9b7c19357c48b518baf2a719f998fd91211f7
v1.0
instruct
Taco
Taco_87_I
You are given a list of IP addresses. Your task is to find out which IP addresses are public and which are private. Classify each IP address and output the result. ### Public vs. Private IP Addresses Public IP addresses are used to access the Internet, while private IP addresses are used within a private network. ###...
def classify_ip(ip_address): """ Classify the given IP address as either 'Private' or 'Public'. """ parts = list(map(int, ip_address.split('.'))) if parts[0] == 10: return "Private" elif parts[0] == 172 and 16 <= parts[1] <= 31: return "Private" elif parts[0] == 192 and ...
from solution import classify_ip, classify_ip_addresses def test_classify_ip_private_10(): assert classify_ip("10.0.0.1") == "Private" assert classify_ip("10.255.255.255") == "Private" def test_classify_ip_private_172(): assert classify_ip("172.16.0.0") == "Private" assert classify_ip("172.31.255.255"...
[ { "docstring": "Classify the given IP address as either 'Private' or 'Public'.", "function_declaration": "def classify_ip(ip_address):", "function_name": "classify_ip", "parameter_list": "(ip_address)" }, { "docstring": null, "function_declaration": "def classify_ip_addresses(ip_addresse...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def classify_ip_addresses(ip_addresses):\n \"\"\"\n Classifies a list of IP addresses as either 'Private' or 'Public'.\n \"\"\"\n private_ranges = [\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000087", "row_id": 87, "seed_ids": "[6102]" }
0.519119
Taco_87
I
[ "classify_ip", "classify_ip_addresses" ]
2
[ [ "classify_ip_addresses", "classify_ip" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fda587389def01288eae670926c136cac560cbb4
c6178feae41dc92eba71adc02f7f97aa786d7b92
v1.0
instruct
Taco
Taco_137_I
Given a binary tree, you need to write a function that finds the left view of the binary tree. The left view of a binary tree is the set of nodes visible when the tree is viewed from the left side. -----Input:----- - The input consists of multiple test cases. - The first line contains an integer $T$, the number of tes...
class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def build_tree(levels): if not levels or levels[0] == -1: return None root = TreeNode(levels[0]) queue = [root] i = 1 while queue and i < len(levels): cur...
from solution import build_tree, left_view, find_left_view_of_trees def test_build_tree(): levels = [1, 2, 3, -1, 5, -1, -1] root = build_tree(levels) assert root.val == 1 assert root.left.val == 2 assert root.right.val == 3 assert root.left.right.val == 5 assert root.left.left == None ...
[]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_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 build_tree(values):\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000137", "row_id": 137, "seed_ids": "[19851]" }
0.64132
Taco_137
I
[ "build_tree", "left_view_util", "left_view", "find_left_view_of_trees" ]
4
[ [ "find_left_view_of_trees", "build_tree" ], [ "find_left_view_of_trees", "left_view" ], [ "left_view", "left_view_util" ] ]
3
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
f27d0dd195236bc354274d986996543764838257
cb99319b7af202f7042edd67aff41d38dd9379d2
v1.0
instruct
Taco
Taco_179_I
The ancient city of Zephyria is celebrated for its intricate network of roads and bridges connecting its numerous islands. Each year, the citizens host a grand festival where they string lights along these roads and bridges in a dazzling display. To make the arrangement more efficient, the city engineers decided to opt...
def find(parent, i): if parent[i] != i: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): rootX = find(parent, x) rootY = find(parent, y) if rootX != rootY: if rank[rootX] > rank[rootY]: parent[rootY] = rootX elif rank[rootX...
def test_min_lights_to_connect_islands(): test_cases = [ (4, 5, [(1, 2, 1), (1, 3, 2), (4, 1, 4), (2, 4, 3), (3, 4, 5)]), (3, 3, [(1, 2, 7), (2, 3, 10), (3, 1, 5)]) ] expected_results = [6, 12] assert min_lights_to_connect_islands(2, test_cases) == expected_results def test_empty_g...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = f...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000179", "row_id": 179, "seed_ids": "[9655]" }
0.727856
Taco_179
I
[ "find", "union", "min_lights_to_connect_islands", "solve" ]
4
[ [ "min_lights_to_connect_islands", "find" ], [ "min_lights_to_connect_islands", "union" ], [ "solve", "min_lights_to_connect_islands" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
199f5afecb31a95658cfa4a53e3c73870e152c69
963ce2419299de130bce24f78796018906bf8554
v1.0
instruct
Taco
Taco_228_I
Ash has been given a task by his computer science professor. He needs to analyze the efficiency of sorting algorithms. Ash is provided with multiple arrays. For each array, he needs to determine the minimum number of adjacent swaps required to sort the array in ascending order. Can you help Ash accomplish this task? -...
def merge_and_count(arr, temp_arr, left, mid, right): i = left # Starting index for left subarray j = mid + 1 # Starting index for right subarray k = left # Starting index to be sorted inv_count = 0 while i <= mid and j <= right: if arr[i] <= arr[j]: temp_arr[k] = arr[i]...
from solution import min_adjacent_swaps def test_min_adjacent_swaps_example(): test_cases = [ (3, [3, 2, 1]), (4, [4, 3, 2, 1]), ] assert min_adjacent_swaps(test_cases) == [3, 6] def test_min_adjacent_swaps_sorted(): test_cases = [ (3, [1, 2, 3]), (4, [1, 2, 3, 4]), ...
[ { "docstring": null, "function_declaration": "def merge_and_count(arr, temp_arr, left, mid, right):", "function_name": "merge_and_count", "parameter_list": "(arr, temp_arr, left, mid, right)" }, { "docstring": null, "function_declaration": "def merge_sort_and_count(arr, temp_arr, left, r...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 # Starting index for right subarray\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000228", "row_id": 228, "seed_ids": "[21429]" }
0.662269
Taco_228
I
[ "merge_and_count", "merge_sort_and_count", "min_adjacent_swaps" ]
3
[ [ "merge_sort_and_count", "merge_and_count" ], [ "min_adjacent_swaps", "merge_sort_and_count" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e10d9e2db64fe9f84c5a0f74efe2d09ccfe92356
81501970c9663a56ada3b910e81d15f9f2edfc08
v1.0
instruct
Taco
Taco_321_I
During a busy weekend at the amusement park, you come across a problem concerning the park's visitor flexibility. The park has several attractions connected with walkways, and each walkway has a specific direction associated with it. Each visitor has a specific start attraction and needs to reach their designated end a...
def is_reachable(attractions, start, end): """ Determine whether there is a path from start to end in the attractions map. :param attractions: Dictionary where keys are attraction names and values are lists of directly reachable attractions. :param start: Starting attraction name. :param end: End a...
import pytest from solution import check_park_route def test_reachable(): M = 4 attractions_lines = [ "Carousel FerrisWheel", "FerrisWheel RollerCoaster", "RollerCoaster HauntedHouse", "HauntedHouse" ] visitor_route = "Carousel HauntedHouse" assert check_park_route(M...
[ { "docstring": "Determine whether there is a path from start to end in the attractions map.\n\n:param attractions: Dictionary where keys are attraction names and values are lists of directly reachable attractions.\n:param start: Starting attraction name.\n:param end: End attraction name.\n:return: \"reachable\"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_reachable(n, adj_list, start, end):\n \"\"\"\n Determines whether there is a simple path from the start attraction to the end attraction.\n \n :...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000321", "row_id": 321, "seed_ids": "[10067]" }
0.659164
Taco_321
I
[ "is_reachable", "check_park_route" ]
2
[ [ "check_park_route", "is_reachable" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b76dc63a7a0758305ea2c7078ec4de0fca2bb575
9897fbea04bc3db5057a135c2ad46baf8e858ba3
v1.0
instruct
Taco
Taco_374_I
You are given a collection of `n` distinct integers. Your task is to find out whether there exists a pair of integers (a, b) in this collection such that their product is a perfect square, and b is greater than or equal to a^2 + a. A perfect square is an integer that is the square of an integer. For example, 1, 4, 9, ...
import math def is_perfect_square(num): if num < 0: return False sqrt_num = int(math.sqrt(num)) return sqrt_num * sqrt_num == num def has_pair_with_condition(n, integers): integers_set = set(integers) for a in integers: for b in integers: if b >= a * a + a: ...
from solution import has_pair_with_condition def test_has_pair_with_valid_pair(): assert has_pair_with_condition(5, [3, 12, 25, 7, 18]) == "YES" def test_has_pair_without_valid_pair(): assert has_pair_with_condition(3, [5, 7, 11]) == "NO" def test_with_negative_numbers(): assert has_pair_with_condition(4...
[ { "docstring": null, "function_declaration": "def is_perfect_square(num):", "function_name": "is_perfect_square", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def has_pair_with_condition(n, integers):", "function_name": "has_pair_with_condition", "pa...
[ 0, 0, 0, 0, 1 ]
1
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef exists_pair_with_conditions(n, numbers):\n \"\"\"\n Check if there exists a pair (a, b) such that:\n - a * b is a perfect square\n -...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000374", "row_id": 374, "seed_ids": "[10308]" }
0.714715
Taco_374
I
[ "is_perfect_square", "has_pair_with_condition" ]
2
[ [ "has_pair_with_condition", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b3569991f88ef6233d3f4d09f9f2962ad1a5fa10
bf6eb8f2ab1a0a1477a37b48310e174a7a76ab88
v1.0
instruct
Taco
Taco_406_I
# Task: Given an integer `n`, write a function to check if it's a prime number and return the `n`-th Fibonacci number if it is, or the sum of all even numbers from `1` to `n` (inclusive) if it is not. ## Example: ```python Input: process_number(7) Output: "7 is prime, 13th Fibonacci number is 13" ``` ```python Inpu...
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def fibonacci(n): """ Ret...
from solution import is_prime, fibonacci, sum_of_evens, process_number def test_is_prime(): assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(10) def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) ...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the n-th Fibonacci number.\nThe Fibonacci sequence starts from 0, 1, 1, 2, 3, 5, 8, ...", "function_declaration": "de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000406", "row_id": 406, "seed_ids": "[6910]" }
0.816532
Taco_406
I
[ "is_prime", "fibonacci", "sum_of_evens", "process_number" ]
4
[ [ "process_number", "fibonacci" ], [ "process_number", "is_prime" ], [ "process_number", "sum_of_evens" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ba198577185f1e3fd9f9aaa251c1e69de464b836
e70a6b5165caf3e934a91924fc19c763e0f5eecd
v1.0
instruct
Taco
Taco_407_I
You are given an undirected graph with N vertices and M edges. Your task is to determine the number of components in the graph that are bipartite. A bipartite graph is a graph whose vertices can be divided into two disjoint sets such that no two graph vertices within the same set are adjacent. ------ Input ------ The...
from collections import defaultdict, deque def is_bipartite_component(graph, start, visited): queue = deque([start]) visited[start] = 1 # Start coloring with 1 while queue: node = queue.popleft() for neighbor in graph[node]: if visited[neighbor] == -1: visited[...
from solution import count_bipartite_components def test_single_component_bipartite(): N, M = 5, 4 edges = [(1, 2), (2, 3), (3, 4), (4, 5)] assert count_bipartite_components(N, M, edges) == 1 def test_multiple_components_bipartite(): N, M = 6, 4 edges = [(1, 2), (2, 3), (4, 5), (5, 6)] assert ...
[ { "docstring": null, "function_declaration": "def is_bipartite_component(graph, start, visited):", "function_name": "is_bipartite_component", "parameter_list": "(graph, start, visited)" }, { "docstring": null, "function_declaration": "def count_bipartite_components(N, M, edges):", "f...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_bipartite_components(N, M, edges):\n from collections import defaultdict, deque\n \n graph = defaultdict(list)\n for u, v in edges:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000407", "row_id": 407, "seed_ids": "[13359]" }
0.623433
Taco_407
I
[ "is_bipartite_component", "count_bipartite_components" ]
2
[ [ "count_bipartite_components", "is_bipartite_component" ] ]
1
[]
false
[]
false
pytest
true
[]
true
63b5bbcfbb1fa225d7c41bff2303ede9f8210bb6
a4ab064a4e69fb29c0de5ebfd3e2a18c25dbf7d6
v1.0
instruct
Taco
Taco_412_I
Problem description: In a distant land, there are different species of magical creatures. Each creature has a different ability level represented by a positive integer. A new threat has emerged, and now the magical council is interested in identifying whether any creatures have an ability level that is a prime number. ...
def is_prime(n): """ Helper function to determine if a number is prime """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import find_prime_creature_ids, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_find_prime_creature_ids_example1(): ab...
[ { "docstring": "Helper function to determine if a number is prime ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the IDs of creatures whose ability levels are prime numbers.", "function_declaration": "def fin...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000412", "row_id": 412, "seed_ids": "[5104]" }
0.55823
Taco_412
I
[ "is_prime", "find_prime_creature_ids" ]
2
[ [ "find_prime_creature_ids", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cc39928d097f69c74076dece88655fd3376b9207
9628141ca63bc4c63298c120efc0caeed100dab3
v1.0
instruct
Taco
Taco_452_I
Alyssa is trying to create a mosaic using a grid of tiles. She has an unlimited supply of tiles of different colors. She wants to color a given grid following specific constraints. The grid is an N x M matrix where each cell can be painted in one of K different colors. She wants to paint the grid in such a way that no...
def is_valid_color(grid, r, c, color, N, M): # Checking adjacent cells for the same color for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]: # Up, Down, Left, Right nr, nc = r + dr, c + dc if 0 <= nr < N and 0 <= nc < M and grid[nr][nc] == color: return False return True def sol...
from solution import solve_mosaic def test_example_case(): N, M, K = 3, 3, 3 initial_grid = [ [1, 0, 0], [0, 0, 0], [0, 0, 2] ] result, grid = solve_mosaic(N, M, K, initial_grid) assert result == "YES" assert grid != None assert grid[0][0] == 1 assert grid[2][2] ...
[ { "docstring": null, "function_declaration": "def is_valid_color(grid, r, c, color, N, M):", "function_name": "is_valid_color", "parameter_list": "(grid, r, c, color, N, M)" }, { "docstring": null, "function_declaration": "def solve_mosaic(N, M, K, initial_grid):", "function_name": "...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_color(grid, row, col, color, N, M):\n # Check adjacent cells to ensure no two adjacent cells have the same color\n directions = [(-1, 0), (1, 0)...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000452", "row_id": 452, "seed_ids": "[9925]" }
0.786779
Taco_452
I
[ "is_valid_color", "solve_mosaic", "main" ]
3
[ [ "solve_mosaic", "is_valid_color" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f32097589f5037d633596ced5d42253946f7158a
c0a392614a3fff7b3fd77bb282bffb49f6a53234
v1.0
instruct
Taco
Taco_464_I
You are given a binary tree where each node contains an integer value. Write a program to transform this binary tree into a binary search tree (BST) while maintaining the original structure of the tree (i.e., the transformed tree should have the same structure as the original tree). ### Specifications 1. **Input**: Th...
class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def build_tree(values): if not values: return None it = iter(values) root = TreeNode(next(it)) queue = [root] while queue: node = queue.pop(0) try: ...
from solution import build_tree, transform_to_bst, inorder_traversal, process_trees def test_single_node_tree(): values = [1] root = build_tree(values) transform_to_bst(root) assert inorder_traversal(root) == [1] def test_already_bst_tree(): values = [1, 2, 3] root = build_tree(values) tra...
[]
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef level_o...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000464", "row_id": 464, "seed_ids": "[21588]" }
0.568986
Taco_464
I
[ "build_tree", "inorder_traversal", "transform_to_bst", "process_trees" ]
4
[ [ "process_trees", "build_tree" ], [ "process_trees", "inorder_traversal" ], [ "process_trees", "transform_to_bst" ], [ "transform_to_bst", "inorder_traversal" ] ]
4
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
0748ca3d8d0d7bf61f45937026c83a6db772f850
dbde3836d2074d843c842112ec88f7f61856de5a
v1.0
instruct
Taco
Taco_513_I
You are given a 2D grid of size NxM. Each cell in the grid contains either a 0 or a 1. Your task is to determine the largest rectangular area that can be formed using only cells that contain the value 1. Write a program that reads the dimensions of the grid and its contents, and then calculates the area of the largest...
def maximal_rectangle(matrix): if not matrix: return 0 n, m = len(matrix), len(matrix[0]) max_area = 0 heights = [0] * m for row in matrix: for j in range(m): heights[j] = heights[j] + 1 if row[j] == 1 else 0 max_area = max(max_area, largest_rectangle_area(heigh...
from solution import maximal_rectangle def test_maximal_rectangle_4x4(): matrix = [ [1, 0, 1, 0], [1, 0, 1, 1], [1, 1, 1, 1], [1, 0, 1, 1] ] assert maximal_rectangle(matrix) == 6 def test_maximal_rectangle_3x3(): matrix = [ [1, 1, 1], [1, 0, 1], ...
[ { "docstring": null, "function_declaration": "def maximal_rectangle(matrix):", "function_name": "maximal_rectangle", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def largest_rectangle_area(heights):", "function_name": "largest_rectangle_area", "pa...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(grid):\n \"\"\"\n This function calculates the area of the largest rectangle consisting only of 1s in a 2D grid.\n :param grid: List ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000513", "row_id": 513, "seed_ids": "[6065]" }
0.778386
Taco_513
I
[ "maximal_rectangle", "largest_rectangle_area" ]
2
[ [ "maximal_rectangle", "largest_rectangle_area" ] ]
1
[]
false
[]
false
pytest
true
[]
true
288eb60d0e054049253ed5e241c67481b5601797
475900f9cbcf94cf4636ca1f907048723743fb15
v1.0
instruct
Taco
Taco_543_I
You are tasked with developing a Customer Satisfaction algorithm for a shopping website. The website collects ratings from customers after each purchase. The ratings are represented as integers on a scale from 1 to 5, with 1 being the lowest and 5 being the highest. Based on these ratings, you need to determine whether...
def determine_satisfaction(ratings_list): """ This function takes a list of lists where each inner list represents the ratings given by a single customer. It returns a list of boolean values indicating whether each customer is satisfied. """ result = [] for ratings in ratings_list: if al...
def test_determine_satisfaction_all_satisfied(): assert determine_satisfaction([[5, 3, 4, 3], [4, 4, 4, 4]]) == [True, True] def test_determine_satisfaction_some_not_satisfied(): assert determine_satisfaction([[5, 3, 4, 3], [2, 1, 5, 3]]) == [True, False] def test_determine_satisfaction_none_satisfied(): ...
[ { "docstring": "This function takes a list of lists where each inner list represents the ratings given by a single customer.\nIt returns a list of boolean values indicating whether each customer is satisfied.", "function_declaration": "def determine_satisfaction(ratings_list):", "function_name": "determ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def customer_satisfaction(customers_ratings):\n \"\"\"\n Determines if customers are satisfied based on their ratings.\n \n Args:\n customers_rating...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000543", "row_id": 543, "seed_ids": "[17348]" }
0.56431
Taco_543
I
[ "determine_satisfaction", "format_satisfaction_result" ]
2
[ [ "format_satisfaction_result", "determine_satisfaction" ] ]
1
[]
false
[]
false
pytest
false
[]
true
81e1b1464d42f8d5c1eca77182ae63698369459f
857c319b2e64baec1435637419cefb711f6237f1
v1.0
instruct
Taco
Taco_558_I
You are given two simple polygons defined by their vertices in the plane. Write a program to calculate the area of the intersection of the two polygons. ### Input The input consists of several datasets. Each dataset starts with the number of vertices, n1, of the first polygon, followed by the coordinates (x1, y1), (...
def polygon_area(polygon): """ Calculate the area of a simple polygon given its vertices. """ n = len(polygon) area = 0 for i in range(n): x1, y1 = polygon[i] x2, y2 = polygon[(i + 1) % n] area += x1 * y2 - y1 * x2 return abs(area) / 2 def inside(p, cp1, cp2): ""...
from solution import solve def test_example_input(): input_str = """ 4 0 0 4 0 4 4 0 4 4 2 2 6 2 6 6 2 6 0 """ expected_output = "4.0000" assert solve(input_str).strip() == expected_output def test_no_intersection(): input_str = """ 4 0 0 2 0...
[ { "docstring": "Calculate the area of a simple polygon given its vertices.", "function_declaration": "def polygon_area(polygon):", "function_name": "polygon_area", "parameter_list": "(polygon)" }, { "docstring": "Check if point p is inside the edge formed by cp1 and cp2.", "function_decl...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from shapely.geometry import Polygon\nimport sys\n\n\ndef compute_intersection_area(polygon1, polygon2):\n \"\"\"\n Computes the area of the intersection of ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000558", "row_id": 558, "seed_ids": "[1257]" }
0.5438
Taco_558
I
[ "polygon_area", "inside", "intersection", "clip_polygon", "intersection_area", "parse_input", "solve" ]
7
[ [ "clip_polygon", "inside" ], [ "clip_polygon", "intersection" ], [ "intersection_area", "clip_polygon" ], [ "intersection_area", "polygon_area" ], [ "solve", "intersection_area" ], [ "solve", "parse_input" ] ]
6
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
62d2db244d273633b3240758d0997a2131fdf33e
928fa294225dfd3ffbdc59a70ba59ced7abe4a8c
v1.0
instruct
Taco
Taco_596_I
You are given a list of operations in the form "X operation Y = Z", where X, Y, and Z are non-negative integers, and operation is one of '+', '-', '*', or '/'. However, the numbers and the operations are encoded in a custom base system using the symbols '0'-'9' and 'a'-'z' representing values from 0 to 35. Each encoded...
def decode_number(encoded_number, base): """ Decodes the encoded number from the specified base to base 10. """ return int(encoded_number, base) def evaluate_operation(x, operator, y): """ Evaluates the expression x operator y. """ if operator == '+': return x + y elif opera...
def test_decode_number(): assert decode_number('10', 16) == 16 assert decode_number('1a', 16) == 26 assert decode_number('z', 36) == 35 def test_evaluate_operation(): assert evaluate_operation(2, '+', 3) == 5 assert evaluate_operation(10, '-', 2) == 8 assert evaluate_operation(1, '*', 2) == 2 ...
[ { "docstring": "Decodes the encoded number from the specified base to base 10.", "function_declaration": "def decode_number(encoded_number, base):", "function_name": "decode_number", "parameter_list": "(encoded_number, base)" }, { "docstring": "Evaluates the expression x operator y.", "f...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_operation_correct(operation, base):\n # Helper function to convert a custom base number to int\n def to_int(value, base):\n return int(value, b...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00000596", "row_id": 596, "seed_ids": "[5454]" }
0.672181
Taco_596
I
[ "decode_number", "evaluate_operation", "is_operation_correct", "parse_statement", "count_correct_operations" ]
5
[ [ "count_correct_operations", "is_operation_correct" ], [ "is_operation_correct", "decode_number" ], [ "is_operation_correct", "evaluate_operation" ], [ "is_operation_correct", "parse_statement" ] ]
4
[]
false
[]
false
pytest
false
[]
true
f58b2510b98213508db4dc71fe118ad24a4702f7
db6c1d77400c7b0f26e13c376f7866af578be240
v1.0
instruct
Taco
Taco_712_I
A manufacturing company uses a robotic arm to place boxes on a conveyor belt. These boxes are labeled with unique integer identifiers and have varying sizes. The conveyor belt has a limited capacity, measured by the sum of the sizes of the boxes it can hold at any given time. You are tasked with managing the placement...
def max_boxes_on_conveyor(max_capacity, boxes): """ Given the max capacity of the conveyor belt and a list of boxes with their sizes, return the maximum number of boxes that can be placed on the belt without exceeding the capacity. Parameters: max_capacity (int): Maximum capacity of the conveyo...
import pytest from solution import max_boxes_on_conveyor def test_sample_input_1(): assert max_boxes_on_conveyor(10, [(1, 3), (2, 4), (3, 2), (4, 5)]) == 3 def test_sample_input_2(): assert max_boxes_on_conveyor(15, [(10, 5), (11, 8), (12, 6), (13, 3), (14, 2)]) == 3 def test_no_boxes(): assert max_boxes...
[ { "docstring": "Given the max capacity of the conveyor belt and a list of boxes with their sizes,\nreturn the maximum number of boxes that can be placed on the belt without exceeding the capacity.\n\nParameters:\nmax_capacity (int): Maximum capacity of the conveyor belt\nboxes (List[Tuple[int, int]]): List of t...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_boxes(capacity, boxes):\n boxes.sort(key=lambda x: x[1])\n total_size = 0\n count = 0\n for _, size in boxes:\n if total_size + size <= ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000712", "row_id": 712, "seed_ids": "[516]" }
0.743997
Taco_712
I
[ "max_boxes_on_conveyor", "manage_boxes" ]
2
[ [ "manage_boxes", "max_boxes_on_conveyor" ] ]
1
[]
false
[]
false
pytest
true
[]
true
793529da5561a95fb5495ff9eadfe857ae58b385
69ce3569e6580ca8fe8c4a740cf63e2f9a5d5b22
v1.0
instruct
Taco
Taco_739_I
Given an integer $n$, find the smallest palindrome larger than $n$. A palindrome is a number that reads the same backward as forward (e.g., $121$ or $12321$). Input Format A single integer $n$. Constraints $1 \leq n \leq 10^{12}$ Output Format Print the smallest palindrome larger than $n$. Sample Input 0 123 Sa...
def is_palindrome(number): """ Helper function to check if a number is a palindrome. """ return str(number) == str(number)[::-1] def next_palindrome(n): """ Function to find the smallest palindrome larger than n. """ n += 1 while not is_palindrome(n): n += 1 return n # ...
from solution import next_palindrome def test_next_palindrome_small_numbers(): assert next_palindrome(123) == 131 assert next_palindrome(130) == 131 assert next_palindrome(999) == 1001 def test_next_palindrome_large_numbers(): assert next_palindrome(1234321) == 1235321 assert next_palindrome(98765...
[ { "docstring": "Helper function to check if a number is a palindrome.", "function_declaration": "def is_palindrome(number):", "function_name": "is_palindrome", "parameter_list": "(number)" }, { "docstring": "Function to find the smallest palindrome larger than n.", "function_declaration"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(x):\n return str(x) == str(x)[::-1]\n\ndef smallest_palindrome_larger_than(n):\n \"\"\"\n Returns the smallest palindrome larger than n....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000739", "row_id": 739, "seed_ids": "[8603]" }
0.869739
Taco_739
I
[ "is_palindrome", "next_palindrome" ]
2
[ [ "next_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
02e58b0960a1606e54f556856caeb8885986f73a
bdb61107202869a29372b8ab10857205f4045fe1
v1.0
instruct
Taco
Taco_805_I
A logistics company needs to optimize the delivery route for their trucks to minimize the total travel distance. The company operates in a city with n cargo distribution centers and m bidirectional roads connecting the centers. Each road has an associated travel distance. The company's goal is to determine the shortes...
def nearest_neighbor_tsp(n, m, k, roads): from collections import defaultdict import heapq graph = defaultdict(list) for u, v, d in roads: graph[u].append((d, v)) graph[v].append((d, u)) visited = [False] * (n + 1) path_cost = 0 current = k for _ in range(n - 1...
from solution import find_approx_hamiltonian_cycle def test_case_1(): n = 4 m = 6 k = 1 roads_info = [ (1, 2, 10), (1, 3, 15), (1, 4, 20), (2, 3, 35), (2, 4, 25), (3, 4, 30) ] assert find_approx_hamiltonian_cycle(n, m, k, roads_info) == 80 def te...
[ { "docstring": null, "function_declaration": "def nearest_neighbor_tsp(n, m, k, roads):", "function_name": "nearest_neighbor_tsp", "parameter_list": "(n, m, k, roads)" }, { "docstring": null, "function_declaration": "def find_approx_hamiltonian_cycle(n, m, k, roads_info):", "function...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def tsp_approximation(n, m, start, roads):\n import itertools\n\n # Build graph (adjacency matrix) based on input roads\n graph = [[float('inf')] * n for ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00000805", "row_id": 805, "seed_ids": "[11471]" }
0.638947
Taco_805
I
[ "nearest_neighbor_tsp", "find_approx_hamiltonian_cycle" ]
2
[ [ "find_approx_hamiltonian_cycle", "nearest_neighbor_tsp" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3874bba1126f93b73bba6c8216876e940e4f3092
f1c70c12b7022386d37c0c2746135ddcaff2a184
v1.0
instruct
Taco
Taco_811_I
You are managing a fleet of N drones that are initially stationed at unique points in a 2D plane. Each drone can travel at a constant speed in any direction. There are several repair stations scattered throughout the plane, where drones can go to get fixed if something goes wrong. Given the current position of each dro...
import math def closest_repair_station_distance(drone_coordinate, repair_stations): """Calculate the closest distance between a drone and repair stations.""" min_distance = float('inf') for rx, ry in repair_stations: distance = math.sqrt((rx - drone_coordinate[0]) ** 2 + (ry - drone_coordinate[1]) ...
import math from solution import closest_repair_station_distance, process_test_case, find_closest_distances_to_stations def test_closest_repair_station_distance(): drones = [(100, 100), (200, 200), (300, 300)] repair_stations = [(150, 150), (250, 250)] assert closest_repair_station_distance(drones[0],...
[ { "docstring": "Calculate the closest distance between a drone and repair stations.", "function_declaration": "def closest_repair_station_distance(drone_coordinate, repair_stations):", "function_name": "closest_repair_station_distance", "parameter_list": "(drone_coordinate, repair_stations)" }, ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef closest_repair_station_distance(drone_coordinate, repair_stations):\n \"\"\"Calculate the closest distance between a drone and repair station...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00000811", "row_id": 811, "seed_ids": "[20579]" }
0.668984
Taco_811
I
[ "closest_repair_station_distance", "process_test_case", "find_closest_distances_to_stations" ]
3
[ [ "find_closest_distances_to_stations", "process_test_case" ], [ "process_test_case", "closest_repair_station_distance" ] ]
2
[ "process_test_case" ]
false
[]
false
pytest
true
[]
true
d9ac5f5d91f6e816cb07fa068575856037706298
1cbf0f796f935e29f02442af6957ac2bf2b035d3
v1.0
instruct
Taco
Taco_887_I
A palindrome is a string that reads the same forward and backward. Given a series of strings, our task is to determine if each string in the list can be rearranged to form a palindrome. Note that an empty string is considered a valid palindrome. -----Input----- The input consists of N cases. The first line of the inpu...
def can_form_palindrome(s): """ Determines if a string can be rearranged to form a palindrome. Args: s (str): The input string consisting of only lowercase letters. Returns: str: "YES" if the string can be rearranged to form a palindrome, otherwise "NO". """ from collections im...
from solution import can_form_palindrome, can_form_palindrome_multiple_cases def test_can_form_palindrome_yes_cases(): assert can_form_palindrome("civic") == "YES" assert can_form_palindrome("ivicc") == "YES" assert can_form_palindrome("aabb") == "YES" assert can_form_palindrome("a") == "YES" asser...
[ { "docstring": "Determines if a string can be rearranged to form a palindrome.\n\nArgs:\ns (str): The input string consisting of only lowercase letters.\n\nReturns:\nstr: \"YES\" if the string can be rearranged to form a palindrome, otherwise \"NO\".", "function_declaration": "def can_form_palindrome(s):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome(s):\n \"\"\"\n Returns 'YES' if the string `s` can be rearranged to form a palindrome, otherwise returns 'NO'.\n \"\"\"\n from ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000887", "row_id": 887, "seed_ids": "[1654]" }
0.815473
Taco_887
I
[ "can_form_palindrome", "can_form_palindrome_multiple_cases" ]
2
[ [ "can_form_palindrome_multiple_cases", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f942ae230da9e4cb2b6c5ae42936d67e26e4910f
e25d0acb7a15908a91f3c8a3484e5bc86e4c0be0
v1.0
instruct
Taco
Taco_943_I
Tina loves solving puzzles. She has a number puzzle that consists of an array of integers. The puzzle asks her to perform operations on the elements of the array to obtain a new array where the sum of the elements is maximum. Here’s how the operation works: Tina can choose any two elements of the array, say $A_i$ and ...
def max_sum_possible(arr): """ Returns the maximum possible sum of elements of the array after performing the operations optimally. """ return sum(arr) def solve_case(n, arr): """ Solves a single test case. """ return max_sum_possible(arr) def max_sum_of_elements(test_cases): ...
from solution import solve_case, max_sum_of_elements def test_solve_case(): assert solve_case(3, [1, 2, 3]) == 6 assert solve_case(4, [5, 3, 9, 1]) == 18 def test_max_sum_of_elements(): assert max_sum_of_elements([ (3, [1, 2, 3]), (4, [5, 3, 9, 1]), ]) == [6, 18] assert max_sum_of...
[ { "docstring": "Returns the maximum possible sum of elements of the array after performing \nthe operations optimally.", "function_declaration": "def max_sum_possible(arr):", "function_name": "max_sum_possible", "parameter_list": "(arr)" }, { "docstring": "Solves a single test case.", "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_after_operations(T, test_cases):\n \"\"\"\n Function to find the maximum possible sum of array elements after performing the specified operations...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00000943", "row_id": 943, "seed_ids": "[21379]" }
0.716558
Taco_943
I
[ "max_sum_possible", "solve_case", "max_sum_of_elements" ]
3
[ [ "max_sum_of_elements", "solve_case" ], [ "solve_case", "max_sum_possible" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4485a5e539b4d9801ea26da3f4a2e086d8046af8
4a9d7934d2aa2fdf9988f274ff4ec7c41128a23b
v1.0
instruct
Taco
Taco_990_I
Shortest Safe Path in a Grid with Landmines You are given a grid representing a minefield where each cell is either safe (0) or contains a landmine (1). Your task is to find the shortest safe path in the minefield grid from the top-left corner (0,0) to the bottom-right corner (n-1,m-1), where n is the number of rows a...
from collections import deque def is_valid_move(x, y, grid, visited): n, m = len(grid), len(grid[0]) return 0 <= x < n and 0 <= y < m and grid[x][y] == 0 and not visited[x][y] def shortest_safe_path(grid): n, m = len(grid), len(grid[0]) if grid[0][0] == 1 or grid[n-1][m-1] == 1: return -1 ...
from solution import shortest_safe_path def test_shortest_safe_path_basic(): grid = [ [0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0], [1, 1, 1, 0] ] assert shortest_safe_path(grid) == 6 def test_shortest_safe_path_no_path(): grid = [ [0, 1, 1, 1], [1, 1, 1, 0]...
[ { "docstring": null, "function_declaration": "def is_valid_move(x, y, grid, visited):", "function_name": "is_valid_move", "parameter_list": "(x, y, grid, visited)" }, { "docstring": null, "function_declaration": "def shortest_safe_path(grid):", "function_name": "shortest_safe_path", ...
[ 0, 0, 0, 1, 1 ]
2
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef shortest_safe_path(grid, n, m):\n if grid[0][0] == 1 or grid[n-1][m-1] == 1:\n return -1\n \n # Directions: (u...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00000990", "row_id": 990, "seed_ids": "[9374]" }
0.731676
Taco_990
I
[ "is_valid_move", "shortest_safe_path" ]
2
[ [ "shortest_safe_path", "is_valid_move" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dc289a2695837d735ebe7e112fc02ec0f89c5ee9
e42b12176fab8211eea5721e1b07ac7ce2a81a32
v1.0
instruct
Taco
Taco_1035_I
Eleanor is organizing a scavenger hunt in her $20 \times 20$ grid park. The park is overlaid with a Cartesian coordinate system so that any point $(x,y)$ in the park has coordinates $x \in [-10, 10]$ and $y \in [-10, 10]$. Eleanor wants to hide $10$ clues in unique locations according to the following rules: The coord...
import math def is_valid_coordinate(x, y, clues): """ Check if the coordinate (x, y) is a valid clue location. """ if any(math.dist((x, y), (cx, cy)) < math.sqrt(2) for cx, cy in clues): return False return True def are_squares_even(x, y, clues): """ Check if the sum of the squares of coordina...
from solution import scavenger_hunt, generate_clues def test_first_clue_2_3(): clues = generate_clues(2, 3) assert len(clues) == 10 assert (2, 3) in clues def test_first_clue_0_0(): clues = generate_clues(0, 0) assert len(clues) == 10 assert (0, 0) in clues def test_distance_check(): clue...
[ { "docstring": "Check if the coordinate (x, y) is a valid clue location. ", "function_declaration": "def is_valid_coordinate(x, y, clues):", "function_name": "is_valid_coordinate", "parameter_list": "(x, y, clues)" }, { "docstring": "Check if the sum of the squares of coordinates remains eve...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_valid_coordinate(x, y, clues):\n \"\"\" Check if the coordinate (x, y) is a valid clue location. \"\"\"\n if any(math.dist((x, y), (cx,...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001035", "row_id": 1035, "seed_ids": "[5942]" }
0.580315
Taco_1035
I
[ "is_valid_coordinate", "are_squares_even", "generate_clues", "scavenger_hunt" ]
4
[ [ "generate_clues", "are_squares_even" ], [ "generate_clues", "is_valid_coordinate" ], [ "scavenger_hunt", "generate_clues" ] ]
3
[]
false
[]
false
pytest
true
[]
true
2bbcf1acc41b69dc1bd1bfcd2ea3d7a9a60ec130
a32a0f4a82318ec4f50f7ae86aa0a1329dba3661
v1.0
instruct
Taco
Taco_1054_I
=====Problem Statement===== You are given another list of rational numbers. Your task is to find and print the sum of these rational numbers in its simplest form. Concept The `fractions.Fraction` class provides support for rational number arithmetic in Python. Using this class, you can easily create fractions and perf...
from fractions import Fraction def sum_of_fractions(fractions_list): """ Takes a list of tuples representing fractions and returns the sum of them in simplest form. Args: fractions_list (list): A list of tuples where each tuple contains two integers (numerator, denominator). Returns: ...
from solution import sum_of_fractions def test_single_fraction(): assert sum_of_fractions([(1, 2)]) == Fraction(1, 2) def test_two_fractions(): assert sum_of_fractions([(1, 3), (2, 5)]) == Fraction(11, 15) def test_multiple_fractions(): assert sum_of_fractions([(1, 2), (1, 3), (1, 6)]) == Fraction(1, 1) ...
[ { "docstring": "Takes a list of tuples representing fractions and returns the sum of them in simplest form.\n\nArgs:\nfractions_list (list): A list of tuples where each tuple contains two integers (numerator, denominator).\n\nReturns:\nFraction: The sum of the fractions in simplest form.", "function_declara...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from fractions import Fraction\n\ndef sum_of_fractions(fractions_list):\n \"\"\"\n Takes a list of tuples representing fractions and returns the sum of them ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00001054", "row_id": 1054, "seed_ids": "[22499]" }
0.59079
Taco_1054
I
[ "sum_of_fractions", "rational_sum" ]
2
[ [ "rational_sum", "sum_of_fractions" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2c559c4131c1777679dd5fbc62a0fe7a31bc7464
4c16193583ff0f04dcb3b0daef1625e3459462f8
v1.0
instruct
Taco
Taco_1085_I
Given a binary tree, return the values of its nodes in a specific order, known as "bottom-up level order traversal". In this order, the tree is traversed level by level from the bottom up, and from left to right within each level. -----Input----- The input consists of a single line that represents the binary tree in l...
from collections import deque class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nodes): if not nodes or nodes[0] == "null": return None root = TreeNode(int(nodes[0])) queue = deque([root]...
from solution import level_order_to_bottom_up def test_level_order_to_bottom_up_example1(): input_str = "3 9 20 null null 15 7" expected_output = "15 7 9 20 3" assert level_order_to_bottom_up(input_str) == expected_output def test_level_order_to_bottom_up_example2(): input_str = "1 2 3 4 null null 5" ...
[]
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00001085", "row_id": 1085, "seed_ids": "[23573]" }
0.541903
Taco_1085
I
[ "build_tree", "bottom_up_level_order_traversal", "level_order_to_bottom_up" ]
3
[ [ "level_order_to_bottom_up", "bottom_up_level_order_traversal" ], [ "level_order_to_bottom_up", "build_tree" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6230f1a6212dd9a937d27daf8258a7ace11c7062
f4a670129287ac64743d8f5a64a512dadd606510