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 | complete | Taco | Taco_40584_C | def minimum_cost_to_construct(N, M, roads, K, new_roads):
"""
The Kingdom of Codesland has N cities connected by M bidirectional roads. Each
road connects two cities and has an associated travel cost. The King wants to
build new roads in such a way that there is exactly one path between any two
citi... | def find(parent, i):
if parent[i] == i:
return 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 ra... | from solution import minimum_cost_to_construct
def test_minimum_cost_case_1():
assert minimum_cost_to_construct(4, 3, [(1, 2, 3), (2, 3, 1), (3, 4, 4)], 2, [(1, 4, 2), (2, 4, 3)]) == 6
def test_minimum_cost_case_2():
assert minimum_cost_to_construct(3, 2, [(1, 2, 5), (2, 3, 10)], 1, [(1, 3, 1)]) == 6
def tes... | [
{
"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,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_min_cost_to_construct_network(N, M, existing_roads, K, new_roads):\n parent = list(range(N + 1))\n \n def find(x):\n if parent[x] != x:\n ... | trial_gpt4o_2 | {
"original_instruction": "The Kingdom of Codesland has $N$ cities connected by $M$ bidirectional roads. Each road connects two cities and has an associated travel cost. The King wants to build new roads in such a way that there is exactly one path between any two cities (i.e., the road network is a tree).\n\nAdditio... | 0.716148 | Taco_40584 | C | [
"find",
"union",
"minimum_cost_to_construct"
] | 3 | [
[
"minimum_cost_to_construct",
"find"
],
[
"minimum_cost_to_construct",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | c95d5bdf60d183d6b7c2d89f5290029f4770aef0 | b7f9c8c8e80d454a716c0f177692dea255242be1 | |||
v1.0 | complete | Taco | Taco_41148_C | def count_twin_primes(n: int) -> int:
""" Returns the number of twin prime pairs (p1, p2) such that both p1 and p2 are less than or equal to n.
>>> count_twin_primes(10) 2
>>> count_twin_primes(20) 4
""" | def is_prime(x):
"""
Helper function to check if a number x is prime.
"""
if x <= 1:
return False
if x <= 3:
return True
if x % 2 == 0 or x % 3 == 0:
return False
i = 5
while i * i <= x:
if x % i == 0 or x % (i + 2) == 0:
return False
i... | from solution import count_twin_primes
def test_small_range():
assert count_twin_primes(10) == 2 # (3, 5) and (5, 7)
def test_with_no_twin_primes():
assert count_twin_primes(3) == 0 # No twin primes in this range
def test_larger_range():
assert count_twin_primes(20) == 4 # (3, 5), (5, 7), (11, 13), an... | [
{
"docstring": "Helper function to check if a number x is prime.",
"function_declaration": "def is_prime(x):",
"function_name": "is_prime",
"parameter_list": "(x)"
},
{
"docstring": "Returns the number of twin prime pairs (p1, p2) such that both p1 and p2 are less than or equal to n.",
... | [
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": "def is_prime(x):\n \"\"\"\n Helper function to check if a number x is prime.\n \"\"\"\n if x <= 1:\n return False\n if x <= 3:\n retur... | trial_gpt4o_0 | {
"original_instruction": "Hi everyone!\n\nLet's tackle a fun problem involving prime numbers. \n\nA twin prime is a prime number that has a prime gap of two. In other words, a twin prime is a pair of prime numbers that differ by 2. For example, (3, 5) and (11, 13) are twin primes.\n\nYour task is to write a function... | 0.643544 | Taco_41148 | C | [
"is_prime",
"count_twin_primes"
] | 2 | [
[
"count_twin_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ee9c3125bf4a4aa0f85ae2380efaceb8f8125e18 | d7e31f9379ce13a95e3eef28aaa6eefd7f6aa45e | |||
v1.0 | complete | Taco | Taco_40670_C | from typing import List
def product_except_self(arr: List[int], mod: int = 10**9+7) -> List[int]:
""" Computes the product of all elements in the array except for the one at the same position,
with each product taken modulo 10^9 + 7.
Args:
arr (List[int]): The input list of distinct integers.
mod (... | def product_except_self(arr, mod=10**9+7):
n = len(arr)
if n < 2:
return []
result = [1] * n
left_product = 1
for i in range(n):
result[i] = left_product
left_product = (left_product * arr[i]) % mod
right_product = 1
for i in range(n-1, -1, -1):
result[i] =... | from solution import product_except_self, compute_products_for_all_cases, parse_input_input
def test_example_case():
test_cases = [[1, 2, 3, 4]]
expected = [[24, 12, 8, 6]]
assert compute_products_for_all_cases(test_cases) == expected
def test_case_with_single_element():
test_cases = [[1]]
expecte... | [
{
"docstring": null,
"function_declaration": "def product_except_self(arr, mod=10 ** 9 + 7):",
"function_name": "product_except_self",
"parameter_list": "(arr, mod=10 ** 9 + 7)"
},
{
"docstring": null,
"function_declaration": "def compute_products_for_all_cases(test_cases):",
"functi... | [
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": "MOD = 10**9 + 7\n\ndef compute_b_list(test_cases):\n results = []\n for n, arr in test_cases:\n total_product = 1\n zero_count = 0\n for... | trial_gpt4o_2 | {
"original_instruction": "Alice has a list of distinct integers $a_1, a_2, \\ldots, a_n$. She wants to create a new list $b$ such that each element in $b$ is equal to the product of all elements in $a$ except the one at the same position. However, she quickly realizes that producing these products could result in ve... | 0.650366 | Taco_40670 | C | [
"product_except_self",
"compute_products_for_all_cases",
"parse_input_input"
] | 3 | [
[
"compute_products_for_all_cases",
"product_except_self"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ba183ceca634eca79161de40bef61daaf99bae80 | 14e326e731f2de946365f9b04a17a684470fcc58 | |||
v1.0 | complete | Taco | Taco_40719_C | def add_truck(fleet, subordinates, capacities, p, c, x):
""" Add a new truck `p` with load capacity `x` as a subordinate to truck `c`.
"""
pass
def update_truck_capacity(capacities, p, x):
""" Update the load capacity of truck `p` to `x`.
"""
pass
def query_total_capacity(subordinates, capacit... | def add_truck(fleet, subordinates, capacities, p, c, x):
capacities.append(x) # Add new truck capacity
fleet[p] = c # Set super truck relationship
if c in subordinates:
subordinates[c].append(p)
else:
subordinates[c] = [p]
def update_truck_capacity(capacities, p, x):
capacities[p-... | def test_manage_fleet():
N = 5
initial_loads = [10, 5, 8, 3, 7]
connections = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [
('Q', 1), # Total load = 10 + 5 + 8 + 3 + 7 = 33
('Q', 2), # Total load = 5 + 3 + 7 = 15
('A', 6, 2, 1), # Add truck 6 with load 2 under truck 1
... | [
{
"docstring": null,
"function_declaration": "def add_truck(fleet, subordinates, capacities, p, c, x):",
"function_name": "add_truck",
"parameter_list": "(fleet, subordinates, capacities, p, c, x)"
},
{
"docstring": null,
"function_declaration": "def update_truck_capacity(capacities, p, ... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\nclass FleetManagement:\n def __init__(self, N, load_capacities, subordinates):\n self.truck_loads = [0] * (... | trial_gpt4o_5 | {
"original_instruction": "A transportation company is planning a new system to manage its fleet of trucks. Each truck is capable of carrying a certain load, and they need to optimize the fleet's efficiency in carrying goods between two locations. The company's fleet is organized into a hierarchical structure where e... | 0.541914 | Taco_40719 | C | [
"add_truck",
"update_truck_capacity",
"query_total_capacity",
"manage_fleet"
] | 4 | [
[
"manage_fleet",
"add_truck"
],
[
"manage_fleet",
"query_total_capacity"
],
[
"manage_fleet",
"update_truck_capacity"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | f17938794c6d5b63f8e101fffb5e8e432ca449c1 | 87ee6810b8ee02558bea73452171790ed7812eca | |||
v1.0 | complete | Taco | Taco_41076_C | import re
from typing import List
def normalize_number(number: str) -> str:
"""Normalize the mobile number by removing any non-numeric characters.
>>> normalize_number("123-456-7890")
'1234567890'
>>> normalize_number("(123) 456 7890")
'1234567890'
"""
pass
def count_unique_numbers(numbers... | import re
def normalize_number(number):
"""
Normalize the mobile number by removing any non-numeric characters.
"""
return re.sub(r'\D', '', number)
def count_unique_numbers(numbers):
"""
Count the number of unique normalized mobile numbers.
"""
normalized_numbers = set(normalize_numbe... | import pytest
from solution import normalize_number, count_unique_numbers
def test_normalize_number():
assert normalize_number("123-456-7890") == "1234567890"
assert normalize_number("(123) 456 7890") == "1234567890"
assert normalize_number("123 456 7890") == "1234567890"
assert normalize_number("12345... | [
{
"docstring": "Normalize the mobile number by removing any non-numeric characters.",
"function_declaration": "def normalize_number(number):",
"function_name": "normalize_number",
"parameter_list": "(number)"
},
{
"docstring": "Count the number of unique normalized mobile numbers.",
"fun... | [
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": "def normalize_mobile_number(number):\n \"\"\"\n Normalize the mobile number by removing non-numeric characters.\n \"\"\"\n normalized = ''.join(filter(... | trial_gpt4o_2 | {
"original_instruction": "In a certain country, mobile numbers follow a specific format. Each mobile number consists of 10 digits, without any separators. However, due to common usage, some people often format numbers with spaces, hyphens, or even parentheses for ease of readability. \n\nFor example, the following a... | 0.601399 | Taco_41076 | C | [
"normalize_number",
"count_unique_numbers"
] | 2 | [
[
"count_unique_numbers",
"normalize_number"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b82cbc92b2a33604c94d1fad9f04a44069c5564c | f3d9f0dbf348cae3f1932857a3806fda0295a7a7 | |||
v1.0 | complete | Taco | Taco_40921_C | from itertools import permutations
from typing import List, Tuple
def permute_books(book_list: List[str]) -> List[Tuple[str]]:
"""
Returns all unique permutations of the books in lexicographical order.
>>> permute_books(["red", "blue", "green"])
[('blue', 'green', 'red'), ('blue', 'red', 'green'), ('gr... | from itertools import permutations
def permute_books(book_list):
"""
Returns all unique permutations of the books in lexicographical order.
"""
book_list = sorted(book_list) # Ensure the input list is sorted lexicographically
perm = permutations(book_list)
unique_permutations = list(dict.fromk... | from solution import permute_books, print_permutations
import pytest
def test_permute_books_single():
books = ["red"]
result = permute_books(books)
expected = [("red",)]
assert result == expected
def test_permute_books_two():
books = ["red", "blue"]
result = permute_books(books)
expected =... | [
{
"docstring": "Returns all unique permutations of the books in lexicographical order.",
"function_declaration": "def permute_books(book_list):",
"function_name": "permute_books",
"parameter_list": "(book_list)"
},
{
"docstring": "Print all unique permutations of the input books in lexicogra... | [
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 itertools import permutations\n\ndef list_permutations(books):\n \"\"\"\n Returns all unique permutations of the books in lexicographical order.\n \n... | trial_gpt4o_2 | {
"original_instruction": "Neha is an avid collector of antique books. She loves organizing her collection in various ways and wants to develop a program to aid her in creating different permutations of her books. Given a list of books she owns, she wants a way to rearrange them into distinct sequences where no book ... | 0.614848 | Taco_40921 | C | [
"permute_books",
"print_permutations"
] | 2 | [
[
"print_permutations",
"permute_books"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cd72035c0926daa62226fcd513c95434af82624e | 3553c7a8e32cba174289e17679de12fa5415701b | |||
v1.0 | complete | Taco | Taco_41235_C | def who_wins(n: int) -> str:
""" Determine who will win the game if both players play optimally.
Alice starts the game and can remove a prime number of tokens.
Bob takes the next turn and can remove a perfect square number of tokens.
>>> who_wins(10) "Alice"
>>> who_wins(15) "Bob"
>>> who_wins(2... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | def test_who_wins_alice():
assert who_wins(10) == "Alice"
def test_who_wins_bob():
assert who_wins(15) == "Bob"
def test_who_wins_small_number_alice():
assert who_wins(2) == "Alice"
def test_who_wins_small_number_bob():
assert who_wins(1) == "Bob"
def test_who_wins_large_number():
assert who_win... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Check if there is any prime number <= n.",
"function_declaration": "def has_prime(n):",
"function_n... | [
0,
0,
0,
0,
1,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef 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 ret... | trial_gpt4o_5 | {
"original_instruction": "Consider an online game where two players, Alice and Bob, take turns playing a game with an initial number of tokens, `n`. The game is played as follows:\n\n- On Alice's turn, she can remove a number of tokens that is a prime number.\n- On Bob's turn, he can remove a number of tokens that i... | 0.711639 | Taco_41235 | C | [
"is_prime",
"has_prime",
"has_perfect_square",
"who_wins"
] | 4 | [
[
"has_prime",
"is_prime"
],
[
"who_wins",
"has_perfect_square"
],
[
"who_wins",
"has_prime"
],
[
"who_wins",
"is_prime"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 1c47909df5bdea59aafa578ce161c96d01fb88de | 4125e71645bd83237a728265fd7a2cb3c2bc1011 | |||
v1.0 | complete | Taco | Taco_41215_C | def is_prime(n: int) -> bool:
""" Helper function to check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(1)
False
"""
def sum_of_primes(numbers: list) -> int:
""" Returns the sum of all prime n... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
if n % d == 0:
return False
... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-3) == False
assert is_prime(17) == True... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the given list.",
"function_declaration": "def sum_of_primes(number... | [
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 \"\"\"Helper function to check if a number is prime.\"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n ... | trial_gpt4o_2 | {
"original_instruction": "In a given list of integers, you are required to find the sum of all the integers which are prime numbers.\n\nYour task is to implement a function to filter out the prime numbers from the list and calculate their sum. Recall that a prime number is a number greater than 1 that is not divisib... | 0.777635 | Taco_41215 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dd7a5b528066325ea0384721d56021af8b267413 | cd85f33afdfa743e9ff0e2c1e737940ec0b0386b | |||
v1.0 | complete | Taco | Taco_40649_C | import sys
from collections import defaultdict, deque
def build_tree(n, edges):
""" Build a tree (an acyclic connected graph) from the list of edges.
>>> build_tree(5, [(1, 2, 3), (1, 3, 4), (2, 4, 2), (2, 5, 6)])
{1: [(2, 3), (3, 4)], 2: [(1, 3), (4, 2), (5, 6)], 3: [(1, 4)], 4: [(2, 2)], 5: [(2, 6)]}
... | import sys
from collections import defaultdict, deque
def build_tree(n, edges):
tree = defaultdict(list)
for u, v, w in edges:
tree[u].append((v, w))
tree[v].append((u, w))
return tree
def bfs(tree, start):
distances = {start: 0}
queue = deque([start])
while queue:
node... | def test_build_tree():
edges = [(1, 2, 3), (1, 3, 4), (2, 4, 2), (2, 5, 6)]
expected_tree = {
1: [(2, 3), (3, 4)],
2: [(1, 3), (4, 2), (5, 6)],
3: [(1, 4)],
4: [(2, 2)],
5: [(2, 6)]
}
assert build_tree(5, edges) == expected_tree
def test_bfs():
tree = {
... | [
{
"docstring": null,
"function_declaration": "def build_tree(n, edges):",
"function_name": "build_tree",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def bfs(tree, start):",
"function_name": "bfs",
"parameter_list": "(tree, start)"
},
{
... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict\nimport heapq\n\ndef build_graph(n, edges):\n graph = defaultdict(list)\n for u, v, w in edges:\n grap... | trial_gpt4o_9 | {
"original_instruction": "In an ancient city, there exists a special kind of road capable of branching out into others, forming an extensive network. Each road in this network is represented by a unique integer length. The residents of the city often take routes that pass through several roads to get from one point ... | 0.621034 | Taco_40649 | C | [
"build_tree",
"bfs",
"answer_queries",
"solve"
] | 4 | [
[
"answer_queries",
"bfs"
],
[
"solve",
"answer_queries"
],
[
"solve",
"build_tree"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 149b16fd919fcf5aa7d16ed26d01a60252d92e57 | fb84822b54e1d37ee8fcea4bded43a382e73a6ce | |||
v1.0 | complete | Taco | Taco_40952_C | from typing import List, Tuple
def shortest_path_through_node(n: int, e: int, s: int, t: int, m: int, edges: List[Tuple[int, int, int]]) -> int:
""" Calculate the shortest path passing through a specific node in a directed graph.
:param n: Number of nodes in the graph
:param e: Number of edges in the graph... | import heapq
def dijkstra(graph, start, n):
dist = [float('inf')] * n
dist[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_dist, node = heapq.heappop(priority_queue)
if current_dist > dist[node]:
continue
for neighbor, we... | def test_shortest_path_through_node():
n = 5
e = 7
s = 0
t = 4
m = 2
edges = [
(0, 1, 10),
(0, 2, 3),
(1, 2, 1),
(1, 3, 2),
(2, 3, 8),
(2, 4, 5),
(3, 4, 2)
]
assert shortest_path_through_node(n, e, s, t, m, edges) == 8
def tes... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_through_node(n, e, s, t, m, edges):",
"function_name": "shortest_path_t... | [
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": "import heapq\n\ndef dijkstra(n, graph, start):\n distances = {node: float('inf') for node in range(n)}\n distances[start] = 0\n priority_queue = [(0, star... | trial_gpt4o_1 | {
"original_instruction": "You are given a directed graph with nodes labeled from $0$ to $n-1$. Each directed edge has a travel time associated with it. Your task is to determine if there is a path from the start node to the end node that passes through a specific required node $m$ and provide the total travel time o... | 0.679908 | Taco_40952 | C | [
"dijkstra",
"shortest_path_through_node",
"main"
] | 3 | [
[
"shortest_path_through_node",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 2886038266501eb336e547104ce707043f56de21 | a1b48be7ebac60f7004f8c7678961d27e55a1e65 | |||
v1.0 | complete | Taco | Taco_41337_C | def find(parent, i):
"""Find the root of the set in which element i is located."""
pass
def union(parent, rank, x, y):
"""Perform the union of two sets x and y."""
pass
def kruskal(n, edges):
"""Implement Kruskal's algorithm to find the Minimum Spanning Tree and return the maximum edge weight in t... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | def test_find():
parent = [0, 1, 2, 3]
assert find(parent, 0) == 0
assert find(parent, 1) == 1
parent[1] = 0
assert find(parent, 1) == 0
def test_union():
parent = [0, 1, 2, 3]
rank = [0, 0, 0, 0]
union(parent, rank, 0, 1)
assert find(parent, 1) == 0
parent = [0, 1, 2, 3]
... | [
{
"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,
0,
0,
0,
0
] | 1 | hard | 0.111 | {
"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 xroot = fi... | trial_gpt4o_5 | {
"original_instruction": "A city has N intersections and M bidirectional roads connecting them. Each road has a unique ID and a travel time. The city's transportation department wants to rearrange the roads to minimize the maximum travel time between any two intersections. The following steps can be performed any nu... | 0.607983 | Taco_41337 | C | [
"find",
"union",
"kruskal",
"min_max_travel_time",
"main"
] | 5 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"min_max_travel_time",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 3732678a779302a2dca689478d4b3405a4195003 | 93ae18d63ce7a500a9806ed1ac2696f3e0f70358 | |||
v1.0 | complete | Taco | Taco_41093_C | from typing import List, Tuple
def max_values_at_levels(n: int, nodes: List[Tuple[int, int, int]]) -> List[int]:
""" Given a number of nodes and a list of tuples representing the binary tree nodes (value, left child, right child),
find the maximum value of the node levels.
>>> max_values_at_levels(7, ... | from collections import defaultdict, deque
def max_values_at_levels(n, nodes):
if n == 0:
return []
tree = defaultdict(lambda: [-1, -1])
for v, l, r in nodes:
tree[v] = [l, r]
levels = defaultdict(list)
queue = deque([(1, 0)]) # (node value, level)
while queue:
... | from solution import max_values_at_levels
def test_max_values_at_levels_basic():
n = 7
nodes = [
(1, 2, 3),
(2, 4, 5),
(3, -1, 6),
(4, -1, -1),
(5, -1, -1),
(6, 7, -1),
(7, -1, -1)
]
result = max_values_at_levels(n, nodes)
assert result == [1,... | [
{
"docstring": null,
"function_declaration": "def max_values_at_levels(n, nodes):",
"function_name": "max_values_at_levels",
"parameter_list": "(n, nodes)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"parameter_list": "()"
}
] | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef max_values_at_levels(n, nodes):\n if n == 0:\n return []\n \n tree = def... | trial_gpt4o_1 | {
"original_instruction": "Given a binary tree, you need to find the maximum value of the node levels. \n\nThe node level is defined as the horizontal distance of a node from the root. For the root node, the level is 0. For any other node, the level is equal to the parent node's level plus 1.\n\nYour task is to deter... | 0.629365 | Taco_41093 | C | [
"max_values_at_levels",
"solve"
] | 2 | [
[
"solve",
"max_values_at_levels"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 588763701f9fb32a3a42262ce16289ce7f2e1d90 | 8f5a5c63c53b38c2dc093f247e5d15a5ec9a5c34 | |||
v1.0 | complete | Taco | Taco_41439_C | def calculate_final_price(M: int) -> float:
"""
Calculate the final price Divya has to pay after applying any applicable discount.
If the meal cost is a prime number, apply a 20% discount.
Parameters:
M (int): Cost of the meal in dollars.
Returns:
float: Final price to be paid... | def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i +... | from solution import calculate_final_price
def test_prime_number_with_discount():
assert calculate_final_price(17) == 13.60
assert calculate_final_price(19) == 15.20
assert calculate_final_price(23) == 18.40
def test_non_prime_number_no_discount():
assert calculate_final_price(21) == 21.00
assert ... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the final price Divya has to pay after applying discount if necessary.",
"function_declaration": "d... | [
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 Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_0 | {
"original_instruction": "Divya wants to purchase a meal that costs M dollars at a restaurant. The restaurant has a promotion where if the cost of the meal is a prime number, Divya gets a 20% discount on the total cost. You need to calculate the final price Divya has to pay after applying the discount (if applicable... | 0.563077 | Taco_41439 | C | [
"is_prime",
"calculate_final_price"
] | 2 | [
[
"calculate_final_price",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4229268ad760e9e006d91d072cfddc496154d5e4 | 7330a85acec654e31a9ce5818f4c9bec86688e87 | |||
v1.0 | complete | Taco | Taco_41323_C | from typing import List, Tuple
def preprocess_text(text: str) -> str:
"""
Preprocess tweet text by converting to lowercase and removing special characters.
:param text: The original tweet text
:return: The preprocessed tweet text
"""
def train_model(training_data: List[Tuple[str, str, str]]) -> di... | import re
import csv
from collections import defaultdict
def preprocess_text(text):
"""
Preprocess tweet text by converting to lowercase and removing special characters.
"""
text = text.lower()
text = re.sub(r'[^\w\s]', '', text)
return text
def train_model(training_data):
"""
Train a ... | from solution import preprocess_text, train_model, classify_tweets
def test_preprocess_text():
assert preprocess_text("Just won a marathon!") == "just won a marathon"
assert preprocess_text("Breaking: the stock market crashes!") == "breaking the stock market crashes"
assert preprocess_text("Can't wait for ... | [
{
"docstring": "Preprocess tweet text by converting to lowercase and removing special characters.",
"function_declaration": "def preprocess_text(text):",
"function_name": "preprocess_text",
"parameter_list": "(text)"
},
{
"docstring": "Train a simple keyword-based classification model based ... | [
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": "import re\nimport numpy as np\nimport pandas as pd\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nfro... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with creating a program that classifies tweets into one of three categories. We have access to a training set of tweets, each labeled with a category: 1 (sports), 2 (news), or 3 (entertainment). The training set includes tweets in CSV format, with each row containing a tweet ... | 0.60233 | Taco_41323 | C | [
"preprocess_text",
"train_model",
"classify_tweet",
"classify_tweets",
"main"
] | 5 | [
[
"classify_tweet",
"preprocess_text"
],
[
"classify_tweets",
"classify_tweet"
],
[
"train_model",
"preprocess_text"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 951a7d49a6f2a6cd6aca98e0b747dc4bba6a3b20 | c500c8ddd4ff0e898d045749045ec0bc1cb3fdcb | |||
v1.0 | complete | Taco | Taco_41155_C | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root_y]:
parent[root_y] ... | def test_kruskal_mst():
n = 4
adjacency_matrix = [
[0, 1, 3, 0],
[1, 0, 3, 6],
[3, 3, 0, 2],
[0, 6, 2, 0]
]
assert calculate_mst_weight(n, adjacency_matrix) == 6
def test_kruskal_mst_single_edge():
n = 2
adjacency_matrix = [
[0, 1],
[1, 0]
]
... | [
{
"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)"
},
... | [
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 find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\... | trial_gpt4o_0 | {
"original_instruction": "You are given an undirected, weighted graph represented by its adjacency matrix. Your task is to determine the minimum spanning tree (MST) of the graph using Kruskal's algorithm and output the sum of the weights of the edges in the MST.\n\nTo achieve this, follow these steps:\n\n1. Extract ... | 0.688699 | Taco_41155 | C | [
"find",
"union",
"kruskal_mst",
"calculate_mst_weight"
] | 4 | [
[
"calculate_mst_weight",
"kruskal_mst"
],
[
"kruskal_mst",
"find"
],
[
"kruskal_mst",
"union"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 1c3bea74b6c4b7bf61703c2367e17dc6cad2fde2 | a69989967f36b4dba8a9517fc8157c7d4389fd37 | |||
v1.0 | complete | Taco | Taco_41483_C | def is_prime(n):
"""
Check if a number is prime.
>>> is_prime(2) True
>>> is_prime(4) False
>>> is_prime(17) True
>>> is_prime(18) False
"""
def get_primes(array):
"""
Returns a new array containing only the prime numbers from the input array,
preserving the order of their f... | def is_prime(n):
"""
Check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True... | from solution import is_prime, get_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(5) == True
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(17) == True
assert is_prime(18) == False
d... | [
{
"docstring": "Check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a new array containing only the prime numbers from the input array,\npreserving the order of their first occurrence.",
... | [
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_0 | {
"original_instruction": "Write a function that takes an array of integers and returns a new array containing only the prime numbers from the input array, preserving the order of their first occurrence.\n\n```\ninput: [arrayOfIntegers]\noutput: [arrayOfPrimes]\nexample: [15, 3, 8, 11, 2, 5, 4, 2] --> [3, 11, 2, 5, ... | 0.853514 | Taco_41483 | C | [
"is_prime",
"get_primes"
] | 2 | [
[
"get_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7dbeb024d60eb1ceb0b6061b28ad4b2e5384ccfa | 25bea629d2a2d8b2810957950178eec8fe6fe0a2 | |||
v1.0 | complete | Taco | Taco_41011_C | def beautify_flower_beds(input_string: str) -> List[int]:
""" Calculate the maximum possible beauty of Mina's flower bed after rearrangement.
Args:
input_string (str): The input string describing the test cases and grids.
Returns:
List[int]: A list of integers representing the maximum possible... | def max_beauty(grid, N, M):
"""
Calculate the maximum possible beauty of the flower bed after rearrangement.
"""
flower_counts = {}
for row in grid:
for flower in row:
if flower in flower_counts:
flower_counts[flower] += 1
else:
flower_... | def test_beautify_flower_beds():
input_string = "3\n3 3 3\n1 2 3\n3 2 1\n1 3 2\n4 4 4\n1 2 1 2\n2 1 2 1\n3 4 3 4\n4 3 4 3\n5 5 5\n1 1 1 1 1\n2 2 2 2 2\n3 3 3 3 3\n4 4 4 4 4\n5 5 5 5 5"
expected_output = [3, 4, 5]
assert beautify_flower_beds(input_string) == expected_output
def test_single_type():
input... | [
{
"docstring": "Calculate the maximum possible beauty of the flower bed after rearrangement.",
"function_declaration": "def max_beauty(grid, N, M):",
"function_name": "max_beauty",
"parameter_list": "(grid, N, M)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str... | [
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": "def max_beauty(grid, N, M):\n \"\"\"\n Calculate the maximum possible beauty of the flower bed after rearrangement.\n \"\"\"\n flower_counts = {}\n ... | trial_gpt4o_0 | {
"original_instruction": "Mina is passionate about gardening and has a special flower bed she takes care of daily. Her flower bed is represented as a 2D grid of dimensions NxM (N rows and M columns), where each position contains a flower of a certain type. The flowers are identified by numbers from 1 to K. Mina’s go... | 0.606826 | Taco_41011 | C | [
"max_beauty",
"parse_input",
"beautify_flower_beds"
] | 3 | [
[
"beautify_flower_beds",
"max_beauty"
],
[
"beautify_flower_beds",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 671993e60709d81978c5b7c0f44462b7f778086b | 4c8db6a5e8ce22b58981b0b2277cf0a11d1e757c | |||
v1.0 | complete | Taco | Taco_41207_C | def find_subsequence(n: int, k: int, sequence: List[int]) -> str:
""" Determines if there exists a contiguous sub-sequence whose sum is divisible by k.
>>> find_subsequence(5, 3, [1, 2, 3, 4, 5])
"YES"
>>> find_subsequence(4, 11, [1, 2, 4, 8])
"NO"
>>> find_subsequence(6, 5, [-1, 2, 9, -4, 3, 1]... | def has_subsequence_divisible_by_k(n, k, sequence):
prefix_sum = 0
prefix_sums_mod_k = {0}
for num in sequence:
prefix_sum += num
mod_k = prefix_sum % k
if mod_k in prefix_sums_mod_k:
return "YES"
prefix_sums_mod_k.add(mod_k)
return "NO... | from solution import find_subsequence
def test_example1():
n = 5
k = 3
sequence = [1, 2, 3, 4, 5]
assert find_subsequence(n, k, sequence) == "YES"
def test_example2():
n = 4
k = 11
sequence = [1, 2, 4, 8]
assert find_subsequence(n, k, sequence) == "NO"
def test_example3():
n = 6
... | [
{
"docstring": null,
"function_declaration": "def has_subsequence_divisible_by_k(n, k, sequence):",
"function_name": "has_subsequence_divisible_by_k",
"parameter_list": "(n, k, sequence)"
},
{
"docstring": null,
"function_declaration": "def find_subsequence(n, k, sequence):",
"functi... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
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_subsequence_divisible(n, k, sequence):\n \"\"\"\n Determines if there exists a contiguous sub-sequence in a sequence whose sum is divisible by k.\n\n ... | trial_gpt4o_6 | {
"original_instruction": "The students of the Russian School of Mathematics have developed a mathematical game which involves finding specific number patterns in sequences of integers. The game is played as follows: Given a sequence of integers, find if there exists a contiguous sub-sequence whose sum is divisible b... | 0.666526 | Taco_41207 | C | [
"has_subsequence_divisible_by_k",
"find_subsequence"
] | 2 | [
[
"find_subsequence",
"has_subsequence_divisible_by_k"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 04cb4455e644526f8ffe3f34fab39852bcf4aa3c | 176a4a694b223c8d468b847275a874cf60aadd2d | |||
v1.0 | complete | Taco | Taco_41647_C | def is_prime(n: int) -> bool:
"""
Determines if the given number n is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
"""
# Complete the function
def smallest_prime_in_range(a: int, b: int) -> int:
"""
Returns the smallest prime number i... | def is_prime(n):
"""
Determines if the given number n is a prime number.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(11) == True
assert is_prime(25) == False
def test_smallest_prime_in_range():
assert smallest_prime_in_range(10, 20) == 11
assert smallest_prime_in_range(24, 28) == -1
a... | [
{
"docstring": "Determines if the given number n is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the smallest prime number in the inclusive range [a, b].\nReturns -1 if there is no such prime num... | [
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_prime(n):\n \"\"\"\n Determines if the given number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n re... | trial_gpt4o_0 | {
"original_instruction": "You are given two long integers, $a$ and $b$, which represent the start and end of a range, respectively. Write a program to compute the smallest prime number that is greater than or equal to $a$ and less than or equal to $b$. If there is no such prime number, return -1.\n\nInput Format\n\n... | 0.784399 | Taco_41647 | C | [
"is_prime",
"smallest_prime_in_range"
] | 2 | [
[
"smallest_prime_in_range",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 9dd36682e48cd3487729b94630eefeb628665c1c | c354f753a24453f975489cc539b74dc2a31af825 | |||
v1.0 | complete | Taco | Taco_41557_C | def maximum_profit(V: int, E: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Given the number of planets and the trade routes that connect them, along with the associated values of these trade routes,
finds the maximum possible profit that can be obtained by establishing a subset of the trade routes ... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | def test_maximum_profit_simple():
V, E = 4, 5
edges = [
(0, 1, 10),
(0, 2, 6),
(0, 3, 5),
(1, 3, 15),
(2, 3, 4)]
assert maximum_profit(V, E, edges) == 31
def test_maximum_profit_all_edges_include():
V, E = 3, 3
edges = [
(0, 1, 5),
(1, 2, 4),
... | [
{
"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)"
},
... | [
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 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 xroot = fi... | trial_gpt4o_1 | {
"original_instruction": "During the intergalactic trading season, a network of trade routes connects different planets. Each trade route has a certain value associated with it. The galactic council needs to determine the most profitable way to establish connections between these planets without forming any cycles (... | 0.579166 | Taco_41557 | C | [
"find",
"union",
"maximum_profit"
] | 3 | [
[
"maximum_profit",
"find"
],
[
"maximum_profit",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 495374c7fb06018b9fea44886a11fee99833990a | 04ea70da5598cc4d9428a218ef47ab5803c3d3a1 | |||
v1.0 | complete | Taco | Taco_41650_C | def product_array(arr: List[int]) -> List[int]:
"""
Returns a list such that each element at index i is the product
of all elements in the array except the one at index i.
>>> product_array([1, 2, 3])
[6, 3, 2]
>>> product_array([1, 2, 3, 4])
[24, 12, 8, 6]
""" | def product_array(arr):
"""
Returns a list such that each element at index i is the product
of all elements in the array except the one at index i.
"""
n = len(arr)
if n == 0:
return []
left_products = [1] * n
right_products = [1] * n
result = [1] * n
# Calcula... | import pytest
from solution import product_array, solve, parse_input, format_output
def test_product_array():
assert product_array([1, 2, 3]) == [6, 3, 2]
assert product_array([1, 2, 3, 4]) == [24, 12, 8, 6]
assert product_array([-1, 1, 0, -3, 3]) == [0, 0, 9, 0, 0]
def test_solve():
test_cases = [
... | [
{
"docstring": "Returns a list such that each element at index i is the product \nof all elements in the array except the one at index i.",
"function_declaration": "def product_array(arr):",
"function_name": "product_array",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_dec... | [
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 product_array(arr):\n \"\"\"\n Returns a list such that each element at index i is the product \n of all elements in the array except the one at index... | trial_gpt4o_0 | {
"original_instruction": "Rina loves playing with arrays and solving puzzles using them. She comes up with an interesting problem. Given a list of integers, she wants to find another list such that each element at index i of the new list is the product of all the numbers in the original list except the one at index ... | 0.726676 | Taco_41650 | C | [
"product_array",
"solve",
"parse_input",
"format_output"
] | 4 | [
[
"solve",
"product_array"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 8c22d5553968162514038993fa8bf6837da38074 | 65e7f1132ee6882ddfa3a349e36ed75521c13a8a | |||
v1.0 | complete | Taco | Taco_41465_C | def count_assignments(M: int, N: int, employees_skills: List[List[int]], projects_requirements: List[List[int]]) -> int:
""" Counts the unique ways to assign employees to projects such that every project has at least one employee assigned.
>>> count_assignments(3, 2, [[1, 2, 3], [2, 3], [4]], [[1, 2], [4]])
... | from itertools import product
def can_assign(employee_skills, project_requirement):
"""
Check if an employee can be assigned to a project based on skills.
"""
return set(project_requirement).issubset(employee_skills)
def count_assignments(M, N, employees_skills, projects_requirements):
"""
Cou... | from solution import count_assignments, parse_input, main
def test_count_assignments():
input_str = "3 2\n3 1 2 3\n2 2 3\n1 4\n2 1 2\n1 4"
M, N, employees_skills, projects_requirements = parse_input(input_str)
assert count_assignments(M, N, employees_skills, projects_requirements) == 2
def test_parse_inpu... | [
{
"docstring": "Check if an employee can be assigned to a project based on skills.",
"function_declaration": "def can_assign(employee_skills, project_requirement):",
"function_name": "can_assign",
"parameter_list": "(employee_skills, project_requirement)"
},
{
"docstring": "Counts the unique... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef can_assign(employee_skills, project_skills):\n \"\"\"\n Checks if an employee with `employee_skills` can be assigne... | trial_gpt4o_7 | {
"original_instruction": "A company has M employees (1 ≤ M ≤ 50) and N projects (1 ≤ N ≤ 50). Each employee i (1 ≤ i ≤ M) has a specific set of skills, represented as a list of integers ranging from 1 to 1000. Each project j (1 ≤ j ≤ N) requires certain skills, also represented as a list of integers from 1 to 1000.\... | 0.643728 | Taco_41465 | C | [
"can_assign",
"count_assignments",
"parse_input",
"main"
] | 4 | [
[
"count_assignments",
"can_assign"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | ffd5df7ba09227f36779f8ad81fc4f34a2cf7d61 | 2bc1834f6edeae188f241703ddfee19d8cb41c73 | |||
v1.0 | complete | Taco | Taco_41598_C | def merchant_max_value(n, W, items):
""" Determine the maximum value of goods that David can carry in his caravan.
>>> merchant_max_value(3, 50, [(10, 60), (20, 100), (30, 120)])
220
>>> merchant_max_value(1, 10, [(10, 100)])
100
>>> merchant_max_value(1, 10, [(20, 100)])
0
>>> merchant_... | def knapsack(n, W, items):
# Create a DP table with dimensions (n+1) x (W+1)
dp = [[0 for _ in range(W + 1)] for _ in range(n + 1)]
# Populate the table
for i in range(1, n + 1):
weight, value = items[i - 1]
for w in range(W + 1):
if weight <= w:
dp[i][w]... | from solution import merchant_max_value
def test_example_case():
n = 3
W = 50
items = [(10, 60), (20, 100), (30, 120)]
assert merchant_max_value(n, W, items) == 220
def test_single_item_just_fits():
n = 1
W = 10
items = [(10, 100)]
assert merchant_max_value(n, W, items) == 100
def tes... | [
{
"docstring": null,
"function_declaration": "def knapsack(n, W, items):",
"function_name": "knapsack",
"parameter_list": "(n, W, items)"
},
{
"docstring": null,
"function_declaration": "def merchant_max_value(n, W, items):",
"function_name": "merchant_max_value",
"parameter_list... | [
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 knapsack(n, W, items):\n \"\"\"\n Returns the maximum value of the goods that can be carried without exceeding the weight limit.\n \n :param n: int... | trial_gpt4o_2 | {
"original_instruction": "David is a traveling merchant who needs to transport his goods using his caravan. His caravan can carry a maximum weight of W units. He has a list of n types of goods, each type having a certain weight and value. David wants to maximize the value of the goods he can carry without exceeding ... | 0.626154 | Taco_41598 | C | [
"knapsack",
"merchant_max_value"
] | 2 | [
[
"merchant_max_value",
"knapsack"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d9350a67c7f5475a6c54606be561a3905ca5830e | a244f725b697e1682883f4eb2ac0c1393b0f055f | |||
v1.0 | complete | Taco | Taco_41596_C | from typing import List, Tuple
def max_smallest_subtree(n: int, edges: List[Tuple[int, int]]) -> int:
""" Find the maximum possible size of the smallest subtree after removing exactly one node.
>>> max_smallest_subtree(5, [(1, 2), (1, 3), (1, 4), (4, 5)]) == 2
>>> max_smallest_subtree(3, [(1, 2), (1, 3)]) ... | from collections import defaultdict, deque
def calculate_subtree_sizes(n, edges):
"""
Calculates the subtree sizes for each node in the tree.
"""
tree = defaultdict(list)
for u, v in edges:
tree[u].append(v)
tree[v].append(u)
# Calculate sizes using DFS
sizes = [0] * (n + 1... | from solution import max_smallest_subtree
def test_example1():
n = 5
edges = [(1, 2), (1, 3), (1, 4), (4, 5)]
assert max_smallest_subtree(n, edges) == 2
def test_example2():
n = 3
edges = [(1, 2), (1, 3)]
assert max_smallest_subtree(n, edges) == 1
def test_single_edge():
n = 2
edges =... | [
{
"docstring": "Calculates the subtree sizes for each node in the tree.",
"function_declaration": "def calculate_subtree_sizes(n, edges):",
"function_name": "calculate_subtree_sizes",
"parameter_list": "(n, edges)"
},
{
"docstring": "Finds the maximum size of the smallest subtree that can re... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_largest_min_subtree_size(n, edges):\n from collections import defaultdict, deque\n\n def bfs(start):\n visited = [False] * (n + 1)\n q... | trial_gpt4o_3 | {
"original_instruction": "John is studying networks and their resilience. He is particularly interested in tree structures. A tree is a connected, undirected graph with n nodes and n-1 edges. He notices that removing some nodes can result in multiple isolated subtrees. John’s task is to find the maximum possible siz... | 0.6454 | Taco_41596 | C | [
"calculate_subtree_sizes",
"max_smallest_subtree"
] | 2 | [
[
"max_smallest_subtree",
"calculate_subtree_sizes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 94deabd841acbc26a125c4dc41a51e1a7a802a38 | 269605c5e659b9610cc5787955a5bd961292dad3 | |||
v1.0 | complete | Taco | Taco_41699_C | def is_palindrome(n: int) -> bool:
""" Check if the given number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
"""
def min_pal(x: int) -> int:
""" Find the minimum palindromic number that is greater than or equal to x.
>>> min_pal(13)
22
>>> min_p... | def is_palindrome(n):
return str(n) == str(n)[::-1]
def min_pal(x):
while not is_palindrome(x):
x += 1
return x
def sum_min_palindromes(a, b):
total_sum = 0
for num in range(a, b+1):
total_sum += min_pal(num)
return total_sum
# Example usage:
# a, b = map(int, input().split())... | from solution import sum_min_palindromes, min_pal, is_palindrome
def test_sum_min_palindromes_example1():
assert sum_min_palindromes(13, 20) == 176
def test_sum_min_palindromes_example2():
assert sum_min_palindromes(123, 127) == 655
def test_sum_min_palindromes_single_value():
assert sum_min_palindromes(... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def min_pal(x):",
"function_name": "min_pal",
"parameter_list": "(x)"
},
{
"docstring": null,
... | [
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_palindrome(n):\n return str(n) == str(n)[::-1]\n\ndef min_pal(x):\n while not is_palindrome(x):\n x += 1\n return x\n\ndef sum_min_palindrom... | trial_gpt4o_1 | {
"original_instruction": "Alice loves palindromic numbers. A palindromic number is a positive integer that remains the same when its digits are reversed. Examples of palindromic numbers are 121, 484, 545, etc.\n\nAlice is curious to know the sum of the minimum palindromic number which is greater than or equal to eac... | 0.720752 | Taco_41699 | C | [
"is_palindrome",
"min_pal",
"sum_min_palindromes"
] | 3 | [
[
"min_pal",
"is_palindrome"
],
[
"sum_min_palindromes",
"min_pal"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3d6efca86f55584c3b0c7217a9bfcdcb1ad8780d | cb9e8ccddb3d67145bdee4a90d8408fb60462ea6 | |||
v1.0 | complete | Taco | Taco_41674_C | from collections import defaultdict
from typing import List, Tuple
def has_path(n: int, edges: List[Tuple[int, int]], queries: List[Tuple[int, int]]) -> List[str]:
"""
Given a directed graph with `n` nodes and `m` edges, determine if there exists a path from
a node `u` to a node `v`.
Parameters:
... | from collections import defaultdict, deque
def build_graph(n, edges):
graph = defaultdict(list)
for a, b in edges:
graph[a].append(b)
return graph
def bfs(graph, start, end):
visited = set()
queue = deque([start])
while queue:
node = queue.popleft()
if node == end:... | def test_basic_graph():
n = 5
edges = [
(1, 2),
(2, 3),
(3, 4),
(4, 5),
(1, 5)
]
queries = [
(1, 5),
(1, 3),
(2, 5),
(5, 1)
]
expected = ["YES", "YES", "YES", "NO"]
assert has_path(n, edges, queries) == expected
def tes... | [
{
"docstring": null,
"function_declaration": "def build_graph(n, edges):",
"function_name": "build_graph",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def bfs(graph, start, end):",
"function_name": "bfs",
"parameter_list": "(graph, start, end)"... | [
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_reach(n, m, edges, queries):\n from collections import defaultdict, deque\n\n def bfs(start, target):\n queue = deque([start])\n visite... | trial_gpt4o_2 | {
"original_instruction": "Given a directed graph with $n$ nodes and $m$ edges, your task is to determine if there exists a path from a node $u$ to a node $v$.\n\n-----Input-----\n\nThe first line of input contains two integers $n$ $(1 \\leq n \\leq 10^5)$ and $m$ $(0 \\leq m \\leq 2 \\cdot 10^5)$, representing the n... | 0.649993 | Taco_41674 | C | [
"build_graph",
"bfs",
"has_path"
] | 3 | [
[
"has_path",
"bfs"
],
[
"has_path",
"build_graph"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 159ad1ccb6d0a46991c4e7e9790fe921f31d5e1b | 63b6e83e2040c7c19e0f41e00ea44b7615ce74fe | |||
v1.0 | complete | Taco | Taco_41154_C | from typing import List, Tuple
def heaviest_edge_on_path(n: int, edges: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:
""" Alice and Bob are playing a game with a tree. A tree is an undirected graph in which any two vertices are connected by exactly one path. The tree has `n` vertices an... | from collections import defaultdict, deque
def build_tree(n, edges):
tree = defaultdict(list)
for u, v, w in edges:
tree[u].append((v, w))
tree[v].append((u, w))
return tree
def bfs_heaviest_edge(tree, n):
max_edge = [[0] * (n + 1) for _ in range(n + 1)]
for start in range(1, ... | def test_heaviest_edge_on_path_case_1():
n = 5
edges = [
(1, 2, 4),
(2, 3, 3),
(3, 4, 5),
(4, 5, 6)
]
queries = [(1, 5), (2, 4), (3, 5)]
assert heaviest_edge_on_path(n, edges, queries) == [6, 5, 6]
def test_heaviest_edge_on_path_case_2():
n = 4
edges = [
... | [
{
"docstring": null,
"function_declaration": "def build_tree(n, edges):",
"function_name": "build_tree",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def bfs_heaviest_edge(tree, n):",
"function_name": "bfs_heaviest_edge",
"parameter_list": "(tre... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Tree:\n def __init__(self, n):\n self.graph = [[] for _ in range(n)]\n self.n = n\n\n def add_edge(self, u, v, w):\n self.graph[u-... | trial_gpt4o_2 | {
"original_instruction": "Alice and Bob are playing a game with a tree. A tree is an undirected graph in which any two vertices are connected by exactly one path. The tree has `n` vertices and `n-1` edges. Each edge has a weight, given by an integer array `w` of length `n-1`.\n\nThey want to know, for each pair of v... | 0.646795 | Taco_41154 | C | [
"build_tree",
"bfs_heaviest_edge",
"heaviest_edge_on_path"
] | 3 | [
[
"heaviest_edge_on_path",
"bfs_heaviest_edge"
],
[
"heaviest_edge_on_path",
"build_tree"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | cb0f29b014882297cf8862c53d2c3a8db9e50e15 | 34f8b44a8399f8cd3cf696b4fba70741fe53b49f | |||
v1.0 | complete | Taco | Taco_41240_C | def max_points(levels):
"""
Determines the maximum points that can be scored in each level by selecting non-overlapping notes.
Args:
levels (List[List[Tuple[int, int, int]]]): A list of levels where each level is a list of tuples.
Each tuple contains... | def max_points(levels):
results = []
for level in levels:
notes = level
notes.sort(key=lambda x: x[1])
max_points = [0] * len(notes)
for i in range(len(notes)):
max_points[i] = notes[i][2]
for j in range(i):
if notes[... | def test_multiple_levels():
T = 2
sequence_data = [
4, # Number of notes in level 1
(0, 3, 10),
(1, 5, 5),
(4, 6, 3),
(5, 8, 8),
3, # Number of notes in level 2
(2, 4, 6),
(1, 3, 4),
(0, 2, 5)
]
result = rhythm_game(T, se... | [
{
"docstring": null,
"function_declaration": "def max_points(levels):",
"function_name": "max_points",
"parameter_list": "(levels)"
},
{
"docstring": null,
"function_declaration": "def rhythm_game(T, sequence_data):",
"function_name": "rhythm_game",
"parameter_list": "(T, sequenc... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_non_overlapping_points(levels):\n def max_points_for_level(notes):\n # Sort notes based on their end_time\n notes.sort(key=lambda note: no... | trial_gpt4o_6 | {
"original_instruction": "A game developer is designing a rhythm game where players need to hit notes in time with the music. Each level of the game consists of a number of note sequences, each with specific timings and points. However, the developer wants to ensure that there are no overlapping notes within each se... | 0.587555 | Taco_41240 | C | [
"max_points",
"rhythm_game"
] | 2 | [
[
"rhythm_game",
"max_points"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0bb15bfaa68bea15559db58414016f429c1552ca | b7a7b7038fdfb1250198fef1f739691a1949cd90 | |||
v1.0 | complete | Taco | Taco_41469_C | def can_hackerman_reach_treasure(grid, start, end):
""" Determine if HackerMan can reach the treasure.
Args:
- grid: List[List[str]], the grid representing the map.
- start: Tuple[int, int], the starting coordinates of HackerMan.
- end: Tuple[int, int], the coordinates of the treasure.
Retu... | def can_hackerman_reach_treasure(grid, start, end):
# Helper function for checking neighbors
def is_safe(x, y):
return 0 <= x < len(grid) and 0 <= y < len(grid[0]) and grid[x][y] != '#'
from collections import deque
M, N = len(grid), len(grid[0])
queue = deque([start])
visited ... | from solution import solve, parse_input
def test_parse_input():
input_str = "2\n5 5\nS....\n.###.\n..#..\n.###.\n....T\n4 6\nS..##.\n.#..#.\n.#..#T\n.####."
test_cases = parse_input(input_str)
expected = [
(
[['S', '.', '.', '.', '.'], ['.', '#', '#', '#', '.'], ['.', '.', '#', '.', '.'... | [
{
"docstring": null,
"function_declaration": "def can_hackerman_reach_treasure(grid, start, end):",
"function_name": "can_hackerman_reach_treasure",
"parameter_list": "(grid, start, end)"
},
{
"docstring": null,
"function_declaration": "def solve(test_cases):",
"function_name": "solv... | [
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 can_reach_treasure(test_cases):\n def bfs(grid, start, end):\n from collections import deque\n queue = deque([start])\n visited = set([... | trial_gpt4o_1 | {
"original_instruction": "HackerMan has discovered a hidden treasure map. The map consists of a grid with cells, where each cell can either be empty (denoted by '.') or contain an obstacle (denoted by '#'). The treasure is hidden in a cell marked with a 'T', and HackerMan starts at a cell marked with an 'S'. \n\nHac... | 0.555078 | Taco_41469 | C | [
"can_hackerman_reach_treasure",
"solve",
"parse_input"
] | 3 | [
[
"solve",
"can_hackerman_reach_treasure"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 237ba8def8824a6d28e6a1eb488dd31c20083d7b | aa87fd59bb91187357fb594483a518f106ada9e8 | |||
v1.0 | complete | Taco | Taco_41461_C | def minimum_additional_connections(n: int, m: int, friendships: List[Tuple[int, int]]) -> int:
""" Determine the minimum number of additional connections required to make the network fully connected.
>>> minimum_additional_connections(5, 3, [(1, 2), (1, 3), (4, 5)]) == 1
>>> minimum_additional_connections(3... | def find_parent(parent, i):
"""
A utility function to find the parent of an element i.
Utilizes path compression for efficiency.
"""
if parent[i] == i:
return i
else:
parent[i] = find_parent(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
"""
A... | def test_minimum_additional_connections():
assert minimum_additional_connections(5, 3, [(1, 2), (1, 3), (4, 5)]) == 1
assert minimum_additional_connections(3, 2, [(1, 2), (2, 3)]) == 0
assert minimum_additional_connections(4, 0, []) == 3
assert minimum_additional_connections(4, 1, [(1, 2)]) == 2
ass... | [
{
"docstring": "A utility function to find the parent of an element i.\nUtilizes path compression for efficiency.",
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": "A function that does union of two sets... | [
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 find_parent(parent, i):\n \"\"\"\n A utility function to find the parent of an element i.\n Utilizes path compression for efficiency.\n \"\"\"\n ... | trial_gpt4o_0 | {
"original_instruction": "A company has a set of n employees, each of whom has a unique ID number from 1 to n. Some employees are good friends and have established a communication network. The CEO wants to make sure that every employee can communicate with every other employee (directly or indirectly). It is the job... | 0.618019 | Taco_41461 | C | [
"find_parent",
"union",
"minimum_additional_connections",
"solve"
] | 4 | [
[
"minimum_additional_connections",
"find_parent"
],
[
"minimum_additional_connections",
"union"
],
[
"solve",
"minimum_additional_connections"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | a40d211b17c56ca96eb403ba1422532926527835 | 8cefcb84ec160a415ed12160bf2ace2345ee2e83 | |||
v1.0 | complete | Taco | Taco_41895_C | def generate_prime_sequences_from_input(input_lines: str) -> list:
"""
Generate the first N prime numbers followed by their sum for multiple test cases.
:param input_lines: Input as a string, where the first line is T, the number of test cases,
and the subsequent lines contain t... | def is_prime(num):
"""
Helper function to determine 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
d... | import pytest
from solution import generate_prime_sequences_from_input
def test_generate_prime_sequences_sample():
input_data = "3\n2\n3\n5\n"
expected_output = [
"2 3 5",
"2 3 5 10",
"2 3 5 7 11 28"
]
assert generate_prime_sequences_from_input(input_data) == expected_output
de... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Generate the first N prime numbers and their sum.",
"function_declaration": "def generate_primes_se... | [
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": "def is_prime(num):\n if num <= 1:\n return False\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n return False\n re... | trial_gpt4o_2 | {
"original_instruction": "The students in a programming class are learning about prime numbers and sequences. They need your help to generate a specific sequence based on prime numbers. Given a number N, generate a sequence of the first N prime numbers followed by their sum.\n\n-----Input:----- \n- The first-line wi... | 0.652012 | Taco_41895 | C | [
"is_prime",
"generate_primes_sequence",
"process_test_cases",
"generate_prime_sequences_from_input"
] | 4 | [
[
"generate_prime_sequences_from_input",
"process_test_cases"
],
[
"generate_primes_sequence",
"is_prime"
],
[
"process_test_cases",
"generate_primes_sequence"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 01fffb174805e506d704616060e6ce41fbf70bbf | f4b79652fa7abdd92dcc6e814646f7b3f2c97173 | |||
v1.0 | complete | Taco | Taco_41665_C | import heapq
from typing import List, Tuple
def shortest_path(n: int, m: int, edges: List[Tuple[int, int, int]], s: int, t: int) -> int:
"""
Find the shortest path from computer s to computer t in a network of n computers and m directed edges.
Returns the shortest amount of time required for data to trav... | import heapq
def shortest_path(n, m, edges, s, t):
"""
Find the shortest path from computer s to computer t in a network of n computers and m directed edges.
"""
graph = {i: [] for i in range(1, n + 1)}
for u, v, d in edges:
graph[u].append((v, d))
return dijkstra(graph, s, t)
def di... | from solution import shortest_path
def test_shortest_path_example1():
n, m = 5, 6
edges = [
(1, 2, 2),
(2, 3, 3),
(3, 5, 1),
(4, 3, 4),
(1, 4, 8),
(5, 4, 2)
]
s, t = 1, 5
assert shortest_path(n, m, edges, s, t) == 6
def test_shortest_path_example2():... | [
{
"docstring": "Find the shortest path from computer s to computer t in a network of n computers and m directed edges.",
"function_declaration": "def shortest_path(n, m, edges, s, t):",
"function_name": "shortest_path",
"parameter_list": "(n, m, edges, s, t)"
},
{
"docstring": "Dijkstra's al... | [
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": "import heapq\n\ndef find_shortest_path(n, m, connections, s, t):\n \"\"\"\n Function to find the shortest time for data to travel from computer s to computer... | trial_gpt4o_2 | {
"original_instruction": "Anna is designing a computer network. The network consists of `n` computers connected by `m` directed cable links. Each connection `i` is described by three integers `u_i`, `v_i`, and `d_i` (1 ≤ `u_i`, `v_i` ≤ `n`), meaning there is a cable from computer `u_i` to computer `v_i` with a delay... | 0.671704 | Taco_41665 | C | [
"shortest_path",
"dijkstra"
] | 2 | [
[
"shortest_path",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | aa3529249ab017f68817a24941edbaf4a8606093 | 678519f53f1c3626ea65243ad6c03e92db9c8296 | |||
v1.0 | complete | Taco | Taco_41820_C | from typing import List
def is_palindrome(num: int) -> bool:
""" Checks if the given number is a palindrome.
>>> is_palindrome(121) True
>>> is_palindrome(123) False
>>> is_palindrome(12321) True
"""
pass
def next_palindrome(n: int) -> int:
""" Finds the smallest palindrome number greater ... | def is_palindrome(num):
"""
Checks if the given number is a palindrome.
"""
return str(num) == str(num)[::-1]
def next_palindrome(n):
"""
Finds the smallest palindrome number greater than n.
"""
n += 1 # Start checking the next number
while not is_palindrome(n):
n += 1
... | from solution import is_palindrome, next_palindrome, find_next_palindromes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
def test_next_palindrome():
assert next_palindrome(123) == 131
assert next_palindrome(808) =... | [
{
"docstring": "Checks if the given number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest palindrome number greater than n.",
"function_declaration": "def next_palindr... | [
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": "def is_palindrome(num):\n \"\"\"\n Helper function to check if a number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef next_palin... | trial_gpt4o_2 | {
"original_instruction": "Alice loves palindrome numbers, but she finds it challenging to identify the smallest larger palindrome for a given number. Therefore, she has come up with the following problem for practice.\n\nGiven a positive integer `n`, produce the smallest palindrome number `p` such that `p > n`.\n\nA... | 0.734713 | Taco_41820 | C | [
"is_palindrome",
"next_palindrome",
"find_next_palindromes"
] | 3 | [
[
"find_next_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 71dae7dc9914be458b8ecfa27a94fb010047f6fd | 70e9b93ac1aee009cc14a911d70bfbbc93fdfe00 | |||
v1.0 | complete | Taco | Taco_41946_C | def longest_prime_subsequence(arr: List[int]) -> List[int]:
""" Determine the longest subsequence where every element is a prime number.
If there are multiple subsequences of the same maximum length, choose the one with the smallest sum.
If there is still a tie, choose the lexicographically smalles... | import math
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def longest_prime... | from solution import longest_prime_subsequence
def test_example_case_1():
assert longest_prime_subsequence([1, 3, 5, 4, 9, 11, 13, 6, 7, 17]) == [3, 5, 11, 13, 7, 17]
def test_example_case_2():
assert longest_prime_subsequence([4, 6, 8, 10, 12, 14]) == []
def test_custom_case_1():
assert longest_prime_su... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def longest_prime_subsequence(arr):",
"function_name": "longest_prime_subsequence",
"parameter_list": "(arr)"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef 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 ret... | trial_gpt4o_0 | {
"original_instruction": "You are given an array of integers. The following algorithm needs to be applied to find a special type of subsequence:\n\n1. Find the longest subsequence where every element is a prime number.\n2. If there are multiple subsequences of the same maximum length, choose the one with the smalles... | 0.679737 | Taco_41946 | C | [
"is_prime",
"longest_prime_subsequence"
] | 2 | [
[
"longest_prime_subsequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2c3f52ad3f3979fd4f89a79c06b1f752e1e1ee96 | 012751deea2e8c46c738aac45fefa43f4295dc42 | |||
v1.0 | complete | Taco | Taco_41849_C | def merge_sort(guests):
""" Sort the guests by their names using Merge Sort algorithm in a case insensitive manner.
>>> merge_sort(["Charlie", "alice", "Bob"])
["alice", "Bob", "Charlie"]
>>> merge_sort(["Alice"])
["Alice"]
"""
pass
def merge(left, right):
""" Merge two sorted lists int... | def merge_sort(guests):
if len(guests) <= 1:
return guests
mid = len(guests) // 2
left = merge_sort(guests[:mid])
right = merge_sort(guests[mid:])
return merge(left, right)
def merge(left, right):
result = []
while left and right:
if left[0].lower() <= right[0].lower():
... | from solution import merge_sort, quick_sort, wedding_seating_arrangement
def test_merge_sort_empty():
assert merge_sort([]) == []
def test_merge_sort_single():
assert merge_sort(["Alice"]) == ["Alice"]
def test_merge_sort_multiple():
assert merge_sort(["Charlie", "Alice", "Bob"]) == ["Alice", "Bob", "Cha... | [
{
"docstring": null,
"function_declaration": "def merge_sort(guests):",
"function_name": "merge_sort",
"parameter_list": "(guests)"
},
{
"docstring": null,
"function_declaration": "def merge(left, right):",
"function_name": "merge",
"parameter_list": "(left, right)"
},
{
... | [
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": "def merge_sort(guests):\n if len(guests) <= 1:\n return guests\n\n mid = len(guests) // 2\n left = merge_sort(guests[:mid])\n right = merge_sort... | trial_gpt4o_0 | {
"original_instruction": "Create a seating arrangement for a wedding. You are given the names of the guests and the number of guests. Your task is to arrange the guests in alphabetical order by their first names using Merge Sort and Quick Sort algorithms respectively. Both algorithms should adhere to the following p... | 0.507019 | Taco_41849 | C | [
"merge_sort",
"merge",
"quick_sort",
"wedding_seating_arrangement"
] | 4 | [
[
"merge_sort",
"merge"
],
[
"wedding_seating_arrangement",
"merge_sort"
],
[
"wedding_seating_arrangement",
"quick_sort"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 522b1ec69540d30f3e7c0115b12e0111f33304fe | 0e1aaa6e9cf32b09698801bb5d74b5adbab9e57e | |||
v1.0 | complete | Taco | Taco_41987_C | def lcs_length(A: str, B: str) -> int:
"""
Helper function to find the length of the Longest Common Subsequence (LCS) of A and B.
>>> lcs_length("abc", "ac") == 2
>>> lcs_length("horizon", "noz") == 2
"""
def smallest_supersequence_length(A: str, B: str) -> int:
"""
Function to find the... | def lcs_length(A, B):
"""
Helper function to find the length of the Longest Common Subsequence (LCS) of A and B.
"""
m = len(A)
n = len(B)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, n + 1):
if A[i - 1] == B[j - 1]:
... | from solution import smallest_supersequence_length, smallest_supersequence_lengths
def test_single_case_1():
assert smallest_supersequence_length('abc', 'ac') == 3
def test_single_case_2():
assert smallest_supersequence_length('horizon', 'noz') == 8
def test_multiple_cases():
test_cases = [('abc', 'ac'),... | [
{
"docstring": "Helper function to find the length of the Longest Common Subsequence (LCS) of A and B.",
"function_declaration": "def lcs_length(A, B):",
"function_name": "lcs_length",
"parameter_list": "(A, B)"
},
{
"docstring": "Function to find the length of the smallest string that conta... | [
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 lcs_length(A, B):\n \"\"\"\n Helper function to find the length of the Longest Common Subsequence (LCS) of A and B.\n \"\"\"\n m = len(A)\n n = ... | trial_gpt4o_2 | {
"original_instruction": "Given two strings, `A` and `B`, find the length of the smallest string that contains both `A` and `B` as subsequences. That means their letters appear in order, but do not need to be contiguous. You have to determine the length of the smallest possible string that includes both `A` and `B` ... | 0.646926 | Taco_41987 | C | [
"lcs_length",
"smallest_supersequence_length",
"smallest_supersequence_lengths"
] | 3 | [
[
"smallest_supersequence_length",
"lcs_length"
],
[
"smallest_supersequence_lengths",
"smallest_supersequence_length"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 54d44cf03cdfb73388509b34ab711039c8b2615e | 5783118123bad2579a6a9c55eda13126246fa471 | |||
v1.0 | complete | Taco | Taco_41926_C | def is_palindrome(n):
return str(n) == str(n)[::-1]
def reverse_number(n):
return int(str(n)[::-1])
def find_lychrel(n: int, m: int) -> int:
""" Generate and validate a sequence of Lychrel numbers starting from a given integer n up to the maximum number of iterations m.
Args:
n (int): The sta... | def is_palindrome(n):
return str(n) == str(n)[::-1]
def reverse_number(n):
return int(str(n)[::-1])
def find_lychrel(n, m):
for _ in range(m):
reversed_n = reverse_number(n)
n += reversed_n
if is_palindrome(n):
return n
return "LYCHREL"
# Example usage:
if __name__... | from solution import find_lychrel
def test_find_lychrel_palindrome_found():
assert find_lychrel(56, 3) == 121
assert find_lychrel(47, 1) == 121
assert find_lychrel(349, 3) == 7337
def test_find_lychrel_no_palindrome():
assert find_lychrel(196, 10) == "LYCHREL"
assert find_lychrel(295, 50) == "LYCH... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def reverse_number(n):",
"function_name": "reverse_number",
"parameter_list": "(n)"
},
{
"docst... | [
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 reverse_number(num):\n return int(str(num)[::-1])\n\ndef is_palindrome(num):\n return str(num) == str(num)[::-1]\n\ndef lychrel_number(n, m):\n for _ ... | trial_gpt4o_4 | {
"original_instruction": "Your task is to write a program that generates and validates a sequence of Lychrel numbers starting from a given integer n up to the maximum number of iterations m.\n\nNote: A Lychrel number is a natural number that cannot form a palindrome through the iterative process of repeatedly revers... | 0.716087 | Taco_41926 | C | [
"is_palindrome",
"reverse_number",
"find_lychrel"
] | 3 | [
[
"find_lychrel",
"is_palindrome"
],
[
"find_lychrel",
"reverse_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f8ff5fc9afea6c5e7a4cf82ef7b88efd4a2e2335 | 8dfd4a95ccdbd327c465512a3540aa95556a43ce | |||
v1.0 | complete | Taco | Taco_41756_C | from typing import List, Tuple
def num_islands(grid: List[List[str]]) -> int:
""" Find the number of islands in the given grid.
>>> num_islands([["1","1","0","0","0"],["1","1","0","0","1"],["0","0","0","1","1"],["0","0","0","1","0"]]) 2
>>> num_islands([["1","1","1","0"],["1","1","0","0"],["1","0","0","1"]... | def num_islands(grid):
def dfs(x, y):
if x < 0 or x >= len(grid) or y < 0 or y >= len(grid[0]) or grid[x][y] == '0':
return
grid[x][y] = '0' # Mark the land as visited
dfs(x - 1, y)
dfs(x + 1, y)
dfs(x, y - 1)
dfs(x, y + 1)
islands_count = 0
... | def test_num_islands():
assert num_islands([
["1","1","0","0","0"],
["1","1","0","0","1"],
["0","0","0","1","1"],
["0","0","0","1","0"]
]) == 2
assert num_islands([
["1","1","1","0"],
["1","1","0","0"],
["1","0","0","1"],
["0","0","1","1"]
... | [
{
"docstring": null,
"function_declaration": "def num_islands(grid):",
"function_name": "num_islands",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_islands(T, test_cases):",
"function_name": "number_of_islands",
"parameter_list": "(T, ... | [
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 num_islands(grid):\n \"\"\"\n Counts the number of islands in a given grid.\n \"\"\"\n if not grid:\n return 0\n\n m, n = len(grid), len(... | trial_gpt4o_2 | {
"original_instruction": "You are given a river represented by a 2D binary grid where '1' represents land and '0' represents water. You need to find the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid... | 0.592599 | Taco_41756 | C | [
"num_islands",
"number_of_islands",
"process_input"
] | 3 | [
[
"number_of_islands",
"num_islands"
],
[
"process_input",
"number_of_islands"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 5ebe4933832de78eaf14dbeedfe9a63ed958e8a3 | 14a424a25ce03588fa9758418ff0bb3459f68453 | |||
v1.0 | complete | Taco | Taco_41563_C | from typing import List, Tuple
def kruskal_min_cost_to_connect_departments(N: int, edges: List[Tuple[int, int, int]]) -> int:
"""
Determines the minimum cost to connect all departments using Kruskal's algorithm.
Parameters:
N (int): The number of departments.
edges (List[Tuple[int, int, int]]... | def find(parent, i):
if parent[i] == i:
return i
return find(parent, parent[i])
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif rank[root_x] < ... | def test_kruskal_min_cost_to_connect_departments():
test_case1 = (4, 5, [(1, 2, 1),
(1, 3, 4),
(1, 4, 3),
(2, 3, 2),
(3, 4, 5)])
result1 = kruskal_min_cost_to_connect_departments(test_case1[0], test_case1[2])
... | [
{
"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)"
},
... | [
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": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\... | trial_gpt4o_0 | {
"original_instruction": "A company wants to optimize its network connection by installing a minimum number of cables to connect all the departments. Each department is represented as a node, and a possible cable connection between two departments is represented as an edge with a weight indicating the cost to instal... | 0.608424 | Taco_41563 | C | [
"find",
"union",
"kruskal_min_cost_to_connect_departments",
"minimum_cost_to_connect_all_departments"
] | 4 | [
[
"kruskal_min_cost_to_connect_departments",
"find"
],
[
"kruskal_min_cost_to_connect_departments",
"union"
],
[
"minimum_cost_to_connect_all_departments",
"kruskal_min_cost_to_connect_departments"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 74022576b760888b18971f8663589c90398b1cf5 | 73891bfca47afb993efc6820a90c09d62f53e331 | |||
v1.0 | complete | Taco | Taco_41717_C | def minimize_absolute_differences(test_cases):
""" Given multiple test cases of arrays, sort each array such that the sum of the absolute differences
between consecutive elements is minimized and return the lexicographically smallest sorted array.
"""
results = []
for case in test_cases:
ar... | def minimize_absolute_differences(test_cases):
results = []
for case in test_cases:
array = case[1:]
sorted_array = sorted(array)
results.append(sorted_array)
return results
def format_output(results):
return [' '.join(map(str, result)) for result in results]
def solve_problem(... | from solution import minimize_absolute_differences, format_output, solve_problem
def test_minimize_absolute_differences():
assert minimize_absolute_differences([[3, 1, 5, 3]]) == [[1, 3, 5]]
assert minimize_absolute_differences([[4, 8, 3, 6, 1]]) == [[1, 3, 6, 8]]
def test_format_output():
assert format_o... | [
{
"docstring": null,
"function_declaration": "def minimize_absolute_differences(test_cases):",
"function_name": "minimize_absolute_differences",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def format_output(results):",
"function_name": "format_ou... | [
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 sort_min_sum_diff(arrays):\n \"\"\"\n Returns the sorted arrays such that the sum of the absolute differences \n between consecutive elements is minim... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers. Your task is to sort the array such that the sum of the absolute differences between consecutive elements is minimized. If there are multiple arrays that produce the same minimal sum of absolute differences, return the lexicographically smallest array.\n\... | 0.676711 | Taco_41717 | C | [
"minimize_absolute_differences",
"format_output",
"solve_problem"
] | 3 | [
[
"solve_problem",
"format_output"
],
[
"solve_problem",
"minimize_absolute_differences"
]
] | 2 | [
"format_output"
] | false | [] | false | pytest | true | [] | true | 933d78b3ab933d4e95254a1aa1eeb197be6df897 | 9e9c2aa55af3fde1e4ab72dc6e0c265d20aace6c | |||
v1.0 | complete | Taco | Taco_41824_C | def sum_of_squares_of_digits(n):
"""
Helper function to calculate the sum of the squares of the digits of a number.
"""
pass
def is_happy_number(n):
"""
Determine if the number 'n' is a Happy Number.
"""
pass
def happy_number_test_cases(test_cases):
"""
Determine if the numbers... | def sum_of_squares_of_digits(n):
"""
Helper function to calculate the sum of the squares of the digits of a number.
"""
return sum(int(digit) ** 2 for digit in str(n))
def is_happy_number(n):
"""
Determine if the number 'n' is a Happy Number.
"""
seen = set()
while n != 1 and n not ... | from solution import happy_number_test_cases
def test_happy_number_test_cases():
assert happy_number_test_cases([19]) == ["HAPPY"]
assert happy_number_test_cases([2]) == ["UNHAPPY"]
assert happy_number_test_cases([7]) == ["HAPPY"]
assert happy_number_test_cases([1]) == ["HAPPY"]
assert happy_number... | [
{
"docstring": "Helper function to calculate the sum of the squares of the digits of a number.",
"function_declaration": "def sum_of_squares_of_digits(n):",
"function_name": "sum_of_squares_of_digits",
"parameter_list": "(n)"
},
{
"docstring": "Determine if the number 'n' is a Happy Number."... | [
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": "def is_happy_number(n):\n \"\"\"\n Determines if the given number n is a Happy Number.\n \"\"\"\n def sum_of_squares(num):\n return sum(int(digi... | trial_gpt4o_3 | {
"original_instruction": "Sara loves playing with numbers and creating new number sequences. She recently came up with a sequence where each term is the sum of the squares of its digits. She calls this sequence \"Digit Square Sum Sequence\". She wants to find out if a number is a \"Happy Number\" or not based on thi... | 0.534679 | Taco_41824 | C | [
"sum_of_squares_of_digits",
"is_happy_number",
"happy_number_test_cases"
] | 3 | [
[
"happy_number_test_cases",
"is_happy_number"
],
[
"is_happy_number",
"sum_of_squares_of_digits"
]
] | 2 | [
"happy_number_test_cases"
] | false | [] | false | pytest | true | [] | true | afc790dd4168eee41257ca4c502885603e648765 | aa0273d53dd5f3b38ab2faafa0b36fbc8ce77f79 | |||
v1.0 | complete | Taco | Taco_42063_C | def min_meeting_rooms(events):
"""
Returns the minimum number of rooms required to accommodate all events.
>>> min_meeting_rooms([(100, 120), (150, 200), (210, 220)]) == 1
>>> min_meeting_rooms([(60, 150), (30, 120), (200, 220), (100, 200), (140, 180), (180, 210)]) == 3
>>> min_meeting_rooms([(0, 30... | def min_meeting_rooms(events):
"""
Returns the minimum number of rooms required to accommodate all events.
"""
if not events:
return 0
start_times = sorted([start for start, end in events])
end_times = sorted([end for start, end in events])
start_ptr, end_ptr = 0, 0
num_rooms, ... | from solution import min_meeting_rooms, min_rooms_for_employees
def test_min_meeting_rooms_no_overlap():
assert min_meeting_rooms([(100, 120), (150, 200), (210, 220)]) == 1
def test_min_meeting_rooms_with_overlap():
assert min_meeting_rooms([(60, 150), (30, 120), (200, 220), (100, 200), (140, 180), (180, 210)... | [
{
"docstring": "Returns the minimum number of rooms required to accommodate all events.",
"function_declaration": "def min_meeting_rooms(events):",
"function_name": "min_meeting_rooms",
"parameter_list": "(events)"
},
{
"docstring": "Given the number of employees and their schedules, return ... | [
0,
0,
0,
1,
0
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_rooms_required(n, schedules):\n events = []\n for employee_schedule in schedules:\n for event in employee_schedule:\n events.append... | trial_gpt4o_3 | {
"original_instruction": "A company has developed a new scheduling application to manage the tasks and meetings of its employees. A meeting or a task can be represented as an event with a start time and an end time in minutes. Each employee has a list of events they need to attend or complete for the day. Two events... | 0.639047 | Taco_42063 | C | [
"min_meeting_rooms",
"min_rooms_for_employees"
] | 2 | [
[
"min_rooms_for_employees",
"min_meeting_rooms"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ec2ca6c06817d4e3db8253543f93c523c5bc84e | 1c99883486a1800f3b12771e82af1d2fa783e610 | |||
v1.0 | complete | Taco | Taco_42092_C | def is_palindrome(number: int) -> bool:
""" Check if a number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
>>> is_palindrome(1)
True
>>> is_palindrome(22)
True
"""
def is_prime(number: int) -> bool:
""" Check if a number is prime.
>>> is_... | def is_palindrome(number):
return str(number) == str(number)[::-1]
def is_prime(number):
if number <= 1:
return False
if number <= 3:
return True
if number % 2 == 0 or number % 3 == 0:
return False
i = 5
while i * i <= number:
if number % i == 0 or number % (i + ... | from solution import is_palindrome, is_prime, smallest_prime_palindrome_greater_than
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1) == True
assert is_palindrome(22) == True
def test_is_prime():
assert is_prime(2) == True
a... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": null,
"function_declaration": "def is_prime(number):",
"function_name": "is_prime",
"parameter_list": "(number)"
},
{
... | [
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": "def is_palindrome(number):\n return str(number) == str(number)[::-1]\n\ndef is_prime(number):\n if number <= 1:\n return False\n if number <= 3:\n ... | trial_gpt4o_0 | {
"original_instruction": "Maya loves to play with words and numbers. Recently, she came across a puzzle involving prime numbers and palindromes. She decided to combine both concepts and created a challenging problem for her friends.\n\nThe task is to find the smallest palindrome that is a prime number and greater th... | 0.690444 | Taco_42092 | C | [
"is_palindrome",
"is_prime",
"smallest_prime_palindrome_greater_than",
"main"
] | 4 | [
[
"smallest_prime_palindrome_greater_than",
"is_palindrome"
],
[
"smallest_prime_palindrome_greater_than",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5a3880a387f8794c0e3785f7853327baece3cb2e | 84de22f599e09b897ed95ca08ca51db3e2251f3b | |||
v1.0 | complete | Taco | Taco_41957_C | def is_prime(num):
""" Check if a number is prime. """
...
def longest_prime_row(n):
""" Calculate the longest row of books with consecutive prime differences.
>>> longest_prime_row(10)
(3, [1, 2, 3])
>>> longest_prime_row(15)
(5, [1, 2, 3, 5, 7])
>>> longest_prime_row(1)
(1, [1])
... | def is_prime(num):
""" 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 longest_prime_row(n):
""... | from solution import longest_prime_row
def test_example_1():
n = 10
k, sequence = longest_prime_row(n)
assert k >= 3 and set(sequence).issubset(set(range(1, n+1)))
def test_example_2():
n = 15
k, sequence = longest_prime_row(n)
assert k >= 5 and set(sequence).issubset(set(range(1, n+1)))
def ... | [
{
"docstring": "Check if a number is prime. ",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Calculate the longest row of books with consecutive prime differences. ",
"function_declaration": "def longest_prime_row(... | [
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": "def is_prime(num):\n \"\"\" Check if a number is prime. \"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 ==... | trial_gpt4o_0 | {
"original_instruction": "Aria loves reading books and she has a large collection of them. Each of her books has a unique serial number from 1 to n. She decides to organize her books in such a way that the difference between the serial numbers of any two consecutive books in a row is a prime number. Aria wants to or... | 0.612009 | Taco_41957 | C | [
"is_prime",
"longest_prime_row"
] | 2 | [
[
"longest_prime_row",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | be85c2d60a9dded525ffbd8b347cc004e72d571b | 76e74f9408a36877d67c77ae4f530348e758e4d6 | |||
v1.0 | complete | Taco | Taco_42054_C | from typing import List
def min_max_pages(chapters: List[int], days: int) -> int:
""" Find the minimum possible maximum number of pages to read in a day such that the book can be completed in the given number of days.
The reading workload should be as balanced as possible across the days.
>>> min_max_pages... | def can_split(chapters, days, max_pages_per_day):
current_sum = 0
days_needed = 1
for pages in chapters:
if current_sum + pages > max_pages_per_day:
days_needed += 1
current_sum = pages
if days_needed > days:
return False
else:
... | from solution import min_max_pages
def test_min_max_pages_case1():
assert min_max_pages([10, 20, 30, 40, 50], 2) == 90
def test_min_max_pages_case2():
assert min_max_pages([10, 30, 40, 20], 3) == 40
def test_min_max_pages_case3():
assert min_max_pages([5, 5, 5, 5, 5], 5) == 5
def test_min_max_pages_case... | [
{
"docstring": null,
"function_declaration": "def can_split(chapters, days, max_pages_per_day):",
"function_name": "can_split",
"parameter_list": "(chapters, days, max_pages_per_day)"
},
{
"docstring": null,
"function_declaration": "def min_max_pages(chapters, days):",
"function_name... | [
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 min_pages(chapters, days):\n def can_read_in_days(max_pages, days):\n current_sum = 0\n required_days = 1\n for pages in chapters:\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers representing the number of pages in each chapter of a book. You need to read the entire book within a given number of days, with the constraint that each day you must read a contiguous sequence of chapters and the total number of pages you read each day shou... | 0.586419 | Taco_42054 | C | [
"can_split",
"min_max_pages"
] | 2 | [
[
"min_max_pages",
"can_split"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7b95a35fa249ab052249782b7f8965bd995239a | 200443471a825e30efc807e4c909d70f835207f0 | |||
v1.0 | complete | Taco | Taco_41868_C | from typing import List
def max_sum_subgrid(test_cases: List[List[List[int]]]) -> List[int]:
"""Find the maximum sum of a sub-grid for a given list of test cases.
Each test case is represented as a list of lists, where the first list contains the number of rows and columns,
and the following lists rep... | def max_sum_subgrid(test_cases):
results = []
for grid in test_cases:
R, C = grid[0]
matrix = grid[1:]
max_sum = float('-inf')
# We use Kadane's algorithm extended to 2D
for left in range(C):
temp = [0] * R
for right in range(left, C):
... | import pytest
from solution import max_sum_subgrid, parse_input
def test_max_sum_subgrid_simple_case():
input_lines = [
"2",
"3 3",
"1 2 3",
"4 5 6",
"7 8 9",
"2 4",
"1 2 3 4",
"5 6 7 8",
]
test_cases = parse_input(input_lines)
results = m... | [
{
"docstring": null,
"function_declaration": "def max_sum_subgrid(test_cases):",
"function_name": "max_sum_subgrid",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def max_subarray_sum(array):",
"function_name": "max_subarray_sum",
"parameter_li... | [
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": "def max_sum_subgrid(T, test_cases):\n results = []\n\n for test_case in test_cases:\n R, C, grid = test_case[\"R\"], test_case[\"C\"], test_case[\"gri... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid with R rows and C columns, each cell containing a non-negative integer. Your task is to find the maximum sum of a sub-grid for given T test cases. A sub-grid is defined as any rectangular section of the grid, possibly the entire grid itself.\n\n------ Input Format -----... | 0.652316 | Taco_41868 | C | [
"max_sum_subgrid",
"max_subarray_sum",
"parse_input"
] | 3 | [
[
"max_sum_subgrid",
"max_subarray_sum"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 1c0e2cd501c6cbb9eccaa6d35e3ef758e8e7f898 | b1127abfc992fbda980e3b71036ed2db2de1346b | |||
v1.0 | complete | Taco | Taco_42106_C | def is_palindrome(word: str) -> bool:
""" Returns True if the provided word is a palindrome, False otherwise.
>>> is_palindrome("aba")
True
>>> is_palindrome("abba")
True
>>> is_palindrome("abc")
False
>>> is_palindrome("a")
True
>>> is_palindrome("")
True
"""
def proces... | def is_palindrome(word):
"""
Returns True if the provided word is a palindrome, False otherwise.
"""
return word == word[::-1]
def process_operations(s, operations):
"""
Processes the given operations on the string s and checks if the resulting
string is a palindrome after each operation.
... | from solution import is_palindrome, process_operations
# Test the is_palindrome function
def test_is_palindrome():
assert is_palindrome("aba") == True
assert is_palindrome("abba") == True
assert is_palindrome("abc") == False
assert is_palindrome("a") == True
assert is_palindrome("") == True
# Test... | [
{
"docstring": "Returns True if the provided word is a palindrome, False otherwise.",
"function_declaration": "def is_palindrome(word):",
"function_name": "is_palindrome",
"parameter_list": "(word)"
},
{
"docstring": "Processes the given operations on the string s and checks if the resulting... | [
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 is_palindrome(word):\n return word == word[::-1]\n\ndef magic_words_game(s, operations):\n results = []\n for char, pos in operations:\n s = s[... | trial_gpt4o_2 | {
"original_instruction": "A group of friends loves playing a game called \"Magic Words\". They believe that some words have magical properties, such as those that can be read the same backward and forward, known as palindromes. They want to create a new version of the game where a sequence of operations can modify w... | 0.800854 | Taco_42106 | C | [
"is_palindrome",
"process_operations",
"main"
] | 3 | [
[
"process_operations",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b5d652a4abb6d1608a33f7ce64616499cabf50e8 | 82627c5ced612fc14e43ce50e1cdd4c9e1db4fc3 | |||
v1.0 | complete | Taco | Taco_42183_C | from math import gcd
from functools import reduce
def lcm(a, b):
""" Helper function to compute the Least Common Multiple (LCM) of two integers. """
return a * b // gcd(a, b)
def smallest_multiple(arr):
"""
Returns the smallest multiple (Least Common Multiple) of all the unique positive integers in t... | from math import gcd
from functools import reduce
def lcm(a, b):
"""
Helper function to compute the Least Common Multiple (LCM) of two integers.
"""
return a * b // gcd(a, b)
def smallest_multiple(arr):
"""
Returns the smallest multiple (Least Common Multiple) of all the unique positive intege... | from solution import smallest_multiple
def test_smallest_multiple_example1():
assert smallest_multiple([5, 7, 11]) == 385
def test_smallest_multiple_example2():
assert smallest_multiple([2, 3, 4, 5]) == 60
def test_smallest_multiple_example3():
assert smallest_multiple([12, 15, 18, 20]) == 180
def test_... | [
{
"docstring": "Helper function to compute the Least Common Multiple (LCM) of two integers.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the smallest multiple (Least Common Multiple) of all the unique positive integ... | [
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": "import math\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"\n Calculate the Least Common Multiple of two integers a and b.\n \"\"\"\n return a... | trial_gpt4o_1 | {
"original_instruction": "Megan wants to determine the smallest multiple of all the integers in a given array. Your task is to devise an efficient algorithm to compute the least common multiple (LCM) of an array of unique positive integers. All inputs will be valid.\nPassing [4, 6, 8] should return 24, as 24 is the ... | 0.676814 | Taco_42183 | C | [
"lcm",
"smallest_multiple"
] | 2 | [
[
"smallest_multiple",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 18572c5a13b8f87f8f7718eaaab7457e2362f13b | cde1589e53c7211759820bf2f17f6a7c2e56738e | |||
v1.0 | complete | Taco | Taco_42253_C | def shortest_palindrome_length(s: str) -> int:
"""
Returns the length of the shortest palindrome that can be obtained by adding the minimum
number of characters at the beginning or end of the string.
>>> shortest_palindrome_length("abc")
5
>>> shortest_palindrome_length("aabb")
6
"""
... | def shortest_palindrome_length(s):
"""
Returns the length of the shortest palindrome that can be obtained by adding the minimum
number of characters at the beginning or end of the string.
"""
n = len(s)
# Check if the string is already a palindrome
if s == s[::-1]:
return n
... | from solution import solve
def test_example_1():
assert solve(2, [(3, 'abc'), (4, 'aabb')]) == [5, 6]
def test_single_character():
assert solve(1, [(1, 'a')]) == [1]
assert solve(1, [(1, 'z')]) == [1]
def test_already_palindrome():
assert solve(1, [(3, 'aba')]) == [3]
assert solve(1, [(4, 'abba')... | [
{
"docstring": "Returns the length of the shortest palindrome that can be obtained by adding the minimum\nnumber of characters at the beginning or end of the string.",
"function_declaration": "def shortest_palindrome_length(s):",
"function_name": "shortest_palindrome_length",
"parameter_list": "(s)"... | [
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": "def shortest_palindrome_length(s):\n \"\"\"\n Returns the length of the shortest palindrome that can be obtained by adding the minimum\n number of charact... | trial_gpt4o_0 | {
"original_instruction": "You are given a string $s$ of length $n$ consisting of lowercase English letters. You want to make the string a palindrome by adding the minimum number of characters to it. You need to determine the length of the shortest palindrome that can be obtained.\n\nTo achieve this, you can insert c... | 0.754071 | Taco_42253 | C | [
"shortest_palindrome_length",
"solve_palindrome_case",
"solve"
] | 3 | [
[
"solve",
"solve_palindrome_case"
],
[
"solve_palindrome_case",
"shortest_palindrome_length"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 245c9e45c8fe1fcd3693b3727465319baea96b1e | 703db2f004c62e9ae8d2b94a8bbd43f0375ea4db | |||
v1.0 | complete | Taco | Taco_42120_C | def build_supplier_dict(n: int, supplier_data: list) -> dict:
""" Build a dictionary where each key is a supplier code and each value is
another dictionary with product codes as keys and prices as values.
"""
pass
def query_prices(n: int, q: int, supplier_data: list, queries: list) -> list:
""" A... | def build_supplier_dict(n, supplier_data):
supplier_dict = {}
index = 0
for i in range(n):
supplier_code = supplier_data[index]
index += 1
m = supplier_data[index]
index += 1
products = {}
for _ in range(m):
product_code, price = supplier_data[inde... | def test_build_supplier_dict():
supplier_data = [
1, 2, 1002, 150, 1003, 200,
2, 3, 1001, 300, 1002, 250, 1003, 350
]
n = 2
expected = {
1: {1002: 150, 1003: 200},
2: {1001: 300, 1002: 250, 1003: 350}
}
assert build_supplier_dict(n, supplier_data) == expected
def... | [
{
"docstring": null,
"function_declaration": "def build_supplier_dict(n, supplier_data):",
"function_name": "build_supplier_dict",
"parameter_list": "(n, supplier_data)"
},
{
"docstring": null,
"function_declaration": "def query_prices(n, q, supplier_data, queries):",
"function_name"... | [
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 manage_supply_chain(suppliers, queries):\n supply_data = {}\n \n for supplier in suppliers:\n supplier_code, products = supplier[0], supplier[1... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with implementing a system that manages a company's supply chain. The company deals in different products, each identified by a unique product code. They have several suppliers who provide these products, and each supplier has a unique supplier code. Each supplier provides ce... | 0.619752 | Taco_42120 | C | [
"build_supplier_dict",
"query_prices"
] | 2 | [
[
"query_prices",
"build_supplier_dict"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 730cf451ece70e04fb99da53c422b572a70ab94d | 908936759c34df3e8ca754992e00ee9069a1c581 | |||
v1.0 | complete | Taco | Taco_42117_C | def is_balanced(s: str) -> bool:
"""
Helper function that checks if a single string s is properly nested and balanced.
"""
def check_brackets(n: int, strings: List[str]) -> List[str]:
"""
Determine whether each string in the list is properly nested and balanced.
Args:
n : int : The number... | def is_balanced(s):
"""
Helper function that checks if a single string s is properly nested and balanced.
"""
stack = []
matching_bracket = {')': '(', '}': '{', ']': '['}
for char in s:
if char in '({[':
stack.append(char)
elif char in ')}]':
if not s... | from solution import check_brackets
def test_check_brackets_single_valid_case():
assert check_brackets(1, ["([]{})"]) == ["YES"]
def test_check_brackets_single_invalid_case():
assert check_brackets(1, ["([)]"]) == ["NO"]
def test_check_brackets_multiple_cases():
assert check_brackets(3, ["([]{})", "([)]"... | [
{
"docstring": "Helper function that checks if a single string s is properly nested and balanced.",
"function_declaration": "def is_balanced(s):",
"function_name": "is_balanced",
"parameter_list": "(s)"
},
{
"docstring": "Returns a list of \"YES\" or \"NO\" for each string, \nindicating if t... | [
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_balanced_brackets(string):\n \"\"\"\n Check if the brackets in the given string are properly nested and balanced.\n \"\"\"\n stack = []\n bra... | trial_gpt4o_2 | {
"original_instruction": "Alice is developing a new feature for her text editor that supports syntax highlighting for nested brackets. She has defined three types of brackets: `()`, `[]`, and `{}`. The editor should be able to verify if a string composed of these brackets is properly nested and balanced. A string is... | 0.774406 | Taco_42117 | C | [
"is_balanced",
"check_brackets"
] | 2 | [
[
"check_brackets",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 55731d81efb83b2e1f7f4877591560ed0f614eaf | cfe3d738422ca0f115ca96c0f671f3f3410681b9 | |||
v1.0 | complete | Taco | Taco_42343_C | def is_prime(num: int) -> bool:
""" Determine if a given number is prime.
>>> is_prime(2) True
>>> is_prime(3) True
>>> is_prime(4) False
>>> is_prime(17) True
>>> is_prime(18) False
>>> is_prime(19) True
>>> is_prime(1) False
>>> is_prime(-5) False
"""
def sum_of_primes(lst: Li... | def is_prime(num):
"""
Helper function to determine 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
... | from solution import is_prime, sum_of_primes
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
assert is_prime(19) == True
assert is_prime(1) == False
assert is_prime(-5) == Fal... | [
{
"docstring": "Helper function to determine if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Returns the sum of all prime numbers in the given list.",
"function_declaration": "def sum_of_prime... | [
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 \"\"\"Helper function to determine if a number is prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a list of integers, write a function that returns the sum of all prime numbers in the list. \n\nInput\nThe first line contains an integer n, which is the number of elements in the list. The second line contains n integers separated by a space.\n\nOutput\nPrint a single integer, which ... | 0.783154 | Taco_42343 | C | [
"is_prime",
"sum_of_primes"
] | 2 | [
[
"sum_of_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a4b253ab11a7d4080fe240b1490542a630eed2ea | 0bdc5c732a2b11a6457ad8e16a61c03bf81ab4b8 | |||
v1.0 | complete | Taco | Taco_42255_C | def balance_reactions(T: int, reactions: List[str]) -> List[str]:
""" Determines if the given chemical reactions are balanced.
>>> balance_reactions(3, ["H2 + O2 -> H2O", "C6H12O6 + O2 -> CO2 + H2O", "CH4 + 2O2 -> CO2 + 2H2O"])
["Unbalanced", "Unbalanced", "Balanced"]
>>> balance_reactions(1, ["Na2CO3 +... | import re
from collections import defaultdict
def parse_formula(formula):
element_counts = defaultdict(int)
elements = re.findall(r'([A-Z][a-z]?)(\d*)', formula)
for element, count in elements:
count = int(count) if count else 1
element_counts[element] += count
return element_counts
de... | from solution import balance_reactions
def test_single_atomic_element():
reactions = ["H2 -> H2"]
assert balance_reactions(1, reactions) == ["Balanced"]
def test_simple():
reactions = ["H2 + O2 -> H2O"]
assert balance_reactions(1, reactions) == ["Unbalanced"]
def test_glucose_reaction():
reaction... | [
{
"docstring": null,
"function_declaration": "def parse_formula(formula):",
"function_name": "parse_formula",
"parameter_list": "(formula)"
},
{
"docstring": null,
"function_declaration": "def parse_side(side):",
"function_name": "parse_side",
"parameter_list": "(side)"
},
{
... | [
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 re\nfrom collections import defaultdict\n\ndef parse_formula(formula):\n \"\"\"\n Parses the chemical formula into a dictionary of element counts.\n ... | trial_gpt4o_4 | {
"original_instruction": "You are in charge of developing software to balance chemical reactions. A chemical reaction consists of a set of reactants and a set of products. Each reactant and product is represented by a chemical formula, which consists of elements and their respective counts. The goal is to determine ... | 0.428896 | Taco_42255 | C | [
"parse_formula",
"parse_side",
"is_balanced_reaction",
"balance_reactions"
] | 4 | [
[
"balance_reactions",
"is_balanced_reaction"
],
[
"is_balanced_reaction",
"parse_side"
],
[
"parse_side",
"parse_formula"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | b1e16e3595a144bec918d76f2d40eaf55c819f80 | 45828e572c90c7f86108ae60d2b163d03e997007 | |||
v1.0 | complete | Taco | Taco_42705_C | from typing import List, Tuple
def binary_tree_paths(N: int, edges: List[Tuple[int, int]]) -> Tuple[int, int]:
"""
Given a binary tree with N nodes and a list of edges, find the maximum Z-path length
and the maximum O-path length.
>>> binary_tree_paths(5, [(1, 2), (1, 3), (2, 4), (2, 5)])
(3... | import sys
from collections import defaultdict, deque
sys.setrecursionlimit(200000)
def find_diameter(tree, N):
def bfs(node):
visited = [-1] * (N + 1)
queue = deque([node])
visited[node] = 0
max_dist, farthest_node = 0, node
while queue:
cur = queue.po... | import pytest
from solution import binary_tree_paths
def test_sample_case_1():
N = 5
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
result = binary_tree_paths(N, edges)
assert result == (3, 3)
def test_linear_case():
N = 4
edges = [(1, 2), (2, 3), (3, 4)]
result = binary_tree_paths(N, edges)
... | [
{
"docstring": null,
"function_declaration": "def find_diameter(tree, N):",
"function_name": "find_diameter",
"parameter_list": "(tree, N)"
},
{
"docstring": null,
"function_declaration": "def binary_tree_paths(N, edges):",
"function_name": "binary_tree_paths",
"parameter_list": ... | [
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_max_path_lengths(N, edges):\n from collections import defaultdict, deque\n \n if N == 1:\n return 0, 0\n \n # Build the graph\n g... | trial_gpt4o_4 | {
"original_instruction": "Anna loves trees and paths. She has a binary tree with N nodes. Each node of the tree has a unique integer value assigned to it. Anna is particularly interested in two types of paths: \"Z-paths\" and \"O-paths.\"\n\n- A \"Z-path\" is a path from one leaf to another leaf passing through thei... | 0.582273 | Taco_42705 | C | [
"find_diameter",
"binary_tree_paths"
] | 2 | [
[
"binary_tree_paths",
"find_diameter"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bbcd86651b72bfcbc9afa79afc8f91d7fe89acc7 | 9c61e4bde7d1642ad8b71db4ae5cf7f347b92f32 | |||
v1.0 | complete | Taco | Taco_42580_C | def is_leap_year(year):
"""
Determines if a given year is a leap year.
Returns "Yes" if the year is a leap year, otherwise "No".
"""
pass
def process_years(years):
"""
Process a list of years and return a list of results for each year.
Each result is either "Yes" or "No", until a year 0... | def is_leap_year(year):
"""
Determines if a given year is a leap year.
Returns "Yes" if the year is a leap year, otherwise "No".
"""
if year == 0:
return None # Special case for input ending
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return "Yes"
else:
... | def test_is_leap_year():
assert is_leap_year(2000) == "Yes"
assert is_leap_year(1996) == "Yes"
assert is_leap_year(1900) == "No"
assert is_leap_year(2001) == "No"
assert is_leap_year(0) == None
def test_process_years():
assert process_years([2000, 1996, 1900, 2001, 0]) == ["Yes", "Yes", "No", "... | [
{
"docstring": "Determines if a given year is a leap year.\nReturns \"Yes\" if the year is a leap year, otherwise \"No\".",
"function_declaration": "def is_leap_year(year):",
"function_name": "is_leap_year",
"parameter_list": "(year)"
},
{
"docstring": "Process a list of years and return a l... | [
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_leap_year(year):\n \"\"\"\n Determines if a given year is a leap year.\n A year is a leap year if:\n 1. It is divisible by 4, but not divisible ... | trial_gpt4o_2 | {
"original_instruction": "Write a program which determines if a given year is a leap year.\n\nConstraints\n\n* The year is a positive integer not greater than 10,000.\n\nInput\n\nThe input consists of multiple datasets. Each dataset consists of a single integer year.\n\nThe input ends with a single 0 (when the year ... | 0.562097 | Taco_42580 | C | [
"is_leap_year",
"process_years"
] | 2 | [
[
"process_years",
"is_leap_year"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8f74027cea2f61361f087c7ba477037466e6eaa4 | b0ff94fd553933c3979ccd3e6f111f04776ce4e0 | |||
v1.0 | complete | Taco | Taco_42725_C | def detect_cycle(n: int) -> str:
""" Determine if the sequence starting with a given number will get stuck in a cycle.
>>> detect_cycle(19) == "No Cycle"
>>> detect_cycle(116) == "Cycle"
"""
pass
# Unit Tests
def test_no_cycle():
assert detect_cycle(19) == "No Cycle"
def test_cycle():
asse... | def sum_of_squares_of_digits(n):
return sum(int(digit) ** 2 for digit in str(n))
def detect_cycle(n):
seen_numbers = set()
while n not in seen_numbers:
if n == 1:
return "No Cycle"
seen_numbers.add(n)
n = sum_of_squares_of_digits(n)
return "Cycle" | from solution import detect_cycle
def test_no_cycle():
assert detect_cycle(19) == "No Cycle"
def test_cycle():
assert detect_cycle(116) == "Cycle"
assert detect_cycle(4) == "Cycle"
def test_no_cycle_for_1():
assert detect_cycle(1) == "No Cycle"
def test_large_number():
assert detect_cycle(123456... | [
{
"docstring": null,
"function_declaration": "def sum_of_squares_of_digits(n):",
"function_name": "sum_of_squares_of_digits",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def detect_cycle(n):",
"function_name": "detect_cycle",
"parameter_list": "(n)"
... | [
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 sum_of_squares_of_digits(n):\n return sum(int(digit) ** 2 for digit in str(n))\n\ndef detect_cycle(start):\n seen = set()\n while start != 1:\n ... | trial_gpt4o_2 | {
"original_instruction": "Adam has a favorite number sequence where each number is the sum of the squares of the digits of the previous number. He starts with a given number and follows this sequence. Sometimes the sequence gets stuck in a cycle, repeating the same numbers indefinitely.\n\nGiven a starting number, d... | 0.524755 | Taco_42725 | C | [
"sum_of_squares_of_digits",
"detect_cycle"
] | 2 | [
[
"detect_cycle",
"sum_of_squares_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 83e49c7fee8518f49518baa925d410cc4bf3b142 | e3aadf9c7beb9a233b9ea5a274cb089f969d2168 | |||
v1.0 | complete | Taco | Taco_42677_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def solve(input_string: str) -> str:
""" Given an integer array with distinct values as a space-separated string,
construct the maximum binary tree and output the pr... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def construct_maximum_binary_tree(nums):
if not nums:
return None
# Find the maximum number and its index
max_index = nums.index(max(nums))
max_value... | from solution import solve
def test_example_1():
input_string = "3 2 1 6 0 5"
assert solve(input_string) == "6 3 2 1 5 0"
def test_example_2():
input_string = "10 9 8 7 6"
assert solve(input_string) == "10 9 8 7 6"
def test_single_element():
input_string = "42"
assert solve(input_string) == "... | [] | [
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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef construct_maximum_binary_tr... | trial_gpt4o_2 | {
"original_instruction": "Maximum Binary Tree\n\nProblem Statement\n\nGiven an integer array with distinct values, the maximum binary tree is defined as follows:\n\n1. The root is the maximum number in the array.\n2. The left subtree is the maximum tree constructed from the left part subarray divided by the maximum ... | 0.532887 | Taco_42677 | C | [
"construct_maximum_binary_tree",
"preorder_traversal",
"maximum_binary_tree_preorder",
"solve"
] | 4 | [
[
"maximum_binary_tree_preorder",
"construct_maximum_binary_tree"
],
[
"maximum_binary_tree_preorder",
"preorder_traversal"
],
[
"solve",
"maximum_binary_tree_preorder"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c48f18f9cb1537d63a00d59e74f0fc8e99e49180 | 3a10e42846672e042e341bfc80f6508331156b9c | |||
v1.0 | complete | Taco | Taco_42523_C | import math
from typing import List, Tuple
import itertools
def euclidean_distance(point1: Tuple[int, int], point2: Tuple[int, int]) -> float:
"""
Calculates the Euclidean distance between two points.
>>> round(euclidean_distance((0, 0), (3, 4)), 2) == 5.00
>>> round(euclidean_distance((1, 1), (1, 1))... | import itertools
import math
def euclidean_distance(point1, point2):
"""
Calculates the Euclidean distance between two points.
"""
return math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)
def minimum_rope_length(pegs):
"""
Computes the minimum length of rope required to co... | def test_euclidean_distance():
assert round(euclidean_distance((0, 0), (3, 4)), 2) == 5.00
assert round(euclidean_distance((1, 1), (1, 1)), 2) == 0.00
assert round(euclidean_distance((0, 0), (0, 0)), 2) == 0.00
assert round(euclidean_distance((-1, -1), (2, 3)), 2) == 5.00
def test_minimum_rope_length_c... | [
{
"docstring": "Calculates the Euclidean distance between two points.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Computes the minimum length of rope required to connect al... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import numpy as np\nfrom scipy.spatial.distance import pdist, squareform\nfrom scipy.optimize import linear_sum_assignment\n\ndef calculate_distance_matrix(coords)... | trial_gpt4o_6 | {
"original_instruction": "A local artist wants to create a unique sculpture consisting of several geometric shapes arranged together. The sculpture should be anchored to the ground with pegs placed at specified coordinates. Given n pegs, the artist needs to use the shortest possible rope to connect the pegs in a clo... | 0.610159 | Taco_42523 | C | [
"euclidean_distance",
"minimum_rope_length",
"read_input"
] | 3 | [
[
"minimum_rope_length",
"euclidean_distance"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | false | [] | true | 17d4da61edc07f415234c34f04c5bc2f7086a003 | 7858cd11921641179b09bc261b3ae094c9134008 | |||
v1.0 | complete | Taco | Taco_42730_C | def filter_primes(numbers: List[int]) -> List[int]:
""" Returns a list containing only the prime numbers from the original list.
>>> filter_primes([2, 3, 4, 5, 28, 29, 30]) [2, 3, 5, 29]
>>> filter_primes([4, 6, 8, 10, 12, 14]) []
>>> filter_primes([2, 3, 5, 7, 11, 13]) [2, 3, 5, 7, 11, 13]
>>> filt... | def is_prime(n):
"""
Helper function to check if a given number n is prime.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False
max_divisor = int(n**0.5) + 1
for d in range(3, max_divisor, 2):
i... | from solution import filter_primes
def test_filter_primes_with_sample_input():
assert filter_primes([2, 3, 4, 5, 28, 29, 30]) == [2, 3, 5, 29]
def test_filter_primes_with_no_primes():
assert filter_primes([4, 6, 8, 10, 12, 14]) == []
def test_filter_primes_with_all_primes():
assert filter_primes([2, 3, 5... | [
{
"docstring": "Helper function to check if a given number n is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list containing only the prime numbers from the original list.\n\nArgs:\nnumbers (list of int... | [
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 Helper function to check if a given number n is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ... | trial_gpt4o_0 | {
"original_instruction": "Write a function that takes in a list of integers and returns a new list that contains only the prime numbers from the original list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\n-----Constraints-----\n- The input list will have... | 0.676049 | Taco_42730 | C | [
"is_prime",
"filter_primes"
] | 2 | [
[
"filter_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d16f7d49d47b44723c37b6456061d55247e0e3c2 | a3f9ea6bf8b9b9f1d473dcb1790d536c8b006d79 | |||
v1.0 | complete | Taco | Taco_42613_C | def longest_increasing_subsequence(arr):
"""
Returns the length of the longest increasing subsequence in the given array.
"""
def max_people_picked(n, hat_numbers):
"""
Returns the maximum number of people that can be picked such that each successive
person in the sub-sequence has a strictl... | def longest_increasing_subsequence(arr):
"""
Returns the length of the longest increasing subsequence in the given array.
"""
if not arr:
return 0
n = len(arr)
dp = [1] * n # dp[i] will be the length of the LIS ending at index i
for i in range(1, n):
for j in range... | def test_longest_increasing_subsequence():
assert max_people_picked(5, [1, 3, 2, 5, 4]) == 3
assert max_people_picked(6, [10, 20, 10, 30, 20, 50]) == 4
assert max_people_picked(1, [1]) == 1
assert max_people_picked(2, [5, 5]) == 1
assert max_people_picked(8, [1, 2, 1, 3, 2, 4, 3, 5]) == 5
assert... | [
{
"docstring": "Returns the length of the longest increasing subsequence in the given array.",
"function_declaration": "def longest_increasing_subsequence(arr):",
"function_name": "longest_increasing_subsequence",
"parameter_list": "(arr)"
},
{
"docstring": "Returns the maximum number of peo... | [
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": "def longest_increasing_subsequence_length(n, hat_numbers):\n if n == 0:\n return 0\n \n # Initialize the DP array\n lis = [1] * n\n \n for... | trial_gpt4o_1 | {
"original_instruction": "In a small town, there is a unique tradition where town members form a queue for a festival and each person wears a unique hat with a number on it. The Festival Committee wants to find a way to identify a specific order in which people can be picked such that each person in this sub-sequenc... | 0.638383 | Taco_42613 | C | [
"longest_increasing_subsequence",
"max_people_picked"
] | 2 | [
[
"max_people_picked",
"longest_increasing_subsequence"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 232fed8a625ef3b225d1596cb1a6c2e50f5b0183 | 52b201f547c7cf0f484709b160e014df2be3cdb3 | |||
v1.0 | complete | Taco | Taco_42719_C | def can_split(nums, n, k, max_sum):
"""
Helper function to check if the array can be split into k or fewer subarrays with maximum sum max_sum.
"""
pass
def minimize_max_sum(n, k, nums):
"""
Minimize the maximum sum among the k non-empty contiguous subarrays.
Args:
n: int - The size... | def can_split(nums, n, k, max_sum):
current_sum = 0
required_subarrays = 1
for num in nums:
if current_sum + num > max_sum:
required_subarrays += 1
current_sum = num
if required_subarrays > k:
return False
else:
current_sum... | from solution import minimize_max_sum, process_input
def test_minimize_max_sum_case1():
n, k = 5, 2
nums = [1, 2, 3, 4, 5]
assert minimize_max_sum(n, k, nums) == 9
def test_minimize_max_sum_case2():
n, k = 3, 1
nums = [1, 2, 3]
assert minimize_max_sum(n, k, nums) == 6
def test_minimize_max_su... | [
{
"docstring": null,
"function_declaration": "def can_split(nums, n, k, max_sum):",
"function_name": "can_split",
"parameter_list": "(nums, n, k, max_sum)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_sum(n, k, nums):",
"function_name": "minimize_max_sum",
"p... | [
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 minimize_maximum_sum(T, test_cases):\n def can_split(nums, max_sum, k):\n current_sum, parts = 0, 1\n for num in nums:\n if current... | trial_gpt4o_2 | {
"original_instruction": "Rashmi is fascinated with arrays of integers and their sums. She has an array of size n and wants to divide the array into k non-empty contiguous subarrays such that the maximum sum among these subarrays is minimized. \n\nShe seeks your help to find the minimized value of the maximum sum am... | 0.6885 | Taco_42719 | C | [
"can_split",
"minimize_max_sum",
"process_input"
] | 3 | [
[
"minimize_max_sum",
"can_split"
],
[
"process_input",
"minimize_max_sum"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d25ed16efb7652373b413f4aa6edc0a7d4cb68a1 | 94fe703478ca01bbb2b46ee278d9ed3795e7ac83 | |||
v1.0 | complete | Taco | Taco_42557_C | def can_divide_with_max_time(time, N, K, max_time):
"""
Helper function to decide if it is possible to divide the segments such that
no runner has to cover more than max_time.
"""
pass
def minimize_max_time(T, test_cases):
""" Determine the minimal maximum segment time that any runner will need... | def can_divide_with_max_time(time, N, K, max_time):
"""
Helper function to decide if it is possible to divide the segments such that
no runner has to cover more than max_time.
"""
current_sum = 0
required_runners = 1
for t in time:
if current_sum + t > max_time:
requ... | from solution import minimize_max_time, process_input
def test_minimize_max_time():
# Test Case 1
input_data = '''2
5 2
1 2 3 4 5
4 3
2 1 4 2'''
T, test_cases = process_input(input_data)
results = minimize_max_time(T, test_cases)
assert results == [9, 4]
# Test Case 2
input_data = '''1... | [
{
"docstring": "Helper function to decide if it is possible to divide the segments such that\nno runner has to cover more than max_time.",
"function_declaration": "def can_divide_with_max_time(time, N, K, max_time):",
"function_name": "can_divide_with_max_time",
"parameter_list": "(time, N, K, max_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 minimize_max_time(T, cases):\n def is_possible(mid, K, time):\n current_sum = 0\n required_runners = 1\n for t in time:\n if... | trial_gpt4o_3 | {
"original_instruction": "A group of friends wants to participate in a relay race. The race track is divided into N segments, each segment potentially having a different terrain and thus, a different time to traverse. The team consists of K runners, and each runner can only cover contiguous segments. The task is to ... | 0.542218 | Taco_42557 | C | [
"can_divide_with_max_time",
"minimize_max_time",
"process_input",
"main"
] | 4 | [
[
"minimize_max_time",
"can_divide_with_max_time"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 54867d8484e9d823c9df433b7374aa4379df3984 | 722bfa81f8ede7c0ea8b0e86c615e7217599fedb | |||
v1.0 | complete | Taco | Taco_42828_C | def longest_subarray_with_limit(arr: List[int], limit: int) -> int:
"""
Determines the length of the longest subarray in which the absolute difference between
the maximum and minimum values is less than or equal to the given limit.
>>> longest_subarray_with_limit([8, 2, 4, 7, 10, 6, 5], 5)
4
... | def longest_subarray_with_limit(arr, limit):
"""
Determines the length of the longest subarray in which the absolute difference between
the maximum and minimum values is less than or equal to the given limit.
"""
from collections import deque
max_deque, min_deque = deque(), deque()
left = 0... | def test_longest_subarray_sample():
input_str = """7
8 2 4 7 10 6 5
5"""
assert longest_subarray_with_limit_from_input(input_str) == 4
def test_longest_subarray_single_element():
input_str = """1
10
0"""
assert longest_subarray_with_limit_from_input(input_str) == 1
def test_longest_subarray_all_elemen... | [
{
"docstring": "Determines the length of the longest subarray in which the absolute difference between\nthe maximum and minimum values is less than or equal to the given limit.",
"function_declaration": "def longest_subarray_with_limit(arr, limit):",
"function_name": "longest_subarray_with_limit",
"... | [
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": "from collections import deque\n\ndef longest_subarray_with_limit(arr, limit):\n max_deque = deque() # holds elements in decreasing order to track the max in th... | trial_gpt4o_1 | {
"original_instruction": "Using the given array of positive integers, determine the length of the longest subarray in which the absolute difference between the maximum and minimum values is less than or equal to a given limit.\n\nInput format:\n- The first input line contains an integer `n` representing the number o... | 0.745515 | Taco_42828 | C | [
"longest_subarray_with_limit",
"longest_subarray_with_limit_from_input"
] | 2 | [
[
"longest_subarray_with_limit_from_input",
"longest_subarray_with_limit"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8cc5e8f42f6aa321468206d984a0b83654427d3e | ac099232520f23f69929bf9cd8e3cfaa221c8fd3 | |||
v1.0 | complete | Taco | Taco_42863_C | from typing import List, Tuple
def josephus(n: int, k: int) -> int:
"""
Given the number of players n and the step rate k,
this function returns the position of the winning player.
>>> josephus(5, 2)
3
>>> josephus(7, 3)
4
>>> josephus(10, 4)
5
"""
def solve(test_cases: List[Tu... | def josephus(n, k):
"""
Given the number of players n and the step rate k,
this function returns the position of the winning player.
"""
if n == 1:
return 1
else:
return (josephus(n - 1, k) + k - 1) % n + 1
def solve(test_cases):
"""
Given a list of test cases, this func... | def test_josephus():
assert josephus(5, 2) == 3
assert josephus(7, 3) == 4
assert josephus(10, 4) == 5
assert josephus(1, 1) == 1
assert josephus(2, 1) == 2
assert josephus(5, 1) == 5
def test_solve():
assert solve([(5, 2), (7, 3), (10, 4)]) == [3, 4, 5]
assert solve([(1, 1), (2, 1)]) =... | [
{
"docstring": "Given the number of players n and the step rate k,\nthis function returns the position of the winning player.",
"function_declaration": "def josephus(n, k):",
"function_name": "josephus",
"parameter_list": "(n, k)"
},
{
"docstring": "Given a list of test cases, this function ... | [
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 josephus(n, k):\n \"\"\"\n Solves the Josephus problem for n players and step rate k.\n \"\"\"\n if n == 1:\n return 1\n else:\n r... | trial_gpt4o_1 | {
"original_instruction": "A popular online game involves players forming a huge circle and engaging in a unique elimination process. Each player is assigned a number from 1 to N. Starting from player 1, every Kth player is removed from the circle, and the game continues from the next player after the removed one. Th... | 0.695723 | Taco_42863 | C | [
"josephus",
"solve",
"parse_input",
"format_output"
] | 4 | [
[
"solve",
"josephus"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | false | [] | true | fdc2399e6bcd78ed0a7f0e5270b7a13c42e7a254 | 493287e7bb5a8eb997461e9d678e2d1cdeda6a6f | |||
v1.0 | complete | Taco | Taco_42885_C | def distribute_books(test_cases):
""" You are given a list of integers representing a collection of books and the number of pages in each book. Your task is to determine whether it is possible to allocate all books to M students such that each student gets at least one book and the maximum number of pages assigned ... | def is_possible(books, n, m, curr_min):
students_required = 1
curr_sum = 0
for i in range(n):
if books[i] > curr_min:
return False
if curr_sum + books[i] > curr_min:
students_required += 1
curr_sum = books[i]
if students_required ... | from solution import distribute_books
def test_distribute_books_case1():
test_cases = [
((4, 2), [12, 34, 67, 90])
]
assert distribute_books(test_cases) == [113]
def test_distribute_books_case2():
test_cases = [
((5, 3), [10, 20, 30, 40, 50])
]
assert distribute_books(test_case... | [
{
"docstring": null,
"function_declaration": "def is_possible(books, n, m, curr_min):",
"function_name": "is_possible",
"parameter_list": "(books, n, m, curr_min)"
},
{
"docstring": null,
"function_declaration": "def find_minimum_pages(books, n, m):",
"function_name": "find_minimum_p... | [
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 canAllocate(pages, n, m, max_pages):\n student_count = 1\n current_sum = 0\n \n for page in pages:\n if page > max_pages:\n retur... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of integers representing a collection of books and the number of pages in each book. Your task is to determine whether it is possible to allocate all books to M students such that each student gets at least one book and the maximum number of pages assigned to a student ... | 0.726304 | Taco_42885 | C | [
"is_possible",
"find_minimum_pages",
"distribute_books"
] | 3 | [
[
"distribute_books",
"find_minimum_pages"
],
[
"find_minimum_pages",
"is_possible"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 6e6b81d9dc578fa12b86b3e4036d0017c261ac86 | 6ffc6c02295005a114429c757f73afe57d408de6 | |||
v1.0 | complete | Taco | Taco_42956_C | def find_prime_gaps(N: int) -> List[int]:
"""
Find all unique prime gaps for prime numbers less than a given number `N`.
The gap between two successive prime numbers is defined as the difference between the latter prime and the former prime.
Arguments:
N -- The upper limit (exclusive) for... | def find_prime_gaps(N):
def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return ... | from solution import find_prime_gaps, format_prime_gaps
def test_find_prime_gaps_small_range():
assert find_prime_gaps(20) == [1, 2, 4]
def test_find_prime_gaps_larger_range():
assert find_prime_gaps(50) == [1, 2, 4, 6]
def test_find_prime_gaps_one_prime_gap():
assert find_prime_gaps(5) == [1]
def test_... | [
{
"docstring": null,
"function_declaration": "def find_prime_gaps(N):",
"function_name": "find_prime_gaps",
"parameter_list": "(N)"
},
{
"docstring": null,
"function_declaration": "def format_prime_gaps(N):",
"function_name": "format_prime_gaps",
"parameter_list": "(N)"
},
{
... | [
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": "def find_prime_gaps(N):\n def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 ... | trial_gpt4o_0 | {
"original_instruction": "Sam loves coding challenges and has currently taken an interest in number theory. One day, while reading about prime numbers, he stumbled upon an interesting property of prime numbers called \"prime gaps\". The gap between two successive prime numbers is defined as the difference between th... | 0.598794 | Taco_42956 | C | [
"find_prime_gaps",
"format_prime_gaps"
] | 2 | [
[
"format_prime_gaps",
"find_prime_gaps"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9b228f59059d3b99412f83d1376d993c22abdb99 | 7a4a44d5ac1e5a0c9717fba8147476a7b341489c | |||
v1.0 | complete | Taco | Taco_42641_C | def is_valid_password(password: str) -> bool:
""" Check if the password meets all security criteria:
at least 8 characters long, include at least one lowercase
and one uppercase letter, contain at least one digit, and have
at least one special character from the set {!, @, #, $, %, ^, &, *, (, ), _, ... | def is_valid_password(password):
if len(password) < 8:
return False
has_lower = has_upper = has_digit = has_special = False
special_characters = set("!@#$%^&*()_+")
for char in password:
if char.islower():
has_lower = True
elif char.isupper():
has_upper ... | from solution import password_checker
def test_valid_passwords():
assert password_checker(3, ["Password1@", "GoodPa$$word123!", "V4l!d*Pwd"]) == ["Valid", "Valid", "Valid"]
def test_invalid_passwords():
assert password_checker(3, ["short1!", "NoSpecialChar123", "lowercase123!"]) == ["Invalid", "Invalid", "Inv... | [
{
"docstring": null,
"function_declaration": "def is_valid_password(password):",
"function_name": "is_valid_password",
"parameter_list": "(password)"
},
{
"docstring": null,
"function_declaration": "def password_checker(t, passwords):",
"function_name": "password_checker",
"param... | [
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 is_valid_password(password):\n \"\"\"\n Checks if the given password is valid based on the specified criteria.\n \"\"\"\n if len(password) < 8:\n ... | trial_gpt4o_2 | {
"original_instruction": "Chris is designing a password checker for a new software application. The goal is to ensure that the password meets specific criteria for security purposes.\n\nThe password must adhere to the following rules:\n\n1. The password must be at least 8 characters long.\n2. The password must inclu... | 0.577756 | Taco_42641 | C | [
"is_valid_password",
"password_checker"
] | 2 | [
[
"password_checker",
"is_valid_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f89ab190f427c04c0ad94626f4b6503d4d603b3a | 6b8f679c4b7aca5b25d67c14a8ce380695e43083 | |||
v1.0 | complete | Taco | Taco_42724_C | class TreeNode:
def __init__(self, key=0, left=None, right=None):
self.key = key
self.left = left
self.right = right
def construct_bst_from_preorder(preorder):
if not preorder:
return None
def build_bst(preorder, index, bound):
if index[0] == len(preorder) or preord... | class TreeNode:
def __init__(self, key=0, left=None, right=None):
self.key = key
self.left = left
self.right = right
def construct_bst_from_preorder(preorder):
if not preorder:
return None
def build_bst(preorder, index, bound):
if index[0] == len(preorder) or preord... | def test_construct_bst_from_preorder():
preorder = [8, 5, 1, 7, 10]
expected_inorder = [1, 5, 7, 8, 10]
n = len(preorder)
assert inorder_from_preorder(n, preorder) == expected_inorder
def test_single_element():
preorder = [5]
expected_inorder = [5]
n = len(preorder)
assert inorder_from_... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, key=0, left=None, right=None):\n self.key = key\n self.left = left\n self.right = right\n\ndef constru... | trial_gpt4o_0 | {
"original_instruction": "Mia loves solving puzzles. One day she came across an interesting problem related to binary trees and permutations. She decided to challenge her friend Tom with the following problem:\n\nTom needs to construct a binary tree from a given preorder traversal list of distinct integers. The tree... | 0.539489 | Taco_42724 | C | [
"construct_bst_from_preorder",
"inorder_traversal",
"inorder_from_preorder"
] | 3 | [
[
"inorder_from_preorder",
"construct_bst_from_preorder"
],
[
"inorder_from_preorder",
"inorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | fe8c1c4f5c015d67dfd0c93789b17020b1368a54 | d345cb3685dc7d610437d35ffab57844039e9af6 | |||
v1.0 | complete | Taco | Taco_43234_C | def largest_fertile_rectangle(n: int, m: int, grid: List[str]) -> int:
""" Given a grid where '1' represents fertile land and '0' represents barren land,
find the area of the largest contiguous rectangular sub-grid of fertile land.
Args:
n : int : Number of rows in the grid
m : int : Number of ... | def max_histogram_area(histogram):
stack = []
max_area = 0
index = 0
while index < len(histogram):
if not stack or histogram[stack[-1]] <= histogram[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (histog... | from solution import largest_fertile_rectangle
def test_sample_input():
n = 4
m = 5
grid = [
"10100",
"10111",
"11111",
"10010"
]
assert largest_fertile_rectangle(n, m, grid) == 6
def test_all_fertile():
n = 3
m = 3
grid = [
"111",
"111",... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(histogram):",
"function_name": "max_histogram_area",
"parameter_list": "(histogram)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle(matrix):",
"function_name": "max_rectangle",
"parameter_lis... | [
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 max_histogram_area(histogram):\n stack = []\n max_area = 0\n index = 0\n \n while index < len(histogram):\n if not stack or histogram[sta... | trial_gpt4o_0 | {
"original_instruction": "Farmer John has a rectangular farm divided into a grid of size n x m. Each cell of the grid represents a piece of the land that can either be fertile or barren. Farmer John wants to find all the rectangular sub-grids that consist solely of fertile land, and among them, identify the one with... | 0.680266 | Taco_43234 | C | [
"max_histogram_area",
"max_rectangle",
"largest_fertile_rectangle"
] | 3 | [
[
"largest_fertile_rectangle",
"max_rectangle"
],
[
"max_rectangle",
"max_histogram_area"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 082fcf1dfcb8ba205b9527c226b6a61924b39ed9 | 80d31b1e2ecc30566f091c2acbe67fb9d2f4bb82 | |||
v1.0 | complete | Taco | Taco_42588_C | from typing import List, Tuple
def is_path_exists(n: int, m: int, q: int, grid: List[str], operations: List[Tuple[int, int]]) -> str:
""" Determine if there exists a path from the top-left corner to the bottom-right corner of the maze after applying the operations.
>>> is_path_exists(4, 4, 2, ["....", ".#..", ... | from collections import deque
def can_escape(grid, n, m):
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)] # Down, Right, Up, Left
visited = [[False] * m for _ in range(n)]
queue = deque([(0, 0)]) # Start from the top-left corner
while queue:
x, y = queue.popleft()
if x == n - 1 and y... | def test_is_path_exists_sample_1():
n, m, q = 4, 4, 2
grid = [
"....",
".#..",
"..#.",
"...."
]
operations = [(1, 3), (3, 4)]
assert is_path_exists(n, m, q, grid, operations) == "YES"
def test_is_path_exists_sample_2():
n, m, q = 3, 3, 1
grid = [
".#.... | [
{
"docstring": null,
"function_declaration": "def can_escape(grid, n, m):",
"function_name": "can_escape",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def is_path_exists(n, m, q, grid, operations):",
"function_name": "is_path_exists",
"parame... | [
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 swap_rows(maze, x, y):\n \"\"\"\n Swaps the x-th row with y-th row in the maze.\n \"\"\"\n maze[x], maze[y] = maze[y], maze[x]\n\ndef find_path_bfs... | trial_gpt4o_1 | {
"original_instruction": "In a country far, far away, there exists a rectangular maze consisting of $N$ rows and $M$ columns. Each cell in the maze is either free (denoted by '.') or blocked (denoted by '#'). You are given the dimensions of the maze and the maze itself. Your task is to determine if there exists a pa... | 0.604374 | Taco_42588 | C | [
"can_escape",
"is_path_exists"
] | 2 | [
[
"is_path_exists",
"can_escape"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 192032d966f48835cbd9474266e89ccb780ec794 | 4fbfa64a92edd25dff0110869a93db8391bf7471 | |||
v1.0 | complete | Taco | Taco_42691_C | import heapq
from typing import List, Tuple
def min_cost_path(n: int, m: int, grid: List[List[int]], sx: int, sy: int, tx: int, ty: int) -> int:
"""
Computes the minimum cost to travel from (sx, sy) to (tx, ty) in a grid.
Parameters:
n (int): The number of rows in the grid.
m (int): The number of ... | import heapq
def min_cost_path(n, m, grid, sx, sy, tx, ty):
"""
Computes the minimum cost to travel from (sx, sy) to (tx, ty) in a grid.
"""
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
cost = [[float('inf')] * m for _ in range(n)]
cost[sx-1][sy-1] = 0
pq = [(0, sx-1, sy-1)]
whi... | from solution import min_cost_path, solve
def test_example_1():
grid = [
[1, 2, 2],
[3, 8, 2],
[5, 3, 5]
]
start = (1, 1)
end = (3, 3)
assert solve(grid, start, end) == 4
def test_example_2():
grid = [
[1, 1000],
[1000, 1]
]
start = (1, 1)
en... | [
{
"docstring": "Computes the minimum cost to travel from (sx, sy) to (tx, ty) in a grid.",
"function_declaration": "def min_cost_path(n, m, grid, sx, sy, tx, ty):",
"function_name": "min_cost_path",
"parameter_list": "(n, m, grid, sx, sy, tx, ty)"
},
{
"docstring": null,
"function_declar... | [
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": "import heapq\n\ndef min_cost_travel(grid, sx, sy, tx, ty):\n n = len(grid)\n m = len(grid[0])\n \n def is_valid(x, y):\n return 0 <= x < n and 0... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid of size n x m, where each cell contains a positive integer representing the elevation at that point. You are also given two points (sx, sy) and (tx, ty) which represent the starting and target points on the grid, respectively. You want to determine the minimum cost to t... | 0.672251 | Taco_42691 | C | [
"min_cost_path",
"solve"
] | 2 | [
[
"solve",
"min_cost_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6b14e3a65b8f42d547763c17a28b5f437d48d8fa | 7e2a7589095ef4216e47718ceba483437f017bf6 | |||
v1.0 | complete | Taco | Taco_42615_C | def generate_magic_square(n):
""" Generates an n x n magic square matrix if n is an odd integer between 3 and 9 inclusive.
>>> generate_magic_square(3)
[[8, 1, 6], [3, 5, 7], [4, 9, 2]]
>>> generate_magic_square(5)
[[17, 24, 1, 8, 15], [23, 5, 7, 14, 16], [4, 6, 13, 20, 22], [10, 12, 19, 21, 3], [11... | def generate_magic_square(n):
if n < 3 or n > 9 or n % 2 == 0:
raise ValueError("n must be an odd integer between 3 and 9 inclusive.")
magic_square = [[0] * n for _ in range(n)]
num = 1
i, j = 0, n // 2
while num <= n * n:
magic_square[i][j] = num
num += 1
... | from solution import generate_magic_square, format_magic_square, magic_square
def test_generate_magic_square():
assert generate_magic_square(3) == [
[8, 1, 6],
[3, 5, 7],
[4, 9, 2]
]
assert generate_magic_square(5) == [
[17, 24, 1, 8, 15],
[23, 5, 7, 14, 16],
... | [
{
"docstring": null,
"function_declaration": "def generate_magic_square(n):",
"function_name": "generate_magic_square",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def format_magic_square(matrix):",
"function_name": "format_magic_square",
"parameter_l... | [
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 generate_magic_square(n):\n \"\"\"\n Generates and returns an n x n magic square.\n \n Parameters:\n n (int): The size of the magic square (... | trial_gpt4o_1 | {
"original_instruction": "A \"Magic Square\" is an n × n matrix of distinct integers such that the sum of the integers in each row, each column, and the two main diagonals is the same. You are given an integer n (odd and 3 ≤ n ≤ 9). Output the **n × n matrix** that forms a magic square.\n\nInput\n\nThe only line of ... | 0.753118 | Taco_42615 | C | [
"generate_magic_square",
"format_magic_square",
"magic_square"
] | 3 | [
[
"magic_square",
"format_magic_square"
],
[
"magic_square",
"generate_magic_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f8ce3ffdcd6f46df884c6d02aed4f991125c48ff | b77144d357da406f16610e91f08fa11c398695f3 | |||
v1.0 | complete | Taco | Taco_42934_C | def nearest_prime(n: int) -> int:
""" Create a function nearest_prime that takes a positive integer n as an argument
and returns the nearest prime number to n. If there is a tie (i.e., two prime
numbers are equidistant from n), return the smaller prime number.
>>> nearest_prime(10)
11
>>>... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def nearest_prime(n):
if i... | from solution import nearest_prime
def test_nearest_prime():
assert nearest_prime(10) == 11
assert nearest_prime(14) == 13
assert nearest_prime(21) == 19
assert nearest_prime(20) == 19
assert nearest_prime(1) == 2
assert nearest_prime(2) == 2
assert nearest_prime(3) == 3
assert nearest_... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def nearest_prime(n):",
"function_name": "nearest_prime",
"parameter_list": "(n)"
}
] | [
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(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 ... | trial_gpt4o_0 | {
"original_instruction": "## Preface\n\nA prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A prime number is only divisible by 1 and itself.\n\n## The Problem\n\nCreate a function `nearest_prime` that takes a positive integer `n` as an argument and ret... | 0.634305 | Taco_42934 | C | [
"is_prime",
"nearest_prime"
] | 2 | [
[
"nearest_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cc91c05fe64e3f9573091d9fc802a1fbb876286c | e36d8c89c83dd421f19018819ef0c58b5667188b | |||
v1.0 | complete | Taco | Taco_42903_C | def is_prime(num):
""" Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False... | def is_prime(num):
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return False
i += 6
return True
def prime_rearrangement(arr):
... | import pytest
from solution import prime_rearrangement
def test_prime_rearrangement():
assert prime_rearrangement([11, 4, 7, 10, 2, 9]) == [11, 7, 2, 4, 10, 9]
assert prime_rearrangement([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13]
assert prime_rearrangement([4, 6, 8, 9, 10, 15]) == [4, 6, 8, 9, 10, 15]
... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def prime_rearrangement(arr):",
"function_name": "prime_rearrangement",
"parameter_list": "(arr)"
}
] | [
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(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 ... | trial_gpt4o_0 | {
"original_instruction": "Write a function `prime_rearrangement()` (JS: `primeRearrangement`) that takes an integer array as input and returns a new array where all the prime numbers are at the beginning and the rest of the numbers follow in the same order they appeared in the original array. Maintain the order of t... | 0.707839 | Taco_42903 | C | [
"is_prime",
"prime_rearrangement"
] | 2 | [
[
"prime_rearrangement",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 268bd3c988069446b194e1a5de11bbbb1619789e | be1b1b2400bcd28daa712bd0131f0180c6f744f3 | |||
v1.0 | complete | Taco | Taco_43201_C | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def is_symmetric_tree(root):
if not root:
return True
def is_mirror(t1, t2):
if not t1 and not t2:
return True
if not t1 or not t2:
return Fal... | class TreeNode:
def __init__(self, val=0):
self.val = val
self.left = None
self.right = None
def is_symmetric_tree(root):
if not root:
return True
def is_mirror(t1, t2):
if not t1 and not t2:
return True
if not t1 or not t2:
return Fa... | import pytest
from solution import isSymmetric
def test_is_symmetric():
# First Test Case
N1 = 7
values1 = [1, 2, 2, 3, 4, 4, 3]
assert isSymmetric(N1, values1) == "Yes"
# Second Test Case
N2 = 5
values2 = [1, 2, 2, -1, 3, -1, 3]
assert isSymmetric(N2, values2) == "No"
# T... | [] | [
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, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef isSymme... | trial_gpt4o_2 | {
"original_instruction": "Given a binary tree, write a function to check whether it is a mirror of itself (i.e., symmetric around its center).\n\nInput:\nFirst line of input contains number of testcases T. For each testcase, there will be two lines of input. First line contains the number of nodes N in the binary tr... | 0.651113 | Taco_43201 | C | [
"is_symmetric_tree",
"construct_tree_from_level_order",
"isSymmetric"
] | 3 | [
[
"isSymmetric",
"construct_tree_from_level_order"
],
[
"isSymmetric",
"is_symmetric_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | a17515e687f96f7da5522ef994f7f1f8fe395992 | c5c631ffcbe00a01427df044f87e02daa9ede262 | |||
v1.0 | complete | Taco | Taco_43030_C | def can_robot_navigate(input_data: str) -> str:
""" Determine if there is a path for the robot to reach the bottom-right corner of the grid.
>>> input_data = '''4 4
. . . #
. # . .
. # # .
. . . .'''
>>> can_robot_navigate(input_data)
'YES'
>>> input_data = '''4 4
. # # #
... | def can_reach_goal(n, m, grid):
from collections import deque
start = (0, 0)
goal = (n-1, m-1)
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return "NO"
queue = deque([start])
visited = set([start])
while queue:... | from solution import can_robot_navigate
def test_example_1():
input_data = '''4 4
. . . #
. # . .
. # # .
. . . .'''
assert can_robot_navigate(input_data) == "YES"
def test_example_2():
input_data = '''4 4
. # # #
# # # .
# # # #
. . . #'''
assert can_robot_navigate(input_data) == "NO"
def test_singl... | [
{
"docstring": null,
"function_declaration": "def can_reach_goal(n, m, grid):",
"function_name": "can_reach_goal",
"parameter_list": "(n, m, grid)"
},
{
"docstring": null,
"function_declaration": "def can_robot_navigate(input_data):",
"function_name": "can_robot_navigate",
"param... | [
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 is_path_exist(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] == '#' or visited[x][y]:\n return False\... | trial_gpt4o_1 | {
"original_instruction": "A robot is designed to navigate a grid-based warehouse, starting at the top-left corner (position (1,1)) and needs to reach the bottom-right corner (position (n,m)). The robot can move in four possible directions: up, down, left, and right. However, some cells in the grid are marked as obst... | 0.624436 | Taco_43030 | C | [
"can_reach_goal",
"can_robot_navigate"
] | 2 | [
[
"can_robot_navigate",
"can_reach_goal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8275591d9fca4eac60b0a32a56bf12c05369479c | 035f9ece54bf58be4bbc49203087c0bf76f4d439 | |||
v1.0 | complete | Taco | Taco_43254_C | def score_hand(cards):
"""
Calculate the total score for a hand of cards.
Each card has a point value associated with it:
- Cards 2 through 10 score points equal to their face value (2 to 10).
- Jacks, Queens, and Kings each score 10 points.
- Aces score 11 points.
:param cards: List o... | def score_hand(cards):
"""
Calculate the total score for a hand of cards.
:param cards: List of cards as strings.
:return: Total score as an integer.
"""
card_values = {
'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10,
'J': 10, 'Q': 10, 'K': 10, 'A': 11
... | from solution import score_hand, score_players_hands
def test_score_hand():
assert score_hand(['10', 'J', 'Q', '9', 'A']) == 50
assert score_hand(['9', '8', '3', '2', 'K']) == 32
assert score_hand(['A', 'A', 'A', '5', '5']) == 43
assert score_hand(['2', '3', '4', '5', '6']) == 20
assert score_hand(... | [
{
"docstring": "Calculate the total score for a hand of cards.\n\n:param cards: List of cards as strings.\n:return: Total score as an integer.",
"function_declaration": "def score_hand(cards):",
"function_name": "score_hand",
"parameter_list": "(cards)"
},
{
"docstring": "Compute the total 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 card_value(card):\n \"\"\"\n Returns the point value of a given card.\n \"\"\"\n if card in {'J', 'Q', 'K'}:\n return 10\n elif card == '... | trial_gpt4o_2 | {
"original_instruction": "problem\n\nA group of friends likes to play a card game every weekend. The game is played with a standard deck of 52 cards. They have recently decided to adopt a new scoring method to make the game more interesting. Each card has a point value associated with it:\n\n- Cards 2 through 10 sco... | 0.643785 | Taco_43254 | C | [
"score_hand",
"score_players_hands"
] | 2 | [
[
"score_players_hands",
"score_hand"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ff1546dbf2c911532d3e39829318d4b058d85466 | 4983848598373009a939c6c0993424afb6a8f684 | |||
v1.0 | complete | Taco | Taco_43067_C | def solve(input_data: str) -> str:
""" You are given an array of integers, and you must check if there exists a subsequence such that the subsequence is a permutation of a palindrome. A palindrome is a string that reads the same forward and backward, and a permutation of a palindrome is a re-arrangement of letters ... | def is_permutation_of_palindrome(arr):
"""
Checks if any subsequence of the array can be rearranged to form a palindrome.
"""
from collections import Counter
# Count frequencies of each number
freq = Counter(arr)
# Count how many numbers have an odd frequency
odd_count = sum(1 ... | import pytest
from solution import solve
def test_solve():
input_data = """2
3
1 2 2
4
1 2 2 3"""
expected_output = "YES\nNO"
assert solve(input_data) == expected_output
def test_solve_single_element():
input_data = """1
1
1"""
expected_output = "YES"
assert solve(input_data) == expected_outpu... | [
{
"docstring": "Checks if any subsequence of the array can be rearranged to form a palindrome.",
"function_declaration": "def is_permutation_of_palindrome(arr):",
"function_name": "is_permutation_of_palindrome",
"parameter_list": "(arr)"
},
{
"docstring": "Takes in a list of test cases and 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 is_palindrome_permutation_possible(arr):\n from collections import Counter\n \n count = Counter(arr)\n odd_count = sum(1 for value in count.values(... | trial_gpt4o_1 | {
"original_instruction": "You are given an array of integers, and you must check if there exists a subsequence such that the subsequence is a permutation of a palindrome. A palindrome is a string that reads the same forward and backward, and a permutation of a palindrome is a re-arrangement of letters to form a pali... | 0.695739 | Taco_43067 | C | [
"is_permutation_of_palindrome",
"check_permutation_of_palindrome",
"solve"
] | 3 | [
[
"check_permutation_of_palindrome",
"is_permutation_of_palindrome"
],
[
"solve",
"check_permutation_of_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d0fc3e32f290c1a1f821446f5044449e493c636f | 67589a05fb28b083193c8d17c9e00b82f1439f24 | |||
v1.0 | complete | Taco | Taco_43002_C | import random
def partition(arr, low, high):
pass # Implement the partitioning logic
def quickselect(arr, low, high, k):
pass # Implement the Quickselect algorithm
def kthSmallest(arr: List[int], k: int) -> int:
""" Given an array arr[] of integers and a positive integer k,
find the k-th smallest e... | import random
def partition(arr, low, high):
pivot_index = random.randint(low, high)
arr[pivot_index], arr[high] = arr[high], arr[pivot_index]
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i = i + 1
arr[i], arr[j] = arr[j], arr[i]
a... | from solution import kthSmallest
def test_kth_smallest_example1():
assert kthSmallest([7, 10, 4, 3, 20, 15], 3) == 7
def test_kth_smallest_example2():
assert kthSmallest([7, 10, 4, 3, 20, 15], 4) == 10
def test_kth_smallest_single_element():
assert kthSmallest([25], 1) == 25
def test_kth_smallest_sorted... | [
{
"docstring": null,
"function_declaration": "def partition(arr, low, high):",
"function_name": "partition",
"parameter_list": "(arr, low, high)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, low, high, k):",
"function_name": "quickselect",
"parameter_list... | [
1,
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 partition(arr, low, high):\n pivot = arr[high]\n i = low - 1 # index of smaller element\n for j in range(low, high):\n if arr[j] <= pivot:\n ... | trial_gpt4o_2 | {
"original_instruction": "Given an array arr[] of integers and a positive integer k. The task is to find the k-th smallest element in the array using Quickselect algorithm.\n\nExample 1:\nInput:\narr[] = [7, 10, 4, 3, 20, 15]\nk = 3\nOutput:\n7\n\nExample 2:\nInput:\narr[] = [7, 10, 4, 3, 20, 15]\nk = 4\nOutput:\n10... | 0.644753 | Taco_43002 | C | [
"partition",
"quickselect",
"kthSmallest"
] | 3 | [
[
"kthSmallest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 230ac3e70f69f109a39b33ddf049220afd39fe26 | 5615794f5f3dd06f77c5b895bde0a752d512a3d2 | |||
v1.0 | complete | Taco | Taco_42963_C | def longestSubsequenceLength(strings: List[str]) -> int:
""" Create a function that takes a list of strings and returns the length of the longest subsequence where each string is a subsequence of the next string.
>>> longestSubsequenceLength(["a", "abc", "ab", "abcd", "b"]) 4
>>> longestSubsequenceLength(["... | def is_subsequence(s1, s2):
"""
Checks if s1 is a subsequence of s2.
"""
it = iter(s2)
return all(char in it for char in s1)
def longestSubsequenceLength(strings):
"""
Returns the length of the longest subsequence where each string is a subsequence of the next string.
"""
n = len(st... | from solution import longestSubsequenceLength
def test_example_1():
assert longestSubsequenceLength(["a", "abc", "ab", "abcd", "b"]) == 4
def test_example_2():
assert longestSubsequenceLength(["x", "xyz", "xy", "zxy", "a"]) == 3
def test_example_3():
assert longestSubsequenceLength(["car", "cat", "cart",... | [
{
"docstring": "Checks if s1 is a subsequence of s2.",
"function_declaration": "def is_subsequence(s1, s2):",
"function_name": "is_subsequence",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Returns the length of the longest subsequence where each string is a subsequence of the next string... | [
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 is_subsequence(small, large):\n \"\"\"Helper function to check if small is a subsequence of large.\"\"\"\n it = iter(large)\n return all(char in it fo... | trial_gpt4o_4 | {
"original_instruction": "Create a function that takes a list of strings and returns the length of the longest subsequence where each string is a subsequence of the next string.\n\nExamples:\n\n`longestSubsequenceLength([\"a\", \"abc\", \"ab\", \"abcd\", \"b\"])` returns 4\n\nExplanation: \"a\" → \"abc\" → \"abcd\",... | 0.722076 | Taco_42963 | C | [
"is_subsequence",
"longestSubsequenceLength"
] | 2 | [
[
"longestSubsequenceLength",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 880056273433ca872579e6faaf2dd8f9858d12aa | 9beb1f29f5ca51ef3c1e6eafc0e0c4a47c2c4e98 | |||
v1.0 | complete | Taco | Taco_42810_C | from typing import List, Tuple
def sieve_of_eratosthenes(n: int) -> List[bool]:
"""
Creates a list of boolean values, where True denotes that the index is a prime number.
Uses the Sieve of Eratosthenes algorithm.
"""
# Implementation goes here
def count_primes_in_ranges(T: int, ranges: List[Tuple[... | def sieve_of_eratosthenes(n):
"""
Creates a list of boolean values, where True denotes that the index is a prime number.
Uses the Sieve of Eratosthenes algorithm.
"""
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False # 0 and 1 are not prime numbers
p = 2
while (p * p <= n):
i... | from solution import count_primes_in_ranges
def test_simple_case():
assert count_primes_in_ranges(2, [(1, 10), (11, 20)]) == [4, 4]
def test_single_element_prime():
assert count_primes_in_ranges(2, [(2, 2), (19, 19)]) == [1, 1]
def test_single_element_non_prime():
assert count_primes_in_ranges(2, [(4, 4)... | [
{
"docstring": "Creates a list of boolean values, where True denotes that the index is a prime number.\nUses the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": "Fo... | [
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 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_1 | {
"original_instruction": "Johnny loves playing with numbers. He recently learned about prime numbers and now he wants to explore how many prime numbers he can find in various ranges.\n\nA number is considered prime if it has no divisors other than 1 and itself.\n\nGiven a list of ranges, Johnny wants to count the nu... | 0.657918 | Taco_42810 | C | [
"sieve_of_eratosthenes",
"count_primes_in_ranges"
] | 2 | [
[
"count_primes_in_ranges",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 583061b720a87f882bda45a3569d89d44dcaf201 | 10559514f9c3eaae8dad7fa6ad994ccb8dd10015 | |||
v1.0 | complete | Taco | Taco_43299_C | def maximalRectangle(matrix: List[List[str]]) -> int:
""" Given a binary matrix, determine the area of the largest rectangle containing only '1's and return its area.
>>> maximalRectangle([
... ["1", "0", "1", "0"],
... ["1", "0", "1", "1"],
... ["1", "1", "1", "1"],
... ["1", "0... | def maximalRectangle(matrix):
if not matrix:
return 0
max_area = 0
dp = [0] * len(matrix[0])
for i in range(len(matrix)):
for j in range(len(matrix[0])):
dp[j] = dp[j] + 1 if matrix[i][j] == '1' else 0
max_area = max(max_area, largestRectangleArea(dp))
return ... | from solution import maximalRectangle, convert_input_to_matrix
def test_maximal_rectangle_case1():
input_matrix = [
"1 0 1 0",
"1 0 1 1",
"1 1 1 1",
"1 0 0 1"
]
matrix = convert_input_to_matrix(input_matrix)
assert maximalRectangle(matrix) == 4
def test_maximal_rectangl... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
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(matrix):\n if not matrix:\n return 0\n max_area = 0\n row_count = len(matrix)\n col_count = len(matrix[0])\n \n heigh... | trial_gpt4o_1 | {
"original_instruction": "Background\n\nShiro is a software engineer who is currently working on a project involving 2D graphics. One of his tasks is to detect the largest rectangle that can be formed within an enclosed area on a 2D grid. The grid is represented by a binary matrix where '1' indicates part of the enc... | 0.689647 | Taco_43299 | C | [
"maximalRectangle",
"largestRectangleArea",
"convert_input_to_matrix"
] | 3 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7499b9c5a5700b4b459cc1af1bfff1943cc82a0d | 6632b143b2062c26dfbe61b302e39287736ff2ea | |||
v1.0 | complete | Taco | Taco_43617_C | def calculate_grade(scores):
"""
Returns the final grade based on the average of five scores
>>> calculate_grade([95, 96, 97, 94, 98]) 'A'
>>> calculate_grade([85, 90, 78, 92, 88]) 'B'
>>> calculate_grade([75, 70, 65, 80, 75]) 'C'
>>> calculate_grade([60, 58, 65, 67, 62]) 'D'
>>> calculate_g... | def calculate_grade(scores):
"""
Returns the final grade based on the average of five scores
"""
average = sum(scores) / 5
if average >= 90:
return 'A'
elif average >= 80:
return 'B'
elif average >= 70:
return 'C'
elif average >= 60:
return 'D'
else:
... | from solution import calculate_grade, determine_grades
def test_calculate_grade_A():
assert calculate_grade([95, 96, 97, 94, 98]) == 'A'
def test_calculate_grade_B():
assert calculate_grade([85, 90, 78, 92, 88]) == 'B'
def test_calculate_grade_C():
assert calculate_grade([75, 70, 65, 80, 75]) == 'C'
def... | [
{
"docstring": "Returns the final grade based on the average of five scores",
"function_declaration": "def calculate_grade(scores):",
"function_name": "calculate_grade",
"parameter_list": "(scores)"
},
{
"docstring": "Takes a list of student scores and returns a list of their final grades",
... | [
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 calculate_grade(scores):\n \"\"\"\n Returns the final grade based on the average of five scores\n \"\"\"\n average = sum(scores) / 5\n if averag... | trial_gpt4o_0 | {
"original_instruction": "A certain university has recently transitioned to a new grading system. For each student, based on their scores in 5 subjects, grades are determined. The grades comply with the following rules:\n\n- A student’s final grade is computed based on the average of the 5 scores.\n- If the average ... | 0.810464 | Taco_43617 | C | [
"calculate_grade",
"determine_grades"
] | 2 | [
[
"determine_grades",
"calculate_grade"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cf8a2d6064076edc3b22e1aff192cdafb5ee0f63 | 4513e6c35b419e7d8a7c38bfd93c18628e981e33 | |||
v1.0 | complete | Taco | Taco_42637_C | def largest_filled_rectangle(grid: List[List[int]]) -> int:
"""Returns the size of the largest filled rectangle in a grid.
Args:
grid (List[List[int]]): A 2D grid where each cell is either 0 (white) or 1 (black).
Returns:
int: The size of the largest filled rectangle that can be formed by ... | def largest_filled_rectangle(grid):
"""
Returns the size of the largest filled rectangle in a grid.
"""
if not grid or not grid[0]:
return 0
M = len(grid)
N = len(grid[0])
max_area = 0
# Create an array to store the heights of each column
heights = [0] * N
for row in r... | def test_largest_filled_rectangle():
assert largest_filled_rectangle([[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]]) == 6
assert largest_filled_rectangle([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) == 0
assert largest_filled_rectangle([[1, 1, 0, 1], [1, 1, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1]]) ==... | [
{
"docstring": "Returns the size of the largest filled rectangle in a grid.",
"function_declaration": "def largest_filled_rectangle(grid):",
"function_name": "largest_filled_rectangle",
"parameter_list": "(grid)"
},
{
"docstring": "Helper function to calculate the maximum rectangle area in a... | [
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\n\ndef largest_filled_rectangle(grid: List[List[int]]) -> int:\n if not grid:\n return 0\n \n M, N = len(grid), len(grid[0]... | trial_gpt4o_2 | {
"original_instruction": "In a grid of size `M x N`, each cell is either black or white. A rectangle is defined as an area bounded by four sides, and a filled rectangle is one where all cells inside it are black. You need to determine the size of the largest filled rectangle in the grid, i.e., the rectangle that con... | 0.681531 | Taco_42637 | C | [
"largest_filled_rectangle",
"max_histogram_area"
] | 2 | [
[
"largest_filled_rectangle",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | fc1cb53c309c0599e823159e12c2fcfcc0a5867c | 8f4ef96bf28d94584ec31d7ae5a7b1d31c3499cd | |||
v1.0 | complete | Taco | Taco_43097_C | from typing import List
def find_largest_palindromic_subgrid(n: int, m: int, grid: List[str]) -> int:
"""
Determine the size of the largest palindromic subgrid in the given grid.
Parameters:
n (int): The number of rows in the grid.
m (int): The number of columns in the grid.
grid (List[str... | def is_palindromic_subgrid(grid, i1, j1, i2, j2):
for i in range(i1, i2 + 1):
if grid[i][j1:j2 + 1] != grid[i][j1:j2 + 1][::-1]:
return False
for j in range(j1, j2 + 1):
col = ''.join(grid[i][j] for i in range(i1, i2 + 1))
if col != col[::-1]:
return False
ret... | import pytest
from solution import find_largest_palindromic_subgrid
def test_example_1():
n = 3
m = 3
grid = [
"ABA",
"BAB",
"ABA"
]
assert find_largest_palindromic_subgrid(n, m, grid) == 3
def test_example_2():
n = 4
m = 4
grid = [
"AAAA",
"ABBA... | [
{
"docstring": null,
"function_declaration": "def is_palindromic_subgrid(grid, i1, j1, i2, j2):",
"function_name": "is_palindromic_subgrid",
"parameter_list": "(grid, i1, j1, i2, j2)"
},
{
"docstring": null,
"function_declaration": "def largest_palindromic_subgrid(n, m, grid):",
"fun... | [
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": "def is_palindromic_subgrid(grid, i1, j1, i2, j2):\n for i in range(i1, i2 + 1):\n if grid[i][j1:j2 + 1] != grid[i][j1:j2 + 1][::-1]:\n return ... | trial_gpt4o_0 | {
"original_instruction": "Let's consider a two-dimensional grid consisting of uppercase English letters. We say that a contiguous subgrid is a \"palindromic subgrid\" if the sequence of letters it contains reads the same forwards and backwards in both its rows and columns.\n\nYour task is to determine the size of th... | 0.521994 | Taco_43097 | C | [
"is_palindromic_subgrid",
"largest_palindromic_subgrid",
"find_largest_palindromic_subgrid"
] | 3 | [
[
"find_largest_palindromic_subgrid",
"largest_palindromic_subgrid"
],
[
"largest_palindromic_subgrid",
"is_palindromic_subgrid"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | a67ed42a930982166b68501885a9521c5c7e656f | a1996bcac34ff1086f3cf0c4dd8220f57a0b071f | |||
v1.0 | complete | Taco | Taco_43797_C | def main(input_str: str) -> List[int]:
""" Execute commands on the given array of soldiers' strength and return results for type '2 L R' commands.
Args:
input_str: str: Multiline input string containing array size, number of commands, initial array values, and commands.
Returns:
List[int]: A li... | 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 execute_commands(n, m, soldie... | from solution import main
def test_example_case():
input_str = """6 5
6 10 3 5 7 15
2 1 6
1 4 11
2 3 5
2 1 3
2 2 4"""
expected_output = [3, 3, 1, 2]
assert main(input_str) == expected_output
def test_single_prime():
input_str = """3 2
1 3 1
2 1 3
2 2 2"""
expected_output = [1, 1]
ass... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def execute_commands(n, m, soldiers, commands):",
"function_name": "execute_commands",
"parameter_list": "(n, m, ... | [
0,
0,
0,
0,
0,
0,
1,
0,
1,
0
] | 2 | hard | 0.2 | {
"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_8 | {
"original_instruction": "You are given N elements in an array A, where each element represents a soldier's strength. There are M commands that you need to execute. Each command is one of two types:\n\n1. `1 X Y`: Update the value of the soldier at position X to Y.\n2. `2 L R`: Compute the total number of soldiers w... | 0.586797 | Taco_43797 | C | [
"is_prime",
"execute_commands",
"process_input",
"main"
] | 4 | [
[
"execute_commands",
"is_prime"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | c35d0d179c02dd09560eae9af177e8d51cf8f09d | 2ddbaac932cff3795b76a322566efa9179e239a0 | |||
v1.0 | complete | Taco | Taco_43598_C | def is_prime(n: int) -> bool:
"""
Determine if a number is a prime.
:param n: An integer number to check.
:return: True if n is a prime number, False otherwise.
"""
# implementation here
def classify_number(n: int) -> str:
"""
Classify a number as prime, composite or neither.
... | def is_prime(n):
"""
Determine if a number is a prime.
:param n: An integer number to check.
:return: 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 rang... | from solution import is_prime, classify_number, process_numbers
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(1) == False
assert is_prime(0) == False
assert is_prime(-3) == False
assert is_prime(17) == True
assert ... | [
{
"docstring": "Determine if a number is a prime.\n\n:param n: An integer number to check.\n:return: True if n is a prime number, False otherwise.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Classify a number as prime,... | [
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 Determine if a number is a prime.\n \n :param n: An integer number to check.\n :return: True if n is a prime number, Fal... | trial_gpt4o_0 | {
"original_instruction": "Write a program that processes a sequence of positive integers and determines for each, whether they are a prime number, a composite number, or neither. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. A composite number is a number greater th... | 0.736327 | Taco_43598 | C | [
"is_prime",
"classify_number",
"process_numbers"
] | 3 | [
[
"classify_number",
"is_prime"
],
[
"process_numbers",
"classify_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 743e7ba0e85061ace5ef758dae6ec8c06c63e93d | 41b2ed95cea565f3eb6603e5545c1f4265db02f8 | |||
v1.0 | complete | Taco | Taco_43741_C | def balanced_binary_strings(n: int) -> int:
""" Calculate the number of balanced binary strings of length 2n mod 10^9 + 7.
>>> balanced_binary_strings(1)
1
>>> balanced_binary_strings(2)
2
>>> balanced_binary_strings(3)
5
"""
def test_balanced_binary_strings():
assert balanced_b... | MOD = 10**9 + 7
def mod_inv(a, m):
return pow(a, m-2, m)
def catalan_number(n, mod):
if n == 0:
return 1
fact = [1] * (2 * n + 1)
for i in range(2, 2 * n + 1):
fact[i] = fact[i - 1] * i % mod
return (fact[2 * n] * mod_inv(fact[n + 1], mod) % mod * mod_inv(fact[n], mod) % mod) ... | def test_balanced_binary_strings():
assert balanced_binary_strings(1) == 1
assert balanced_binary_strings(2) == 2
assert balanced_binary_strings(3) == 5
assert balanced_binary_strings(4) == 14
assert balanced_binary_strings(5) == 42
def test_balanced_binary_strings_large():
assert balanced_bina... | [
{
"docstring": null,
"function_declaration": "def mod_inv(a, m):",
"function_name": "mod_inv",
"parameter_list": "(a, m)"
},
{
"docstring": null,
"function_declaration": "def catalan_number(n, mod):",
"function_name": "catalan_number",
"parameter_list": "(n, mod)"
},
{
"d... | [
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": "MOD = 10**9 + 7\n\ndef mod_inv(a, m):\n return pow(a, m-2, m)\n\ndef catalan_number(n, mod):\n if n == 0:\n return 1\n fact = [1] * (2 * n + 1)\n ... | trial_gpt4o_0 | {
"original_instruction": "In a distant galaxy, there is a planet named Zog where the inhabitants speak a language consisting of binary strings. A binary string is considered \"balanced\" if the number of '0's equals the number of '1's, and no prefix of the string has more '1's than '0's. For example, the strings \"0... | 0.627639 | Taco_43741 | C | [
"mod_inv",
"catalan_number",
"balanced_binary_strings"
] | 3 | [
[
"balanced_binary_strings",
"catalan_number"
],
[
"catalan_number",
"mod_inv"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 1d42edd68c446e44200dcda22b5afe30f46acf0a | dcfb8e2402cc1cf164570e3d7463639dc22de986 | |||
v1.0 | complete | Taco | Taco_43458_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def insert_nodes(nodes, edges):
if not nodes:
return None
node_dict = {val: TreeNode(val) for val in nodes}
for parent_val, child_val in edges:
parent = node_dict[parent_val]
... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def insert_nodes(nodes, edges):
if not nodes:
return None
node_dict = {val: TreeNode(val) for val in nodes}
for parent_val, child_val in edges:
parent = node_dict[parent_val]
... | from solution import is_tree_balanced
def test_example_0():
assert is_tree_balanced(7, [1, 2, 3, 4, 5, 6, 7], [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)]) == "YES"
def test_example_1():
assert is_tree_balanced(5, [1, 2, 3, 4, 5], [(1, 2), (1, 3), (2, 4), (4, 5)]) == "NO"
def test_empty_tree():
asser... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"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 insert_nodes(nodes, edges):\n if n... | trial_gpt4o_0 | {
"original_instruction": "Given a binary tree, determine if it is height-balanced. A height-balanced binary tree is defined as a tree in which the depth of the two subtrees of every node never differs by more than 1.\n\nInput Format\n\nThe first line contains an integer $n$, the number of nodes in the binary tree. I... | 0.749918 | Taco_43458 | C | [
"insert_nodes",
"is_balanced",
"is_tree_balanced"
] | 3 | [
[
"is_tree_balanced",
"insert_nodes"
],
[
"is_tree_balanced",
"is_balanced"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 09e30d8aba93dd6d523d2e758a5f5e326f37c062 | 3ff52574a612d4d330f23436cfe47102648747f8 | |||
v1.0 | complete | Taco | Taco_43908_C | def solve(n: int, grid_values: List[List[str]]) -> Union[List[str], str]:
""" Determine whether it is possible to plant trees in an NxN grid such that no two trees share the same row or column, and no trees are planted on occupied plots.
Args:
n (int): Size of the grid (2 ≤ n ≤ 10)
grid_values (Lis... | def plant_trees(grid):
"""
This function takes an NxN grid and determines if it is possible to plant one tree ('T') in each row and each column
without placing a tree on an occupied plot ('X').
"""
def find_place(row, col_occupied, grid, N):
if row == N:
return True
for c... | def test_plant_trees_possible():
grid_values = [
"0 0 X".split(),
"X 0 0".split(),
"0 X 0".split()
]
assert solve(3, grid_values) == [
'T 0 X',
'X T 0',
'0 X T'
]
def test_plant_trees_not_possible():
grid_values = [
"X X 0".split(),
"0... | [
{
"docstring": "This function takes an NxN grid and determines if it is possible to plant one tree ('T') in each row and each column\nwithout placing a tree on an occupied plot ('X').",
"function_declaration": "def plant_trees(grid):",
"function_name": "plant_trees",
"parameter_list": "(grid)"
},
... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def plant_trees(n, grid):\n def is_valid(row, col, solution):\n for r in range(row):\n if solution[r][col] == 'T':\n ... | trial_gpt4o_8 | {
"original_instruction": "The city of Gridland is designed in a grid format with dimensions NxN. Mayor Patel wants to plant trees in Gridland such that no two trees fall in the same row or the same column. To achieve this, he has decided to plant exactly one tree in each row and each column. One day, he notices that... | 0.612442 | Taco_43908 | C | [
"plant_trees",
"solve"
] | 2 | [
[
"solve",
"plant_trees"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 778232697ea9b0d07ed2903a6a0e1889ccf82aa9 | 8713cc93ef3165a424c587c7a841710827a191d6 | |||
v1.0 | complete | Taco | Taco_43628_C | def is_magic(square: List[List[int]]) -> bool:
""" Check if a given square is a magic square.
>>> is_magic([
[2, 7, 6],
[9, 5, 1],
[4, 3, 8]
]) True
>>> is_magic([
[3, 7, 6],
[9, 5, 1],
[4, 3, 8]
]) False
"""
def complete_magic_square(n: int, grid: List[List[int]... | import itertools
def is_magic(square):
n = len(square)
target_sum = sum(square[0])
# Check rows
for row in square:
if sum(row) != target_sum:
return False
# Check columns
for col in range(n):
if sum(square[row][col] for row in range(n)) != target_sum:
... | import pytest
from solution import is_magic, complete_magic_square
def test_is_magic():
assert is_magic([
[2, 7, 6],
[9, 5, 1],
[4, 3, 8]
]) == True
assert is_magic([
[8, 1, 6],
[3, 5, 7],
[4, 9, 2]
]) == True
assert is_magic([
[3, 7... | [
{
"docstring": null,
"function_declaration": "def is_magic(square):",
"function_name": "is_magic",
"parameter_list": "(square)"
},
{
"docstring": null,
"function_declaration": "def complete_magic_square(n, grid):",
"function_name": "complete_magic_square",
"parameter_list": "(n, ... | [
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 is_magic_square(grid, n):\n target_sum = n * (n * n + 1) // 2\n\n # Check rows\n for row in grid:\n if sum(row) != target_sum:\n ret... | trial_gpt4o_2 | {
"original_instruction": "A magic square is a grid of distinct positive integers arranged in a square such that the sum of the numbers in each row, each column, and both main diagonals are all the same. You are given an n x n grid where some cells may already contain numbers. Complete the grid to form a magic square... | 0.635146 | Taco_43628 | C | [
"is_magic",
"complete_magic_square",
"solve"
] | 3 | [
[
"complete_magic_square",
"is_magic"
],
[
"solve",
"complete_magic_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b31dc00eb44c4f2dbfd8276fea11f09a4adc3a07 | 28f7aa796a2c31ddd05a09cd54185fa46d696899 | |||
v1.0 | complete | Taco | Taco_43926_C | def is_palindrome(num: int) -> bool:
""" Checks if a number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(123)
False
>>> is_palindrome(1221)
True
>>> is_palindrome(12321)
True
>>> is_palindrome(12331)
False
"""
def next_palindrome(N: int) -> int:
"""... | def is_palindrome(num):
"""
Checks if a number is a palindrome.
"""
return str(num) == str(num)[::-1]
def next_palindrome(N):
"""
Finds the smallest palindrome greater than N.
"""
N += 1 # Start checking from the next number
while not is_palindrome(N):
N += 1
return N
... | from solution import is_palindrome, next_palindrome, find_next_palindromes
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(123) == False
assert is_palindrome(1221) == True
assert is_palindrome(12321) == True
assert is_palindrome(12331) == False
def test_next_palind... | [
{
"docstring": "Checks if a number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Finds the smallest palindrome greater than N.",
"function_declaration": "def next_palindrome(N):",
"... | [
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_palindrome(n):\n \"\"\"Helper function to check if a number is a palindrome.\"\"\"\n return str(n) == str(n)[::-1]\n\ndef next_palindrome(n):\n \"\... | trial_gpt4o_1 | {
"original_instruction": "A palindrome is a sequence that reads the same backward as forward. Given an integer `N`, your task is to find the smallest palindrome that is greater than `N`. \n\nInput: The first line contains the number of test cases. Each test case is a single integer `N`.\n\nOutput: Print the smallest... | 0.732774 | Taco_43926 | C | [
"is_palindrome",
"next_palindrome",
"find_next_palindromes"
] | 3 | [
[
"find_next_palindromes",
"next_palindrome"
],
[
"next_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f1ee6be460a23d49e8046c6e9ed6e30fc6b795da | a346675ba862ea246e20cb90aebdb031ba4b24ab | |||
v1.0 | complete | Taco | Taco_43922_C | from typing import List, Tuple
def statement1(total_sum: int) -> bool:
""" Determine if Wendy could say 'I cannot determine the three numbers' given the sum.
>>> statement1(6)
False
>>> statement1(10)
True
"""
def statement2(total_product: int) -> bool:
""" Determine if Chris could say 'I ... | from itertools import combinations
def find_sum_triplets(total_sum):
triplets = []
for x in range(1, total_sum - 1):
for y in range(x + 1, total_sum - x):
z = total_sum - x - y
if z > y:
triplets.append((x, y, z))
return triplets
def find_product_triplets(to... | from solution import statement1, statement2, statement3, statement4, find_numbers
def test_statement1():
# In the case of sum 6, we have possible sets of (1, 2, 3)
assert statement1(6) == False
# In the case of sum 10, we have possible sets of (1, 3, 6) and (2, 3, 5)
assert statement1(10) == True
def ... | [
{
"docstring": null,
"function_declaration": "def find_sum_triplets(total_sum):",
"function_name": "find_sum_triplets",
"parameter_list": "(total_sum)"
},
{
"docstring": null,
"function_declaration": "def find_product_triplets(total_product):",
"function_name": "find_product_triplets... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def statement1(s):\n \"\"\"\n Wendy cannot determine the three numbers given the sum.\n There should be multiple sets of (a, b, c) that add up to s.\n ... | trial_gpt4o_6 | {
"original_instruction": "Three friends, John, Wendy, and Chris, are playing a number guessing game. John says he will think of three different numbers, all greater than or equal to 1. He announces to Wendy what the sum of these three numbers is, and to Chris what the product of these three numbers is. However, John... | 0.629938 | Taco_43922 | C | [
"find_sum_triplets",
"find_product_triplets",
"statement1",
"statement2",
"statement3",
"statement4",
"find_numbers"
] | 7 | [
[
"find_numbers",
"find_sum_triplets"
],
[
"statement1",
"find_sum_triplets"
],
[
"statement2",
"find_product_triplets"
],
[
"statement3",
"find_sum_triplets"
],
[
"statement3",
"statement2"
],
[
"statement4",
"find_product_triplets"
],
[
"... | 7 | [] | false | [] | false | pytest | true | [] | true | 9d2445c6661d6f3ef629002d4a6969534037bb8d | 2c56f4a6304fe851d1d47ba752fdebec6e70acab | |||
v1.0 | complete | Taco | Taco_43973_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(node_list):
""" Build a binary tree from a list of tuples.
Each tuple contains a node's value, its left child's value, and its right child's value.
... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(node_list):
if not node_list:
return None
nodes = {val: TreeNode(val) for val, left, right in node_list}
for val, left, right in node... | from solution import TreeNode, build_tree, max_path_sum, find_max_path_sum
def test_max_path_sum():
node_list = [(1, 2, 3), (2, 4, 5), (3, None, None), (4, None, None), (5, None, None)]
assert find_max_path_sum(node_list) == 8
def test_single_node():
node_list = [(1, None, None)]
assert find_max_path_... | [] | [
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": "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 build_t... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree where each node contains a digit (0-9). The path sum of a binary tree is the sum of all the values from the root to a leaf node. Write a program to find out the maximum path sum from the root to a leaf.\n\nA binary tree is represented using the following structur... | 0.593979 | Taco_43973 | C | [
"build_tree",
"max_path_sum",
"find_max_path_sum"
] | 3 | [
[
"find_max_path_sum",
"build_tree"
],
[
"find_max_path_sum",
"max_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 024ed57f66b0c5d32957e6167df306ef5733aae6 | 3a741fad0cdf618eed822aff443c72dbd2472564 | |||
v1.0 | complete | Taco | Taco_44099_C | import math
from typing import List
def lcm(x: int, y: int) -> int:
"""Calculate the least common multiple (LCM) of two numbers."""
return (x * y) // math.gcd(x, y)
def max_sum_after_operations(N: int) -> int:
"""
Function to compute the maximum possible sum of the sequence after performing the allowe... | import math
from functools import reduce
from itertools import combinations
def lcm(x, y):
return (x * y) // math.gcd(x, y)
def max_sum_after_operations(N):
"""
Function to compute the maximum possible sum of the sequence after performing the allowed operations.
"""
# Initial sequence
sequence... | from solution import max_sum_after_operations
def test_max_sum_after_operations_1():
assert max_sum_after_operations(4) == 12
def test_max_sum_after_operations_2():
assert max_sum_after_operations(6) == 60
def test_max_sum_after_operations_single():
assert max_sum_after_operations(1) == 1
def test_max_s... | [
{
"docstring": null,
"function_declaration": "def lcm(x, y):",
"function_name": "lcm",
"parameter_list": "(x, y)"
},
{
"docstring": "Function to compute the maximum possible sum of the sequence after performing the allowed operations.",
"function_declaration": "def max_sum_after_operatio... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef max_sum_after_operations(N):\n \"\"\"\n Returns the maximum possible sum of the ... | trial_gpt4o_6 | {
"original_instruction": "Alice is participating in a game where she needs to create a sequence of numbers based on specific rules. The game starts with a sequence of integers `1, 2, ..., N`. She can perform some operations to transform the sequence in order to achieve the highest possible value for the sum of the s... | 0.628814 | Taco_44099 | C | [
"lcm",
"max_sum_after_operations"
] | 2 | [
[
"max_sum_after_operations",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 426638187641cef800fa572af8d95ca1387a41aa | 6e9a17a4c11f04eace793e4f53678e0ef44ab617 | |||
v1.0 | complete | Taco | Taco_43952_C | from itertools import permutations
def is_palindrome(s: str) -> bool:
""" Check if the given string s is a palindrome.
>>> is_palindrome("aba")
True
>>> is_palindrome("racecar")
True
>>> is_palindrome("abc")
False
"""
pass
def unique_palindrome_permutations(word: str) -> int:
"... | from itertools import permutations
def is_palindrome(s):
"""
Check if the given string s is a palindrome.
"""
return s == s[::-1]
def unique_palindrome_permutations(word):
"""
Generate all unique permutations of the given word and count how many of them are palindromes.
"""
permut_set ... | from solution import is_palindrome, unique_palindrome_permutations, count_palindrome_permutations
def test_is_palindrome():
assert is_palindrome("aba")
assert is_palindrome("racecar")
assert not is_palindrome("abc")
assert is_palindrome("a")
assert is_palindrome("")
def test_unique_palindrome_perm... | [
{
"docstring": "Check if the given string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Generate all unique permutations of the given word and count how many of them are palindromes.",
"f... | [
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": "from itertools import permutations\n\ndef is_palindrome(word):\n return word == word[::-1]\n\ndef unique_palindromic_permutations(word):\n unique_permutation... | trial_gpt4o_2 | {
"original_instruction": "You are asked to create a program that can generate all unique permutations of a given word's characters and then filter out only those permutations that are palindromes. A palindrome is a word that reads the same backward as forward. The result should display the total number of unique pal... | 0.704859 | Taco_43952 | C | [
"is_palindrome",
"unique_palindrome_permutations",
"count_palindrome_permutations"
] | 3 | [
[
"count_palindrome_permutations",
"unique_palindrome_permutations"
],
[
"unique_palindrome_permutations",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 7766c7bc97f930b9ec9857353dcf5b763ffe94ae | 189e2ec2554e9f2f7edbe8638feec4a5fae64b60 | |||
v1.0 | complete | Taco | Taco_44171_C | def is_palindrome(s):
"""Check if a given string is a palindrome.
>>> is_palindrome("121")
True
>>> is_palindrome("123")
False
"""
pass # Replace with your solution
def next_palindrome(N):
"""Find the smallest palindrome greater than the given number.
>>> next_palindrome("123")
... | def is_palindrome(s):
return s == s[::-1]
def next_palindrome(N):
N = str(int(N) + 1)
while not is_palindrome(N):
N = str(int(N) + 1)
return N
def smallest_palindromes(test_cases):
results = []
for N in test_cases:
results.append(next_palindrome(N))
return results
def proc... | from solution import process_input, next_palindrome, is_palindrome
def test_is_palindrome():
assert is_palindrome("121") == True
assert is_palindrome("123") == False
assert is_palindrome("1221") == True
assert is_palindrome("12321") == True
def test_next_palindrome():
assert next_palindrome("123")... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def next_palindrome(N):",
"function_name": "next_palindrome",
"parameter_list": "(N)"
},
{
"doc... | [
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": "def next_palindrome(n):\n \"\"\"\n Find the smallest palindrome greater than a given number n.\n \"\"\"\n def is_palindrome(s):\n return s == s[... | trial_gpt4o_2 | {
"original_instruction": "Little Chandu loves palindromes and symmetry. Recently, he discovered a series of numbers that when converted to strings create a palindrome. Right now, he wants to find the smallest palindrome greater than a given number. You being his elder sibling, are asked to help him write a program t... | 0.750616 | Taco_44171 | C | [
"is_palindrome",
"next_palindrome",
"smallest_palindromes",
"process_input"
] | 4 | [
[
"next_palindrome",
"is_palindrome"
],
[
"process_input",
"smallest_palindromes"
],
[
"smallest_palindromes",
"next_palindrome"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 299087144a28759aa712792247160ef546622010 | 4110fd6d2e9a0d25956108c23a64e1079066ec4e | |||
v1.0 | complete | Taco | Taco_43803_C | def max_water_delivery(n: int, m: int, edges: List[Tuple[int, int, int]], t: int) -> int:
"""
Compute the maximum amount of water that can be delivered from the reservoir to a specified target farm.
Parameters:
n (int): Number of nodes (including the reservoir and all farms).
m (int): Number o... | from collections import defaultdict, deque
def bfs_capacity(graph, source, sink, parent):
"""
Breadth-First Search to find if there is a path from source to sink in residual graph.
If there is a path, return True and fills parent to store the path.
"""
visited = [False] * len(graph)
queue = deq... | from solution import max_water_delivery
def test_max_water_delivery_example_1():
assert max_water_delivery(4, 5, [(1, 2, 40), (1, 3, 20), (2, 3, 10), (2, 4, 30), (3, 4, 20)], 4) == 50
def test_max_water_delivery_example_2():
assert max_water_delivery(3, 3, [(1, 2, 100), (1, 3, 50), (2, 3, 50)], 3) == 100
def... | [
{
"docstring": "Breadth-First Search to find if there is a path from source to sink in residual graph.\nIf there is a path, return True and fills parent to store the path.",
"function_declaration": "def bfs_capacity(graph, source, sink, parent):",
"function_name": "bfs_capacity",
"parameter_list": "... | [
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 bfs(residual_graph, source, sink, parent):\n visited = [False] * len(residual_graph)\n queue = [source]\n visited[source] = True\n \n while queu... | trial_gpt4o_2 | {
"original_instruction": "In an ancient civilization, a system of water canals was used to transport water from a central reservoir to various farms. The farms are scattered and connected by a series of interconnected canals forming a network. Each canal segment has a flow capacity and there may be multiple routes t... | 0.667548 | Taco_43803 | C | [
"bfs_capacity",
"edmonds_karp_max_flow",
"max_water_delivery"
] | 3 | [
[
"edmonds_karp_max_flow",
"bfs_capacity"
],
[
"max_water_delivery",
"edmonds_karp_max_flow"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 68f8e9ca4cf93931440eaa235cf84dcc803461f1 | 77a8a6707fa930042f044ad93c4bfc8ac703ee3b | |||
v1.0 | complete | Taco | Taco_44136_C | def min_fatigue(n: int, m: int, bridges: List[Tuple[int, int, int]]) -> int:
""" Calculate the minimum possible value of the highest resistance level
that John must endure to travel from island 1 to island n.
>>> min_fatigue(4, 5, [(1, 2, 7), (1, 3, 3), (2, 3, 2), (2, 4, 9), (3, 4, 8)])
8
>>> ... | from collections import deque
def can_reach_with_max_resistance(graph, n, max_resistance):
visited = [False] * (n + 1)
queue = deque([1])
visited[1] = True
while queue:
current = queue.popleft()
if current == n:
return True
for neighbor, resistance in graph[curr... | def test_case_1():
n = 4
m = 5
bridges = [
(1, 2, 7),
(1, 3, 3),
(2, 3, 2),
(2, 4, 9),
(3, 4, 8)
]
assert min_fatigue(n, m, bridges) == 8
def test_case_2():
n = 3
m = 3
bridges = [
(1, 2, 2),
(2, 3, 2),
(1, 3, 5)
]
... | [
{
"docstring": null,
"function_declaration": "def can_reach_with_max_resistance(graph, n, max_resistance):",
"function_name": "can_reach_with_max_resistance",
"parameter_list": "(graph, n, max_resistance)"
},
{
"docstring": null,
"function_declaration": "def min_fatigue(n, m, bridges):",... | [
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": "import heapq\nfrom collections import defaultdict\n\ndef minimize_max_resistance(n, m, bridges):\n graph = defaultdict(list)\n for a, b, r in bridges:\n ... | trial_gpt4o_1 | {
"original_instruction": "John is participating in a treasure hunt and there are $n$ islands connected by $m$ bridges. Each bridge $i$ connects island $a_i$ to island $b_i$ and has a resistance level $r_i$. John starts on island $1$ and needs to reach island $n$ with the minimum fatigue possible. John's fatigue is d... | 0.641501 | Taco_44136 | C | [
"can_reach_with_max_resistance",
"min_fatigue"
] | 2 | [
[
"min_fatigue",
"can_reach_with_max_resistance"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4e64b8b84c348757be46e28d555d84368d38c7e8 | 2854da06c76a82a1ab0441f2726953595e8ccda9 | |||
v1.0 | complete | Taco | Taco_44347_C | def max_bridges(n: int, A: List[int], B: List[int]) -> int:
""" Determine the maximum number of bridges that can be built without any two bridges intersecting.
Parameters:
n (int): The number of proposed bridge positions on each side of the river.
A (List[int]): The positions on the left bank.
B (L... | def max_bridges(n, A, B):
bridges = sorted(zip(A, B))
LIS = []
for bridge in bridges:
pos = binary_search(LIS, bridge[1])
if pos == len(LIS):
LIS.append(bridge[1])
else:
LIS[pos] = bridge[1]
return len(LIS)
def binary_search(LIS, value):
low, hi... | from solution import max_bridges
def test_example():
assert max_bridges(5, [1, 3, 5, 2, 4], [2, 4, 1, 5, 3]) == 2
def test_all_same_position():
assert max_bridges(3, [1, 2, 3], [4, 5, 6]) == 3
def test_increasing_order():
assert max_bridges(4, [1, 2, 3, 4], [1, 2, 3, 4]) == 4
def test_decreasing_order()... | [
{
"docstring": null,
"function_declaration": "def max_bridges(n, A, B):",
"function_name": "max_bridges",
"parameter_list": "(n, A, B)"
},
{
"docstring": null,
"function_declaration": "def binary_search(LIS, value):",
"function_name": "binary_search",
"parameter_list": "(LIS, val... | [
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": "def max_bridges(n, A, B):\n \"\"\"\n Determine the maximum number of bridges that can be built without any two bridges intersecting.\n \n Args:\n n ... | trial_gpt4o_2 | {
"original_instruction": "In a small village, there is a river running through it, dividing the village into two halves. The villagers have decided to build a series of bridges to connect the two halves, but they want to do it in such a way that no two bridges intersect when viewed from above. \n\nYou're given two l... | 0.680871 | Taco_44347 | C | [
"max_bridges",
"binary_search"
] | 2 | [
[
"max_bridges",
"binary_search"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f449b9695d8eab771aafd7b23bdf668e06bf71b4 | 4e863a2b3242b7cf330373d6a4361e7fb5750448 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.