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_19481_C | def find_hikers_meeting_time(test_cases: List[List[int]]) -> List[int]:
"""
Calculate the minimum number of minutes until all hikers meet again at the starting point.
Each test case contains the walking speeds of hikers in minutes.
Args:
test_cases (List[List[int]]): A list of test cases, wher... | import math
from functools import reduce
# Function to find the Least Common Multiple (LCM) of two numbers
def lcm(a, b):
return abs(a * b) // math.gcd(a, b)
# Function to find the LCM of a list of numbers using reduce
def find_lcm_for_list(lst):
return reduce(lcm, lst)
def find_hikers_meeting_time(test_case... | from solution import find_hikers_meeting_time
def test_case_1():
assert find_hikers_meeting_time([[3, 4]]) == [12]
def test_case_2():
assert find_hikers_meeting_time([[1, 2, 3]]) == [6]
def test_case_3():
assert find_hikers_meeting_time([[2, 3, 6, 9]]) == [18]
def test_multiple_cases():
test_cases =... | [
{
"docstring": null,
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def find_lcm_for_list(lst):",
"function_name": "find_lcm_for_list",
"parameter_list": "(lst)"
},
{
"docstring... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef lcm(a, b):\n \"\"\"Return least common multiple.\"\"\"\n return a * b // gcd(a, b)\n\ndef lcm_multi... | trial_gpt4o_2 | {
"original_instruction": "A group of hikers is exploring a mountain trail. The trail is a circle, meaning it starts and ends at the same point. Each hiker starts from the beginning of the trail at the same time and walks at a constant speed. The trail has markers at regular intervals, and we want to know when all th... | 0.586063 | Taco_19481 | C | [
"lcm",
"find_lcm_for_list",
"find_hikers_meeting_time"
] | 3 | [
[
"find_hikers_meeting_time",
"find_lcm_for_list"
],
[
"find_lcm_for_list",
"lcm"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | eb6c37b307496a166b29ee2cb58f806a5e4dbc56 | f6fbf3d527a743321163b4f17977cae888570114 | |||
v1.0 | complete | Taco | Taco_12835_C | from typing import List, Tuple
def get_gcd(a: int, b: int) -> int:
"""
Find the Greatest Common Divisor (GCD) of two integers.
>>> get_gcd(10, 5) # 5
>>> get_gcd(0, 1) # 1
"""
while b:
a, b = b, a % b
return abs(a)
def max_straight_path_length(test_cases: List[Tuple[int, List[Tup... | def max_straight_path_length(test_cases):
results = []
for N, points in test_cases:
if N < 2:
results.append(N)
continue
max_length = 0
for i in range(N):
slopes = {}
duplicate = 1
for j in range(i + 1, N):
... | def test_function():
test_cases = [
(5, [(1, 1), (2, 2), (3, 3), (4, 5), (5, 6)]),
(4, [(1, 2), (4, 5), (7, 8), (10, 11)]),
(3, [(0, 0), (0, 0), (0, 0)]),
(6, [(1, 2), (2, 4), (3, 6), (4, 8), (5, 10), (6, 15)]),
(2, [(1, 2), (1, 3)])
]
expected_results = [3, 4, 3, 5,... | [
{
"docstring": null,
"function_declaration": "def max_straight_path_length(test_cases):",
"function_name": "max_straight_path_length",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def get_gcd(a, b):",
"function_name": "get_gcd",
"parameter_lis... | [
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 gcd(a, b):\n \"\"\"\n Computes the greatest common divisor of a and b using the Euclidean algorithm.\n \"\"\"\n while b:\n a, b = b, a % b\n... | trial_gpt4o_2 | {
"original_instruction": "Maria is a nature enthusiast and loves tracking the movements of various species in the forest using her smart gadgets. Recently, she recorded GPS coordinates of a particularly elusive bird known for its erratic flying patterns. She wants to analyze these coordinates to determine the bird's... | 0.622671 | Taco_12835 | C | [
"max_straight_path_length",
"get_gcd"
] | 2 | [
[
"max_straight_path_length",
"get_gcd"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 02f1832436a1d61c308c689d01e57eb46028fddd | 618c82ff03d9ec8acfee607fea2535029d01b733 | |||
v1.0 | complete | Taco | Taco_12646_C | def compute_grade(score: int) -> str:
""" Return the letter grade based on the score using the grading scale.
>>> compute_grade(95)
'A'
>>> compute_grade(85)
'B'
>>> compute_grade(75)
'C'
>>> compute_grade(65)
'D'
>>> compute_grade(55)
'F'
"""
def process_student_gra... | def compute_grade(score):
"""
Return the letter grade based on the score using the grading scale.
"""
if 90 <= score <= 100:
return 'A'
elif 80 <= score < 90:
return 'B'
elif 70 <= score < 80:
return 'C'
elif 60 <= score < 70:
return 'D'
else:
retu... | from solution import compute_grade, process_student_grades, get_student_grades
def test_compute_grade():
assert compute_grade(95) == 'A'
assert compute_grade(85) == 'B'
assert compute_grade(75) == 'C'
assert compute_grade(65) == 'D'
assert compute_grade(55) == 'F'
def test_process_student_grades()... | [
{
"docstring": "Return the letter grade based on the score using the grading scale.",
"function_declaration": "def compute_grade(score):",
"function_name": "compute_grade",
"parameter_list": "(score)"
},
{
"docstring": "Process the student score data and return a dictionary with names and th... | [
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 compute_grade(score):\n \"\"\"\n This function takes a score and returns the corresponding letter grade.\n \"\"\"\n if 90 <= score <= 100:\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of students and their scores in a particular subject. Your task is to compute the final letter grade for a given student based on their score. The grading scale is as follows:\n\n- A: 90 <= score <= 100\n- B: 80 <= score < 90\n- C: 70 <= score < 80\n- D: 60 <= score < 7... | 0.7356 | Taco_12646 | C | [
"compute_grade",
"process_student_grades",
"get_student_grades"
] | 3 | [
[
"get_student_grades",
"process_student_grades"
],
[
"process_student_grades",
"compute_grade"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2ddc124939f32e267d150db159abe2af1b6154f4 | e47a85808a841e2e8aa2ca3565d9612ae738309d | |||
v1.0 | complete | Taco | Taco_13457_C | class Node:
def __init__(self):
self.left = None
self.right = None
def create_tree_tree_structure(n, children):
nodes = [None] + [Node() for _ in range(n)]
for i in range(1, n + 1):
left, right = children[i - 1]
if left != -1:
nodes[i].left = nodes[left]
... | class Node:
def __init__(self):
self.left = None
self.right = None
def create_tree_tree_structure(n, children):
nodes = [None] + [Node() for _ in range(n)]
for i in range(1, n + 1):
left, right = children[i - 1]
if left != -1:
nodes[i].left = nodes[left]
... | def test_sample_input_1():
input_str = "5\n2 3\n-1 -1\n-1 4\n-1 -1\n-1 -1"
assert parse_input_and_find_max_depth(input_str) == 3
def test_single_node():
input_str = "1\n-1 -1"
assert parse_input_and_find_max_depth(input_str) == 1
def test_linear_tree():
input_str = "3\n2 -1\n3 -1\n-1 -1"
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):\n self.left = None\n self.right = None\n\ndef build_tree(nodes_info):\n n = len(nodes_info)\n if n == ... | trial_gpt4o_2 | {
"original_instruction": "Alice is working with binary trees. She needs to determine the maximum depth (or height) of a binary tree, defined as the number of nodes along the longest path from the root node down to the farthest leaf node. Given a binary tree, your task is to calculate its maximum depth.\n\n------ Inp... | 0.553327 | Taco_13457 | C | [
"create_tree_tree_structure",
"max_depth",
"binary_tree_max_depth",
"parse_input_and_find_max_depth"
] | 4 | [
[
"binary_tree_max_depth",
"create_tree_tree_structure"
],
[
"binary_tree_max_depth",
"max_depth"
],
[
"parse_input_and_find_max_depth",
"binary_tree_max_depth"
]
] | 3 | [
"parse_input_and_find_max_depth"
] | false | [
"Node"
] | true | pytest | false | [] | true | 10538d37c9a56636c42a1f145dd5a97a6081db80 | 5ca2245f9fadd9c20cf96df0d04dbf4009f17f82 | |||
v1.0 | complete | Taco | Taco_19748_C | from typing import List
def minimum_cost_to_connect_cities(n: int, m: int, roads: List[List[int]]) -> int:
""" Determine the minimum cost to construct a network of roads to ensure all cities are connected.
If it's impossible to connect all the cities, return -1.
Args:
n : int : The number of cities.
... | def find(parent, i):
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return 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[... | from solution import minimum_cost_to_connect_cities
def test_example_1():
n = 4
m = 5
roads = [
[1, 2, 1],
[1, 3, 4],
[2, 3, 2],
[3, 4, 3],
[1, 4, 5]
]
assert minimum_cost_to_connect_cities(n, m, roads) == 6
def test_example_2():
n = 3
m = 1
road... | [
{
"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,
0,
1,
0,
1,
1
] | 3 | 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 else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(paren... | trial_gpt4o_9 | {
"original_instruction": "Anna is developing a strategy game where players need to fortify their kingdoms by constructing a network of roads. The kingdom consists of n cities connected by m bidirectional roads such that each road has a cost associated with it. The cities are numbered from 1 to n.\n\nA key aspect of ... | 0.68599 | Taco_19748 | C | [
"find",
"union",
"minimum_cost_to_connect_cities"
] | 3 | [
[
"minimum_cost_to_connect_cities",
"find"
],
[
"minimum_cost_to_connect_cities",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 11f26489bfb9f0be8745cbc8ccfe3512f5aa4e7e | 7517d5c73ba04f5f54923ba0e8e997e09591ffec | |||
v1.0 | complete | Taco | Taco_20097_C | def is_prime(n: int) -> bool:
"""Determine if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
>>> is_prime(9)
False
>>> is_prime(1)
False
"""
def serve_or_not(dish_number: int) -> None:
"""Determine... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def serve_or_not(dish_number):
if is_prime(dish_number):
print("Serve")
... | from solution import is_prime, serve_or_not
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(9) == False
assert is_prime(1) == False
def test_serve_or_not(capsys):
serve_or_not(7)
captured ... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def serve_or_not(dish_number):",
"function_name": "serve_or_not",
"parameter_list": "(dish_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 if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n return False\n for i in range(3, int(n*... | trial_gpt4o_0 | {
"original_instruction": "The school cafeteria serves lunch in a very specific way. There are multiple types of dishes available, but each student can pick only one type of dish. Each type of dish can be represented as a number. The cafeteria serves lunch only if the selected dish type's number is prime.\n\nGiven a ... | 0.69336 | Taco_20097 | C | [
"is_prime",
"serve_or_not"
] | 2 | [
[
"serve_or_not",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 13baec34c694a2d09dab8c66d8492d811d5247e7 | 283d3d80613c2f5c5182a3b90353db56d99d047d | |||
v1.0 | complete | Taco | Taco_19065_C | import math
from typing import List, Tuple
def calculate_distance(x1: float, y1: float, x2: float, y2: float) -> float:
""" Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).
>>> calculate_distance(0, 0, 3, 4)
5.0
>>> calculate_distance(-1, -1, -4, -5)
5.0
"""
def t... | import math
def calculate_distance(x1, y1, x2, y2):
"""
Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).
"""
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def total_distance_covered(vehicle_locations):
"""
Calculate the total distance covered by a vehicle given a ... | from solution import calculate_distance, total_distance_covered, process_input
def test_calculate_distance():
assert math.isclose(calculate_distance(0, 0, 3, 4), 5.0)
assert math.isclose(calculate_distance(-1, -1, -4, -5), 5.0)
assert math.isclose(calculate_distance(0, 0, 0, 0), 0.0)
def test_total_distan... | [
{
"docstring": "Calculate the Euclidean distance between two points (x1, y1) and (x2, y2).",
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Calculate the total distance covered ... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
1
] | 3 | hard | 0.3 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)\n\ndef calculate_total_distance(vehicle_data):\n t... | trial_gpt4o_9 | {
"original_instruction": "You are a software developer at a logistics company. Your team is working on optimizing delivery routes by keeping track of the locations of delivery vehicles throughout the day.\n\nEach vehicle records its location at various times during the day, and the goal is to determine the total dis... | 0.59034 | Taco_19065 | C | [
"calculate_distance",
"total_distance_covered",
"process_input"
] | 3 | [
[
"process_input",
"total_distance_covered"
],
[
"total_distance_covered",
"calculate_distance"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | a3826e3ea9c3da247a366924feedf81d44db01e8 | baf86b7e6a24fedc5d0cc3b63d9f60ee03415d2f | |||
v1.0 | complete | Taco | Taco_13824_C | def prim_minimum_spanning_tree(towers):
"""
Uses Prim's algorithm to find the minimum total energy required to connect all towers.
"""
def minimum_total_energy(t, datasets):
"""
Calculate the minimum total energy required to connect all towers for each dataset.
"""
def parse_input(input_data):... | import math
from heapq import heappush, heappop
def prim_minimum_spanning_tree(towers):
"""
Uses Prim's algorithm to find the minimum total energy required to connect all towers.
"""
n = len(towers)
if n == 1:
return 0
# Priority queue to select the edge with the minimum weight
... | def test_prim_minimum_spanning_tree():
assert prim_minimum_spanning_tree([(0, 0, 10), (0, 1, 10), (1, 0, 10)]) == 2
assert prim_minimum_spanning_tree([(0, 0, 10), (1, 0, 20), (0, 1, 30), (1, 1, 40)]) == 3
def test_minimum_total_energy():
assert minimum_total_energy(2,
[
... | [
{
"docstring": "Uses Prim's algorithm to find the minimum total energy required to connect all towers.",
"function_declaration": "def prim_minimum_spanning_tree(towers):",
"function_name": "prim_minimum_spanning_tree",
"parameter_list": "(towers)"
},
{
"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 math\nimport heapq\n\ndef calculate_distance(x1, y1, x2, y2):\n return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)\n\ndef prim_minimum_spanning_tree(n, towers... | trial_gpt4o_2 | {
"original_instruction": "A mythical city is thriving in the middle of a desert, heavily guarded by a circle of magical towers. Each tower has a certain energy level and is placed at specific coordinates on a 2D plane. The city plans to connect these towers with magical beams so that they form a single interconnecte... | 0.620607 | Taco_13824 | C | [
"prim_minimum_spanning_tree",
"minimum_total_energy",
"parse_input",
"solve"
] | 4 | [
[
"minimum_total_energy",
"prim_minimum_spanning_tree"
],
[
"solve",
"minimum_total_energy"
],
[
"solve",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | ee17462e511bde009c58ff24c8ae6b5c913774bb | f4dfc6726f546a54d2399b3bd951bb27665b27a9 | |||
v1.0 | complete | Taco | Taco_19467_C | def min_energy_path_from_input(input_str: str) -> int:
""" Finds the minimum energy path in a grid from top-left to bottom-right.
Parses input string representing a grid and returns the minimum energy sum
needed to move from the top left to the bottom right cell by only moving right or down.
Args:... | def min_energy_path(grid):
"""
Finds the minimum energy path in a grid from top-left to bottom-right.
"""
r = len(grid)
c = len(grid[0])
# Create a 2D dp array to store the minimum path sum up to each cell
dp = [[0] * c for _ in range(r)]
# Initialize the starting point
dp[... | from solution import min_energy_path_from_input
def test_easy_case():
input_str = """\
3 4
5 9 1 3
4 7 2 6
8 5 3 2"""
assert min_energy_path_from_input(input_str) == 22
def test_single_row():
input_str = """\
1 4
1 2 3 4"""
assert min_energy_path_from_input(input_str) == 10
def test_single_column():
... | [
{
"docstring": "Finds the minimum energy path in a grid from top-left to bottom-right.",
"function_declaration": "def min_energy_path(grid):",
"function_name": "min_energy_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def min_energy_path_from_input(in... | [
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_energy_path(r, c, grid):\n \"\"\"\n Returns the minimum energy sum required to move from the top-left \n to the bottom-right cell of the grid.\n ... | trial_gpt4o_3 | {
"original_instruction": "You are given a rectangular grid with cells arranged in r rows and c columns. Each cell has a specific energy value. You need to find a path from the top-left cell (1, 1) to the bottom-right cell (r, c) such that the sum of the energy values of the cells in the path is minimized. You can on... | 0.675621 | Taco_19467 | C | [
"min_energy_path",
"min_energy_path_from_input"
] | 2 | [
[
"min_energy_path_from_input",
"min_energy_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e8884a35f601c9198df376cd4efddb263d4ed52 | 0d212fe1f3e101e59921c15394a61a94e2655487 | |||
v1.0 | complete | Taco | Taco_12270_C | class TreeNode:
def __init__(self, node_id, value):
self.node_id = node_id
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
"""
Helper function to build the binary tree from list of nodes
nodes: List of tuples containing node_id, left_id, righ... | class TreeNode:
def __init__(self, node_id, value):
self.node_id = node_id
self.value = value
self.left = None
self.right = None
def build_tree(nodes):
tree = {}
for node in nodes:
node_id, left_id, right_id, node_value = node
if node_id not in tree:
... | from solution import find_max_sum
def test_single_node():
assert find_max_sum(1, [(1, [(0, -1, -1, 1)])]) == [1]
def test_balanced_tree():
assert find_max_sum(1, [(5, [(0, 1, 2, 5), (1, 3, 4, 10), (2, -1, -1, 20), (3, -1, -1, 1), (4, -1, -1, 50)])]) == [65]
def test_left_heavy_tree():
assert find_max_sum... | [] | [
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 find_max_sum(node, children, values, memo):\n if node == -1:\n return 0\n if node in memo:\n return memo[node]\n \n left_child, right... | trial_gpt4o_1 | {
"original_instruction": "In a galaxy far, far away, the interstellar council uses a unique binary tree structure to transmit secret messages between planets. Each planet represents a node in the tree, and each message travels from the root planet to a leaf planet.\n\nThe secret message transmission is designed so t... | 0.61435 | Taco_12270 | C | [
"build_tree",
"max_sum_path",
"find_max_sum"
] | 3 | [
[
"find_max_sum",
"build_tree"
],
[
"find_max_sum",
"max_sum_path"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1921baf661ff669cd30819511aac5b5ce71ea65a | 18ba107b0174fe7d07824917da9a792631ea168c | |||
v1.0 | complete | Taco | Taco_12613_C | def minimum_distance_to_connect_all_parts(n: int, m: int, paths: List[List[int]]) -> Union[int, str]:
"""
Given the number of nodes, number of edges, and the list of edges (paths),
return the minimum distance to connect all nodes, or "impossible" if it can't be done.
Args:
n : int : Number of nodes... | def kruskal(n, edges):
"""
Function to find the minimum cost to connect all nodes using Kruskal's algorithm.
"""
# Sort edges based on weight
edges.sort(key=lambda x: x[2])
parent = list(range(n))
def find(x):
if parent[x] != x:
parent[x] = find(parent[x])
r... | from solution import minimum_distance_to_connect_all_parts
def test_sample_1():
n = 4
m = 5
paths = [
[1, 2, 2],
[1, 3, 3],
[1, 4, 1],
[2, 3, 4],
[3, 4, 5]
]
assert minimum_distance_to_connect_all_parts(n, m, paths) == 6
def test_sample_2():
n = 3
m ... | [
{
"docstring": "Function to find the minimum cost to connect all nodes using Kruskal's algorithm.",
"function_declaration": "def kruskal(n, edges):",
"function_name": "kruskal",
"parameter_list": "(n, edges)"
},
{
"docstring": "Given the number of nodes, number of edges, and the list of edge... | [
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 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_2 | {
"original_instruction": "A park is designed with several pathways representing a connected, undirected graph. Each pathway has a specific distance associated with it. The objective is to find the minimum distance required to connect all parts of the park (i.e., find the minimum spanning tree of the graph). \n\nYou ... | 0.645933 | Taco_12613 | C | [
"kruskal",
"minimum_distance_to_connect_all_parts"
] | 2 | [
[
"minimum_distance_to_connect_all_parts",
"kruskal"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 606539e48bcfad70dcb568c2eed1125dfe7afd8c | 0e3991cd8de3c7bf397791f24d38bb87d62168fc | |||
v1.0 | complete | Taco | Taco_12841_C | def max_path_sum(n: int, values: List[int], edges: List[Tuple[int, int]]) -> int:
""" You are given an undirected tree with `n` nodes numbered from `1` to `n`. A tree is an acyclic connected graph.
Each node has a value associated with it. Your task is to find the maximum sum of nodes in a simple path between
... | import sys
sys.setrecursionlimit(200000)
def dfs(node, parent, graph, values, subtree_sum, max_sum):
# base case
if node not in graph:
return 0
current_sum = values[node - 1]
for neighbor in graph[node]:
if neighbor == parent:
continue
child_sum = dfs(neighbor, ... | from solution import max_path_sum
def test_case_1():
n = 5
values = [1, 2, 3, 4, 5]
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
assert max_path_sum(n, values, edges) == 15
def test_case_2():
n = 3
values = [1, 10, 10]
edges = [(1, 2), (1, 3)]
assert max_path_sum(n, values, edges) == 21
d... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, graph, values, subtree_sum, max_sum):",
"function_name": "dfs",
"parameter_list": "(node, parent, graph, values, subtree_sum, max_sum)"
},
{
"docstring": null,
"function_declaration": "def max_path_sum(n, values, edges):... | [
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_max_sum_in_path(n, values, edges):\n from collections import defaultdict, deque\n \n def dfs(u, parent):\n max1, max2 = 0, 0\n glob... | trial_gpt4o_2 | {
"original_instruction": "You are given an undirected tree with $n$ nodes numbered from $1$ to $n$. A tree is an acyclic connected graph. Each node has a value associated with it. Your task is to find the maximum sum of nodes in a simple path between two nodes in this tree.\n\nA simple path is a path that does not r... | 0.701778 | Taco_12841 | C | [
"dfs",
"max_path_sum"
] | 2 | [
[
"max_path_sum",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c129c4d8f110059d78142a500d5be44cc1fcfcab | 0d6ffaa5cb118384c284c8a30d4eefa546cd656d | |||
v1.0 | complete | Taco | Taco_20115_C | def is_perfect_square(x):
""" Check if a number is a perfect square.
>>> is_perfect_square(4)
True
>>> is_perfect_square(10)
False
"""
pass
def max_beautiful_subsequence_length(t, test_cases):
""" Determine the maximum length of a beautiful subsequence from multiple test cases.
>>> ... | import math
def is_perfect_square(x):
r = int(math.isqrt(x))
return r * r == x
def max_beautiful_subsequence_length(t, test_cases):
results = []
for i in range(t):
n = test_cases[i][0]
array = test_cases[i][1]
dp = []
for j in range(n):
if is_perfec... | from solution import max_beautiful_subsequence_length
def test_case1():
t = 3
test_cases = [
(4, [1, 2, 3, 4]),
(5, [1, 2, 2, 3, 3]),
(6, [1, 4, 9, 16, 25, 36])
]
assert max_beautiful_subsequence_length(t, test_cases) == [2, 1, 6]
def test_case2():
t = 2
test_cases = [
... | [
{
"docstring": null,
"function_declaration": "def is_perfect_square(x):",
"function_name": "is_perfect_square",
"parameter_list": "(x)"
},
{
"docstring": null,
"function_declaration": "def max_beautiful_subsequence_length(t, test_cases):",
"function_name": "max_beautiful_subsequence_... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "import math\n\ndef is_perfect_square(num):\n \"\"\"\n Checks if a number is a perfect square.\n \"\"\"\n root = int(math.isqrt... | trial_gpt4o_4 | {
"original_instruction": "Sam loves playing with numbers, and one of his favorite hobbies is finding beautiful subsequences within an array. A subsequence is considered beautiful if the product of its elements is a perfect square. Given an array of integers, Sam wants to determine the maximum length of a beautiful s... | 0.581488 | Taco_20115 | C | [
"is_perfect_square",
"max_beautiful_subsequence_length"
] | 2 | [
[
"max_beautiful_subsequence_length",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 01c6ecd8dbb95edab44d2719ad73ccd824e16482 | ac47428f6f307a01a2b012987bc345aef33cb0fb | |||
v1.0 | complete | Taco | Taco_18390_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def hasPathSum(root, targetSum):
""" Check if there is a root-to-leaf path in a binary tree that equals the given sum.
>>> root = TreeNode(5)
>>> root.left = Tre... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def hasPathSum(root, targetSum):
if not root:
return False
if not root.left and not root.right and root.val == targetSum:
return True
targetSum -=... | def test_checkRootToLeafPath_no_nodes():
assert checkRootToLeafPath(22, 0, []) == "No"
def test_checkRootToLeafPath_single_node_true():
assert checkRootToLeafPath(5, 1, [(5, -1, -1)]) == "Yes"
def test_checkRootToLeafPath_single_node_false():
assert checkRootToLeafPath(10, 1, [(5, -1, -1)]) == "No"
def t... | [] | [
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": "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_3 | {
"original_instruction": "You are given a binary tree where each node contains an integer value. Write a program to determine whether there exists a root-to-leaf path that sums up to a given number.\n\nA root-to-leaf path is a sequence of nodes in a tree starting from the root node and ending at any leaf node. The s... | 0.630137 | Taco_18390 | C | [
"hasPathSum",
"buildTree",
"checkRootToLeafPath"
] | 3 | [
[
"checkRootToLeafPath",
"buildTree"
],
[
"checkRootToLeafPath",
"hasPathSum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 3dac31555b62d0874e59743aee48c9caa3fe6ca4 | 3a4320f9a54e6fb76ff34bf4cafed4b2e7bef621 | |||
v1.0 | complete | Taco | Taco_20031_C | def is_valid_bracket_sequence(sequence):
"""
Check if a given sequence of brackets is valid.
:param sequence: str
:return: bool
>>> is_valid_bracket_sequence("([])") == True
>>> is_valid_bracket_sequence("{[()()]}") == True
>>> is_valid_bracket_sequence("{[(])}") == False
>>> is_val... | def is_valid_bracket_sequence(sequence):
"""
Check if a given sequence of brackets is valid.
:param sequence: str
:return: bool
"""
stack = []
bracket_map = {")": "(", "]": "[", "}": "{"}
for char in sequence:
if char in bracket_map:
top_element = stack.pop(... | from solution import is_valid_bracket_sequence, check_bracket_sequence
def test_is_valid_bracket_sequence():
assert is_valid_bracket_sequence("([])") == True
assert is_valid_bracket_sequence("{[()()]}") == True
assert is_valid_bracket_sequence("{[(])}") == False
assert is_valid_bracket_sequence("((()}"... | [
{
"docstring": "Check if a given sequence of brackets is valid.\n\n:param sequence: str\n:return: bool",
"function_declaration": "def is_valid_bracket_sequence(sequence):",
"function_name": "is_valid_bracket_sequence",
"parameter_list": "(sequence)"
},
{
"docstring": "Checks if the given bra... | [
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_valid_bracket_sequence(s):\n \"\"\"\n Checks if the sequence of brackets is valid.\n\n Args:\n s (str): The input string containing a sequence o... | trial_gpt4o_1 | {
"original_instruction": "Peter is a competitive programmer who participates in many programming contests. After solving several problems, he realized that he often made mistakes with bracket sequences. He decided to write a program that helps him to check if a sequence of brackets is valid.\n\nA sequence of bracket... | 0.819988 | Taco_20031 | C | [
"is_valid_bracket_sequence",
"check_bracket_sequence"
] | 2 | [
[
"check_bracket_sequence",
"is_valid_bracket_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f773cfbe8e16a899bb0d560715f2eb011f1e7273 | 0199ac4daa7f0e295c23382305eacc99db437f5b | |||
v1.0 | complete | Taco | Taco_20418_C | def process_queries(N: int, Q: int, arr: List[int], queries: List[List[int]]) -> List[int]:
"""Processes a list of queries on the array.
The first type of query updates the value at a specific index in the array.
The second type of query finds the majority element within a given subarray.
Exam... | def update_array(array, index, x):
"""
Updates the element at the given index with the value x.
"""
array[index] = x
def find_majority_element(array, L, R):
"""
Finds the majority element in the subarray from index L to R (inclusive).
"""
subarray = array[L:R+1]
count = {}
for n... | from solution import process_queries
def test_queries():
N = 7
Q = 5
arr = [2, 3, 2, 4, 2, 2, 5]
queries = [
[2, 1, 5],
[1, 3, 1],
[2, 1, 5],
[2, 1, 7],
[2, 6, 7]
]
expected = [2, -1, -1, -1]
assert process_queries(N, Q, arr, queries) == expected
def... | [
{
"docstring": "Updates the element at the given index with the value x.",
"function_declaration": "def update_array(array, index, x):",
"function_name": "update_array",
"parameter_list": "(array, index, x)"
},
{
"docstring": "Finds the majority element in the subarray from index L to R (inc... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import collections\n\ndef update(arr, i, x):\n arr[i - 1] = x\n\ndef find_majority_element(arr, L, R):\n subarray = arr[L - 1:R]\n count = collections.Cou... | trial_gpt4o_9 | {
"original_instruction": "Majority Element in Subarrays\n\nGiven an array of integers, handle two types of queries.\n\nThe first type of query updates the value at a specific index in the array.\n\nThe second type of query finds the majority element within a given subarray. The majority element is the element that a... | 0.673147 | Taco_20418 | C | [
"update_array",
"find_majority_element",
"process_queries"
] | 3 | [
[
"process_queries",
"find_majority_element"
],
[
"process_queries",
"update_array"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | d1924674fb454fcb7cd4d5dfd65832eaa33ced58 | 6cfa6d06cfe0b78c90be5198bade2f8ed35c3688 | |||
v1.0 | complete | Taco | Taco_19134_C | class TreeNode:
def __init__(self, value=0):
self.value = value
self.children = []
def build_tree(edges, values):
nodes = [TreeNode(val) for val in values]
for u, v in edges:
nodes[u-1].children.append(nodes[v-1])
nodes[v-1].children.append(nodes[u-1])
return nodes[0]
d... | class TreeNode:
def __init__(self, value=0):
self.value = value
self.children = []
def build_tree(edges, values):
nodes = [TreeNode(val) for val in values]
for u, v in edges:
nodes[u-1].children.append(nodes[v-1])
nodes[v-1].children.append(nodes[u-1])
return nodes[0]
d... | def test_solves_example():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
values = [10, 2, 10, -1, 3]
assert solve(n, edges, values) == 23
def test_single_node():
n = 1
edges = []
values = [1]
assert solve(n, edges, values) == 1
def test_linear_tree():
n = 5
edges = [(1, 2), (2... | [] | [
0,
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict\n\ndef dfs(node, parent, node_values, adj_list):\n max_sum = node_values[node - 1]\n max_single_path = 0\n for neighbo... | trial_gpt4o_8 | {
"original_instruction": "You are given a binary tree, where each node contains an integer value. The goal is to determine the maximum sum of values obtained by visiting nodes in any downward path in the tree. A downward path is defined as starting from any node and moving downward to any node without revisiting any... | 0.651259 | Taco_19134 | C | [
"build_tree",
"max_path_sum",
"solve"
] | 3 | [
[
"solve",
"build_tree"
],
[
"solve",
"max_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 358f97b5560e432da682208617376f90df89446d | a1dd4b48981438f9e9ff17348c02e6c0c29f53c3 | |||
v1.0 | complete | Taco | Taco_19982_C | from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Return True if n is a prime number, else False.
"""
def preprocess_primes(nums: List[int]) -> List[int]:
""" Preprocess the list of numbers to return a list where each element at index i
contains the sum of all prime numbers up to the i... | from typing import List, Tuple
def is_prime(n: int) -> bool:
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def preprocess_primes(nums: List[int]) -> List[int]:
prime_prefix_sum = [0] * (len(nums) + 1)
for i in range(1... | def test_is_prime():
assert is_prime(2)
assert is_prime(3)
assert not is_prime(4)
assert is_prime(5)
assert not is_prime(9)
assert is_prime(11)
def test_preprocess_primes():
nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
expected = [0, 2, 5, 5, 10, 10, 17, 17, 17, 17, 28]
assert preprocess... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def preprocess_primes(nums):",
"function_name": "preprocess_primes",
"parameter_list": "(nums)"
},
{
"doc... | [
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 sieve(limit):\n is_prime = [True] * (limit + 1)\n is_prime[0] = is_prime[1] = False\n for start in range(2, int(limit**0.5) + 1):\n if is_prime... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers and a set of queries. Each query consists of two integers representing lower and upper bounds. Your task is to return the sum of all prime numbers within those bounds for each query.\n\nInput format:\nThe first line contains an integer N representing the num... | 0.654318 | Taco_19982 | C | [
"is_prime",
"preprocess_primes",
"query_prime_sum",
"process_queries"
] | 4 | [
[
"preprocess_primes",
"is_prime"
],
[
"process_queries",
"preprocess_primes"
],
[
"process_queries",
"query_prime_sum"
]
] | 3 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 2a46e635859676d1ef6ebbd892e04819d2e02820 | 1efe3e2e56710f4b76d811230ac936bbfd3bcf8d | |||
v1.0 | complete | Taco | Taco_25093_C | def findKthLargest(arr: List[int], k: int) -> int:
""" Find the k-th largest element in the array using a quickselect algorithm.
>>> findKthLargest([3, 2, 1, 5, 6, 4], 2)
5
>>> findKthLargest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4)
4
""" | import random
def partition(arr, left, right):
pivot_index = random.randint(left, right)
pivot = arr[pivot_index]
arr[pivot_index], arr[right] = arr[right], arr[pivot_index]
i = left
for j in range(left, right):
if arr[j] > pivot: # Note: We use '>' to find the k-th largest element.
... | def test_findKthLargest_example1():
assert findKthLargest([3, 2, 1, 5, 6, 4], 2) == 5
def test_findKthLargest_example2():
assert findKthLargest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == 4
def test_findKthLargest_single_element():
assert findKthLargest([1], 1) == 1
def test_findKthLargest_all_elements_same():
... | [
{
"docstring": null,
"function_declaration": "def partition(arr, left, right):",
"function_name": "partition",
"parameter_list": "(arr, left, right)"
},
{
"docstring": null,
"function_declaration": "def quickselect(arr, left, right, k):",
"function_name": "quickselect",
"paramete... | [
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 random\n\ndef findKthLargest(arr, k):\n \"\"\"\n Returns the k-th largest element in the array using Quickselect algorithm.\n \"\"\"\n\n def par... | trial_gpt4o_1 | {
"original_instruction": "Given an array arr[] of integers and an integer k such that 1 <= k <= n where n is the length of the array. Your task is to find the k-th largest element in the array using a quickselect algorithm.\n\nExample 1:\nInput:\narr[] = [3,2,1,5,6,4]\nk = 2\nOutput:\n5\nExplanation: The 2nd largest... | 0.680348 | Taco_25093 | C | [
"partition",
"quickselect",
"findKthLargest"
] | 3 | [
[
"findKthLargest",
"quickselect"
],
[
"quickselect",
"partition"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 30354d2f211a227ba6ea4691f9320e6591e0e837 | 192e936e061822833f2218269d4dc26b008dbc36 | |||
v1.0 | complete | Taco | Taco_20299_C | from typing import Dict
def letter_frequency(s: str) -> Dict[str, int]:
"""
Determines the frequency of each letter in the string and returns the results in alphabetical order.
:param s: Input string containing only lowercase letters
:return: A dictionary with letters as keys and their frequencies... | def letter_frequency(s: str):
"""
Determines the frequency of each letter in the string and returns results in alphabetical order.
:param s: Input string containing only lowercase letters
:return: A dictionary with letters as keys and their frequencies as values
"""
from collections import ... | from solution import letter_frequency, pretty_print_frequency
def test_letter_frequency_simple():
result = letter_frequency("banana")
expected = {'a': 3, 'b': 1, 'n': 2}
assert result == expected
def test_letter_frequency_single_char():
result = letter_frequency("a")
expected = {'a': 1}
assert... | [
{
"docstring": "Determines the frequency of each letter in the string and returns results in alphabetical order.\n\n:param s: Input string containing only lowercase letters\n:return: A dictionary with letters as keys and their frequencies as values",
"function_declaration": "def letter_frequency(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": "from collections import Counter\n\ndef letter_frequency(s):\n \"\"\"\n Returns the frequency of each letter in the string in alphabetical order.\n \"\"\"\... | trial_gpt4o_1 | {
"original_instruction": "You are given a string containing only lowercase letters. Your task is to determine the frequency of each letter in the string and output the results in alphabetical order.\n\n-----Input-----\nA single string S (1 <= |S| <= 10^6) where S consists of only lowercase letters.\n\n-----Output---... | 0.732794 | Taco_20299 | C | [
"letter_frequency",
"pretty_print_frequency"
] | 2 | [
[
"pretty_print_frequency",
"letter_frequency"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ceed9cc3e89f814ff4cdbacebf23707e29107fad | 2503c017f84dbe367bde32727101a52d393828f5 | |||
v1.0 | complete | Taco | Taco_25232_C | def determine_quasi_palindromes(n: int, strings: List[str]) -> List[str]:
""" Determines if each string in the list 'strings' is a quasi-palindrome.
Parameters:
- n: int, the number of datasets
- strings: list of str, the strings to check
Returns:
- list of str, "YES" or "NO" for each stri... | def is_quasi_palindrome(s):
"""
Returns True if the string s can be a palindrome by removing at most one character, False otherwise.
"""
# Helper function to check if a substring is a palindrome
def is_palindrome_range(l, r):
while l < r:
if s[l] != s[r]:
return F... | from solution import determine_quasi_palindromes
def test_all_yes_cases():
assert determine_quasi_palindromes(3, ['abca', 'abccba', 'a']) == ["YES", "YES", "YES"]
def test_all_no_cases():
assert determine_quasi_palindromes(3, ['abcdef', 'abcd', 'abcdefghij']) == ["NO", "NO", "NO"]
def test_mix_cases():
a... | [
{
"docstring": "Returns True if the string s can be a palindrome by removing at most one character, False otherwise.",
"function_declaration": "def is_quasi_palindrome(s):",
"function_name": "is_quasi_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Determines if each string in the li... | [
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_palindrome(s):\n \"\"\"\n Checks if a given string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef is_quasi_palindrome(s):\n \"\"\"\... | trial_gpt4o_4 | {
"original_instruction": "Write a program that determines if a given string is a \"quasi-palindrome.\" A quasi-palindrome is defined as a string that can be made into a palindrome by removing at most one character.\n\nInput\n\nThe input consists of several datasets. The first line contains the number of datasets $n$... | 0.726903 | Taco_25232 | C | [
"is_quasi_palindrome",
"determine_quasi_palindromes"
] | 2 | [
[
"determine_quasi_palindromes",
"is_quasi_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 19cc7f817cf2adedc172bdfa7905e2b4173c3483 | 61a2f27ad976ec4b874159181068fda7ab4d5c71 | |||
v1.0 | complete | Taco | Taco_20840_C | def precompute_prefix_sums(arr):
""" Computes the prefix sums array for the given input array.
>>> precompute_prefix_sums([1, 2, 3, 4, 5, 6])
[0, 1, 3, 6, 10, 15, 21]
>>> precompute_prefix_sums([10, -10, 20, -20, 30, -30])
[0, 10, 0, 20, 0, 30, 0]
"""
pass
def subarray_sum_query(arr, querie... | def precompute_prefix_sums(arr):
"""
Computes the prefix sums array for the given input array.
"""
N = len(arr)
prefix_sums = [0] * (N + 1)
for i in range(1, N + 1):
prefix_sums[i] = prefix_sums[i - 1] + arr[i - 1]
return prefix_sums
def subarray_sum_query(arr, queries):
"""
... | from solution import precompute_prefix_sums, subarray_sum_query
def test_precompute_prefix_sums():
arr = [1, 2, 3, 4, 5, 6]
expected_prefix_sums = [0, 1, 3, 6, 10, 15, 21]
assert precompute_prefix_sums(arr) == expected_prefix_sums
def test_subarray_sum_query():
arr = [1, 2, 3, 4, 5, 6]
queries = [... | [
{
"docstring": "Computes the prefix sums array for the given input array.",
"function_declaration": "def precompute_prefix_sums(arr):",
"function_name": "precompute_prefix_sums",
"parameter_list": "(arr)"
},
{
"docstring": "Processes subarray sum queries using the prefix sums array.",
"f... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def subarray_sum_query(n, q, array, queries):\n # Compute prefix sums to enable efficient sum calculation\n prefix_sums = [0] * (n + 1)\n \n for i in r... | trial_gpt4o_2 | {
"original_instruction": "Subarray Sum Query\n\nGiven an array of integers a_1, a_2, .., a_N.\n\nYou will be given Q queries, each with two integers l and r. For each query, compute the sum of the elements in the subarray from index l to index r (inclusive).\n\nInput\n\nN Q\na_1 a_2 ... a_N\nl_1 r_1\nl_2 r_2\n::\nl_... | 0.621199 | Taco_20840 | C | [
"precompute_prefix_sums",
"subarray_sum_query"
] | 2 | [
[
"subarray_sum_query",
"precompute_prefix_sums"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | fc24124417baeda4b868707470c49d966337ee13 | 1e4436e0e838e21312d901b262af16c5faed37c5 | |||
v1.0 | complete | Taco | Taco_25758_C | def nthFibonacci(n: int) -> int:
""" Determine the nth Fibonacci number modulo 10^9+7.
>>> nthFibonacci(5)
5
>>> nthFibonacci(10)
55
""" | def mat_mult(A, B, mod=10**9+7):
"""
Matrix multiplication (modular).
"""
return [[(A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mod,
(A[0][0] * B[0][1] + A[0][1] * B[1][1]) % mod],
[(A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod,
(A[1][0] * B[0][1] + A[1][1] * B[1][1]) ... | from solution import nthFibonacci
def test_small_values():
assert nthFibonacci(1) == 1
assert nthFibonacci(2) == 1
assert nthFibonacci(3) == 2
assert nthFibonacci(4) == 3
assert nthFibonacci(5) == 5
def test_larger_values():
assert nthFibonacci(10) == 55
assert nthFibonacci(20) == 6765
... | [
{
"docstring": "Matrix multiplication (modular).",
"function_declaration": "def mat_mult(A, B, mod=10 ** 9 + 7):",
"function_name": "mat_mult",
"parameter_list": "(A, B, mod=10 ** 9 + 7)"
},
{
"docstring": "Matrix exponentiation with modular arithmetic.",
"function_declaration": "def mat... | [
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": "MOD = 10**9 + 7\n\ndef matrix_mult(a, b):\n return [\n [(a[0][0] * b[0][0] + a[0][1] * b[1][0]) % MOD,\n (a[0][0] * b[0][1] + a[0][1] * b[1][1]) ... | trial_gpt4o_3 | {
"original_instruction": "Determine the nth Fibonacci Number modulo 10^9+7.\nThe Fibonacci sequence is a series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers. Typically, it starts with 0 and 1.\n\nExample 1:\nInput:\nn = 5\nOutput:\n5\nExplanation:\nThe first 6 Fibonacci ... | 0.825091 | Taco_25758 | C | [
"mat_mult",
"mat_pow",
"nthFibonacci"
] | 3 | [
[
"mat_pow",
"mat_mult"
],
[
"nthFibonacci",
"mat_pow"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | cde5e1808a2ef4879aa96e6916d9fb64540033c5 | 96bf541d872307ec53b145007b1bb2f305bafca5 | |||
v1.0 | complete | Taco | Taco_20562_C | from typing import List, Tuple
def find_kth_smallest_elements(test_cases: List[Tuple[int, List[int]]]) -> List[int]:
"""
For each test case, find the k-th smallest element in the BST formed by the level-order traversal.
Args:
test_cases: List of tuples where each tuple contains an integer k and a... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def insert_into_bst(root, value):
if not root:
return TreeNode(value)
if value < root.value:
root.left = insert_into_bst(root.left, value)
e... | from solution import find_kth_smallest_elements
def test_case_1():
test_cases = [
(3, [5, 3, 8, 2, 4, 6, 9]),
(1, [7, 3, 9, 2, 5]),
]
assert find_kth_smallest_elements(test_cases) == [4, 2]
def test_case_k_greater_than_nodes():
test_cases = [
(5, [4, 2, 6, 1, 3, 5, 7]),
... | [] | [
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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef i... | trial_gpt4o_0 | {
"original_instruction": "An adventure with Binary Search Trees!\n\nBob has a love for trees, not just any trees, but Binary Search Trees (BST). One day, while relaxing under a big Oak tree, he thought of a new problem. He wants to find the k-th smallest element in a BST. Since he loves coding, he decides to write a... | 0.628551 | Taco_20562 | C | [
"insert_into_bst",
"build_bst_from_level_order",
"kth_smallest_element",
"find_kth_smallest_elements"
] | 4 | [
[
"find_kth_smallest_elements",
"build_bst_from_level_order"
],
[
"find_kth_smallest_elements",
"kth_smallest_element"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 42b9fa3e28b6e9cfa66c301a7edd28aace71f5b3 | 3de5537bd6916fc698777104cafdab8200544366 | |||
v1.0 | complete | Taco | Taco_25172_C | import math
def max_trolls_affected(N, R, trolls):
""" Determine the optimal position to aim the energy wave to affect the maximum number of trolls.
>>> max_trolls_affected(5, 2, [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)])
3
>>> max_trolls_affected(6, 3, [(-2, -2), (1, 1), (0, 2), (2, 3), (5, 5), (-1, -3... | import math
from itertools import combinations
def distance(troll1, troll2):
return math.sqrt((troll1[0] - troll2[0]) ** 2 + (troll1[1] - troll2[1]) ** 2)
def max_trolls_affected(N, R, trolls):
max_affected = 0
for troll1, troll2 in combinations(trolls, 2):
mid_point = ((troll1[0] + troll2[0]... | from solution import max_trolls_affected
def test_example1():
N, R = 5, 2
trolls = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)]
assert max_trolls_affected(N, R, trolls) == 3
def test_example2():
N, R = 6, 3
trolls = [(-2, -2), (1, 1), (0, 2), (2, 3), (5, 5), (-1, -3)]
assert max_trolls_affected(N,... | [
{
"docstring": null,
"function_declaration": "def distance(troll1, troll2):",
"function_name": "distance",
"parameter_list": "(troll1, troll2)"
},
{
"docstring": null,
"function_declaration": "def max_trolls_affected(N, R, trolls):",
"function_name": "max_trolls_affected",
"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 max_trolls_affected(N, R, trolls):\n from itertools import combinations\n from math import sqrt\n\n def distance(p1, p2):\n return sqrt((p1[0] ... | trial_gpt4o_2 | {
"original_instruction": "A group of wizards in the mystical land of Alvora are trying to protect their sacred tower from an incoming horde of trolls. They have a magical defense system that can release a powerful energy wave to eliminate the trolls. The energy wave can only be fired once, and it must be aimed strat... | 0.590073 | Taco_25172 | C | [
"distance",
"max_trolls_affected",
"main"
] | 3 | [
[
"max_trolls_affected",
"distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5ba21e5a6564b38b857ecb2466da485ee8282280 | 83bd7e83f2f7c4c69f94bfb3c45261b5a98b8733 | |||
v1.0 | complete | Taco | Taco_25256_C | from typing import List
def treasure_hunt_solution(n: int, cases: List[str]) -> List[int]:
""" Identify the number of unique pairs of digits in each message.
Args:
n (int): The number of test cases.
cases (List[str]): List of strings, each representing a test case with digits.
Returns:
List[i... | def count_unique_pairs(case_strings):
result = []
for s in case_strings:
pairs = set()
for i in range(len(s) - 1):
pairs.add(s[i:i+2])
result.append(len(pairs))
return result
# Function to parse the input and call count_unique_pairs
def treasure_hunt_solution(n, cases):
... | from solution import treasure_hunt_solution
def test_single_case():
assert treasure_hunt_solution(1, ["1234"]) == [3]
def test_repeated_digits():
assert treasure_hunt_solution(1, ["1111"]) == [1]
def test_mix_pairs():
assert treasure_hunt_solution(1, ["432123"]) == [5]
def test_multiple_cases():
... | [
{
"docstring": null,
"function_declaration": "def count_unique_pairs(case_strings):",
"function_name": "count_unique_pairs",
"parameter_list": "(case_strings)"
},
{
"docstring": null,
"function_declaration": "def treasure_hunt_solution(n, cases):",
"function_name": "treasure_hunt_sol... | [
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 unique_digit_pairs(N, messages):\n results = []\n for message in messages:\n pairs = {message[i:i+2] for i in range(len(message)-1)}\n resu... | trial_gpt4o_1 | {
"original_instruction": "Sara is an avid participant in treasure hunts. Recently, she came across a peculiar treasure hunt that involves deciphering secret messages encoded in strings. These messages contain clues as pairs of digits. For instance, the string \"1234\" contains pairs 12, 23, and 34.\n\nSara needs to ... | 0.609929 | Taco_25256 | C | [
"count_unique_pairs",
"treasure_hunt_solution"
] | 2 | [
[
"treasure_hunt_solution",
"count_unique_pairs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 021b5ead8809b851ac5d11e51c7a3d23874e04ee | 981fdab8af6b74be0d3ff74d0f5cc2a3fe7f2276 | |||
v1.0 | complete | Taco | Taco_25581_C | from typing import List, Tuple
def min_cost_through_intermediate(n: int, m: int, k: int, highways: List[Tuple[int, int, int]]) -> int:
""" Computes the minimum travel cost from city 1 to city n through the specified intermediate city k.
>>> min_cost_through_intermediate(6, 7, 4, [(1, 2, 1), (2, 3, 2), (3, 6, 3... | import heapq
def dijkstra(start, graph, n):
"""
Uses Dijkstra's algorithm to find the shortest paths from a starting node
to all other nodes in a graph. Returns a list of minimum distances.
"""
distances = [float('inf')] * (n + 1)
distances[start] = 0
priority_queue = [(0, start)]
... | from solution import min_cost_through_intermediate
def test_example_1():
n = 6
m = 7
k = 4
highways = [
(1, 2, 1),
(2, 3, 2),
(3, 6, 3),
(1, 3, 2),
(2, 4, 4),
(4, 5, 2),
(5, 6, 3)
]
assert min_cost_through_intermediate(n, m, k, highways) =... | [
{
"docstring": "Uses Dijkstra's algorithm to find the shortest paths from a starting node \nto all other nodes in a graph. Returns a list of minimum distances.",
"function_declaration": "def dijkstra(start, graph, n):",
"function_name": "dijkstra",
"parameter_list": "(start, graph, n)"
},
{
... | [
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 heapq\nimport sys\n\ndef dijkstra(graph, start):\n \"\"\"\n Returns the shortest paths from start to all other nodes using Dijkstra's algorithm\n \... | trial_gpt4o_1 | {
"original_instruction": "A network of cities and highways can be represented as a graph with $n$ nodes and $m$ edges. Each node represents a city, and each edge represents a bidirectional highway with an associated travel cost. You are starting in city $1$ and want to visit city $n$ with the least cost. However, yo... | 0.696548 | Taco_25581 | C | [
"dijkstra",
"min_cost_through_intermediate"
] | 2 | [
[
"min_cost_through_intermediate",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5588ecca09c1880bce5f76c7df1be18ea0a0a35d | da54555b6dc97afee0892cd76412a916b02e289c | |||
v1.0 | complete | Taco | Taco_25596_C | class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def parse_tree(data: str) -> Node:
""" Parse the given tree representation string and return the root node of the binary tree.
>>> parse_tree("1(2(4)(5))(3)")
Node(1)
"""
def is_ba... | class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def parse_tree(data):
def parse_helper(index):
if index >= len(data) or data[index] == ')':
return None, index
start = index
while index < len(data) and (dat... | from solution import check_height_balanced
def test_balanced_tree():
assert check_height_balanced("1(2(4)(5))(3)") == "Yes"
def test_unbalanced_tree():
assert check_height_balanced("1(2(4()()))(3())") == "No"
def test_empty_tree():
assert check_height_balanced("") == "Yes"
def test_balanced_tree_with_mu... | [] | [
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": "class TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef d... | trial_gpt4o_1 | {
"original_instruction": "Given a binary tree, determine if it is height-balanced.\n\nA height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differs by more than 1.\n\n-----Input-----\n\nThe input consists of a binary tree represented as a string in the f... | 0.743252 | Taco_25596 | C | [
"parse_tree",
"is_balanced",
"check_height_balanced"
] | 3 | [
[
"check_height_balanced",
"is_balanced"
],
[
"check_height_balanced",
"parse_tree"
]
] | 2 | [] | false | [
"Node"
] | true | pytest | true | [] | true | 07856d132281803cbf49132f62b39324194c5ca6 | d296b95e19d9796449e0c34dde785da42bffb355 | |||
v1.0 | complete | Taco | Taco_25401_C | def is_prime(num: int) -> bool:
""" Check if the number is prime.
>>> is_prime(2) == True
>>> is_prime(3) == True
>>> is_prime(4) == False
>>> is_prime(5) == True
>>> is_prime(16) == False
>>> is_prime(17) == True
"""
pass
def count_unique_primes(arr: List[int]) -> int:
""" Coun... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
p = 3
while p * p <= num:
if num % p == 0:
return False
p += 2
return True
def count_unique_primes(arr):
primes = set()
for number in a... | from solution import process_test_cases, is_prime, count_unique_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(16) == False
assert is_prime(17) == True
def test_count_unique_primes():
... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def count_unique_primes(arr):",
"function_name": "count_unique_primes",
"parameter_list": "(arr)"
},
{
... | [
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(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n p = 3\n while... | trial_gpt4o_2 | {
"original_instruction": "Given an array of integers, you need to count the frequency of unique prime numbers present in that array. Prime numbers are those numbers greater than 1 that have no divisors other than 1 and itself.\n\n-----Input:-----\n- First line will contain $T$, the number of test cases. Then the tes... | 0.713391 | Taco_25401 | C | [
"is_prime",
"count_unique_primes",
"process_test_cases"
] | 3 | [
[
"count_unique_primes",
"is_prime"
],
[
"process_test_cases",
"count_unique_primes"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 30183cc77487f7f68202db0a9d977279e1b127d4 | 59bbac2f6f478057b7e87c5fba85fc8dc7a9c302 | |||
v1.0 | complete | Taco | Taco_25709_C | from typing import List, Tuple
def best_city_for_hospital(n: int, residents: List[int], roads: List[Tuple[int, int]]) -> int:
""" Determine the best city to locate the hospital such that the maximum distance between the hospital and any city is minimized.
>>> best_city_for_hospital(4, [3, 6, 2, 4], [(1, 2), (2... | from collections import defaultdict, deque
def farthest_node_and_dist(graph, start):
visited = set()
queue = deque([(start, 0)])
farthest_node, max_dist = start, 0
while queue:
current, dist = queue.popleft()
if dist > max_dist:
farthest_node, max_dist = curren... | def test_best_city_for_hospital():
assert best_city_for_hospital(4, [3, 6, 2, 4], [(1, 2), (2, 3), (2, 4)]) == 2
assert best_city_for_hospital(6, [1, 2, 1, 3, 4, 5], [(1, 2), (1, 3), (3, 4), (3, 5), (5, 6)]) == 3
assert best_city_for_hospital(5, [10, 20, 30, 40, 50], [(2, 1), (2, 3), (3, 4), (4, 5)]) == 3
... | [
{
"docstring": null,
"function_declaration": "def farthest_node_and_dist(graph, start):",
"function_name": "farthest_node_and_dist",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def best_city_for_hospital(n, residents, roads):",
"function_name":... | [
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 find_best_city(n, residents, roads):\n if n == 1:\n return 1\n \n # Building the adjacency list for the graph ... | trial_gpt4o_1 | {
"original_instruction": "In Farland, there are n cities connected by n - 1 roads in such a way that there is exactly one path between any two cities. Each city has a certain number of residents, and there is exactly one hospital in one of the cities.\n\nEach day, ambulances travel from the hospital to any city thro... | 0.622193 | Taco_25709 | C | [
"farthest_node_and_dist",
"best_city_for_hospital"
] | 2 | [
[
"best_city_for_hospital",
"farthest_node_and_dist"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 414e5bc601c7430f00c9ba72cce57a08825cd84b | c9598f351f5ce18bdc5a6d616b00ae6e6281e60e | |||
v1.0 | complete | Taco | Taco_25695_C | def read_input_and_solve(input_data: str) -> list:
"""
Given input data representing multiple test cases of graphs, determine the length of the shortest simple cycle in each graph.
If no cycle exists in the graph, return -1 for that test case.
Args:
input_data: str - The input data containing multi... | from collections import defaultdict, deque
def shortest_cycle_length(N, edges):
def bfs(start):
dist = [-1] * N
parent = [-1] * N
q = deque([start])
dist[start] = 0
while q:
node = q.popleft()
for neighbor in graph[node]:
if dist[neigh... | import pytest
from solution import read_input_and_solve
def test_example_cases():
input_data = "2\n3 3\n1 2\n2 3\n3 1\n4 3\n1 2\n2 3\n3 4\n"
expected_output = [3, -1]
assert read_input_and_solve(input_data) == expected_output
def test_no_cycle():
input_data = "1\n4 2\n1 2\n3 4\n"
expected_output =... | [
{
"docstring": null,
"function_declaration": "def shortest_cycle_length(N, edges):",
"function_name": "shortest_cycle_length",
"parameter_list": "(N, edges)"
},
{
"docstring": null,
"function_declaration": "def solve(T, cases):",
"function_name": "solve",
"parameter_list": "(T, c... | [
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 sys\nfrom collections import deque, defaultdict\n\ndef find_shortest_cycle(n, m, edges):\n adj = defaultdict(list)\n for u, v in edges:\n adj[u... | trial_gpt4o_2 | {
"original_instruction": "You are given an undirected graph with N nodes and M edges.\n\nYour task is to determine the length of the shortest simple cycle in the graph, or to determine that no cycle exists.\n\nA simple cycle is a cycle that does not repeat any vertices except for the start and end vertex.\n\n------ ... | 0.612202 | Taco_25695 | C | [
"shortest_cycle_length",
"solve",
"read_input_and_solve"
] | 3 | [
[
"read_input_and_solve",
"solve"
],
[
"solve",
"shortest_cycle_length"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f188b72b54b617527a3b2bdf50dbacab3ef2c139 | c0be8c39635f8e0384d5c2829baf36672f64c45f | |||
v1.0 | complete | Taco | Taco_25197_C | from typing import List
def possiblePalindromes(S: str) -> List[str]:
""" Given a string S, return a list of all unique substrings of S that are palindromes.
>>> possiblePalindromes("aab")
["a", "aa", "b"]
>>> possiblePalindromes("abcba")
["a", "abcba", "b", "bcb", "c"]
"""
# Unit Tests
def te... | def is_palindrome(s):
"""
Helper function to check if a given string is a palindrome.
"""
return s == s[::-1]
def possiblePalindromes(S):
"""
This function returns a list of all unique palindromic substrings of the input string S.
"""
n = len(S)
palindromes = set()
for i in... | from solution import possiblePalindromes
def test_possiblePalindromes_example1():
assert possiblePalindromes("aab") == ["a", "aa", "b"]
def test_possiblePalindromes_example2():
assert possiblePalindromes("abcba") == ["a", "abcba", "b", "bcb", "c"]
def test_possiblePalindromes_single_character():
assert p... | [
{
"docstring": "Helper function to check if a given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "This function returns a list of all unique palindromic substrings of the input string S.... | [
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 possiblePalindromes(S):\n \"\"\"\n Returns a list of all unique palindromic substrings of S in lexicographical order.\n \"\"\"\n def is_palindrome(... | trial_gpt4o_4 | {
"original_instruction": "Given a string S, your task is to complete the function possiblePalindromes() which returns a list of all unique substrings of S that are palindromes. A palindrome is a string that reads the same forward and backward.\n \nExample 1:\nInput:\nS = \"aab\"\nOutput: [\"a\", \"aa\", \"b\"]\n\nEx... | 0.697396 | Taco_25197 | C | [
"is_palindrome",
"possiblePalindromes"
] | 2 | [
[
"possiblePalindromes",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 77d0de3489f2a9cfbec899107b42d06c57751f74 | 8c99a419f213bb417503f08dc45fc912e8a4fa6c | |||
v1.0 | complete | Taco | Taco_20915_C | def check_polygon_type(points: List[Tuple[int, int]]) -> str:
""" Determine if a set of 2D points form a closed polygon and its type (convex or concave).
>>> check_polygon_type([(0, 0), (0, 3), (3, 3), (3, 0)])
'CONVEX'
>>> check_polygon_type([(1, 2), (2, 1), (3, 0)])
'CONVEX'
>>> check_polygon_... | def orientation(p, q, r):
# To find orientation of ordered triplet (p, q, r).
# The function returns following values
# 0 -> p, q and r are collinear
# 1 -> Clockwise
# 2 -> Counterclockwise
val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
if val == 0:
return ... | from solution import check_polygon_type
def test_no_polygon():
assert check_polygon_type([(1, 2), (2, 1)]) == "NO POLYGON"
def test_convex_example_1():
assert check_polygon_type([(0, 0), (0, 3), (3, 3), (3, 0)]) == "CONVEX"
def test_convex_example_2():
assert check_polygon_type([(1, 2), (2, 1), (3, 0... | [
{
"docstring": null,
"function_declaration": "def orientation(p, q, r):",
"function_name": "orientation",
"parameter_list": "(p, q, r)"
},
{
"docstring": null,
"function_declaration": "def is_polygon(points):",
"function_name": "is_polygon",
"parameter_list": "(points)"
},
{
... | [
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 cross_product(o, a, b):\n return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])\n\ndef is_convex_polygon(points):\n n = len(points)\n i... | trial_gpt4o_1 | {
"original_instruction": "You have been assigned the task of developing a new visualization tool for a company dealing with geospatial data. One of the key functionalities of this tool is to analyze whether a given set of points in a 2D plane form a closed shape, and if so, determine the type of polygon (convex or c... | 0.591346 | Taco_20915 | C | [
"orientation",
"is_polygon",
"check_polygon_type"
] | 3 | [
[
"check_polygon_type",
"is_polygon"
],
[
"check_polygon_type",
"orientation"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 73079d1387b23b9abd9b59637062afea679b1252 | a39acc5ec947fe48c23df1a7c08a9b3ed95cc67f | |||
v1.0 | complete | Taco | Taco_26393_C | from typing import List
def custom_sort(subject_codes: List[int]) -> List[int]:
"""
Returns the subject codes sorted by the sum of their digits
in non-decreasing order. If two subject codes have the same
sum of digits, they are sorted by their numeric value.
>>> custom_sort([56, 23, 89, 12, 34... | def sum_of_digits(num):
"""
Returns the sum of the digits of a given number.
"""
return sum(int(digit) for digit in str(num))
def custom_sort(subject_codes):
"""
Returns the subject codes sorted by the sum of their digits
in non-decreasing order. If two subject codes have the same
sum o... | from solution import custom_sort
def test_single_code():
assert custom_sort([15]) == [15]
def test_multiple_codes_with_different_digit_sums():
assert custom_sort([56, 23, 89, 12, 34]) == [12, 23, 34, 56, 89]
def test_multiple_codes_with_same_digit_sums():
assert custom_sort([102, 210, 31]) == [102, 210, ... | [
{
"docstring": "Returns the sum of the digits of a given number.",
"function_declaration": "def sum_of_digits(num):",
"function_name": "sum_of_digits",
"parameter_list": "(num)"
},
{
"docstring": "Returns the subject codes sorted by the sum of their digits\nin non-decreasing order. If two su... | [
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 sort_subject_codes(subject_codes):\n \"\"\"\n Sort subject codes first by the sum of their digits in non-decreasing order,\n then by their numerical v... | trial_gpt4o_2 | {
"original_instruction": "In the magical realm of Hogwarts, students must choose their subjects at the start of each term. However, there's a peculiar way to determine their schedules. Each subject is assigned a unique code, and students must solve a puzzle involving these codes to finalize their schedule.\n\nThe pu... | 0.686753 | Taco_26393 | C | [
"sum_of_digits",
"custom_sort"
] | 2 | [
[
"custom_sort",
"sum_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a0fe793e995bcbab3d1c1ce8cd21cec45293c5b4 | b963a86c89b3e783c7b6d4e4871ccf1d4e629dd4 | |||
v1.0 | complete | Taco | Taco_19898_C | def rotate_matrix_90_clockwise(matrix):
"""
Rotates a given n x n matrix 90 degrees clockwise.
Parameters:
matrix (list of list of int): 2D list representing the n x n matrix.
Returns:
list of list of int: The matrix rotated 90 degrees clockwise.
"""
def read_and_process_input(in_data):
... | def rotate_matrix_90_clockwise(matrix):
"""
Rotates a given n x n matrix 90 degrees clockwise.
Parameters:
matrix (list of list of int): 2D list representing the n x n matrix.
Returns:
list of list of int: The matrix rotated 90 degrees clockwise.
"""
n = len(matrix)
rotated_matrix ... | from solution import rotate_matrix_90_clockwise, read_and_process_input
def test_rotate_matrix_3x3():
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
expected = [
[7, 4, 1],
[8, 5, 2],
[9, 6, 3]
]
assert rotate_matrix_90_clockwise(matrix) == expected
de... | [
{
"docstring": "Rotates a given n x n matrix 90 degrees clockwise.\n\nParameters:\nmatrix (list of list of int): 2D list representing the n x n matrix.\n\nReturns:\nlist of list of int: The matrix rotated 90 degrees clockwise.",
"function_declaration": "def rotate_matrix_90_clockwise(matrix):",
"functio... | [
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 rotate_matrix_90_clockwise(n, matrix):\n \"\"\"\n Rotates the given n x n matrix 90 degrees clockwise.\n \n :param n: Size of the matrix\n :para... | trial_gpt4o_2 | {
"original_instruction": "Python is a popular high-level programming language known for its simplicity and readability. However, sometimes the fluid nature of its list operations can lead to inefficiencies if not used carefully. One common operation in programming involves manipulating a 2D grid, such as rotating it... | 0.560344 | Taco_19898 | C | [
"rotate_matrix_90_clockwise",
"read_and_process_input"
] | 2 | [
[
"read_and_process_input",
"rotate_matrix_90_clockwise"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bdee600b5d38068f04213e705d385534719560af | 901fe955f6bf62c710a8eea55635783ab87d654d | |||
v1.0 | complete | Taco | Taco_20234_C | class ListNode:
def __init__(self, value=0, next=None):
self.value = value
self.next = next
def reverse_linked_list(head):
"""
Reverses a singly linked list.
"""
def list_to_linked_list(values):
"""
Converts a list of values to a linked list.
"""
def linked_list_to_list(he... | class ListNode:
def __init__(self, value=0, next=None):
self.value = value
self.next = next
def reverse_linked_list(head):
"""
Reverses a singly linked list.
"""
prev = None
current = head
while current:
next_node = current.next
current.next = prev
pr... | def test_reverse_linked_list():
assert linked_list_to_list(reverse_linked_list(list_to_linked_list([1, 2, 3, 4, 5]))) == [5, 4, 3, 2, 1]
assert linked_list_to_list(reverse_linked_list(list_to_linked_list([10, 20, 30, 40]))) == [40, 30, 20, 10]
assert linked_list_to_list(reverse_linked_list(list_to_linked_li... | [] | [
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 ListNode:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef reverse_linked_list(head):\n prev = No... | trial_gpt4o_1 | {
"original_instruction": "In the realm of data structures, linked lists are fundamental components that offer a dynamic and flexible way to manage collections of data. One common operation with singly linked lists is the reversal of the list. This involves rearranging the links between the nodes so that the first no... | 0.488612 | Taco_20234 | C | [
"reverse_linked_list",
"list_to_linked_list",
"linked_list_to_list",
"process_datasets"
] | 4 | [
[
"process_datasets",
"linked_list_to_list"
],
[
"process_datasets",
"list_to_linked_list"
],
[
"process_datasets",
"reverse_linked_list"
]
] | 3 | [
"process_datasets"
] | false | [
"ListNode"
] | true | pytest | false | [] | true | 7772b6bb2522cfef60a1539ea3d58b718a32dcfc | 2a24fe8ec67476ae39f467b7f6dcf724ec04cef4 | |||
v1.0 | complete | Taco | Taco_26628_C | import re
from typing import List
def validate_username(username: str) -> str:
"""
Validates a single username according to the specified rules.
Parameters:
username (str): The username to validate.
Returns:
str: "Valid" if the username is valid, otherwise "Invalid".
"""
pass
... | import re
def validate_username(username):
"""
Validates a single username according to the specified rules.
Parameters:
username (str): The username to validate.
Returns:
str: "Valid" if the username is valid, otherwise "Invalid".
"""
# Check if the username is between 5 and ... | from solution import validate_username, validate_usernames
def test_validate_username():
assert validate_username("user_1") == "Invalid"
assert validate_username("User2") == "Valid"
assert validate_username("aVeryLongUsername123") == "Invalid"
assert validate_username("abc") == "Invalid"
assert val... | [
{
"docstring": "Validates a single username according to the specified rules.\n\nParameters:\nusername (str): The username to validate.\n\nReturns:\nstr: \"Valid\" if the username is valid, otherwise \"Invalid\".",
"function_declaration": "def validate_username(username):",
"function_name": "validate_us... | [
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 re\n\ndef is_valid_username(username):\n \"\"\"\n Validates a username based on the following rules:\n 1. The username must be between 5 and 15 cha... | trial_gpt4o_1 | {
"original_instruction": "Write a program that validates a series of username strings based on specific rules. The rules for a valid username are:\n1. The username must be between 5 and 15 characters long.\n2. The username must start with an alphabetic character.\n3. The username can contain only alphanumeric charac... | 0.530908 | Taco_26628 | C | [
"validate_username",
"validate_usernames"
] | 2 | [
[
"validate_usernames",
"validate_username"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 908cd8ddfde715c30d5f7d14a9d0495a7070776d | e30bb9f7e20aeefaca823ff85f2fd830d8cf81b7 | |||
v1.0 | complete | Taco | Taco_26096_C | def is_valid_password(password):
"""
Returns "Valid" if the password complies with all the security rules, otherwise returns "Invalid".
Rules:
1. It must contain at least one uppercase letter.
2. It must contain at least one lowercase letter.
3. It must contain at least one digit.
4. It... | def is_valid_password(password):
"""
Returns "Valid" if the password complies with all the security rules, otherwise returns "Invalid".
"""
# Rule: Password must be at least 8 characters long
if len(password) < 8:
return "Invalid"
# Rule: Password must not contain any spaces
if ... | from solution import is_valid_password, process_passwords
def test_is_valid_password():
assert is_valid_password("P@ssw0rd") == "Valid"
assert is_valid_password("incorrect") == "Invalid"
assert is_valid_password("Secure2021") == "Valid"
assert is_valid_password("Alph@numeric1") == "Valid"
assert is... | [
{
"docstring": "Returns \"Valid\" if the password complies with all the security rules, otherwise returns \"Invalid\".",
"function_declaration": "def is_valid_password(password):",
"function_name": "is_valid_password",
"parameter_list": "(password)"
},
{
"docstring": "Processes a list of pas... | [
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": "def is_valid_password(password):\n \"\"\"\n Check if the given password is valid as per the specified rules.\n \"\"\"\n if len(password) < 8:\n ... | trial_gpt4o_7 | {
"original_instruction": "A notable tech company has developed a secure system that requires password updates from employees every 30 days. The system leverages a policy that enforces each password to be a combination of numbers and letters, both uppercase and lowercase. As part of this policy, a password is conside... | 0.597322 | Taco_26096 | C | [
"is_valid_password",
"process_passwords"
] | 2 | [
[
"process_passwords",
"is_valid_password"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e6005c7a6134a212d8923603ade6e687b92bd85e | 8e775109868c455cd8bdf2bed4211df2bd9a7af6 | |||
v1.0 | complete | Taco | Taco_25112_C | from typing import List, Tuple
def to_minutes(time_str: str) -> int:
""" Converts a time string in HH:MM format to the total number of minutes since 00:00.
>>> to_minutes("00:00")
0
>>> to_minutes("01:00")
60
>>> to_minutes("12:34")
754
>>> to_minutes("23:59")
1439
"""
pass
... | def to_minutes(time_str):
"""
Converts a time string in HH:MM format to the total number of minutes since 00:00.
"""
hh, mm = map(int, time_str.split(':'))
return hh * 60 + mm
def max_overlap(events):
"""
Determines the maximum number of overlapping events.
"""
times = []
#... | def test_max_overlap_single_event():
assert max_overlap([("09:00", "10:00")]) == 1
def test_max_overlap_no_overlap():
assert max_overlap([("09:00", "10:00"), ("10:00", "11:00")]) == 1
def test_max_overlap_full_overlap():
assert max_overlap([("09:00", "10:00"), ("09:30", "09:45")]) == 2
def test_max_overl... | [
{
"docstring": "Converts a time string in HH:MM format to the total number of minutes since 00:00.",
"function_declaration": "def to_minutes(time_str):",
"function_name": "to_minutes",
"parameter_list": "(time_str)"
},
{
"docstring": "Determines the maximum number of overlapping events.",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_overlap(events):\n \"\"\"\n Calculate the maximum number of overlapping intervals.\n \n Args:\n events (list of tuples): List of events with... | trial_gpt4o_2 | {
"original_instruction": "A company hosts several events annually, and each event has a specific start and end time represented in 24-hour format (HH:MM). The HR team wants to know the maximum number of events that overlap at any point in time during the day.\n\nThe task is to write a program that, given a list of e... | 0.558787 | Taco_25112 | C | [
"to_minutes",
"max_overlap",
"process_test_cases"
] | 3 | [
[
"max_overlap",
"to_minutes"
],
[
"process_test_cases",
"max_overlap"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | 203ce7ec6e7aef6ac483ba2e4f6d3e338c492948 | f09bd7f4c99375c973a65d4777153e4968e3cb8d | |||
v1.0 | complete | Taco | Taco_26678_C | def max_product_after_swap(n: int) -> int:
"""
Given an integer n, find the maximum product of its digits after performing at most one swap between any two digits of the number.
If the number remains the same, the product of its digits should be calculated once. The product of digits of a number
is def... | import itertools
def max_product_after_swap(n: int) -> int:
"""
Compute the maximum product of digits of the number n after performing at most one swap between any two digits.
Args:
n (int): The integer number for which the maximum product needs to be evaluated.
Returns:
int: The maxi... | from solution import max_product_after_swap
def test_max_product_after_swap_2736():
assert max_product_after_swap(2736) == 252
def test_max_product_after_swap_9973():
assert max_product_after_swap(9973) == 1701
def test_max_product_after_swap_321():
assert max_product_after_swap(321) == 6
def test_max_p... | [
{
"docstring": "Compute the maximum product of digits of the number n after performing at most one swap between any two digits.\n\nArgs:\nn (int): The integer number for which the maximum product needs to be evaluated.\n\nReturns:\nint: The maximum product of digits after the potential one swap.",
"function... | [
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": "from itertools import permutations\n\ndef digit_product(num):\n \"\"\"\n Helper function to calculate the product of digits of the number.\n \"\"\"\n p... | trial_gpt4o_6 | {
"original_instruction": "Given an integer n, find the maximum product of its digits after performing at most one swap between any two digits of the number. If the number remains the same, the product of its digits should be calculated once. The product of digits of a number is defined as the product of all its digi... | 0.647984 | Taco_26678 | C | [
"max_product_after_swap",
"product_of_digits"
] | 2 | [
[
"max_product_after_swap",
"product_of_digits"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6206c5f1845ed702eb790aa8850f6700703343e7 | e0d34bd6876c1901d469ca6d06cba31ebd07310c | |||
v1.0 | complete | Taco | Taco_27089_C | def largest_rectangle(input_string: str) -> int:
""" Determine the area of the largest rectangle that can be formed using any contiguous set of vertical sticks.
The input consists of a single line containing pairs of integers representing the x-coordinate and the height of each stick.
Parameters:
... | def largest_rectangle_area(sticks):
heights = [sticks[i] for i in range(1, len(sticks), 2)]
max_area = 0
stack = []
heights.append(0)
for i in range(len(heights)):
while stack and heights[i] < heights[stack[-1]]:
h = heights[stack.pop()]
width = i if not stack el... | from solution import largest_rectangle
def test_example_1():
assert largest_rectangle("1 2 2 1 3 5 4 6 5 2") == 10
def test_example_2():
assert largest_rectangle("1 1 2 2 3 3 4 4 5 5") == 9
def test_example_3():
assert largest_rectangle("1 6 2 3 3 4") == 9
def test_single_stick():
assert largest_rec... | [
{
"docstring": null,
"function_declaration": "def largest_rectangle_area(sticks):",
"function_name": "largest_rectangle_area",
"parameter_list": "(sticks)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_string):",
"function_name": "parse_input",
"parameter... | [
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 largest_rectangle_area(sticks):\n \"\"\"\n Finds the largest rectangular area that can be formed using any contiguous set of sticks.\n \n Args:\n ... | trial_gpt4o_2 | {
"original_instruction": "You are given a 2-dimensional plane with a horizontal number line represented by an x-axis. A set of vertical sticks of varying lengths is placed on this line. All sticks are standing on the x-axis at different x-coordinates.\n\nWrite a function to determine the area of the largest rectangl... | 0.741785 | Taco_27089 | C | [
"largest_rectangle_area",
"parse_input",
"largest_rectangle"
] | 3 | [
[
"largest_rectangle",
"largest_rectangle_area"
],
[
"largest_rectangle",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 8b9709f56aa819c517bea64c1ba105aeef66aee9 | 8b66277e3faeb145dc39dd877efce2ec45a24ecc | |||
v1.0 | complete | Taco | Taco_26563_C | def shortest_travel_time(n, m, q, roads, queries):
"""
Main function to return shortest travel times for given queries.
Args:
- n (int): Number of intersections
- m (int): Number of roads
- q (int): Number of queries
- roads (list of tuples): Each tuple contains (u, v, w) representing ... | import heapq
def dijkstra(n, graph, start):
"""
Performs the Dijkstra's algorithm to find the shortest path from
start node to all other nodes.
Args:
- n (int): Number of nodes
- graph (dict of lists): Adjacency list where the key is the node
and the value is ... | def test_shortest_travel_time():
n, m, q = 4, 4, 2
roads = [(1, 2, 5), (2, 3, 10), (3, 4, 2), (1, 4, 100)]
queries = [(1, 3), (2, 4)]
assert shortest_travel_time(n, m, q, roads, queries) == [15, 12]
def test_no_path():
n, m, q = 4, 2, 2
roads = [(1, 2, 7), (3, 4, 5)]
queries = [(1, 4), (2, ... | [
{
"docstring": "Performs the Dijkstra's algorithm to find the shortest path from\nstart node to all other nodes.\n\nArgs:\n- n (int): Number of nodes\n- graph (dict of lists): Adjacency list where the key is the node\n and the value is a list of (neighbor, weight)\n- start (int): Starti... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_paths(n, roads, queries):\n def dijkstra(start):\n \"\"\"\n The function uses Dijkstra's algorithm to find the shorte... | trial_gpt4o_2 | {
"original_instruction": "A delivery company has decided to optimize the delivery routes by using an automated system that can determine the shortest path for the vehicles. The roads in the city are represented as a bidirectional weighted graph, where intersections are the nodes and roads between them are the edges ... | 0.72134 | Taco_26563 | C | [
"dijkstra",
"shortest_travel_time"
] | 2 | [
[
"shortest_travel_time",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | f73dbb4cbd5db0e2fdb0a818a22b9e4568fbc93b | bc3e53510b9169387e3884dcae6c8b0cb5a9bdad | |||
v1.0 | complete | Taco | Taco_25738_C | from collections import deque
def maze_solver(maze_str: str) -> int:
""" Finds the shortest path from the entrance to the exit of the maze.
The maze is represented as a 2D grid where each cell is either passable ('.') or a wall ('#').
The entrance is at the top-left corner, and the exit is at the bott... | from collections import deque
def shortest_path(maze, n, m):
# Directions for moving in the maze (right, down, left, up)
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Helper function to check if a position is valid and passable
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and maze[... | from solution import maze_solver
def test_shortest_path_example1():
maze_str = "5 5\n.....\n.#.#.\n.#.#.\n.#.#.\n....."
assert maze_solver(maze_str) == 8
def test_shortest_path_example2():
maze_str = "3 3\n.#.\n###\n.#."
assert maze_solver(maze_str) == -1
def test_shortest_path_single_path():
maz... | [
{
"docstring": null,
"function_declaration": "def shortest_path(maze, n, m):",
"function_name": "shortest_path",
"parameter_list": "(maze, n, m)"
},
{
"docstring": null,
"function_declaration": "def maze_solver(maze_str):",
"function_name": "maze_solver",
"parameter_list": "(maze... | [
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 collections import deque\n\ndef shortest_path_in_maze(n, m, maze):\n \"\"\"\n Finds the shortest path from the entrance (top-left) to the exit (bottom-r... | trial_gpt4o_2 | {
"original_instruction": "Marc loves to explore new places and wants to implement a maze-solving algorithm to help him find the shortest path from the entrance to the exit of a maze. The maze is represented as a 2D grid where each cell is either passable ('.') or a wall ('#'). Marc can move up, down, left, or right ... | 0.630468 | Taco_25738 | C | [
"shortest_path",
"maze_solver"
] | 2 | [
[
"maze_solver",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8cb192e9bde79032c5c724a8bf03df56390e90cb | f55e7198f40c61aaeab45d4d9169def2d7d908a8 | |||
v1.0 | complete | Taco | Taco_27837_C | def smallest_lexicographic_rotation(word: str) -> str:
"""
Returns the lexicographically smallest rotation of the given word.
>>> smallest_lexicographic_rotation("bca") "abc"
>>> smallest_lexicographic_rotation("zxy") "xyz"
>>> smallest_lexicographic_rotation("abc") "abc"
>>> smallest_lexicograp... | def smallest_lexicographic_rotation(word):
"""
Returns the lexicographically smallest rotation of the given word.
"""
concatenated = word + word
smallest_rotation = word
for i in range(1, len(word)):
rotation = concatenated[i:i+len(word)]
if rotation < smallest_rotation:
... | from solution import smallest_lexicographic_rotation, decode_messages
def test_smallest_lexicographic_rotation():
assert smallest_lexicographic_rotation("bca") == "abc"
assert smallest_lexicographic_rotation("zxy") == "xyz"
assert smallest_lexicographic_rotation("abc") == "abc"
assert smallest_lexicogr... | [
{
"docstring": "Returns the lexicographically smallest rotation of the given word.",
"function_declaration": "def smallest_lexicographic_rotation(word):",
"function_name": "smallest_lexicographic_rotation",
"parameter_list": "(word)"
},
{
"docstring": "Given a list of words, return a list wi... | [
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 smallest_lexicographic_rotation(word):\n \"\"\"\n Returns the lexicographically smallest rotation of the given word.\n \"\"\"\n concatenated = word... | trial_gpt4o_0 | {
"original_instruction": "A secret spy agency has developed a new encrypted communication system. Each message is composed of a sequence of words, and each word is represented by a string of lowercase English letters. In order to decode the messages, agents must apply a specific transformation to each word.\n\nThe t... | 0.659579 | Taco_27837 | C | [
"smallest_lexicographic_rotation",
"decode_messages"
] | 2 | [
[
"decode_messages",
"smallest_lexicographic_rotation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 441d6e2b1bb44b0443ef02a01205fb42ae7610f9 | d498d8cff5b9f5d68f6d447c3bb803e4324c9571 | |||
v1.0 | complete | Taco | Taco_27269_C | def count_paths_from_input(n, m, grid_lines):
"""Determine the number of ways to move from the top-left to the bottom-right corner of the grid without passing through obstacles.
:param n: The number of rows in the grid.
:param m: The number of columns in the grid.
:param grid_lines: A list of strin... | def count_paths(grid, n, m):
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return 0
dp = [[0] * m for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == '#':
dp[i][j] = 0
else:
if i > 0:
... | from solution import count_paths_from_input
def test_example_case():
n, m = 3, 3
grid_lines = [
".#.",
"...",
"#.."
]
assert count_paths_from_input(n, m, grid_lines) == 2
def test_no_path_due_to_obstacle():
n, m = 3, 3
grid_lines = [
".#.",
".#.",
... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid, n, m):",
"function_name": "count_paths",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def count_paths_from_input(n, m, grid_lines):",
"function_name": "count_paths_from_input",
... | [
0,
0,
0,
1
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def count_paths(grid, n, m):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n\n dp = [[0] * m for _ in range(n)]\n dp[0][0] = 1\n\n ... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid with $n$ rows and $m$ columns. Each cell is either empty ('.') or filled with an obstacle ('#'). You need to determine how many ways there are to move from the top-left corner of the grid (cell $(1, 1)$) to the bottom-right corner (cell $(n, m)$) by only moving down or ... | 0.747091 | Taco_27269 | C | [
"count_paths",
"count_paths_from_input"
] | 2 | [
[
"count_paths_from_input",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e7e20ba4d51d4343d832b63e56db2d03ab29f086 | 8f0cac8840efe6039cd4ac4169ee14dc4b6a347a | |||
v1.0 | complete | Taco | Taco_27373_C | def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
pass
def sum_of_digits(n):
"""
Returns the sum of the digits of n.
"""
pass
def smallest_multiple_with_min_digit_sum(a, b):
"""
Returns the smallest integer n that is a multiple of both a and b and has the min... | import math
def lcm(a, b):
"""
Returns the least common multiple of a and b.
"""
return abs(a * b) // math.gcd(a, b)
def sum_of_digits(n):
"""
Returns the sum of the digits of n.
"""
return sum(int(digit) for digit in str(n))
def smallest_multiple_with_min_digit_sum(a, b):
"""
... | from solution import smallest_multiple_with_min_digit_sum
def test_smallest_multiple_with_min_digit_sum():
assert smallest_multiple_with_min_digit_sum(12, 15) == 60
assert smallest_multiple_with_min_digit_sum(13, 17) == 221
assert smallest_multiple_with_min_digit_sum(10, 20) == 20
def test_lcm():
asse... | [
{
"docstring": "Returns the least common multiple of a and b.",
"function_declaration": "def lcm(a, b):",
"function_name": "lcm",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the sum of the digits of n.",
"function_declaration": "def sum_of_digits(n):",
"function_name": "sum... | [
0,
0,
0,
0,
0,
1,
0,
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": "import math\n\ndef lcm(a, b):\n return abs(a * b) // math.gcd(a, b)\n\ndef sum_of_digits(number):\n return sum(int(digit) for digit in str(number))\n\ndef sm... | trial_gpt4o_8 | {
"original_instruction": "Bob loves playing with numbers. In particular, he is fascinated with the concept of sequences and wants to create a special sequence with a specific property.\n\nGiven two integers, a and b, Bob wants to find the smallest positive integer n such that it satisfies the following conditions:\n... | 0.634693 | Taco_27373 | C | [
"lcm",
"sum_of_digits",
"smallest_multiple_with_min_digit_sum"
] | 3 | [
[
"smallest_multiple_with_min_digit_sum",
"lcm"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 07d55eb6aa1f6210a70cc44554be90873e977654 | 21a348bf5ef694947604c5fb486f67f40cfe97ce | |||
v1.0 | complete | Taco | Taco_26056_C | def arrange_lanterns(n: int, heights: List[int]) -> Union[List[int], str]:
""" In the land of Pyroland, there is a peculiar ritual involving lanterns.
The Pyrolandians want to create a unique sequence of lanterns for their annual festival.
Given an array of lantern heights, Pyrolandians want to arrange... | def arrange_lanterns(n, heights):
if n < 3:
return "Impossible"
heights.sort()
mid = (n - 1) // 2
lows = heights[:mid+1]
highs = heights[mid+1:]
arranged = []
while lows or highs:
if lows:
arranged.append(lows.pop())
if highs:
arran... | from solution import arrange_lanterns
def test_example_1():
assert arrange_lanterns(3, [2, 3, 1]) == [2, 3, 1] or arrange_lanterns(3, [2, 3, 1]) == [3, 1, 2]
def test_example_2():
assert arrange_lanterns(4, [5, 1, 2, 4]) == [2, 5, 1, 4] or arrange_lanterns(4, [5, 1, 2, 4]) == [1, 5, 2, 4]
def test_impossible... | [
{
"docstring": null,
"function_declaration": "def arrange_lanterns(n, heights):",
"function_name": "arrange_lanterns",
"parameter_list": "(n, heights)"
},
{
"docstring": null,
"function_declaration": "def is_alternating(arranged):",
"function_name": "is_alternating",
"parameter_l... | [
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 arrange_lanterns(heights):\n \"\"\"\n Arranges the lanterns such that each peak is higher than its neighbors and each trough is lower than its neighbors.... | trial_gpt4o_3 | {
"original_instruction": "In the land of Pyroland, there is a peculiar ritual involving lanterns. The Pyrolandians want to create a unique sequence of lanterns for their annual festival. Due to the symbolism of unique peaks and troughs in their culture, they have set specific rules for arranging the heights of these... | 0.575288 | Taco_26056 | C | [
"arrange_lanterns",
"is_alternating"
] | 2 | [
[
"arrange_lanterns",
"is_alternating"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e73e4e337b1d7c540b549ccbbce07d0d1852eb5f | fb4726d7dd020fe7a4f24f1c97893b5b072df59b | |||
v1.0 | complete | Taco | Taco_27120_C | def interstellar_programming_contest(input_data: str) -> List[str]:
"""
The Galaxy Federation is organizing an interstellar programming contest.
Each team is assigned one spaceship and asked to solve a set of programming
problems during the course of a galactic journey. The journey consists of
a ... | def calculate_energy_points_and_metrics(missions):
energy_points = 0
successful_missions = 0
pirate_encounters = 0
for mission in missions:
if mission == 'S':
energy_points += 3
successful_missions += 1
elif mission == 'E':
energy_points -= 1
... | def test_interstellar_programming_contest():
input_data = "2\n3\nSSNN\nSSEW\nSENNN\n2\nSESENS\nENS\n"
expected_output = ["1", "1"]
assert interstellar_programming_contest(input_data) == expected_output
def test_interstellar_programming_contest_with_tie():
input_data = "1\n3\nSSSSS\nSSSSS\nEEE\n"
ex... | [
{
"docstring": null,
"function_declaration": "def calculate_energy_points_and_metrics(missions):",
"function_name": "calculate_energy_points_and_metrics",
"parameter_list": "(missions)"
},
{
"docstring": null,
"function_declaration": "def find_winner(test_cases):",
"function_name": "... | [
0,
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find_winner(test_cases):\n def calculate_points(team_result):\n points = 0\n successful_missions = 0\n encounters = 0\n for miss... | trial_gpt4o_9 | {
"original_instruction": "The Galaxy Federation is organizing an interstellar programming contest. Each team is assigned one spaceship and asked to solve a set of programming problems during the course of a galactic journey. The journey consists of a series of missions, and for each mission, the teams can earn energ... | 0.655412 | Taco_27120 | C | [
"calculate_energy_points_and_metrics",
"find_winner",
"interstellar_programming_contest"
] | 3 | [
[
"find_winner",
"calculate_energy_points_and_metrics"
],
[
"interstellar_programming_contest",
"find_winner"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | fd2b0f5c809cf4cb6766f4cf939d4eeb595f409f | 32aa49a153a7664bb0ec9e41e8091d9fff102cb8 | |||
v1.0 | complete | Taco | Taco_26877_C | def rotate_90(grid):
""" Rotates a given grid 90 degrees clockwise.
>>> rotate_90([
[0, 1, 0, 1],
[1, 1, 1, 0],
[0, 0, 1, 1]
])
[[0, 1, 0],
[0, 1, 1],
[1, 1, 0],
[1, 0, 1]]
"""
pass
def max_continuous_crops(row):
""" Returns the maximum number of conti... | def rotate_90(grid):
"""
Rotates a given grid 90 degrees clockwise.
"""
n, m = len(grid), len(grid[0])
return [[grid[n - j - 1][i] for j in range(n)] for i in range(m)]
def max_continuous_crops(row):
"""
Returns the maximum number of continuous crops (1s) in a row.
"""
max_count = 0... | from solution import rotate_90, max_continuous_crops, process_queries
def test_rotate_90():
grid = [
[0, 1, 0, 1],
[1, 1, 1, 0],
[0, 0, 1, 1]
]
rotated = rotate_90(grid)
expected = [
[0, 1, 0],
[0, 1, 1],
[1, 1, 0],
[1, 0, 1]
]
assert rota... | [
{
"docstring": "Rotates a given grid 90 degrees clockwise.",
"function_declaration": "def rotate_90(grid):",
"function_name": "rotate_90",
"parameter_list": "(grid)"
},
{
"docstring": "Returns the maximum number of continuous crops (1s) in a row.",
"function_declaration": "def max_contin... | [
0,
0,
0,
0,
0,
1,
0,
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_continuous_crops_after_rotation(n, m, grid, queries):\n def rotate_grid_90_clockwise(grid):\n return [[grid[n - 1 - j][i] for j in range(n)] for ... | trial_gpt4o_5 | {
"original_instruction": "You are given a 2D grid of size n × m representing a farm. Each cell in the grid has either a crop (represented by 1) or is left empty (represented by 0). The farm can be rotated 90 degrees clockwise a certain number of times to change its orientation, which can help in performing various a... | 0.606459 | Taco_26877 | C | [
"rotate_90",
"max_continuous_crops",
"process_queries"
] | 3 | [
[
"process_queries",
"max_continuous_crops"
],
[
"process_queries",
"rotate_90"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 3b1bc1dfdf3a2450565795d7ffd39831ae3f03cb | 1ed776b6bdc7d1855c1a729ed7861920ed75d965 | |||
v1.0 | complete | Taco | Taco_27881_C | def find_new_stamp_position(N: int, stamps: List[int], X: int) -> int:
"""
Determine the position of a new stamp in the sorted collection in descending order.
Args:
N (int): Number of stamps in the current collection.
stamps (List[int]): List of integers representing the values of the stamps.
X... | def find_new_stamp_position(test_cases):
results = []
for test_case in test_cases:
N, stamps, X = test_case
stamps.append(X)
stamps.sort(reverse=True)
position = stamps.index(X) + 1
results.append(position)
return results
def parse_input(input_data):
lines = inpu... | def test_find_new_stamp_position():
input_data = "2\n3\n5 10 3\n4\n4\n8 1 6 2\n5"
expected_output = [3, 3]
assert execute(input_data) == expected_output
def test_all_same_values():
input_data = "1\n3\n5 5 5\n5"
expected_output = [1]
assert execute(input_data) == expected_output
def test_single... | [
{
"docstring": null,
"function_declaration": "def find_new_stamp_position(test_cases):",
"function_name": "find_new_stamp_position",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"p... | [
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 find_stamp_position(T, test_cases):\n \"\"\"\n For each test case, find the position of the new stamp in the sorted (in descending order) collection.\n ... | trial_gpt4o_2 | {
"original_instruction": "David loves to collect stamps. He has a unique collection of stamps from various countries. His collection consists of N stamps, each with a unique positive integer representing its value. David wants to sort his stamps based on their value in descending order. However, after visiting a sta... | 0.526584 | Taco_27881 | C | [
"find_new_stamp_position",
"parse_input",
"execute"
] | 3 | [
[
"execute",
"find_new_stamp_position"
],
[
"execute",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | dc7ae8a31263ffaffccebcaac904f501f8773dd7 | b8a69e34201fa5cc67be6dc6bebfa940ec7ac0a3 | |||
v1.0 | complete | Taco | Taco_33222_C | def rock_paper_scissors_tournament(test_cases):
""" Simulate a Rock, Paper, Scissors tournament and output the winner's strategy.
Args:
test_cases (List[List[str]]): List of test cases, where each test case is a list of strings representing player strategies.
Returns:
List[str]: List of win... | import random
def simulate_game(player1, player2):
choices = ['Rock', 'Paper', 'Scissors']
if player1 == 'Random':
player1 = random.choice(choices)
if player2 == 'Random':
player2 = random.choice(choices)
if player1 == player2:
return player1 # In the case of a ti... | from solution import rock_paper_scissors_tournament
import random
def test_single_case():
test_cases = [
["Rock", "Paper", "Scissors", "Random"]
]
result = rock_paper_scissors_tournament(test_cases)
assert result[0] in ["Rock", "Paper", "Scissors", "Random"]
def test_all_rock():
test_cases... | [
{
"docstring": null,
"function_declaration": "def simulate_game(player1, player2):",
"function_name": "simulate_game",
"parameter_list": "(player1, player2)"
},
{
"docstring": null,
"function_declaration": "def simulate_tournament(strategies):",
"function_name": "simulate_tournament"... | [
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 random\n\ndef simulate_match(player1, player2):\n winning_combinations = {\n (\"Rock\", \"Scissors\"): player1,\n (\"Scissors\", \"Rock\"):... | trial_gpt4o_4 | {
"original_instruction": "### Rock, Paper, Scissors Tournament\n\nYou have been chosen to write a simulation for a \"Rock, Paper, Scissors\" tournament. In this tournament, players are paired up and play against each other, with the winners advancing to the next round until only one winner is left.\n\nThe rules for ... | 0.648552 | Taco_33222 | C | [
"simulate_game",
"simulate_tournament",
"rock_paper_scissors_tournament"
] | 3 | [
[
"rock_paper_scissors_tournament",
"simulate_tournament"
],
[
"simulate_tournament",
"simulate_game"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c675b48c6ef51e076a07df7ce8e462d06a314b01 | 1362d71814f51597f5dc06c746df7666f7d27c0c | |||
v1.0 | complete | Taco | Taco_33869_C | def is_prime_list(integers: List[int]) -> List[bool]:
""" Determine which integers from the list are prime numbers.
>>> is_prime_list([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
[False, True, False, True, False, False, False, True, False, True]
>>> is_prime_list([2, 3, 4, 5, 6, 7, 8, 9, 10])
[True, Tr... | def is_prime(n):
"""
Returns True if n is a prime number, else False
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i ... | from solution import is_prime_list
def test_is_prime_list_sample():
integers = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
result = [False, True, False, True, False, False, False, True, False, True]
assert is_prime_list(integers) == result
def test_is_prime_list_single_prime():
integers = [2]
result ... | [
{
"docstring": "Returns True if n is a prime number, else False",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of booleans indicating the primality of each integer in the input list.",
"function_declara... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of integers. Your task is to determine which integers from the list are prime numbers. A prime number is defined as a number that has exactly two distinct positive divisors: 1 and itself. \n\nWrite a function to return a list of booleans where each element corresponds t... | 0.827149 | Taco_33869 | C | [
"is_prime",
"is_prime_list"
] | 2 | [
[
"is_prime_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6da91fb97a236eba78b00736e043191311928672 | 0b5f8f11683a9956050938212bccef1343828f5d | |||
v1.0 | complete | Taco | Taco_33490_C | from typing import List
def is_prime(n: int) -> bool:
""" Checks if a number is prime.
"""
# Function implementation goes here
def exists_prime_subset_sum(N: int, array: List[int]) -> str:
""" Determines if there exists a subset of the given array such that the sum of
the subset is a prime number... | from itertools import combinations
def is_prime(n):
"""
Checks 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 F... | from solution import exists_prime_subset_sum
def test_example_1():
assert exists_prime_subset_sum(5, [1, 2, 3, 4, 5]) == "YES"
def test_example_2():
assert exists_prime_subset_sum(4, [4, 6, 8, 10]) == "NO"
def test_single_element_prime():
assert exists_prime_subset_sum(1, [2]) == "YES"
def test_single_e... | [
{
"docstring": "Checks if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Determines if there exists a subset of the given array such that the sum of \nthe subset is a prime number.",
"function_decla... | [
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": "from itertools import combinations\n\ndef is_prime(n):\n \"\"\"\n Returns True if n is a prime number, False otherwise.\n \"\"\"\n if n <= 1:\n ... | trial_gpt4o_4 | {
"original_instruction": "This problem is about subsets of positive integers and their arithmetic properties. You're given an array of integers, and you need to determine if there exists a subset of this array whose sum is a prime number.\n\nA prime number is a natural number greater than 1 that cannot be formed by ... | 0.73631 | Taco_33490 | C | [
"is_prime",
"exists_prime_subset_sum"
] | 2 | [
[
"exists_prime_subset_sum",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d92806bc42ad2a6603fbefd9bb29d432a3fcb3a8 | 15237583ea628a257a91d3a5d742ec6241e095ef | |||
v1.0 | complete | Taco | Taco_32795_C | def sieve_of_eratosthenes(limit):
""" Sieve of Eratosthenes algorithm to find all prime numbers up to a limit.
>>> sieve_of_eratosthenes(10) == [2, 3, 5, 7]
>>> sieve_of_eratosthenes(1) == []
"""
def largest_prime_factorial(N):
""" Returns the largest prime factor of N!.
>>> largest_prime_facto... | def sieve_of_eratosthenes(limit):
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
for start in range(2, int(limit ** 0.5) + 1):
if is_prime[start]:
for multiple in range(start * start, limit + 1, start):
is_prime[multiple] = False
return [num for num... | from solution import solve_prime_factors_of_factorials, largest_prime_factorial, sieve_of_eratosthenes
def test_sieve_of_eratosthenes():
assert sieve_of_eratosthenes(10) == [2, 3, 5, 7]
assert sieve_of_eratosthenes(1) == []
assert sieve_of_eratosthenes(20) == [2, 3, 5, 7, 11, 13, 17, 19]
def test_largest_... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(limit):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(limit)"
},
{
"docstring": "Returns the largest prime factor of N!.",
"function_declaration": "def largest_prime_factorial(N):",
"function_na... | [
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 sieve_of_eratosthenes(n):\n \"\"\"\n Returns a list of all prime numbers up to n.\n \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while p * ... | trial_gpt4o_1 | {
"original_instruction": "Michelle is an avid mathematician who loves working with prime numbers. One day, she came up with the following problem while playing with her favorite numbers and started wondering if there was a pattern. The problem she came up with is this:\n\nGiven an integer N, find the largest prime f... | 0.665145 | Taco_32795 | C | [
"sieve_of_eratosthenes",
"largest_prime_factorial",
"solve_prime_factors_of_factorials"
] | 3 | [
[
"largest_prime_factorial",
"sieve_of_eratosthenes"
],
[
"solve_prime_factors_of_factorials",
"largest_prime_factorial"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | eac7a1868a3a1b7e0f8cf5091e552cc495f1c709 | 6b022a47d09e8890399dcdc4588e4af40c3fbc93 | |||
v1.0 | complete | Taco | Taco_31646_C | def is_convincing(phrase: str) -> str:
""" Check if the given phrase is convincing based on the criteria.
- It contains at least one of the keywords: 'urgent', 'emergency', 'help', 'immediate'.
- It does not contain more than three exclamation marks in the entire phrase.
- It does not have any sequences... | def is_convincing(phrase):
"""
Check if the given phrase is convincing based on the criteria.
"""
keywords = {'urgent', 'emergency', 'help', 'immediate'}
exclamation_count = phrase.count('!')
has_keyword = any(keyword in phrase for keyword in keywords)
no_triple_repeats = not any(char * 3 in... | from solution import is_convincing, check_phrases
def test_is_convincing():
assert is_convincing("This is an urgent request! Please respond immediately!!") == "Convincing"
assert is_convincing("We need help!!! This is an emergency!") == "Not Convincing"
assert is_convincing("Please respond as soon as possi... | [
{
"docstring": "Check if the given phrase is convincing based on the criteria.",
"function_declaration": "def is_convincing(phrase):",
"function_name": "is_convincing",
"parameter_list": "(phrase)"
},
{
"docstring": "Returns a list of results for the given phrases.",
"function_declaratio... | [
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_convincing(phrase):\n \"\"\"\n Check if the given phrase is convincing based on the criteria.\n \"\"\"\n keywords = {'urgent', 'emergency', 'hel... | trial_gpt4o_0 | {
"original_instruction": "A popular persuasion technique involves a person posing as an emergency service operator trying to convince the “rescued” person to provide critical information. The technique relies on the ability to sound convincing, especially given the urgency of the situation. To simulate this techniqu... | 0.573375 | Taco_31646 | C | [
"is_convincing",
"check_phrases"
] | 2 | [
[
"check_phrases",
"is_convincing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ed1ff6190f8da20878e3cba64b0cb373fcc226a5 | a8f7fed93d4e333cd599133868c8955e401933d0 | |||
v1.0 | complete | Taco | Taco_32590_C | import datetime
from typing import List
def parse_timestamp(timestamp: str) -> datetime.datetime:
return datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
def find_unique_ips(log_file_path: str, start_interval: str, end_interval: str, n: int) -> List[str]:
""" Identify unique IP addresses that made e... | def parse_timestamp(timestamp):
from datetime import datetime
return datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
def find_unique_ips(log_file_path, start_interval, end_interval, n):
from collections import defaultdict
start_time = parse_timestamp(start_interval)
end_time = parse_timestam... | from solution import find_unique_ips
def test_no_access_attempts():
log_file_path = "log_test_1.txt"
with open(log_file_path, 'w') as file:
file.write("")
start_interval = "2023-01-01 12:00:00"
end_interval = "2023-01-01 12:30:00"
n = 3
assert find_unique_ips(log_file_path, start_interv... | [
{
"docstring": null,
"function_declaration": "def parse_timestamp(timestamp):",
"function_name": "parse_timestamp",
"parameter_list": "(timestamp)"
},
{
"docstring": null,
"function_declaration": "def find_unique_ips(log_file_path, start_interval, end_interval, n):",
"function_name":... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from datetime import datetime\n\ndef unique_ips(log_file_path, start_interval, end_interval, n):\n start_dt = datetime.strptime(start_interval, \"%Y-%m-%d %H:%M... | trial_gpt4o_2 | {
"original_instruction": "Endpoint Security Solutions Inc. wants to develop a software that can identify unique IP addresses that made 'n' number of access attempts within a given time interval from their server logs. The log file is a text file where each line contains an IP address and a timestamp (in the format Y... | 0.638049 | Taco_32590 | C | [
"parse_timestamp",
"find_unique_ips"
] | 2 | [
[
"find_unique_ips",
"parse_timestamp"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 36ab33c7542eb511d5ea6da265a6da3d207b21f7 | 5b081374fa7410f658fe66f39ae621a8a73ba619 | |||
v1.0 | complete | Taco | Taco_26980_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(preorder, inorder):
if not preorder or not inorder:
return None
root_val = preorder[0]
root = TreeNode(root_val)
root_index_inorde... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(preorder, inorder):
if not preorder or not inorder:
return None
root_val = preorder[0]
root = TreeNode(root_val)
root_index_inorde... | from solution import reconstruct_and_postorder
def test_example():
n = 6
preorder = [1, 2, 4, 5, 3, 6]
inorder = [4, 2, 5, 1, 6, 3]
assert reconstruct_and_postorder(n, preorder, inorder) == [4, 5, 2, 6, 3, 1]
def test_single_node():
n = 1
preorder = [1]
inorder = [1]
assert reconstruct... | [] | [
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, 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** consisting of `n` nodes. A binary tree can be uniquely identified by its **preorder** and **inorder** traversals (both given in arrays).\n\nWrite a program to reconstruct the binary tree from its preorder and inorder traversal arrays, and then perform a **pos... | 0.52615 | Taco_26980 | C | [
"build_tree",
"postorder_traversal",
"reconstruct_and_postorder"
] | 3 | [
[
"reconstruct_and_postorder",
"build_tree"
],
[
"reconstruct_and_postorder",
"postorder_traversal"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | c947ff83630f4bff3b2e4923fb4fb3a18af696f3 | e8d4629efb41d6dfa1edf0ea2fc0844a1b54c9a1 | |||
v1.0 | complete | Taco | Taco_33771_C | from typing import List
def process_input(input_data: List[str]) -> List[str]:
"""
Determine if Alice can navigate from the top-left corner to the bottom-right corner of the grid.
Parameters:
input_data (List[str]): The list of input strings representing multiple datasets.
Returns:
List[str]:... | from collections import deque
def valid(r, c, H, W, grid, visited):
return 0 <= r < H and 0 <= c < W and grid[r][c] == '.' and not visited[r][c]
def bfs(grid, H, W):
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(0, 0)])
visited = [[False]*W for _ in range(H)]
visited[0][0] = True... | from solution import process_input
def test_sample_input():
input_data = [
"3 3",
"..#",
".#.",
"...",
"3 3",
"..#",
"###",
"...",
"4 4",
"....",
".#.#",
"....",
"....",
"0 0"
]
expected_output =... | [
{
"docstring": null,
"function_declaration": "def valid(r, c, H, W, grid, visited):",
"function_name": "valid",
"parameter_list": "(r, c, H, W, grid, visited)"
},
{
"docstring": null,
"function_declaration": "def bfs(grid, H, W):",
"function_name": "bfs",
"parameter_list": "(grid... | [
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": "from collections import deque\n\ndef bfs(grid, H, W):\n \"\"\" Perform Breadth-First Search to see if a path exists from start to end. \"\"\"\n if grid[0][0]... | trial_gpt4o_2 | {
"original_instruction": "Maze Solver \n\nBob and Alice are playing another board game. The game is played on an H by W grid. Initially, the grid contains open paths (.) and walls (#). Bob can play first and he can place a wall on any open path to block it. Alice’s goal is to start from the top-left corner of the g... | 0.545599 | Taco_33771 | C | [
"valid",
"bfs",
"can_alice_escape",
"process_input"
] | 4 | [
[
"bfs",
"valid"
],
[
"can_alice_escape",
"bfs"
],
[
"process_input",
"can_alice_escape"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 184fa6a1e5fcf6808ba4d9f9f2d11c07e2cf8e74 | 84f8ac29add9973b7bdee7db823164a993b6bcbf | |||
v1.0 | complete | Taco | Taco_33446_C | def minimum_cost_to_connect_water_tanks(n: int, m: int, pipes: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum maintenance cost required to connect all water tanks in a city.
Args:
n (int): The number of water tanks.
m (int): The number of pipes.
pipes (List[Tuple[int, int, int]]): A ... | 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... | from solution import minimum_cost_to_connect_water_tanks
def test_minimum_cost_example():
assert minimum_cost_to_connect_water_tanks(4, 5, [(1, 2, 1), (1, 3, 2), (1, 4, 3), (2, 3, 4), (3, 4, 5)]) == 6
def test_minimum_cost_single_pipe():
assert minimum_cost_to_connect_water_tanks(2, 1, [(1, 2, 10)]) == 10
de... | [
{
"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(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_2 | {
"original_instruction": "You are tasked with managing a city's water distribution system comprised of a series of underground pipes. Each pipe connects two distinct water tanks in the city and ensures the flow of water between them. The city has a total of n water tanks, numbered from 1 to n, and m pipes. Each pipe... | 0.616304 | Taco_33446 | C | [
"find",
"union",
"kruskal",
"minimum_cost_to_connect_water_tanks"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_cost_to_connect_water_tanks",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | d528d5dab51793d971c9759b219a0b2bb06a0665 | 40bbd8bdc4cc7002f7d476a52854242d6eadda4e | |||
v1.0 | complete | Taco | Taco_33416_C | def largest_square_submatrix(matrix):
""" Find the side length of the largest square sub-matrix where all characters are the same.
>>> largest_square_submatrix([
... ['a', 'a', 'a', 'b', 'b', 'b'],
... ['a', 'a', 'a', 'b', 'b', 'b'],
... ['a', 'a', 'a', 'c', 'c', 'c'],
... ['b', 'b', 'b', 'c', '... | def largest_square_submatrix(matrix):
if not matrix:
return 0
M = len(matrix)
N = len(matrix[0])
# Initialize dp table
dp = [[0] * N for _ in range(M)]
max_side_length = 0
for i in range(M):
for j in range(N):
if i == 0 or j == 0:
dp... | def test_largest_square_submatrix():
# Test case from the example 1
input1 = "5 6\na a a b b b\na a a b b b\na a a c c c\nb b b c c c\nb b b c c c"
assert read_input_and_solve(input1) == 3
# Test case from the example 2
input2 = "4 4\np p q q\np p q q\nl l k k\nl l k k"
assert read_input_an... | [
{
"docstring": null,
"function_declaration": "def largest_square_submatrix(matrix):",
"function_name": "largest_square_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def read_input_and_solve(input_str):",
"function_name": "read_input_and_sol... | [
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 largest_square_submatrix(matrix):\n if not matrix:\n return 0\n \n M = len(matrix)\n N = len(matrix[0])\n \n # Initialize dp table\n ... | trial_gpt4o_0 | {
"original_instruction": "You are given a matrix of characters that represents a grid, and each cell contains a lowercase English letter. Your goal is to find the largest square sub-matrix such that all the cells in that sub-matrix contain the same character. The side length of this largest square sub-matrix is your... | 0.585068 | Taco_33416 | C | [
"largest_square_submatrix",
"read_input_and_solve"
] | 2 | [
[
"read_input_and_solve",
"largest_square_submatrix"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 6ff62563effcbecf25559237c4b10bc478f4c491 | 58ec40f96ed8aeaaeab9b6111b95eb8d52929162 | |||
v1.0 | complete | Taco | Taco_27624_C | from typing import List
class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def deserialize(data: str) -> TreeNode:
""" Deserialize a serialized representation of a binary tree. Each value in the tree is a s... | from collections import deque
class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def deserialize(data):
if not data:
return None
nodes = data.split(',')
if nodes[0] == 'null':
return No... | from solution import process_test_cases, deserialize, level_order_traversal
def test_deserialize_and_level_order_traversal():
serialization = "1,2,null,null,3,4,null,null,5,null,null"
root = deserialize(serialization)
assert level_order_traversal(root) == [1, 2, 3, 4, 5]
serialization = "1,null,2,null... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n ... | trial_gpt4o_1 | {
"original_instruction": "Create a function that takes a string as input, which is a serialized representation of a binary tree, and reconstructs the binary tree. Each value in the tree is a single digit (0-9), and the serialization format follows preorder traversal where 'null' indicates a missing node.\n\nInput Fo... | 0.476839 | Taco_27624 | C | [
"deserialize",
"level_order_traversal",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"deserialize"
],
[
"process_test_cases",
"level_order_traversal"
]
] | 2 | [
"process_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 8fa71ecbe339fc4ebbf5dcbe0b052324d71d552a | 5c7ee979b92f36e7a29b86b6c9e0a3ec23023f44 | |||
v1.0 | complete | Taco | Taco_32383_C | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
else:
if root.val < key:
root.right = insert(root.right, key)
else:
root.left = ins... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
else:
if root.val < key:
root.right = insert(root.right, key)
else:
root.left = ins... | from solution import process_input
def test_example():
input_data = "2\n5 3\n5 3 8 2 4\n7 4\n10 5 1 7 40 50 8"
assert process_input(input_data) == [4, 8]
def test_single_node():
input_data = "1\n1 1\n5"
assert process_input(input_data) == [5]
def test_all_nodes_same():
input_data = "1\n5 3\n7 7 7... | [] | [
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):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert_node(root, key):\n if r... | trial_gpt4o_2 | {
"original_instruction": "Aditi is fascinated by Binary Search Trees (BST) and loves working on them. One day, her friend Vikram challenged her with an interesting problem. He gave her a list of integers and asked her to construct a BST out of it. Once the BST is constructed, she needs to find the k-th smallest elem... | 0.577952 | Taco_32383 | C | [
"insert",
"inorder_traversal",
"kth_smallest_element",
"find_kth_smallest_element",
"process_input"
] | 5 | [
[
"find_kth_smallest_element",
"insert"
],
[
"find_kth_smallest_element",
"kth_smallest_element"
],
[
"kth_smallest_element",
"inorder_traversal"
],
[
"process_input",
"find_kth_smallest_element"
]
] | 4 | [
"process_input"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b4c780f43785f416c22b190e9ebf83118414afc9 | 96f98fc763f17197c7ef542a0b21f65e94c33217 | |||
v1.0 | complete | Taco | Taco_33880_C | def process_input(data: List[str]) -> List[str]:
"""
Given a list of strings representing the input data, return a list of strings where each string is either 'yes' or 'no'
indicating whether the pairs of chemical formulas represent the same composition.
>>> process_input(["3", "H2O", "O1H2", "CH4", "... | from collections import defaultdict
import re
def parse_formula(formula):
"""
Parse the chemical formula into a dictionary of elements and their quantities.
"""
elements = defaultdict(int)
for elem, qty in re.findall(r'([A-Z][a-z]*)(\d*)', formula):
qty = int(qty) if qty else 1
elem... | import pytest
from solution import process_input
def test_formula_parsing():
assert process_input(["3", "H2O", "O1H2", "CH4", "C2H2", "H", "HH", "2", "O2", "O2", "N2", "N2O", "0"]) == ["yes", "no", "no", "yes", "no"]
def test_single_element():
assert process_input(["1", "H", "H2", "0"]) == ["no"]
assert p... | [
{
"docstring": "Parse the chemical formula into a dictionary of elements and their quantities.",
"function_declaration": "def parse_formula(formula):",
"function_name": "parse_formula",
"parameter_list": "(formula)"
},
{
"docstring": "Check if the two formulas have the same composition.",
... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\nfrom collections import defaultdict\n\ndef parse_formula(formula):\n \"\"\"\n Parse a chemical formula into a dictionary of element counts.\n \... | trial_gpt4o_2 | {
"original_instruction": "Alice is working on analyzing chemical compositions found in various substances. To help with her research, she needs a program that can determine if two given chemical formulas correspond to the same composition, even if the formulas are written differently. For simplicity, these chemical ... | 0.561427 | Taco_33880 | C | [
"parse_formula",
"is_same_composition",
"check_formula_pairs",
"process_input"
] | 4 | [
[
"check_formula_pairs",
"is_same_composition"
],
[
"is_same_composition",
"parse_formula"
],
[
"process_input",
"check_formula_pairs"
]
] | 3 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 58a3ae6536a4093fc2c9aa95dbbd91214ada4e4a | f8a9f6ba64a65e714fcd9c3d44141889bae3e48d | |||
v1.0 | complete | Taco | Taco_35156_C | def count_divisors(x: int) -> int:
"""
Returns the number of distinct divisors of x.
"""
<function implementation here>
def custom_sort(arr: List[int]) -> List[int]:
"""
Custom sort based on the count of divisors.
"""
<function implementation here>
def sort_index_cards(n: int, cards: ... | def count_divisors(x):
"""
Returns the number of distinct divisors of x.
"""
count = 0
for i in range(1, int(x ** 0.5) + 1):
if x % i == 0:
count += 1
if i != x // i:
count += 1
return count
def custom_sort(arr):
"""
Custom sort based on t... | from solution import sort_index_cards
def test_sort_index_cards_case1():
assert sort_index_cards(5, [2, 3, 4, 6, 5]) == [2, 3, 5, 4, 6]
def test_sort_index_cards_case2():
assert sort_index_cards(4, [12, 15, 10, 8]) == [8, 10, 15, 12]
def test_sort_index_cards_single_element():
assert sort_index_cards(1, ... | [
{
"docstring": "Returns the number of distinct divisors of x.",
"function_declaration": "def count_divisors(x):",
"function_name": "count_divisors",
"parameter_list": "(x)"
},
{
"docstring": "Custom sort based on the count of divisors.",
"function_declaration": "def custom_sort(arr):",
... | [
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 math\n\ndef num_divisors(n):\n \"\"\"\n Calculates the number of distinct divisors of a given integer n.\n \"\"\"\n count = 0\n for i in rang... | trial_gpt4o_1 | {
"original_instruction": "In a desk organizer, Anna has a set of index cards, each with a unique integer written on it. She loves sorting them efficiently using a custom sorting algorithm. The sorting algorithm she uses can be defined as follows: \n\nGiven an array of integers, the custom sort arranges the integers ... | 0.59877 | Taco_35156 | C | [
"count_divisors",
"custom_sort",
"sort_index_cards"
] | 3 | [
[
"custom_sort",
"count_divisors"
],
[
"sort_index_cards",
"custom_sort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 263e7d295eebe01c22a9ffa10216791e1b95f5c7 | 65a29ac00e56785261005839874f437efb93b9e6 | |||
v1.0 | complete | Taco | Taco_34163_C | def gcd(a: int, b: int) -> int:
"""
Compute the Greatest Common Divisor of a and b.
"""
def euler_totient(n: int) -> int:
"""
Compute Euler's Totient Function φ(n), which counts the number of positive integers up to n that are relatively prime to n.
>>> euler_totient(1) == 1
>>> euler_... | def gcd(a, b):
"""
Compute the Greatest Common Divisor of a and b.
"""
while b:
a, b = b, a % b
return a
def euler_totient(n):
"""
Compute Euler's Totient Function φ(n).
"""
if n == 1:
return 1
count = 0
for i in range(1, n + 1):
if gcd(n, i) == 1:
... | from solution import euler_totient
def test_euler_totient_basic():
assert euler_totient(1) == 1
assert euler_totient(2) == 1
assert euler_totient(3) == 2
assert euler_totient(4) == 2
assert euler_totient(5) == 4
def test_euler_totient_larger_numbers():
assert euler_totient(10) == 4
assert ... | [
{
"docstring": "Compute the Greatest Common Divisor of a and b.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Compute Euler's Totient Function φ(n).",
"function_declaration": "def euler_totient(n):",
"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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef euler_totient(n):\n count = 0\n for i in range(1, n + 1):\n if gcd(i, n) ==... | trial_gpt4o_2 | {
"original_instruction": "# Task\nEuler's Totient Function, φ(n), is an important function in number theory. It counts the number of positive integers up to n that are relatively prime to n. Two numbers are relatively prime if their greatest common divisor (gcd) is 1. Your task is to compute φ(n) for a given n.\n\n#... | 0.712869 | Taco_34163 | C | [
"gcd",
"euler_totient"
] | 2 | [
[
"euler_totient",
"gcd"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b31fac8f46c6f91c017fbec23e96d7647720a2ae | e4e9f88ff69b2a1b66b116fd4f55ef12344b7d01 | |||
v1.0 | complete | Taco | Taco_32046_C | def count_distinct_subarrays(arr, k):
"""
Counts the number of distinct subarrays of length k in the given array.
:param arr: List of integers
:param k: Length of subarrays to consider
:return: Number of distinct subarrays of length k
"""
pass # Implement the function
def process_quer... | def count_distinct_subarrays(arr, k):
"""
Counts the number of distinct subarrays of length k in the given array.
:param arr: List of integers
:param k: Length of subarrays to consider
:return: Number of distinct subarrays of length k
"""
subarrays = set()
for i in range(len(arr) - ... | from solution import solve
def test_single_query():
test_cases = [
([1, 2, 1, 3, 2], [3])
]
assert solve(test_cases) == [[3]]
def test_multiple_queries():
test_cases = [
([1, 2, 1, 3, 2], [3, 2])
]
assert solve(test_cases) == [[3, 4]]
def test_duplicate_elements():
test_ca... | [
{
"docstring": "Counts the number of distinct subarrays of length k in the given array.\n\n:param arr: List of integers\n:param k: Length of subarrays to consider\n:return: Number of distinct subarrays of length k",
"function_declaration": "def count_distinct_subarrays(arr, k):",
"function_name": "count... | [
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 distinct_subarrays(n, array, queries):\n results = []\n for k in queries:\n subarrays = set()\n for i in range(n - k + 1):\n sub... | trial_gpt4o_2 | {
"original_instruction": "You are given an array of n integers and a series of m queries. Each query asks for the number of distinct subarrays of the given length k that can be formed from the array. A subarray is a contiguous part of an array.\n\nFor example, in the array `[1, 2, 1, 3, 2]` and with the query `k = 3... | 0.601836 | Taco_32046 | C | [
"count_distinct_subarrays",
"process_queries",
"solve"
] | 3 | [
[
"process_queries",
"count_distinct_subarrays"
],
[
"solve",
"process_queries"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 9e962e3329761df3011da8ee478a1f05fa4d8619 | 268bbaf05a9d8f3acd4d90c26c2d2435e0c2bed0 | |||
v1.0 | complete | Taco | Taco_35620_C | def is_prime(num: int) -> bool:
""" Determine if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(5)
True
"""
def find_primes_in_range(a: int, b: int) -> list:
""" Find all unique prime numbers in the range [a, b] inclu... | 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 find_primes_in_range(a, b)... | from solution import is_prime, find_primes_in_range, process_input
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... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def find_primes_in_range(a, b):",
"function_name": "find_primes_in_range",
"parameter_list": "(a, b)"
},
... | [
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_1 | {
"original_instruction": "You are given an integer `n` and `n` pairs of integers. For each pair `(a_i, b_i)`, you should print all unique prime numbers that are in the range `[a_i, b_i]` inclusive. If no prime numbers exist in that range, print `-1` for that pair.\n\n### Input\n- The first line contains a single int... | 0.671744 | Taco_35620 | C | [
"is_prime",
"find_primes_in_range",
"process_input"
] | 3 | [
[
"find_primes_in_range",
"is_prime"
],
[
"process_input",
"find_primes_in_range"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | b29c56f4e059e89c7c347ba72cd0834d80cd33b2 | bfe473fda5aef1d7350eb3389362f7c14bced98e | |||
v1.0 | complete | Taco | Taco_38265_C | def is_palindromic(number: int) -> bool:
"""
Returns True if the number is palindromic, False otherwise.
>>> is_palindromic(1)
True
>>> is_palindromic(121)
True
>>> is_palindromic(123)
False
"""
pass
def count_palindromic_numbers(L: int, R: int) -> int:
"""
Returns the ... | def is_palindromic(number):
"""
Returns True if the number is palindromic, False otherwise.
"""
str_num = str(number)
return str_num == str_num[::-1]
def count_palindromic_numbers(L, R):
"""
Returns the count of palindromic numbers in the range [L, R].
"""
count = 0
for num in r... | from solution import is_palindromic, count_palindromic_numbers, solve
def test_is_palindromic():
assert is_palindromic(1) == True
assert is_palindromic(121) == True
assert is_palindromic(12321) == True
assert is_palindromic(123) == False
def test_count_palindromic_numbers_small_ranges():
assert co... | [
{
"docstring": "Returns True if the number is palindromic, False otherwise.",
"function_declaration": "def is_palindromic(number):",
"function_name": "is_palindromic",
"parameter_list": "(number)"
},
{
"docstring": "Returns the count of palindromic numbers in the range [L, R].",
"functio... | [
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 count_palindromic_numbers(L, R):\n \"\"\"\n Returns the count of palindromic numbers in the range [L, R].\n \"\"\"\n def is_palindrome(n):\n ... | trial_gpt4o_4 | {
"original_instruction": "Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.\n\nChef has recently become interested in palindromic numbers. A number is called palindromic if it reads the same backwards as forwards. Chef wants to know how many palindromic numbers exist within a given range ... | 0.735191 | Taco_38265 | C | [
"is_palindromic",
"count_palindromic_numbers",
"solve"
] | 3 | [
[
"count_palindromic_numbers",
"is_palindromic"
],
[
"solve",
"count_palindromic_numbers"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 928ef5cdfa3bc7cc92ac235f2e5d4e3f12ac90ad | 3058234b8032ffdb1c8d95076faabfce6b11ce33 | |||
v1.0 | complete | Taco | Taco_43818_C | def solve(N: int, M: int, grid: List[str]) -> int:
""" Determine the minimum number of steps required to move from the entrance to the exit.
>>> solve(3, 3, ['000', '010', '000'])
4
>>> solve(3, 3, ['010', '111', '000'])
-1
""" | from collections import deque
def min_steps_to_exit(grid):
"""
Determine the minimum number of steps required to move from the entrance to the exit.
"""
N = len(grid)
M = len(grid[0])
# Check if the entrance or exit is a wall
if grid[0][0] == '1' or grid[N-1][M-1] == '1':
retur... | from solution import solve
def test_solve_example_1():
N = 3
M = 3
grid = [
'000',
'010',
'000'
]
assert solve(N, M, grid) == 4
def test_solve_example_2():
N = 3
M = 3
grid = [
'010',
'111',
'000'
]
assert solve(N, M, grid) == -1
... | [
{
"docstring": "Determine the minimum number of steps required to move from the entrance to the exit.",
"function_declaration": "def min_steps_to_exit(grid):",
"function_name": "min_steps_to_exit",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(N, M... | [
0,
0,
0,
0,
0,
0,
0,
1,
1,
0
] | 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 deque\n\ndef min_steps_to_exit(grid):\n N = len(grid)\n M = len(grid[0])\n \n if grid[0][0] == '1' or grid[N-1][M-1] == '1':\n ... | trial_gpt4o_8 | {
"original_instruction": "You are given a rectangular grid of N x M cells. Each cell of the grid contains either a '0' (an empty cell) or a '1' (a wall). The grid has exactly one entrance at the top-left corner (cell (1,1)) and exactly one exit at the bottom-right corner (cell (N, M)). You are allowed to move up, do... | 0.605897 | Taco_43818 | C | [
"min_steps_to_exit",
"solve"
] | 2 | [
[
"solve",
"min_steps_to_exit"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7de2976709d0079a267031d7086e2ed5329a0293 | 46a0a495fac18f03a5193061385d65b3d32db1a7 | |||
v1.0 | complete | Taco | Taco_31680_C | import heapq
from typing import List
def add_edge(graph, a, b, d):
""" Adds or updates a direct connection with a specified latency between two hubs. """
if a not in graph:
graph[a] = {}
if b not in graph:
graph[b] = {}
graph[a][b] = d
graph[b][a] = d
def dijkstra(graph, start):
... | import heapq
def add_edge(graph, a, b, d):
if a not in graph:
graph[a] = {}
if b not in graph:
graph[b] = {}
graph[a][b] = d
graph[b][a] = d
def dijkstra(graph, start):
distances = {node: float('inf') for node in graph}
distances[start] = 0
priority_queue = [(0, start)]
... | import pytest
from solution import process_operations
def test_process_operations():
n = 5
q = 7
operations = [
"ADD 1 2 10",
"ADD 2 3 5",
"ADD 3 4 7",
"QUERY 1 4",
"ADD 1 4 15",
"ADD 4 5 1",
"QUERY 1 5"
]
expected = [22, 16]
assert proces... | [
{
"docstring": null,
"function_declaration": "def add_edge(graph, a, b, d):",
"function_name": "add_edge",
"parameter_list": "(graph, a, b, d)"
},
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start):",
"function_name": "dijkstra",
"parameter_list": "(graph, s... | [
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\n\nclass Network:\n def __init__(self, n):\n self.n = n\n self.adj = {i: {} for i in range(1, n+1)}\n \n def add(self, a, b, d)... | trial_gpt4o_2 | {
"original_instruction": "A telecommunications company is setting up a new routing system for its network of hubs. Each node in the network represents a hub and each edge represents a direct connection between two hubs with a specified latency. The company wants to ensure that there is a way to quickly determine the... | 0.53933 | Taco_31680 | C | [
"add_edge",
"dijkstra",
"process_operations"
] | 3 | [
[
"process_operations",
"add_edge"
],
[
"process_operations",
"dijkstra"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 2b34d18f234ce9462daa76a9b105140c78b03f1b | 380e3ac103089a0bd4b8c0cad0139867dd88b9ed | |||
v1.0 | complete | Taco | Taco_31935_C | def kruskal_mst(V, edges):
"""
Returns the total length of the roads in the minimum spanning tree using Kruskal's algorithm.
>>> kruskal_mst(4, [(1, 2, 10), (1, 3, 6), (1, 4, 5), (2, 3, 4), (3, 4, 7)])
15
>>> kruskal_mst(3, [(1, 2, 3), (2, 3, 5), (1, 3, 4)])
7
"""
pass
def solve_ms... | def kruskal_mst(V, edges):
"""
Returns the total length of the roads in the minimum spanning tree using Kruskal's algorithm.
"""
# Sort edges by ascending edge weight
edges.sort(key=lambda x: x[2])
parent = list(range(V + 1))
rank = [0] * (V + 1)
def find(x):
if parent[... | def test_kruskal_mst():
assert kruskal_mst(4, [(1, 2, 10), (1, 3, 6), (1, 4, 5), (2, 3, 4), (3, 4, 7)]) == 15
assert kruskal_mst(3, [(1, 2, 3), (2, 3, 5), (1, 3, 4)]) == 7
def test_solve_mst_cases():
test_cases = [
(4, 5, [(1, 2, 10), (1, 3, 6), (1, 4, 5), (2, 3, 4), (3, 4, 7)]),
(3, 3, [(1... | [
{
"docstring": "Returns the total length of the roads in the minimum spanning tree using Kruskal's algorithm.",
"function_declaration": "def kruskal_mst(V, edges):",
"function_name": "kruskal_mst",
"parameter_list": "(V, edges)"
},
{
"docstring": null,
"function_declaration": "def solve_... | [
0,
0,
0,
0,
0,
0,
0,
1,
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 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_8 | {
"original_instruction": "In a land far away, there is a unique kingdom with exactly one road connecting each pair of villages. The kingdom is represented as an undirected graph with V villages and E roads, where each road has a length associated with it.\n\nThe king wishes to improve the travel time by reducing the... | 0.604736 | Taco_31935 | C | [
"kruskal_mst",
"solve_mst_cases",
"parse_input",
"main"
] | 4 | [
[
"solve_mst_cases",
"kruskal_mst"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 09613473b2c3c467fd0dcc899236513eaa065dcb | 624e9d35a507de764caa6b045cca2fa3550dedd7 | |||
v1.0 | complete | Taco | Taco_32614_C | def count_distinct_paths(n: int, m: int, grid: List[List[str]]) -> int:
""" Compute the number of distinct paths from the top-left corner to the bottom-right corner of a grid, while avoiding obstacles.
A cell containing a '1' represents an obstacle and cannot be traversed, whereas a cell containing a '0' i... | def num_paths(grid):
n = len(grid)
m = len(grid[0])
if grid[0][0] == '1' or grid[n-1][m-1] == '1':
return 0
dp = [[0] * m for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == '1':
dp[i][j] = 0
... | from solution import count_distinct_paths
def test_no_obstacles():
grid = [['0', '0', '0'],
['0', '0', '0'],
['0', '0', '0']]
assert count_distinct_paths(3, 3, grid) == 6
def test_one_obstacle():
grid = [['0', '0', '0'],
['0', '1', '0'],
['0', '0', '0']]
... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid):",
"function_name": "num_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def count_distinct_paths(n, m, grid):",
"function_name": "count_distinct_paths",
"parameter_list": "(n, m... | [
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 distinct_paths(n, m, grid):\n if grid[0][0] == '1' or grid[n-1][m-1] == '1':\n return 0\n \n dp = [[0] * m for _ in range(n)]\n dp[0][0]... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular grid of size n x m, where each cell in the grid can either be empty or contain an obstacle. Winnie-the-Pooh starts at the top-left corner of the grid (cell (1, 1)) and wants to traverse to the bottom-right corner of the grid (cell (n, m)). Winnie-the-Pooh can onl... | 0.70569 | Taco_32614 | C | [
"num_paths",
"count_distinct_paths"
] | 2 | [
[
"count_distinct_paths",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7adb531766ac02f319a6f7385cb810849c18ba9a | 4099ff56987f68511e748166546bd00ddbf8d6b6 | |||
v1.0 | complete | Taco | Taco_27163_C | def parse_input(input_str: str) -> List[List[Tuple[int, int, int]]]:
"""Parse the input string into a list of datasets.
Each dataset is represented as a list of (N, M), (a1, b1, s1), ..., (aM, bM, sM).
Args:
input_str (str): The input string.
Returns:
List[List[Tuple[int, int, int]]]: The pars... | import heapq
def dijkstra(graph, N):
max_security = [float('inf')] * (N + 1)
max_security[1] = 0
pq = [(0, 1)]
while pq:
current_security, u = heapq.heappop(pq)
for v, security in graph[u]:
max_security_level = max(current_security, security)
if max... | def test_parse_input():
input_str = "6 7\n1 2 3\n1 3 4\n2 4 2\n3 4 6\n4 5 1\n5 6 3\n4 6 4\n4 4\n1 2 5\n1 3 4\n2 4 1\n3 4 2\n0 0\n"
expected_output = [
[(6, 7), (1, 2, 3), (1, 3, 4), (2, 4, 2), (3, 4, 6), (4, 5, 1), (5, 6, 3), (4, 6, 4)],
[(4, 4), (1, 2, 5), (1, 3, 4), (2, 4, 1), (3, 4, 2)],
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, N):",
"function_name": "dijkstra",
"parameter_list": "(graph, N)"
},
{
"docstring": null,
"function_declaration": "def find_safest_route(datasets):",
"function_name": "find_safest_route",
"parameter_list": "(datase... | [
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, node):\n if parent[node] != node:\n parent[node] = find(parent, parent[node])\n return parent[node]\n\ndef union(parent, rank, u, v):... | trial_gpt4o_1 | {
"original_instruction": "Dr. Victor is a scientist who has a laboratory with a unique security system. His lab is located in a facility having multiple rooms connected by a series of passageways. Each passageway has a different security level which represents the risk associated with passing through it. Dr. Victor ... | 0.580231 | Taco_27163 | C | [
"dijkstra",
"find_safest_route",
"parse_input",
"main"
] | 4 | [
[
"find_safest_route",
"dijkstra"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | fdb9f585c2f0f4a173bd36c41ec23b8650d94bd9 | 4022fe3546e84e33c5ec6ccb9de37fcdbe41ad58 | |||
v1.0 | complete | Taco | Taco_38525_C | from collections import deque
from typing import List
def get_shortest_path_length(n: int, m: int, grid: List[str]) -> int:
""" Find the length of the shortest path that Nikita can take to reach the exit of the maze.
If there's no possible way to reach the exit, return -1.
Args:
- n (int): Number ... | from collections import deque
def shortest_path(grid, start, end):
rows, cols = len(grid), len(grid[0])
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
queue = deque([(start[0], start[1], 0)]) # (row, col, distance)
visited = set()
visited.add((start[0], start[1]))
while queue:
row, c... | from solution import get_shortest_path_length
def test_shortest_path_basic():
grid = [
"s#...",
".#.#.",
".#...",
".###.",
"...e."
]
assert get_shortest_path_length(5, 5, grid) == 7
def test_no_path():
grid = [
"s#.",
"###",
"..e"
]
... | [
{
"docstring": null,
"function_declaration": "def shortest_path(grid, start, end):",
"function_name": "shortest_path",
"parameter_list": "(grid, start, end)"
},
{
"docstring": null,
"function_declaration": "def get_shortest_path_length(n, m, grid):",
"function_name": "get_shortest_pa... | [
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": "from collections import deque\n\ndef shortest_path_in_maze(N, M, grid):\n def is_valid_move(x, y):\n return 0 <= x < N and 0 <= y < M and grid[x][y] != '... | trial_gpt4o_3 | {
"original_instruction": "Nikita is trying to escape from a maze, which can be represented as a grid of N rows and M columns. Some cells in the grid are blocked, and others are not. Nikita can move up, down, left, or right, but cannot move diagonally or through blocked cells. She needs to find the shortest path from... | 0.652817 | Taco_38525 | C | [
"shortest_path",
"get_shortest_path_length"
] | 2 | [
[
"get_shortest_path_length",
"shortest_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5412700ef1a90d032eda98f0590559e8d0540781 | 1571898d58067cf510a42189f1c8fc1d593faaaf | |||
v1.0 | complete | Taco | Taco_35043_C | import math
from typing import List, Tuple
def calculate_distance(x1: int, y1: int, x2: int, y2: int) -> float:
"""
Calculate Euclidean distance between two points (x1, y1) and (x2, y2).
Args:
x1 (int): x-coordinate of the first point.
y1 (int): y-coordinate of the first point.
x2 (int): x-coor... | import math
def calculate_distance(x1, y1, x2, y2):
"""
Calculate Euclidean distance between two points (x1, y1) and (x2, y2).
"""
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
def minimum_total_travel_distance(n, m, warehouses, tasks):
"""
Calculate the total minimum travel distance for a... | def test_calculate_distance():
assert math.isclose(calculate_distance(0, 0, 3, 4), 5.0)
assert math.isclose(calculate_distance(1, 1, 4, 5), 5.0)
assert math.isclose(calculate_distance(-1, -1, -4, -5), 5.0)
def test_minimum_total_travel_distance():
n = 3
m = 3
warehouses = [(0, 0), (2, 2), (5, 5... | [
{
"docstring": "Calculate Euclidean distance between two points (x1, y1) and (x2, y2).",
"function_declaration": "def calculate_distance(x1, y1, x2, y2):",
"function_name": "calculate_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Calculate the total minimum travel distan... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_total_travel_distance(n, m, warehouses, deliveries):\n def distance(x1, y1, x2, y2):\n return abs(x1 - x2) + abs(y1 - y2)\n \n total_distan... | trial_gpt4o_1 | {
"original_instruction": "You are tasked with developing a logistics program for a small-scale delivery company. The company has `n` warehouses, each located at unique coordinates on a 2D plane, and `m` delivery tasks. Each delivery task involves transporting goods from one warehouse to another.\n\nThe company wants... | 0.59342 | Taco_35043 | C | [
"calculate_distance",
"minimum_total_travel_distance",
"logistics_min_travel_distance"
] | 3 | [
[
"logistics_min_travel_distance",
"minimum_total_travel_distance"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0cb144bc41dd67260bc3dbeff112d80f34be5789 | 905b526ae6dc61f074c40ba5fbefbc4c992533e9 | |||
v1.0 | complete | Taco | Taco_39545_C | from typing import List
def longest_increasing_path(matrix: List[List[int]]) -> int:
"""
Determine the length of the longest strictly increasing path in a matrix.
Args:
matrix (List[List[int]]): A 2D list of integers representing the heights of cells in the matrix.
Returns:
int: The ... | def longest_increasing_path(matrix):
if not matrix or not matrix[0]:
return 0
n, m = len(matrix), len(matrix[0])
dp = [[-1] * m for _ in range(n)]
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
def dfs(x, y):
if dp[x][y] != -1:
return dp[x][y]
max_path... | from solution import longest_increasing_path
def test_case_1():
matrix = [
[9, 9, 4],
[6, 6, 8],
[2, 1, 1]
]
assert longest_increasing_path(matrix) == 4 # Path: 1 -> 2 -> 6 -> 9
def test_case_2():
matrix = [
[1, 2, 3],
[6, 5, 4],
[7, 8, 9]
]
ass... | [
{
"docstring": null,
"function_declaration": "def longest_increasing_path(matrix):",
"function_name": "longest_increasing_path",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def read_and_process_input():",
"function_name": "read_and_process_input",
... | [
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 longest_increasing_path(grid):\n if not grid:\n return 0\n n, m = len(grid), len(grid[0])\n dp = [[-1] * m for _ in range(n)]\n\n def dfs(x,... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid with $\\boldsymbol{n}$ rows and $\\boldsymbol{m}$ columns. Each cell in the grid has a value representing the height at that cell. You need to determine the length of the longest strictly increasing path starting from any cell in the grid. A strictly increasing path is ... | 0.694513 | Taco_39545 | C | [
"longest_increasing_path",
"read_and_process_input"
] | 2 | [
[
"read_and_process_input",
"longest_increasing_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 156064e693cd36c85ec9bc7c2820c8a44934976b | b327d4a3e25d3c79ce0d67471c4d732f0c2f0a4e | |||
v1.0 | complete | Taco | Taco_44041_C | def are_anagrams(str1: str, str2: str) -> bool:
""" Check if two strings are anagrams.
>>> are_anagrams("listen", "silent")
True
>>> are_anagrams("apple", "pale")
False
"""
def check_anagram_pairs(pairs: List[Tuple[str, str]]) -> List[str]:
""" Given a list of pairs of strings, determine if... | def are_anagrams(str1, str2):
"""
Check if two strings are anagrams.
"""
return sorted(str1) == sorted(str2)
def check_anagram_pairs(pairs):
"""
Given a list of pairs of strings, determine if each pair are anagrams.
"""
results = []
for str1, str2 in pairs:
if are_anagrams(s... | from solution import are_anagrams, check_anagram_pairs
def test_are_anagrams_yes():
assert are_anagrams("listen", "silent") == True
assert are_anagrams("triangle", "integral") == True
def test_are_anagrams_no():
assert are_anagrams("apple", "pale") == False
assert are_anagrams("hello", "world") == Fal... | [
{
"docstring": "Check if two strings are anagrams.",
"function_declaration": "def are_anagrams(str1, str2):",
"function_name": "are_anagrams",
"parameter_list": "(str1, str2)"
},
{
"docstring": "Given a list of pairs of strings, determine if each pair are anagrams.",
"function_declaratio... | [
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 are_anagrams(a, b):\n \"\"\"\n Check if the two strings a and b are anagrams of each other.\n \"\"\"\n return sorted(a) == sorted(b)\n\ndef check_a... | trial_gpt4o_2 | {
"original_instruction": "An earthquake shook the city of Anagramland, causing some string mix-ups! You have a list of pairs of strings; each pair represents two possible anagrams. Your task is to determine if each pair of strings can be rearranged to form an exact match of one another. Write a function to check the... | 0.631997 | Taco_44041 | C | [
"are_anagrams",
"check_anagram_pairs"
] | 2 | [
[
"check_anagram_pairs",
"are_anagrams"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a91c3e5b8ef0574787eff7ebcceba84e37f70bf8 | b6a108d2a667272f843cc46e3a8c4649b5d6b2a7 | |||
v1.0 | complete | Taco | Taco_39129_C | def countInversions(arr):
""" Count the number of inversions in an array using a modified merge sort algorithm.
An inversion is a pair (arr[i], arr[j]) such that i < j and arr[i] > arr[j].
Args:
arr: List[int] - an array of integers to count inversions
Returns:
int - the number of inversion... | def countInversions(arr):
n = len(arr)
temp_arr = [0]*n
return _mergeSort(arr, temp_arr, 0, n-1)
def _mergeSort(arr, temp_arr, left, right):
inv_count = 0
if left < right:
mid = (left + right)//2
inv_count += _mergeSort(arr, temp_arr, left, mid)
inv_count += _mergeSort(arr... | from solution import countInversions
def test_countInversions_sample():
arr = [2, 4, 1, 3, 5]
assert countInversions(arr) == 3
def test_countInversions_sorted():
arr = [1, 2, 3, 4, 5]
assert countInversions(arr) == 0
def test_countInversions_reverse():
arr = [5, 4, 3, 2, 1]
assert countInvers... | [
{
"docstring": null,
"function_declaration": "def countInversions(arr):",
"function_name": "countInversions",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def _mergeSort(arr, temp_arr, left, right):",
"function_name": "_mergeSort",
"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 countInversions(arr):\n def merge_and_count(arr, temp_arr, left, mid, right):\n i = left # Starting index for left subarray\n j = mid + 1 #... | trial_gpt4o_2 | {
"original_instruction": "About Sorting and Searching Algorithms\n\nThis set of challenges focuses on understanding and implementing various sorting and searching algorithms that are essential in computer science. As you work through these problems, you'll not only solidify your understanding of these concepts but a... | 0.745112 | Taco_39129 | C | [
"countInversions",
"_mergeSort",
"_merge"
] | 3 | [
[
"_mergeSort",
"_merge"
],
[
"countInversions",
"_mergeSort"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | b7548c92943131fd61007ca6d4c2808fd1facc2e | e6582fe3d1da52d39bb3de40dae8c018c74ed18c | |||
v1.0 | complete | Taco | Taco_40214_C | from typing import List
def find_primes(arr: List[int]) -> List[int]:
""" Given an array of integers, return an array containing only the prime numbers
from the original array, in ascending order.
>>> find_primes([3, 12, 5, 16, 7, 11])
[3, 5, 7, 11]
>>> find_primes([4, 6, 8, 10, 12])
[]
... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
return False
return True
def find_primes(arr):
primes = [x for x in arr if is_prime(x)]
return sort... | from solution import find_primes
def test_find_primes_example():
assert find_primes([3, 12, 5, 16, 7, 11]) == [3, 5, 7, 11]
def test_find_primes_no_primes():
assert find_primes([4, 6, 8, 10, 12]) == []
def test_find_primes_all_primes():
assert find_primes([2, 3, 5, 7, 11, 13]) == [2, 3, 5, 7, 11, 13]
de... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def find_primes(arr):",
"function_name": "find_primes",
"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(n):\n \"\"\"\n Helper function to check if a number is a prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n retur... | trial_gpt4o_2 | {
"original_instruction": "Given an array of integers, return an array containing only the prime numbers from the original array, in ascending order.\n\nFor example, considering the input array `[3, 12, 5, 16, 7, 11]`, the result would be `[3, 5, 7, 11]`.\n\n`find_primes([3, 12, 5, 16, 7, 11]) = [3, 5, 7, 11]`\n\nWri... | 0.728727 | Taco_40214 | C | [
"is_prime",
"find_primes"
] | 2 | [
[
"find_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17b7295487884e7f75c1042107b5ee9cb721195e | 3e54db4274e5154fc9473661ecab3119943c366e | |||
v1.0 | complete | Taco | Taco_32462_C | from typing import List
def is_valid_knight_move(start: str, end: str) -> bool:
"""
Determines if a move from start position to end position is a valid knight's move on a chessboard.
"""
# Mapping columns to indices
col_to_index = {chr(i + ord('a')): i for i in range(8)}
row_to_index = {str(i +... | def is_valid_knight_move(start, end):
"""
Determines if a move from start position to end position is a valid knight's move on a chessboard.
"""
# Mapping columns to indices
col_to_index = {chr(i + ord('a')): i for i in range(8)}
row_to_index = {str(i + 1): i for i in range(8)}
start_co... | from solution import check_moves
def test_sample_moves():
moves = ["a1->b3", "a1->c2", "h8->g6", "b1->c2"]
assert check_moves(moves) == ["VALID", "VALID", "VALID", "INVALID"]
def test_all_valid_moves():
moves = ["a1->c2", "c2->a3", "f3->g5", "h8->f7"]
assert check_moves(moves) == ["VALID", "VALID", "V... | [
{
"docstring": "Determines if a move from start position to end position is a valid knight's move on a chessboard.",
"function_declaration": "def is_valid_knight_move(start, end):",
"function_name": "is_valid_knight_move",
"parameter_list": "(start, end)"
},
{
"docstring": null,
"functio... | [
0,
0,
0,
0,
1,
1,
1,
1,
0
] | 4 | medium | 0.444 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_valid_knight_move(start, end):\n \"\"\"\n Given a start and end position representing a knight's move, \n determine if it ... | trial_gpt4o_8 | {
"original_instruction": "Marco and Polo are designing a sequence of steps on a chessboard. The chessboard is an 8x8 grid, and each position on the board can be represented using standard chess notation (e.g., \"a1\", \"h8\"). Marco starts the knight at the \"a1\" position and provides a series of moves for the knig... | 0.680554 | Taco_32462 | C | [
"is_valid_knight_move",
"check_moves"
] | 2 | [
[
"check_moves",
"is_valid_knight_move"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 4b60daaa76ef787f4aa47ff6d1a0bf7292fbc020 | fd8ed2a1e4c5f17ac5dab1caf58679f649a43bad | |||
v1.0 | complete | Taco | Taco_38853_C | def calculate_prefix_sum(matrix):
""" Calculates and returns the prefix sum matrix for the given matrix """
pass
def sum_query(prefix_sum, r1, c1, r2, c2):
""" Calculates the sum of the submatrix defined by (r1, c1) to (r2, c2) """
pass
def solve(T, test_cases):
""" Solves the submatrix sum querie... | def calculate_prefix_sum(matrix):
"""
Calculates and returns the prefix sum matrix for the given matrix.
"""
N = len(matrix)
M = len(matrix[0])
prefix_sum = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, M + 1):
prefix_sum[i][j] = (... | import pytest
from solution import solve
def test_sample_input_1():
T = 1
test_cases = [
{
'N': 3,
'M': 3,
'matrix': [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
],
'Q': 2,
'queries': [
... | [
{
"docstring": "Calculates and returns the prefix sum matrix for the given matrix.",
"function_declaration": "def calculate_prefix_sum(matrix):",
"function_name": "calculate_prefix_sum",
"parameter_list": "(matrix)"
},
{
"docstring": "Calculates the sum of the submatrix defined by (r1, c1) 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 compute_prefix_sums(matrix, N, M):\n prefix_sums = [[0] * (M + 1) for _ in range(N + 1)]\n for i in range(1, N + 1):\n for j in range(1, M + 1):\n... | trial_gpt4o_2 | {
"original_instruction": "You are given a matrix with $N$ rows and $M$ columns. You need to answer $Q$ queries about the sum of values within submatrices.\n\nFor each query, you should calculate the sum of values in the submatrix starting from $(r1, c1)$ to $(r2, c2)$ (inclusive).\n\n------ Input ------\nThe first ... | 0.537964 | Taco_38853 | C | [
"calculate_prefix_sum",
"sum_query",
"solve"
] | 3 | [
[
"solve",
"calculate_prefix_sum"
],
[
"solve",
"sum_query"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 0cb13b6c1766d59b57358bf0b1a5ab149c485c6a | e944019a56c5ce2d1fd89a19878ae9b6e4b4f218 | |||
v1.0 | complete | Taco | Taco_38746_C | def maximum_sum_submatrix(matrix):
""" Given an integer matrix M of size N x N, find the maximum sum of elements in any submatrix of M.
>>> maximum_sum_submatrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
45
>>> maximum_sum_submatrix([[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]])
-1
>>> maxi... | def maximum_sum_submatrix(matrix):
def kadane(nums):
max_sum = current_sum = nums[0]
for num in nums[1:]:
current_sum = max(num, current_sum + num)
max_sum = max(max_sum, current_sum)
return max_sum
N = len(matrix)
max_sum = float('-inf')
for lef... | from solution import parse_input, process_test_cases, process_output
def test_maximum_sum_submatrix():
input_string = "1\n3\n1 2 3\n4 5 6\n7 8 9\n"
test_cases = parse_input(input_string)
result = process_test_cases(test_cases)
output = process_output(result)
assert output == "45"
def test_maximum_... | [
{
"docstring": null,
"function_declaration": "def maximum_sum_submatrix(matrix):",
"function_name": "maximum_sum_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def process_test_cases(test_cases):",
"function_name": "process_test_cases",
... | [
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 maximum_sum_submatrix(matrix):\n def kadane(array):\n max_sum = float('-inf')\n current_sum = 0\n for x in array:\n current_... | trial_gpt4o_2 | {
"original_instruction": "Given an integer matrix `M` of size `N x N`, you need to find the maximum sum of elements in any submatrix of `M`.\n\nA submatrix of `M` is a matrix that is formed by deleting several (possibly zero) rows from the top and bottom and several (possibly zero) columns from the left and right.\n... | 0.605089 | Taco_38746 | C | [
"maximum_sum_submatrix",
"process_test_cases",
"parse_input",
"process_output"
] | 4 | [
[
"process_test_cases",
"maximum_sum_submatrix"
]
] | 1 | [
"process_test_cases",
"parse_input"
] | false | [] | false | pytest | true | [] | true | 21adbd6cf69382a82ca1a5467a8e1dc7d8ea0e56 | 3aa9edb02fa77ebb3aeefa37333a9849c8bc9f99 | |||
v1.0 | complete | Taco | Taco_33099_C | def create_secret_santa_pairings(n: int, participants: List[str], last_year_pairs: List[str]) -> List[Tuple[str, str]]:
""" Determine a valid new Secret Santa drawing that satisfies the given conditions.
>>> create_secret_santa_pairings(4, ["Alice", "Bob", "Charlie", "Dave"], ["Alice Bob", "Bob Charlie", "Charl... | import random
def secret_santa(n, participants, last_year_pairs):
# Convert last year pairs into a dictionary for fast lookup
last_year_dict = {pair[0]: pair[1] for pair in last_year_pairs}
# Initial constraint where no one should get themselves
current_year = {name: None for name in participants}
... | def test_secret_santa_base_case():
n = 4
participants = ["Alice", "Bob", "Charlie", "Dave"]
last_year_pairs = ["Alice Bob", "Bob Charlie", "Charlie Dave", "Dave Alice"]
result = create_secret_santa_pairings(n, participants, last_year_pairs)
# Convert the results to a dictionary for easy ve... | [
{
"docstring": null,
"function_declaration": "def secret_santa(n, participants, last_year_pairs):",
"function_name": "secret_santa",
"parameter_list": "(n, participants, last_year_pairs)"
},
{
"docstring": null,
"function_declaration": "def create_secret_santa_pairings(n, participants, l... | [
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 random\n\ndef secret_santa(participants, last_year_pairs):\n \"\"\"\n Generates a new Secret Santa drawing that ensures no one draws their own name\n ... | trial_gpt4o_1 | {
"original_instruction": "### Secret Santa Code:\n\nEvery year, the employees of a company participate in a Secret Santa gift exchange. Each participant must draw a name to determine who they will give a gift to. The company wants to ensure that each year, no one draws their own name, and that the same person doesn'... | 0.55972 | Taco_33099 | C | [
"secret_santa",
"create_secret_santa_pairings"
] | 2 | [
[
"create_secret_santa_pairings",
"secret_santa"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 66f17fe03c6f63abab61f25ffa8740b9aad16ecb | 8fc7072e149090fd44cf976fe23443e206f2fb76 | |||
v1.0 | complete | Taco | Taco_43522_C | def largest_rectangle(grid):
""" Determines the area of the largest rectangular park that can be built in the city grid.
>>> largest_rectangle([['1', '0', '1', '0'], ['1', '0', '0', '1'], ['1', '1', '1', '0'], ['0', '0', '0', '0']])
4
>>> largest_rectangle([['1', '1'], ['1', '1']])
0
>>> largest... | def max_histogram_area(heights):
stack = []
max_area = 0
index = 0
while index < len(heights):
if not stack or heights[stack[-1]] <= heights[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (heights[top_of... | import pytest
from solution import largest_rectangle
def test_example_case():
grid = [
['1', '0', '1', '0'],
['1', '0', '0', '1'],
['1', '1', '1', '0'],
['0', '0', '0', '0']
]
assert largest_rectangle(grid) == 4
def test_all_buildings():
grid = [
['1', '1'],
... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(heights):",
"function_name": "max_histogram_area",
"parameter_list": "(heights)"
},
{
"docstring": null,
"function_declaration": "def largest_rectangle(grid):",
"function_name": "largest_rectangle",
"parameter_l... | [
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 max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n \n while index < len(heights):\n if not stack or heights[stack[-1]... | trial_gpt4o_0 | {
"original_instruction": "Given a city grid represented as an NxM matrix, each cell in the grid can either be '1' representing a building or '0' representing an empty space. The mayor wants to build the largest possible park in the city. A park can only be built on empty spaces (cells with '0') and must be rectangul... | 0.683811 | Taco_43522 | C | [
"max_histogram_area",
"largest_rectangle"
] | 2 | [
[
"largest_rectangle",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 83e6f0dd65e791d6c92a16af4b553364c14745ef | 8d8db089c1a33cd36b6b9a7934eb864e5d3b28e2 | |||
v1.0 | complete | Taco | Taco_45689_C | from typing import List
def escape_grid(input_str: str) -> int:
""" Find the minimum number of moves required to reach the bottom-right corner from the top-left corner, avoiding all obstacles.
>>> escape_grid("5 5\n.....\n.###.\n.#.#.\n.#.#.\n.....")
8
>>> escape_grid("4 4\n....\n.##.\n####\n....")
... | from collections import deque
def min_moves_to_reach_end(grid):
n = len(grid)
m = len(grid[0])
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m and grid[x][y] == '.'
queue = deque([(0, 0, 0)]) # (x, y, distance)
visited = se... | from solution import escape_grid
def test_example_1():
input_str = "5 5\n.....\n.###.\n.#.#.\n.#.#.\n....."
assert escape_grid(input_str) == 8
def test_example_2():
input_str = "4 4\n....\n.##.\n####\n...."
assert escape_grid(input_str) == -1
def test_no_obstacles():
input_str = "3 3\n...\n...\n.... | [
{
"docstring": null,
"function_declaration": "def min_moves_to_reach_end(grid):",
"function_name": "min_moves_to_reach_end",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list":... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_moves(grid, n, m):\n \"\"\"\n Finds the minimum number of moves required to reach the bottom-right corner of the gri... | trial_gpt4o_1 | {
"original_instruction": "You are tasked with transporting an item across a grid while avoiding obstacles. The grid is represented as an n x m matrix where each cell can be either empty (.) or contain an obstacle (#). You start at the top-left corner of the grid (1,1) and must reach the bottom-right corner (n,m). Yo... | 0.650278 | Taco_45689 | C | [
"min_moves_to_reach_end",
"parse_input",
"escape_grid"
] | 3 | [
[
"escape_grid",
"min_moves_to_reach_end"
],
[
"escape_grid",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3e5f3a1e7a707199306c0f56a78cd497bd6853d1 | c62e31cb2ca183e35fa3034cdcb9b9bde57a915e | |||
v1.0 | complete | Taco | Taco_50199_C | def hex_string_prime(s: str) -> str:
""" Convert the given hexadecimal string to an integer and check whether the number is prime.
Args:
s (str): A string consisting of digits from '0' to '9' and characters 'a' to 'f'.
Returns:
str: "Prime" if the integer is prime, otherwise "Not Prime".
... | 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 hex_string_prime(s):
num = int(s, 16)
... | def test_hex_string_prime_prime():
assert hex_string_prime("11") == "Prime"
assert hex_string_prime("2b") == "Prime"
assert hex_string_prime("7") == "Prime"
def test_hex_string_prime_not_prime():
assert hex_string_prime("2a") == "Not Prime"
assert hex_string_prime("10") == "Not Prime"
assert he... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def hex_string_prime(s):",
"function_name": "hex_string_prime",
"parameter_list": "(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 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_0 | {
"original_instruction": "You are given a string consisting of digits from '0' to '9' and characters 'a' to 'f'. Each digit can be interpreted as is, and each character from 'a' to 'f' corresponds to a hexadecimal digit (10, 11, 12, 13, 14, 15). Your task is to convert the string into an integer and determine whethe... | 0.809372 | Taco_50199 | C | [
"is_prime",
"hex_string_prime"
] | 2 | [
[
"hex_string_prime",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c731c2c31ca57bab50dd254041f66edc740929c1 | 684a6902b56ae3a5a7397d888ae5b21770522ccb | |||
v1.0 | complete | Taco | Taco_44427_C | def count_peaks_in_city_map(input_str: str) -> int:
""" Count the number of peaks in the given city map grid. A peak is defined as a building whose height is greater
than or equal to the heights of all its adjacent buildings (considering the buildings adjacent horizontally,
vertically, and diagonally).
... | def count_peaks(grid):
def is_peak(grid, i, j):
directions = [(-1, -1), (-1, 0), (-1, 1),
(0, -1), (0, 1),
(1, -1), (1, 0), (1, 1)]
for di, dj in directions:
ni, nj = i + di, j + dj
if 0 <= ni < len(grid) and 0 <= nj < len(g... | from solution import count_peaks_in_city_map
def test_example_1():
input_str = '3 3\n1 2 1\n2 3 2\n1 2 1'
assert count_peaks_in_city_map(input_str) == 1
def test_example_2():
input_str = '4 4\n3 3 3 3\n3 4 4 3\n3 4 4 3\n3 3 3 3'
assert count_peaks_in_city_map(input_str) == 4
def test_single_peak():
... | [
{
"docstring": null,
"function_declaration": "def count_peaks(grid):",
"function_name": "count_peaks",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(input_str)"
},
... | [
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 count_peaks(grid):\n \"\"\"\n Counts the number of peak buildings in the grid.\n \n A peak is defined as a building whose height is greater than or... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid of digits representing a city map where each digit indicates the height of the building at that position. Your task is to find the number of \"peaks\" in the grid. A peak is defined as a building whose height is greater than or equal to the heights of all its adjacent b... | 0.594827 | Taco_44427 | C | [
"count_peaks",
"parse_input",
"count_peaks_in_city_map"
] | 3 | [
[
"count_peaks_in_city_map",
"count_peaks"
],
[
"count_peaks_in_city_map",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 11287ff6bcdf063d278863dcfbb41f7e2741d189 | a905aeb2a4f01062f35ee8992cdb54af337268d4 | |||
v1.0 | complete | Taco | Taco_44111_C | def calculate_salary(hourly_wage, hours_worked, overtime):
"""
Calculate the total salary based on hourly wage, hours worked and overtime policy.
Args:
hourly_wage (float): The hourly wage of the employee.
hours_worked (float): The number of hours worked by the employee.
overtime (bool): Wh... | def calculate_salary(hourly_wage, hours_worked, overtime):
"""
Calculate the total salary based on hourly wage, hours worked and overtime policy.
Args:
hourly_wage (float): The hourly wage of the employee.
hours_worked (float): The number of hours worked by the employee.
overtime (bool): Wh... | from solution import calculate_salary, sort_employees_by_salary
def test_calculate_salary_no_overtime():
assert calculate_salary(15.00, 40, False) == 600.00
assert calculate_salary(15.00, 35, False) == 525.00
def test_calculate_salary_with_overtime():
assert calculate_salary(15.00, 45, True) == 712.50
... | [
{
"docstring": "Calculate the total salary based on hourly wage, hours worked and overtime policy.\n\nArgs:\nhourly_wage (float): The hourly wage of the employee.\nhours_worked (float): The number of hours worked by the employee.\novertime (bool): Whether overtime pay applies.\n\nReturns:\nfloat: The total sala... | [
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 calculate_total_salary(hourly_wage, hours_worked, overtime_applicable):\n \"\"\"\n Calculate the total salary given the hourly wage, total hours worked a... | trial_gpt4o_4 | {
"original_instruction": "A company is looking to implement a simple payroll system and needs your expertise.\n\nFirst, write a function that, given the hourly wage (as a float), the total number of hours worked (as a float), and a boolean indicating whether overtime pay applies, will calculate the total salary. The... | 0.616239 | Taco_44111 | C | [
"calculate_salary",
"sort_employees_by_salary"
] | 2 | [
[
"sort_employees_by_salary",
"calculate_salary"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5fc8eca3407f318f441ef0846e442c6325cda781 | 66088b095b96ba7cb5bf72ceff234c6266aa4d7b | |||
v1.0 | complete | Taco | Taco_38976_C | def find_shortest_paths(t: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]], int]]) -> List[List[Union[int, str]]]:
""" Finds the shortest path from a starting attraction to all other attractions in a city with a given network of paths.
Parameters:
t (int): The number of test cases.
... | import heapq
def dijkstra(n, edges, start):
graph = [[] for _ in range(n)]
for u, v, w in edges:
graph[u].append((w, v))
distances = [float('inf')] * n
distances[start] = 0
min_heap = [(0, start)]
while min_heap:
current_distance, u = heapq.heappop(min_heap)
... | from solution import find_shortest_paths
def test_example_case():
t = 2
test_cases = [
(4, 4, [(0, 1, 1), (0, 2, 4), (1, 2, 2), (2, 3, 1)], 0),
(3, 3, [(0, 1, 2), (1, 2, 3), (0, 2, 5)], 1)
]
result = find_shortest_paths(t, test_cases)
assert result == [
[0, 1, 3, 4],
... | [
{
"docstring": null,
"function_declaration": "def dijkstra(n, edges, start):",
"function_name": "dijkstra",
"parameter_list": "(n, edges, start)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_paths(t, test_cases):",
"function_name": "find_shortest_paths",
"pa... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef shortest_paths(t, test_cases):\n results = []\n for case in test_cases:\n n, m, edges, s = case\n \n # Create adjace... | trial_gpt4o_1 | {
"original_instruction": "In a beautiful city, there is a fantastic network of paths that connects various attractions. Each attraction is numbered and there are one-way paths between some of the attractions. Every path has a specific travel time associated with it. As a visitor, you want to minimize the time it tak... | 0.73711 | Taco_38976 | C | [
"dijkstra",
"find_shortest_paths"
] | 2 | [
[
"find_shortest_paths",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | caa5410d4bbf96a9a4ff22f5dad308fe22847323 | 1e55fe9ffd1079b8a3f07e5d504d80e8dd4e4c4f | |||
v1.0 | complete | Taco | Taco_33500_C | from typing import List, Tuple
def is_valid_triangle(a: Tuple[int, int], b: Tuple[int, int], c: Tuple[int, int]) -> bool:
"""
Check if three points a, b, c form a valid triangle.
The area of the triangle must be non-zero.
@param a: tuple containing the first point's coordinates (x, y)
@param b: tu... | def is_valid_triangle(a, b, c):
"""
Check if three points a, b, c form a valid triangle.
The area of the triangle must be non-zero.
"""
# a, b, c are tuples of the form (x, y)
(x1, y1), (x2, y2), (x3, y3) = a, b, c
# The determinant of the matrix formed by the vectors
# (x2 - x1, y2 - y... | def test_is_valid_triangle():
assert is_valid_triangle((0, 0), (1, 1), (0, 1)) == True
assert is_valid_triangle((0, 0), (1, 1), (2, 2)) == False
assert is_valid_triangle((1, 1), (2, 3), (3, 2)) == True
assert is_valid_triangle((0, 0), (0, 1), (0, 2)) == False
def test_can_form_triangle_yes():
point... | [
{
"docstring": "Check if three points a, b, c form a valid triangle.\nThe area of the triangle must be non-zero.",
"function_declaration": "def is_valid_triangle(a, b, c):",
"function_name": "is_valid_triangle",
"parameter_list": "(a, b, c)"
},
{
"docstring": "Determine if there exists a set... | [
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_valid_triangle(points):\n \"\"\"\n Determines if a valid triangle can be formed from any three points.\n A triangle is valid if the area formed by ... | trial_gpt4o_2 | {
"original_instruction": "You are given `n` points on a 2D plane, and you are to determine if a valid triangle can be formed from any three of these points. The coordinates of the points are given as integer pairs (x, y).\n\nInput:\nThe first line contains one integer `n` (3 ≤ n ≤ 1000) — the number of points. Each ... | 0.826473 | Taco_33500 | C | [
"is_valid_triangle",
"can_form_triangle"
] | 2 | [
[
"can_form_triangle",
"is_valid_triangle"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c0fa3021287c7cf8cb61c8f8b046e7516ba5c2ab | e02a6efb8c9b6b15959634882c1d3c19361c3732 | |||
v1.0 | complete | Taco | Taco_45844_C | def min_difference(M: int, points: List[int]) -> int:
""" Determine the minimum possible difference between the points collected by Alice and Bob after completing all levels.
>>> min_difference(4, [1, 4, 2, 7])
0
>>> min_difference(3, [5, 8, 6])
3
>>> min_difference(5, [3, 1, 4, 2, 2])
0
... | def minimum_point_difference(M, points):
total_points = sum(points)
half_points = total_points // 2
dp = [0] * (half_points + 1)
for point in points:
for j in range(half_points, point - 1, -1):
dp[j] = max(dp[j], dp[j - point] + point)
best_distribution = dp[half_points... | from solution import min_difference
def test_min_difference_example_1():
assert min_difference(4, [1, 4, 2, 7]) == 0
def test_min_difference_example_2():
assert min_difference(3, [5, 8, 6]) == 3 # "|(5 + 6) - 8| = 3"
def test_min_difference_example_3():
assert min_difference(5, [3, 1, 4, 2, 2]) == 0 # ... | [
{
"docstring": null,
"function_declaration": "def minimum_point_difference(M, points):",
"function_name": "minimum_point_difference",
"parameter_list": "(M, points)"
},
{
"docstring": null,
"function_declaration": "def min_difference(M, points):",
"function_name": "min_difference",
... | [
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 minimum_difference(M, points):\n total_points = sum(points)\n half_points = total_points // 2\n \n # Initialize the DP array\n dp = [False] * (h... | trial_gpt4o_1 | {
"original_instruction": "Alice and Bob are avid gamers and play a game where they collect points by completing various levels. They have to complete M levels in total, and each level gives a certain number of points. Alice and Bob want to divide the levels among themselves such that their total points are as balanc... | 0.660825 | Taco_45844 | C | [
"minimum_point_difference",
"min_difference"
] | 2 | [
[
"min_difference",
"minimum_point_difference"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 48b055bc37acfc70002f58eed812b072b0042612 | 18061e0f82dbe88039d16e0ec2efc09fbe9822ed | |||
v1.0 | complete | Taco | Taco_40792_C | def decode_sequence(sequence: str) -> str:
"""
Decodes a sequence by replacing each letter with the letter 2 places ahead in the alphabet.
Wraps from 'z' back to 'a' and 'b'.
"""
pass
def decode_sequences(sequences: List[str]) -> List[str]:
"""
Takes a list of sequences and returns a list o... | def decode_sequence(sequence):
"""
Decodes a sequence by replacing each letter with the letter 2 places ahead in the alphabet.
Wraps from 'z' back to 'a' and 'b'.
"""
result = []
for char in sequence:
new_char = chr(((ord(char) - ord('a') + 2) % 26) + ord('a'))
result.append(new_... | from solution import decode_sequence, decode_sequences
def test_decode_sequence():
assert decode_sequence("abc") == "cde"
assert decode_sequence("xyz") == "zab"
assert decode_sequence("mno") == "opq"
assert decode_sequence("a") == "c"
assert decode_sequence("z") == "b"
assert decode_sequence("z... | [
{
"docstring": "Decodes a sequence by replacing each letter with the letter 2 places ahead in the alphabet.\nWraps from 'z' back to 'a' and 'b'.",
"function_declaration": "def decode_sequence(sequence):",
"function_name": "decode_sequence",
"parameter_list": "(sequence)"
},
{
"docstring": "T... | [
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 decode_sequence(sequence):\n \"\"\"\n Decodes a given sequence of lowercase letters by shifting each letter 2 places ahead in the alphabet.\n Wrapping... | trial_gpt4o_1 | {
"original_instruction": "Many ancient civilizations believed in unique forms of astronomy including intriguing patterns and shapes. A certain ancient Martian civilization has left behind encoded messages based on the arrangement of stars in the night sky. These codes are formed using sequences of different celestia... | 0.610211 | Taco_40792 | C | [
"decode_sequence",
"decode_sequences"
] | 2 | [
[
"decode_sequences",
"decode_sequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 84168525b8926db83059770b5444cf4f77d94870 | 75160ccb846f63a7da064c0ea36c8232f32253f7 | |||
v1.0 | complete | Taco | Taco_39697_C | def is_valid_discount_code(code: str) -> str:
"""
Determines if a discount code is valid based on the following criteria:
- It contains at least one uppercase letter.
- It contains at least one digit.
- It does not contain any repeating characters.
Args:
code (str): The discount code to... | def is_valid_discount_code(code):
"""
Determines if a discount code is valid based on the following criteria:
- It contains at least one uppercase letter.
- It contains at least one digit.
- It does not contain any repeating characters.
Args:
code (str): The discount code to validate.
... | def test_is_valid_discount_code():
assert is_valid_discount_code("A1B2C3") == "Valid"
assert is_valid_discount_code("123456") == "Invalid"
assert is_valid_discount_code("ABCDEF") == "Invalid"
assert is_valid_discount_code("A1X") == "Valid"
assert is_valid_discount_code("AAA111") == "Invalid"
ass... | [
{
"docstring": "Determines if a discount code is valid based on the following criteria:\n- It contains at least one uppercase letter.\n- It contains at least one digit.\n- It does not contain any repeating characters.\n\nArgs:\ncode (str): The discount code to validate.\n\nReturns:\nstr: \"Valid\" if the discou... | [
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_valid_discount_code(code):\n \"\"\"\n This function checks if the discount code is valid based on the given criteria:\n - It contains at least one ... | trial_gpt4o_2 | {
"original_instruction": "Background\n\nKyouko is a software engineer working on developing an e-commerce platform. One of the key features of this platform is the ability to manage discount codes effectively. To ensure customers get the best deals, Kyouko needs to implement a feature that validates discount codes b... | 0.548426 | Taco_39697 | C | [
"is_valid_discount_code",
"validate_discount_codes"
] | 2 | [
[
"validate_discount_codes",
"is_valid_discount_code"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 0cdacf23737ae38785a3dde9cf7a60e11deb56d0 | 4c544ed8e1681e3e3434c74672249d79add8a867 | |||
v1.0 | complete | Taco | Taco_39141_C | def sieve_of_eratosthenes(n):
""" Computes the list of prime numbers up to n using the Sieve of Eratosthenes algorithm.
"""
pass
def count_primes_up_to_n(cases):
""" Given a list of integers, returns a list where each element is the count of prime numbers less than or equal to the corresponding input i... | def sieve_of_eratosthenes(n):
"""
Computes the list of prime numbers up to n using the Sieve of Eratosthenes algorithm.
"""
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p, n + 1, p):
is_prime[i] = False
... | from solution import sieve_of_eratosthenes, count_primes_up_to_n
def test_sieve_of_eratosthenes():
prime_counts = sieve_of_eratosthenes(20)
assert prime_counts[5] == 3
assert prime_counts[10] == 4
assert prime_counts[20] == 8
assert prime_counts[1] == 0
assert prime_counts[2] == 1
def test_cou... | [
{
"docstring": "Computes the list of prime numbers up to n using the Sieve of Eratosthenes algorithm.",
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def count_pr... | [
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 count_primes_up_to_n(n, is_prime):\n \"\"\"\n Counts the number of primes up to and including n.\n \"\"\"\n count = 0\n for i in range(2, n + 1)... | trial_gpt4o_2 | {
"original_instruction": "Alex is learning about prime numbers, but he finds it challenging to determine if a given number is a prime. He decides to write a program that will help him with this task. Your job is to assist Alex by creating a program that can check if a number is a prime number and count all the prime... | 0.74913 | Taco_39141 | C | [
"sieve_of_eratosthenes",
"count_primes_up_to_n"
] | 2 | [
[
"count_primes_up_to_n",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 62ca051cd0887746896adfb3d58956955a70c4ff | 6b88607e3e27fc0be24be627cb262bcbe2374bd8 | |||
v1.0 | complete | Taco | Taco_54725_C | def solution(queries):
"""
Given a list of integers queries, return a list of counts of distinct prime pairs for each query.
Example:
>>> solution([10, 6, 8])
[2, 1, 1]
""" | def sieve(limit):
"""
Generate a list of boolean values indicating whether numbers from `0` to `limit` are prime.
"""
is_prime = [True] * (limit + 1)
is_prime[0] = is_prime[1] = False
for num in range(2, int(limit**0.5) + 1):
if is_prime[num]:
for multiple in range(num*num, l... | from solution import solution
def test_solution():
queries = [10, 6, 8]
expected = [2, 1, 1]
assert solution(queries) == expected
def test_solution_with_large_inputs():
queries = [100, 50, 90, 92, 1000, 10000]
# We will not specify the expected result for each query manually. This is more of a str... | [
{
"docstring": "Generate a list of boolean values indicating whether numbers from `0` to `limit` are prime.",
"function_declaration": "def sieve(limit):",
"function_name": "sieve",
"parameter_list": "(limit)"
},
{
"docstring": "Count the number of distinct pairs of prime numbers (a, b) such ... | [
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 sieve_of_eratosthenes(n):\n sieve = [True] * (n+1)\n p = 2\n while (p * p <= n):\n if (sieve[p] == True):\n for i in range(p * p, n+... | trial_gpt4o_1 | {
"original_instruction": "You are given Q queries, where each query consists of an integer X. For each query, determine the number of distinct pairs [a, b] (a ≤ b) such that a and b satisfy the following conditions:\n\n* a and b are both prime numbers.\n* a + b is equal to X.\n\nInput format:\n\nThe input is given i... | 0.609055 | Taco_54725 | C | [
"sieve",
"prime_pairs_count",
"solution"
] | 3 | [
[
"solution",
"prime_pairs_count"
],
[
"solution",
"sieve"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 270fac60e4247630d7cd5f59a688357cbb798f1e | 7fc9520524e66ffab0503927996606dedf72fa3b | |||
v1.0 | complete | Taco | Taco_50921_C | def is_prime(n):
"""
Determines if a number is prime.
"""
def find_primes_in_list(numbers):
"""
Returns a list of prime numbers found in the input list, sorted in ascending order.
"""
def main(N, str_numbers):
"""
N is the number of elements in the list.
str_numbers is a string of ... | def is_prime(n):
"""
Determines if a number is prime.
"""
if n <= 1:
return False
if n == 2:
return True # 2 is the only even prime number
if n % 2 == 0:
return False # all other even numbers are not primes
sqrt_n = int(n**0.5) + 1
for i in range(3, sqrt_n, 2):... | from solution import is_prime, find_primes_in_list, main
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(13) == True
assert is_prime(15) == False
assert is_prime(1) == False
assert is_prime(29) == True
def test_find_pri... | [
{
"docstring": "Determines if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of prime numbers found in the input list, sorted in ascending order.",
"function_declaration": "def find_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": "import math\n\ndef is_prime(n):\n \"\"\"\n Determines if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of numbers. Your task is to identify all the prime numbers in the list and print them in ascending order.\n\nInput Format\n\nThe first line will contain a single integer $\\mathbf{N}$ which represents the number of elements in the list.\n\nThe second line of input will ... | 0.796135 | Taco_50921 | C | [
"is_prime",
"find_primes_in_list",
"main"
] | 3 | [
[
"find_primes_in_list",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a2c07127fd3d9fca7cff9d1811b6c7167eb12132 | ea7222c4da6692eacbe478ed592fd043a3dec1ef | |||
v1.0 | complete | Taco | Taco_45607_C | def minimal_spanning_tree(n: int, m: int, roads: List[Tuple[int, int, int]]) -> int:
""" Find the weight of the Minimum Spanning Tree (MST) of the given graph of cities and roads.
>>> minimal_spanning_tree(4, 5, [(1, 2, 3), (1, 3, 1), (3, 2, 3), (2, 4, 6), (3, 4, 5)])
9
>>> minimal_spanning_tree(2, 1, [... | def find_parent(parent, i):
if parent[i] == i:
return i
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
root_x = find_parent(parent, x)
root_y = find_parent(parent, y)
if rank[root_x] < rank[root_y]:
parent[root_x] = root_y
elif rank[root_x] > rank[root... | def test_minimal_spanning_tree():
N, M = 4, 5
roads = [
(1, 2, 3),
(1, 3, 1),
(3, 2, 3),
(2, 4, 6),
(3, 4, 5)
]
assert minimal_spanning_tree(N, M, roads) == 9
def test_minimal_spanning_tree_single_edge():
N, M = 2, 1
roads = [
(1, 2, 3)
]
... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank... | [
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(parent, i):\n if parent[i] == i:\n return i\n return find_parent(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = fi... | trial_gpt4o_0 | {
"original_instruction": "In a kingdom far away, there are N cities connected by M bi-directional roads. Each road has a specific distance associated with it. The kingdom wants to build a network such that every city is reachable from any other city, but they don't want to spend more distance than required. Therefor... | 0.724196 | Taco_45607 | C | [
"find_parent",
"union",
"kruskal_mst",
"minimal_spanning_tree"
] | 4 | [
[
"kruskal_mst",
"find_parent"
],
[
"kruskal_mst",
"union"
],
[
"minimal_spanning_tree",
"kruskal_mst"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | dd490edbe70e6f7e1e60c2c27831b92b2beac6d6 | 819780c9dc1bc69d532eab8d5ddaefcf9fa8568e | |||
v1.0 | complete | Taco | Taco_46032_C | def max_subarray_sum(arr) -> int:
""" Find the sum of the maximum subarray.
>>> max_subarray_sum([1, -2, 3, -2, 5])
6
>>> max_subarray_sum([-1, -2, -3, -4])
-1
"""
pass
def min_subarray_sum(arr) -> int:
""" Find the sum of the minimum subarray.
>>> min_subarray_sum([1, -2, 3, -2, 5]... | def max_subarray_sum(arr):
"""
Finds the sum of the maximum subarray using Kadane's algorithm.
"""
max_ending_here = max_so_far = arr[0]
for x in arr[1:]:
max_ending_here = max(x, max_ending_here + x)
max_so_far = max(max_so_far, max_ending_here)
return max_so_far
def min_subarr... | def test_max_subarray_sum():
assert max_subarray_sum([1, -2, 3, -2, 5]) == 6
assert max_subarray_sum([-1, -2, -3, -4]) == -1
assert max_subarray_sum([1, 2, 3, 4]) == 10
assert max_subarray_sum([3, -1, 2, -1]) == 4
def test_min_subarray_sum():
assert min_subarray_sum([1, -2, 3, -2, 5]) == -2
ass... | [
{
"docstring": "Finds the sum of the maximum subarray using Kadane's algorithm.",
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": "Finds the sum of the minimum subarray, using a modified Kadane's algorithm... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subarray_sum(arr):\n max_ending_here = max_so_far = arr[0]\n for num in arr[1:]:\n max_ending_here = max(num, max_ending_here + num)\n ... | trial_gpt4o_2 | {
"original_instruction": "Given an array of integers `arr`, you need to find two integers `x` and `y` such that:\n\n1. `x` is the sum of the maximum subarray.\n2. `y` is the sum of the minimum subarray.\n\nReturn the sum of `x` and `y`.\n\n-----Constraints-----\n- 1 \\leq |arr| \\leq 10^5\n- -10^4 \\leq arr[i] \\leq... | 0.706489 | Taco_46032 | C | [
"max_subarray_sum",
"min_subarray_sum",
"sum_of_max_and_min_subarray"
] | 3 | [
[
"sum_of_max_and_min_subarray",
"max_subarray_sum"
],
[
"sum_of_max_and_min_subarray",
"min_subarray_sum"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 217c9661471105b4ca1fb40f61b652d73f6f7a52 | 2cd36593cdc546823ce9af73faabedeffbeec841 | |||
v1.0 | complete | Taco | Taco_33916_C | def rotate_matrix(matrix):
""" Rotates the given NxN matrix 90 degrees clockwise.
Args:
matrix: List[List[int]] - NxN matrix to be rotated
Returns:
List[List[int]] - The rotated matrix
>>> rotate_matrix([[1, 2], [3, 4]])
[[3, 1], [4, 2]]
>>> rotate_matrix([[1, 2, 3], [4, 5, 6],... | def rotate_matrix(matrix):
"""
Rotates the given NxN matrix 90 degrees clockwise.
:param matrix: List[List[int]] - NxN matrix to be rotated
:return: List[List[int]] - The rotated matrix
"""
N = len(matrix)
rotated = [[0] * N for _ in range(N)]
for i in range(N):
for j in ran... | import pytest
from solution import rotate_matrix, process_input_and_rotate_matrices, parse_input, format_output
def test_rotate_matrix_2x2():
matrix = [
[1, 2],
[3, 4]
]
rotated = rotate_matrix(matrix)
expected = [
[3, 1],
[4, 2]
]
assert rotated == expected
de... | [
{
"docstring": "Rotates the given NxN matrix 90 degrees clockwise.\n\n:param matrix: List[List[int]] - NxN matrix to be rotated\n:return: List[List[int]] - The rotated matrix",
"function_declaration": "def rotate_matrix(matrix):",
"function_name": "rotate_matrix",
"parameter_list": "(matrix)"
},
... | [
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 rotate_matrix_90_clockwise(matrix):\n \"\"\"\n Rotates the given square matrix 90 degrees clockwise.\n \"\"\"\n N = len(matrix)\n rotated = [[0]... | trial_gpt4o_1 | {
"original_instruction": "You have been given a square matrix `M` of size `NxN` containing integers. Your task is to rotate the matrix 90 degrees clockwise and output the new rotated matrix.\n\n-----Input:-----\n- The first line contains an integer $T$, the number of test cases.\n- For each test case:\n - The first... | 0.541096 | Taco_33916 | C | [
"rotate_matrix",
"process_input_and_rotate_matrices",
"parse_input",
"format_output"
] | 4 | [
[
"process_input_and_rotate_matrices",
"rotate_matrix"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | ae6116785deb44fe9a18d5ae25f245b852652057 | 87d321a0774cabe7e767fd01f1f3496891c9196d | |||
v1.0 | complete | Taco | Taco_45574_C | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def sortList(head):
"""
Given the head of a singly linked list, sort the list in ascending order.
:param head: ListNode, the head of the linked list
:return: ListNode, the head of the sorted l... | class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def sortList(head):
"""
Sorts a linked list in ascending order.
:param head: ListNode, the head of the linked list
:return: ListNode, the head of the sorted linked list
"""
if not head or ... | from solution import ListNode, sortList
def list_to_linked_list(elements):
if not elements:
return None
head = ListNode(elements[0])
current = head
for element in elements[1:]:
current.next = ListNode(element)
current = current.next
return head
def linked_list_to_list(head)... | [] | [
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 ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef sort_list(head):\n \"\"\"\n Sorts a singl... | trial_gpt4o_2 | {
"original_instruction": "Given the head of a singly linked list, return the list after sorting it in ascending order.\n\nExample 1:\n\nInput: head = [4,2,1,3]\nOutput: [1,2,3,4]\n\nExample 2:\n\nInput: head = [-1,5,3,4,0]\nOutput: [ -1,0,3,4,5]\n\nExample 3:\n\nInput: head = []\nOutput: []\n\nConstraints:\n\nThe nu... | 0.570938 | Taco_45574 | C | [
"sortList",
"get_middle",
"merge"
] | 3 | [
[
"sortList",
"get_middle"
],
[
"sortList",
"merge"
]
] | 2 | [] | false | [
"ListNode"
] | true | pytest | true | [] | true | 2ea1542b78f239a103c02566df60654f582990d4 | 183defe8f633cbebb1bbe36be8493c09815fcb4c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.