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_44087_C | def can_type_word(n: int, m: int, keyboard: List[List[str]], word: str) -> bool:
""" Determines if a given word can be typed on the alien keyboard by traversing through adjacent keys.
>>> can_type_word(4, 5, [
['a', 'b', 'c', 'd', 'e'],
['f', 'g', 'h', 'i', 'j'],
['k', 'l', 'm', 'n'... | def can_type_word(n, m, keyboard, word):
directions = [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (-1, 1), (1, -1), (1, 1)]
def is_valid(x, y):
return 0 <= x < n and 0 <= y < m
def dfs(x, y, word_idx):
if word_idx == len(word):
return True
temp = keyboard[x][y]
... | def test_can_type_word():
assert can_type_word(4, 5, [
['a', 'b', 'c', 'd', 'e'],
['f', 'g', 'h', 'i', 'j'],
['k', 'l', 'm', 'n', 'o'],
['p', 'q', 'r', 's', 't']
], 'hello') == False
assert can_type_word(3, 3, [
['a', 'b', 'c'],
['d', 'e', 'f'],
['g',... | [
{
"docstring": null,
"function_declaration": "def can_type_word(n, m, keyboard, word):",
"function_name": "can_type_word",
"parameter_list": "(n, m, keyboard, word)"
},
{
"docstring": null,
"function_declaration": "def read_and_solve():",
"function_name": "read_and_solve",
"param... | [
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 can_type_word(n, m, keyboard, word):\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (-1, 1), (1, -1), (1, 1)]\n\n def is_valid(x, y):\n ... | trial_gpt4o_0 | {
"original_instruction": "Alien Keyboard\n\nIn a distant galaxy, humans have discovered an alien civilization with a different keyboard layout. Instead of letters and numbers, their keyboard has symbols and special characters. The alien keyboard has N rows and M columns, forming a rectangular grid. Each key on the k... | 0.615718 | Taco_44087 | C | [
"can_type_word",
"read_and_solve"
] | 2 | [
[
"read_and_solve",
"can_type_word"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 87e1200ee7a8283b55ca74016fdbccb421e732ee | b5a7212b2f15fdd7d0210318a8db2b00d88bfd14 | |||
v1.0 | complete | Taco | Taco_44390_C | def encrypt_message(shift: int, message: str) -> str:
""" Encrypts the message by shifting its letters by the given shift value.
>>> encrypt_message(3, "secure")
'vhfxuh'
>>> encrypt_message(-1, "abcd")
'zabc'
>>> encrypt_message(3, "xyz")
'abc'
"""
# Implementation here
def decrypt... | def encrypt_message(shift, message):
"""
Encrypts the message by shifting its letters by the given shift value.
"""
encrypted_message = []
for char in message:
new_char = chr(((ord(char) - ord('a') + shift) % 26) + ord('a'))
encrypted_message.append(new_char)
return ''.join(encry... | from solution import encrypt_message, decrypt_message, process_message
def test_encrypt_message_with_positive_shift():
assert encrypt_message(3, "secure") == "vhfxuh"
def test_decrypt_message_with_positive_shift():
assert decrypt_message(3, "vhfxuh") == "secure"
def test_encrypt_message_with_negative_shift()... | [
{
"docstring": "Encrypts the message by shifting its letters by the given shift value.",
"function_declaration": "def encrypt_message(shift, message):",
"function_name": "encrypt_message",
"parameter_list": "(shift, message)"
},
{
"docstring": "Decrypts the message by reversing the shift its... | [
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 encrypt_message(message, shift):\n \"\"\"\n Encrypts the message by shifting each letter by the shift value.\n Wraps around the alphabet if necessary.... | trial_gpt4o_2 | {
"original_instruction": "Crypto messaging service \"SecuMessage\" is designed to allow secure communication between users by encrypting messages. Given an encryption mechanism, your task is to implement this encryption and decryption algorithms. \n\nThe encryption mechanism works as follows:\n1. Each letter in the ... | 0.726807 | Taco_44390 | C | [
"encrypt_message",
"decrypt_message",
"process_message"
] | 3 | [
[
"process_message",
"decrypt_message"
],
[
"process_message",
"encrypt_message"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9be2908a909acb442a60ac4fe55a209df55d85df | 94d541ec52bd7e2fc9aff19500701ce22e3f4c74 | |||
v1.0 | complete | Taco | Taco_44204_C | def factorial(n):
"""
Compute the factorial of n.
:param n: The number to compute the factorial of.
:return: The factorial of n.
"""
pass
def count_unique_words(A, L):
"""
Returns the number of unique words of length L that can be formed using
the first A letters of the alphabet, wi... | def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
def count_unique_words(A, L):
"""
Returns the number of unique words of length L that can be formed using
the first A letters of the alphabet, with no letter used more than once.
"""
if L > A:
retu... | from solution import count_unique_words, unique_words_from_cases
def test_count_unique_words_basic():
assert count_unique_words(3, 2) == 6
assert count_unique_words(4, 3) == 24
def test_count_unique_words_edge_cases():
assert count_unique_words(1, 1) == 1
assert count_unique_words(15, 15) == 130767436... | [
{
"docstring": null,
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Returns the number of unique words of length L that can be formed using\nthe first A letters of the alphabet, with no letter used more than once.",
"... | [
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 count_unique_words(A, L):\n \"\"\"\n Returns the number of unique words of length L that can be formed using A letters,\n with no lette... | trial_gpt4o_2 | {
"original_instruction": "An archaic language, which is unfortunately becoming extinct, is written using unique alphabets. In an attempt to preserve it, a group of linguists is interested in keeping track of all unique words formatted according to the following rules:\n\n1. Each word must be of a fixed length `L`.\n... | 0.67666 | Taco_44204 | C | [
"factorial",
"count_unique_words",
"unique_words_from_cases"
] | 3 | [
[
"count_unique_words",
"factorial"
],
[
"unique_words_from_cases",
"count_unique_words"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 4cafa00f232a96e642241a8304cc38e6a26a4eb2 | 18e47ff69a1ca256c51f575a020132326a3456b5 | |||
v1.0 | complete | Taco | Taco_44272_C | def garden_planner(n, m, q, grid, plants):
"""
Emma is planning her garden and wants to allocate space optimally for her plants. She has a plot that is divided
into n rows and m columns, forming an n × m grid. Some cells might be blocked due to rocks or other obstacles,
and Emma cannot use these for p... | def can_place(garden, n, m, r, c, x, y):
if x + r > n or y + c > m:
return False
for i in range(r):
for j in range(c):
if garden[x + i][y + j] == '1':
return False
return True
def mark_taken(garden, r, c, x, y):
for i in range(r):
for j in range(c):
... | from solution import garden_planner
def test_garden_planner_case1():
n = 5
m = 6
q = 2
grid = [
"001000",
"000100",
"010000",
"000000",
"100010"
]
plants = [(2, 3), (3, 2)]
assert garden_planner(n, m, q, grid, plants) == "YES"
def test_garden_planner... | [
{
"docstring": null,
"function_declaration": "def can_place(garden, n, m, r, c, x, y):",
"function_name": "can_place",
"parameter_list": "(garden, n, m, r, c, x, y)"
},
{
"docstring": null,
"function_declaration": "def mark_taken(garden, r, c, x, y):",
"function_name": "mark_taken",
... | [
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 can_place_plants(grid, plants):\n n = len(grid)\n m = len(grid[0])\n \n def can_place(r, c, x, y):\n if x + r > n or y + c > m:\n ... | trial_gpt4o_3 | {
"original_instruction": "Emma is planning her garden and wants to allocate space optimally for her plants. She has a plot that is divided into n rows and m columns, forming an n × m grid. Some cells might be blocked due to rocks or other obstacles, and Emma cannot use these for planting. A cell is denoted as blocke... | 0.666034 | Taco_44272 | C | [
"can_place",
"mark_taken",
"garden_planner"
] | 3 | [
[
"garden_planner",
"can_place"
],
[
"garden_planner",
"mark_taken"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 04d972a9bf02df50b4f059b0301c4f5354351cec | cfa7254d7ab816d4a6807d89ef99303820c40138 | |||
v1.0 | complete | Taco | Taco_44360_C | def is_mirror_string(s: str) -> bool """
Determines if the given string is a "mirror" string.
A "mirror" string is one that appears the same when reversed and
characters are replaced by their mirror counterparts.
Only the characters {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}
are mi... | def is_mirror_string(s):
"""
Determines if the given string is a "mirror" string.
A "mirror" string is one that appears the same when reversed and
characters are replaced by their mirror counterparts.
Only the characters {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}
are mirror cha... | from solution import is_mirror_string, check_mirror_strings
def test_is_mirror_string():
# Test cases where the output should be True
assert is_mirror_string("AHA") == True
assert is_mirror_string("YXY") == True
assert is_mirror_string("A") == True
# Test cases where the output should be False
... | [
{
"docstring": "Determines if the given string is a \"mirror\" string.\n\nA \"mirror\" string is one that appears the same when reversed and\ncharacters are replaced by their mirror counterparts.\nOnly the characters {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}\nare mirror characters.\n\nParameters:\... | [
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 is_mirror_string(s):\n mirror_chars = set('AHIMOTUVWXY')\n for char in s:\n if char not in mirror_chars:\n return \"NO\"\n return \"... | trial_gpt4o_3 | {
"original_instruction": "Chef is an expert in strings and loves to solve problems related to string manipulation. One day, he came across a problem that he found particularly interesting and challenging. He wants to find out whether a given string is a \"mirror\" string. A \"mirror\" string is a string that looks t... | 0.696054 | Taco_44360 | C | [
"is_mirror_string",
"check_mirror_strings"
] | 2 | [
[
"check_mirror_strings",
"is_mirror_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 75a42343be5a88bb351a541927941a0d290e0bb0 | 8e0e64d56a62891369132ac7fd10106c5e9fa87c | |||
v1.0 | complete | Taco | Taco_44439_C | from typing import List, Tuple
def apply_backspace(s: str) -> str:
"""
Applies the backspace operation on the string `s`.
"""
result = []
for char in s:
if char == '#':
if result:
result.pop()
else:
result.append(char)
return ''.join(resul... | def apply_backspace(s):
"""
Applies the backspace operation on the string s.
"""
result = []
for char in s:
if char == '#':
if result:
result.pop()
else:
result.append(char)
return ''.join(result)
def is_backspace_equal(s, t):
"""
... | from solution import apply_backspace, is_backspace_equal, process_test_cases
def test_apply_backspace():
assert apply_backspace("ab#c") == "ac"
assert apply_backspace("ab##") == ""
assert apply_backspace("a##c") == "c"
assert apply_backspace("a#b#c#") == ""
def test_is_backspace_equal():
assert is... | [
{
"docstring": "Applies the backspace operation on the string s.",
"function_declaration": "def apply_backspace(s):",
"function_name": "apply_backspace",
"parameter_list": "(s)"
},
{
"docstring": "Determines if the processed string s is equal to string t.",
"function_declaration": "def i... | [
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 process_string(s):\n result = []\n for char in s:\n if char == '#':\n if result:\n result.pop()\n else:\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given two strings, `s` and `t`. The string `s` consists of alphabetic characters and special characters '#'. The character '#' acts as a backspace, i.e., it removes the last non-special character of `s`. Your task is to determine whether the final processed string `s` is equal to st... | 0.627483 | Taco_44439 | C | [
"apply_backspace",
"is_backspace_equal",
"process_test_cases"
] | 3 | [
[
"is_backspace_equal",
"apply_backspace"
],
[
"process_test_cases",
"is_backspace_equal"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 5e07fc08b89f630f6d34c2c84f76fe047f0704e5 | 66320cedcd435b60bffd13512072a9f816bc249f | |||
v1.0 | complete | Taco | Taco_44492_C | from typing import List
def max_rectangle(grid: List[List[int]]) -> int:
""" Determine the area of the largest rectangle of contiguous vacant cells.
>>> max_rectangle([
... [1, 0, 1, 0],
... [0, 0, 1, 0],
... [0, 0, 0, 0],
... [1, 0, 1, 1]
... ]) == 4
>>> max_rectangle([... | def max_histogram_area(histogram):
stack = []
max_area = 0
index = 0
while index < len(histogram):
if not stack or histogram[stack[-1]] <= histogram[index]:
stack.append(index)
index += 1
else:
top_of_stack = stack.pop()
area = (histogram[... | from solution import max_rectangle
def test_max_rectangle_1():
grid = [
[1, 0, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0],
[1, 0, 1, 1]
]
assert max_rectangle(grid) == 4
def test_max_rectangle_2():
grid = [
[0, 1, 0, 0, 1],
[1, 1, 0, 0, 0],
[0, 0, 0, 1, 0... | [
{
"docstring": null,
"function_declaration": "def max_histogram_area(histogram):",
"function_name": "max_histogram_area",
"parameter_list": "(histogram)"
},
{
"docstring": null,
"function_declaration": "def max_rectangle(grid):",
"function_name": "max_rectangle",
"parameter_list"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_histogram_area(histogram):\n \"\"\"Helper function to calculate max area in a histogram\"\"\"\n stack = []\n max_area = 0\n index = 0\n\n wh... | trial_gpt4o_1 | {
"original_instruction": "The city of Gridland is built on an n x m grid. Some cells have buildings blocking the view, and you need to find the largest possible rectangle of vacant cells in order to build a new park. Vacant cells are denoted by 0, while cells with buildings are denoted by 1.\n\nWrite a program to de... | 0.729055 | Taco_44492 | C | [
"max_histogram_area",
"max_rectangle"
] | 2 | [
[
"max_rectangle",
"max_histogram_area"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 02b12aa56c474df4901153cdb96ccd4c760e9fdb | fbd6e01a8c2b2b592a6e1b7158b2885f2021dea1 | |||
v1.0 | complete | Taco | Taco_44507_C | def minimum_travel_times(n: int, m: int, edges: List[Tuple[int, int, int]], start: int) -> List[Union[int, str]]:
"""
Compute the shortest travel times from the starting bus stop to all other bus stops.
Parameters:
n: int - Number of bus stops (vertices).
m: int - Number of bus routes (edges).
... | import heapq
def dijkstra(n, graph, start):
"""
Compute the shortest travel times from the starting bus stop to all other bus stops.
Parameters:
n: int - Number of bus stops.
graph: List[Tuple[int, int, int]] - List of bus routes (u, v, w).
start: int - Starting bus stop.
Returns:... | from solution import minimum_travel_times
def test_minimum_travel_times_case_1():
n = 4
m = 4
edges = [(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 5)]
start = 1
assert minimum_travel_times(n, m, edges, start) == [0, 3, 2, 7]
def test_minimum_travel_times_case_2():
n = 6
m = 7
edges = [(1, ... | [
{
"docstring": "Compute the shortest travel times from the starting bus stop to all other bus stops.\n\nParameters:\nn: int - Number of bus stops.\ngraph: List[Tuple[int, int, int]] - List of bus routes (u, v, w).\nstart: int - Starting bus stop.\n\nReturns:\nList[Union[int, str]] - List of shortest travel time... | [
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\ndef dijkstra(n, m, edges, start):\n INF = float('inf')\n adj = [[] for _ in range(n)]\n for u, v, w in edges:\n adj[u-1].append((w,... | trial_gpt4o_2 | {
"original_instruction": "A company wants to optimize their bus routes. They have a set of bus stops and routes between them. Each route has a specific travel time. They want to find out the minimum travel time required to reach each bus stop from a given starting bus stop.\n\nThe company provides you with an undire... | 0.729493 | Taco_44507 | C | [
"dijkstra",
"minimum_travel_times"
] | 2 | [
[
"minimum_travel_times",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 54500bf81b19b7fb05d4beb047f9d3d4651f485e | 525b1a86d955b154fd4d9a6177b24093229b688a | |||
v1.0 | complete | Taco | Taco_44726_C | from typing import List, Tuple
def minimum_energy_required(N: int, coordinates: List[Tuple[int, int]]) -> int:
"""Calculate the minimum energy required to cut down all trees and return to the starting tree.
Args:
N (int): Number of trees.
coordinates (List[Tuple[int, int]]): List of the (x... | import itertools
def calculate_distance(point1, point2):
"""
Calculate the Manhattan distance between two points.
"""
return abs(point1[0] - point2[0]) + abs(point1[1] - point2[1])
def find_min_energy(trees):
"""
Find the minimum energy required to cut down all trees and return to the starting... | from solution import minimum_energy_required
def test_minimum_energy_basic():
assert minimum_energy_required(3, [(0, 0), (1, 0), (0, 1)]) == 4
def test_single_tree():
assert minimum_energy_required(1, [(0, 0)]) == 0
def test_two_trees():
assert minimum_energy_required(2, [(0, 0), (1, 1)]) == 4
def t... | [
{
"docstring": "Calculate the Manhattan distance between two points.",
"function_declaration": "def calculate_distance(point1, point2):",
"function_name": "calculate_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Find the minimum energy required to cut down all trees and ... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import permutations\n\ndef minimum_energy(N, trees):\n def manhattan_distance(tree1, tree2):\n return abs(tree1[0] - tree2[0]) + abs(tree1... | trial_gpt4o_3 | {
"original_instruction": "In a forest, there are N trees positioned on a 2D grid. Each tree is represented by its coordinates (x_i, y_i). Lumberjacks need to cut down all trees, but they can only move between adjacent trees. The adjacent tree to a tree at (x_i, y_i) is a tree located at any of (x_i+1, y_i), (x_i-1, ... | 0.611322 | Taco_44726 | C | [
"calculate_distance",
"find_min_energy",
"minimum_energy_required"
] | 3 | [
[
"find_min_energy",
"calculate_distance"
],
[
"minimum_energy_required",
"find_min_energy"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 16b85bda29c89994b8cfaed85b2f0b044a1727fc | 029794b7d8f42bae2e58de72a9c8a0ce40b993af | |||
v1.0 | complete | Taco | Taco_43733_C | from typing import List
def perfect_square_sum_sequence(N: int, A: List[int]) -> str:
"""
Check if it is possible to find a permutation of the given sequence of integers
such that the sum of any two consecutive numbers is a perfect square.
>>> perfect_square_sum_sequence(3, [1, 17, 8])
"YES"... | from itertools import permutations
import math
def is_perfect_square(n):
"""
Helper function to check if a number is a perfect square.
"""
root = int(math.sqrt(n))
return root * root == n
def can_form_perfect_square_sum_sequence(N, sequence):
"""
Check if there exists a permutation of the ... | from solution import perfect_square_sum_sequence
def test_case_1():
assert perfect_square_sum_sequence(3, [1, 17, 8]) == "YES"
def test_case_2():
assert perfect_square_sum_sequence(4, [1, 14, 2, 3]) == "NO"
def test_case_3():
assert perfect_square_sum_sequence(1, [16]) == "YES"
def test_case_4():
as... | [
{
"docstring": "Helper function to check if a number is a perfect square.",
"function_declaration": "def is_perfect_square(n):",
"function_name": "is_perfect_square",
"parameter_list": "(n)"
},
{
"docstring": "Check if there exists a permutation of the sequence such that the sum of \nany two... | [
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\n\ndef is_perfect_square(x):\n return int(math.isqrt(x)) ** 2 == x\n\ndef can_form_perfect_square_permutation(nums):\n def dfs(path):\n if... | trial_gpt4o_2 | {
"original_instruction": "Write a function that checks if it is possible to find a permutation of the given sequence of integers such that the sum of any two consecutive numbers is a perfect square.\n\nInput\n\nThe first line of the input consists of a single integer $ N $, the length of the sequence. The second lin... | 0.656738 | Taco_43733 | C | [
"is_perfect_square",
"can_form_perfect_square_sum_sequence",
"perfect_square_sum_sequence"
] | 3 | [
[
"can_form_perfect_square_sum_sequence",
"is_perfect_square"
],
[
"perfect_square_sum_sequence",
"can_form_perfect_square_sum_sequence"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 152d58c33aa943e5a929fd92e2e4853d8ddd1732 | ed1fce7f7d7ef8691ab1c577ec12da4a7f80a0e3 | |||
v1.0 | complete | Taco | Taco_44367_C | def largest_clique(n, m, friendships):
""" Find the largest clique in which every student is directly connected to every other student.
>>> largest_clique(5, 6, [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3), (2, 4)])
4
>>> largest_clique(4, 2, [(1, 2), (3, 4)])
2
""" | from itertools import combinations
def is_clique(graph, nodes):
for i in range(len(nodes)):
for j in range(i + 1, len(nodes)):
if nodes[j] not in graph[nodes[i]]:
return False
return True
def largest_clique(n, m, friendships):
graph = {i: set() for i in range(1, n + 1)}... | from solution import largest_clique
def test_example_case1():
n, m = 5, 6
friendships = [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3), (2, 4)]
assert largest_clique(n, m, friendships) == 4
def test_example_case2():
n, m = 4, 2
friendships = [(1, 2), (3, 4)]
assert largest_clique(n, m, friendships) =... | [
{
"docstring": null,
"function_declaration": "def is_clique(graph, nodes):",
"function_name": "is_clique",
"parameter_list": "(graph, nodes)"
},
{
"docstring": null,
"function_declaration": "def largest_clique(n, m, friendships):",
"function_name": "largest_clique",
"parameter_li... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from itertools import combinations\n\ndef largest_clique(n, m, edges):\n \"\"\"\n Given the number of students n and the list of edges representing friendshi... | trial_gpt4o_2 | {
"original_instruction": "Anna is a university student who wants to create a study group. She has a number of friends, each friend is represented by a unique student ID, and the friendship between them can be represented as an undirected graph where each node is a student, and an edge between two nodes indicates tha... | 0.587045 | Taco_44367 | C | [
"is_clique",
"largest_clique"
] | 2 | [
[
"largest_clique",
"is_clique"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae66645a00548c1470c5b2e2f252c082530689d1 | 3b15f8c93d8216cf15a569f2418ab5de8bdad4f5 | |||
v1.0 | complete | Taco | Taco_44659_C | def is_palindrome(number: int) -> bool:
"""
Checks if a given number is a palindrome.
"""
str_num = str(number)
return str_num == str_num[::-1]
def largest_palindrome(n: int) -> int:
"""
Write a function that takes an integer `n` and returns the largest palindrome number less than `n`.
... | def is_palindrome(number):
"""
Checks if a given number is a palindrome.
"""
str_num = str(number)
return str_num == str_num[::-1]
def largest_palindrome(n):
"""
Returns the largest palindrome number less than n.
"""
for num in range(n-1, -1, -1):
if is_palindrome(num):
... | from solution import largest_palindrome
def test_palindrome_below_123():
assert largest_palindrome(123) == 121
def test_palindrome_below_1000():
assert largest_palindrome(1000) == 999
def test_palindrome_below_10():
assert largest_palindrome(10) == 9
def test_palindrome_below_1():
assert largest_pal... | [
{
"docstring": "Checks if a given number is a palindrome.",
"function_declaration": "def is_palindrome(number):",
"function_name": "is_palindrome",
"parameter_list": "(number)"
},
{
"docstring": "Returns the largest palindrome number less than n.",
"function_declaration": "def largest_pa... | [
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 largest_palindrome(n):\n \"\"\"\n Returns the largest palindrome number less than n.\n \"\"\"\n # Iterate from n-1 to 1 to find the largest palindr... | trial_gpt4o_4 | {
"original_instruction": "Write a function that takes an integer `n` and returns the largest palindrome number less than `n`.\n\n### Examples\n```python\nlargest_palindrome(123) => 121 # 121 is the largest palindrome number less than 123\nlargest_palindrome(1000) => 999 # 999 is a palindrome and less than 1000\nlar... | 0.718866 | Taco_44659 | C | [
"is_palindrome",
"largest_palindrome"
] | 2 | [
[
"largest_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1a383562f4fe0418486074bcf2f920dd4f12d527 | b54821dafe7b297be7056ab9c306996797ba9e95 | |||
v1.0 | complete | Taco | Taco_44682_C | def is_cyclic_permutation(s1, s2):
"""
Determines if one string is a cyclic permutation of another string.
>>> is_cyclic_permutation("abcd", "dabc")
True
>>> is_cyclic_permutation("abcd", "abdc")
False
>>> is_cyclic_permutation("abc", "cab")
True
>>> is_cyclic_permutation("aa", "aa")... | def is_cyclic_permutation(s1, s2):
"""
Determines if s1 is a cyclic permutation of s2.
"""
if len(s1) != len(s2):
return False
return s2 in (s1 + s1)
def check_cyclic_permutations(pairs):
"""
Given a list of string pairs, return a list of "yes" or "no" indicating
if one string ... | from solution import is_cyclic_permutation, check_cyclic_permutations
def test_is_cyclic_permutation():
assert is_cyclic_permutation("abcd", "dabc") == True
assert is_cyclic_permutation("abcd", "abdc") == False
assert is_cyclic_permutation("abc", "cab") == True
assert is_cyclic_permutation("aa", "aa") ... | [
{
"docstring": "Determines if s1 is a cyclic permutation of s2.",
"function_declaration": "def is_cyclic_permutation(s1, s2):",
"function_name": "is_cyclic_permutation",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Given a list of string pairs, return a list of \"yes\" or \"no\" indicatin... | [
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_cyclic_permutation(str1, str2):\n \"\"\"\n Determines if str1 is a cyclic permutation of str2.\n \"\"\"\n if len(str1) != len(str2):\n re... | trial_gpt4o_2 | {
"original_instruction": "A string is called a cyclic permutation of another string if it can be obtained by shifting its characters circularly any number of times. Write a program that, given two strings, determines if one is a cyclic permutation of the other. \n\nFor example, the strings \"abcd\" and \"dabc\" are ... | 0.631076 | Taco_44682 | C | [
"is_cyclic_permutation",
"check_cyclic_permutations"
] | 2 | [
[
"check_cyclic_permutations",
"is_cyclic_permutation"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 69675b01aaff3260250f650223bba848c175d37f | 90d01ebaef1fa3bef670f9c1882f8d49e68efcca | |||
v1.0 | complete | Taco | Taco_44369_C | from typing import List, Dict, Tuple
from collections import defaultdict, deque
def simulate_datasets(datasets: List[Dict]) -> List[int]:
"""
Simulate multiple datasets of network traffic scenarios and return the results of data transfer requests.
Arguments:
datasets -- List of dictionaries, wher... | from collections import defaultdict, deque
def bfs(capacity, parent, source, sink):
visited = set()
queue = deque([source])
visited.add(source)
while queue:
u = queue.popleft()
for v in capacity[u]:
if v not in visited and capacity[u][v] > 0: # If there's avai... | from solution import simulate_datasets
def test_single_small_case():
datasets = [{
'meta': (4, 5, 3),
'links': [
(0, 1, 10),
(0, 2, 5),
(1, 2, 15),
(1, 3, 10),
(2, 3, 5)
],
'requests': [
(0, 3, 10),
... | [
{
"docstring": null,
"function_declaration": "def bfs(capacity, parent, source, sink):",
"function_name": "bfs",
"parameter_list": "(capacity, parent, source, sink)"
},
{
"docstring": null,
"function_declaration": "def edmonds_karp(capacity, source, sink):",
"function_name": "edmonds... | [
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 defaultdict, deque\n\ndef bfs_capacity_path(flow, source, sink, path):\n visited = set()\n queue = deque([source])\n visited.add(s... | trial_gpt4o_3 | {
"original_instruction": "You are tasked with the development of a sophisticated program that can analyze and manage network traffic in a simulated environment. The network consists of several nodes interconnected by bidirectional links. Each link between two nodes has an associated bandwidth representing the maximu... | 0.539331 | Taco_44369 | C | [
"bfs",
"edmonds_karp",
"analyze_network",
"simulate_datasets",
"main"
] | 5 | [
[
"analyze_network",
"edmonds_karp"
],
[
"edmonds_karp",
"bfs"
],
[
"simulate_datasets",
"analyze_network"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 242fd59de5cd2a3b1093a4aec811371a3780c785 | 900d3b16c43ea8d36938c85f99f35868792d0655 | |||
v1.0 | complete | Taco | Taco_44616_C | import math
from typing import List
def is_prime(n: int) -> bool:
"""
Helper function to check 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
for i in range(3, int(math.sqrt(n)) ... | import math
def is_prime(n):
"""
Helper function to check 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
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
... | from solution import count_prime_ages_greater_than_x
def test_example_1():
assert count_prime_ages_greater_than_x(6, 10, [11, 14, 17, 18, 19, 21]) == 3
def test_example_2():
assert count_prime_ages_greater_than_x(5, 20, [22, 23, 24, 29, 30]) == 2
def test_all_ages_non_prime():
assert count_prime_ages_gre... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Counts the number of ages that are both greater than X and prime numbers.",
"function_declaration": "def co... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n... | trial_gpt4o_0 | {
"original_instruction": "We have an array of N elements where each element represents the age of a person in a community. Write a function to determine the number of people whose age is both greater than a given X and a prime number.\n\nConstraints\n\n* All values in input are integers.\n* 1 \\leq N \\leq 100\n* 1 ... | 0.715684 | Taco_44616 | C | [
"is_prime",
"count_prime_ages_greater_than_x"
] | 2 | [
[
"count_prime_ages_greater_than_x",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b7bf7a0c4319cb0e2fa2c798dd7c6056519b7fb0 | c8ef190373ad1687e5f16b28cedbe592ced07898 | |||
v1.0 | complete | Taco | Taco_44806_C | def get_mst_cost(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Calculate the total cost of the Minimum Spanning Tree for the given number of locations and edges.
Return -1 if it's not possible to connect all nodes.
Args:
n (int): Number of locations (nodes).
edges (List[Tuple[int, int,... | 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 get_mst_cost
def test_mst_basic():
assert get_mst_cost(4, [(1, 2, 1), (2, 3, 4), (3, 4, 2), (4, 1, 3)]) == 6
def test_mst_disconnected():
assert get_mst_cost(4, [(1, 2, 1), (2, 3, 4)]) == -1 # Node 4 is disconnected
def test_mst_single_node():
assert get_mst_cost(1, []) == 0
def te... | [
{
"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,
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 else:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(paren... | trial_gpt4o_1 | {
"original_instruction": "A company has a transportation system that moves goods between different locations. Each location is represented as a node, and each direct route between two locations is represented as an edge with a given weight corresponding to the cost of transportation. Due to cost constraints, the com... | 0.709385 | Taco_44806 | C | [
"find",
"union",
"get_mst_cost"
] | 3 | [
[
"get_mst_cost",
"find"
],
[
"get_mst_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 6d77ab4ca222774e714dbad19638854b28f9a02f | 6c7cca42859fa6b54222425974ce4bba515151f6 | |||
v1.0 | complete | Taco | Taco_44184_C | import random
def secret_santa(names):
"""Generate a random Secret Santa gift-giving assignment for a list of friends.
Ensure that no one gives a gift to themselves and no one receives more than one gift.
Args:
names (List[str]): List of names of friends participating in Secret Santa.
Returns... | import random
def secret_santa(names):
total_friends = len(names)
givers = names[:]
receivers = names[:]
random.shuffle(receivers)
# Ensure no one receives their own gift
while any(giver == receiver for giver, receiver in zip(givers, receivers)):
random.shuffle(receivers)
... | from solution import parse_input, generate_assignments, secret_santa, format_output
def test_secret_santa():
names = ['alice', 'bob', 'charlie']
assignments = secret_santa(names)
givers = [assignment.split(" -> ")[0] for assignment in assignments]
receivers = [assignment.split(" -> ")[1] for assignment... | [
{
"docstring": null,
"function_declaration": "def secret_santa(names):",
"function_name": "secret_santa",
"parameter_list": "(names)"
},
{
"docstring": null,
"function_declaration": "def generate_assignments(test_cases):",
"function_name": "generate_assignments",
"parameter_list"... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import random\n\ndef secret_santa_assignment(num_cases, cases):\n results = []\n for case in cases:\n N = case[0]\n friends = case[1]\n ... | trial_gpt4o_2 | {
"original_instruction": "A group of friends are planning a \"Secret Santa\" gift exchange for the holidays. Each friend buys a gift for another randomly assigned friend. However, because the group takes their holiday fun very seriously, they have imposed some strict rules to ensure fairness and mystery:\n\n1. No on... | 0.591144 | Taco_44184 | C | [
"secret_santa",
"generate_assignments",
"parse_input",
"format_output"
] | 4 | [
[
"generate_assignments",
"secret_santa"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | 91ca728a6a16b8c7e158f7251e0e03007edbe5f3 | 9ab4f3fb6bd7a1f1f8add7c7faa917dd7b6ddaba | |||
v1.0 | complete | Taco | Taco_44522_C | def maximum_bandwidth_within_budget(n: int, m: int, B: int, cables: List[Tuple[int, int, int, int]]) -> int:
"""
Determine the maximum bandwidth capacity of a connected network that can be established within a given budget.
Parameters:
n (int): The number of computers.
m (int): The number of c... | import heapq
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):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
... | import pytest
from solution import maximum_bandwidth_within_budget
def test_case1():
assert maximum_bandwidth_within_budget(4, 5, 20, [(1, 2, 5, 4), (2, 3, 6, 5), (3, 4, 4, 3), (1, 3, 2, 6), (1, 4, 3, 8)]) == 15
def test_case2():
assert maximum_bandwidth_within_budget(3, 3, 7, [(1, 2, 3, 8), (2, 3, 2, 5), (1... | [
{
"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,
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": "import heapq\nfrom collections import defaultdict\n\ndef maximum_bandwidth(n, m, B, cables):\n def kruskal(n, edges):\n parent = list(range(n))\n ... | trial_gpt4o_7 | {
"original_instruction": "Eleanor is managing a network of computers for a scientific research organization. The network consists of n computers (numbered from 1 to n) and m bidirectional cables (numbered from 1 to m) connecting pairs of computers. Each cable has a bandwidth capacity and a cost associated with its u... | 0.55606 | Taco_44522 | C | [
"find",
"union",
"maximum_bandwidth_within_budget"
] | 3 | [
[
"maximum_bandwidth_within_budget",
"find"
],
[
"maximum_bandwidth_within_budget",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 4f72fb598cdca06fa46a674fdcb00df3984f0d88 | f8e76c5adfadf79eb8580bc2c5900bb43fe75792 | |||
v1.0 | complete | Taco | Taco_43895_C | def is_adjacent(x1, y1, x2, y2):
"""
Checks if two coordinates are adjacent.
>>> is_adjacent(1, 1, 1, 2)
True
>>> is_adjacent(1, 1, 2, 1)
True
>>> is_adjacent(1, 1, 2, 2)
True
>>> is_adjacent(1, 1, 3, 3)
False
>>> is_adjacent(1, 1, 1, 1)
True
"""
def max_non_adjacent... | def is_adjacent(x1, y1, x2, y2):
"""
Checks if two coordinates are adjacent.
"""
return abs(x1 - x2) <= 1 and abs(y1 - y2) <= 1
def max_non_adjacent_treasures(N, locations):
"""
Returns the maximum number of non-adjacent treasures that can be hidden.
"""
from itertools import combinatio... | def test_is_adjacent():
assert is_adjacent(1, 1, 1, 2) == True
assert is_adjacent(1, 1, 2, 1) == True
assert is_adjacent(1, 1, 2, 2) == True
assert is_adjacent(1, 1, 3, 3) == False
assert is_adjacent(1, 1, 1, 1) == True
def test_max_non_adjacent_treasures():
assert max_non_adjacent_treasures(4,... | [
{
"docstring": "Checks if two coordinates are adjacent.",
"function_declaration": "def is_adjacent(x1, y1, x2, y2):",
"function_name": "is_adjacent",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": "Returns the maximum number of non-adjacent treasures that can be hidden.",
"functi... | [
0,
1
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_adjacent(x1, y1, x2, y2):\n \"\"\"\n Checks if two coordinates (x1, y1) and (x2, y2) are adjacent horizontally,\n vertical... | trial_gpt4o_2 | {
"original_instruction": "A group of friends are planning a treasure hunt and need your help to determine the optimal way to hide their treasure using locations in the forest. Here’s how the game works:\n\nThey have a map of the forest divided into a grid of cells. Each cell is identified by a pair of coordinates (x... | 0.602867 | Taco_43895 | C | [
"is_adjacent",
"max_non_adjacent_treasures",
"solve_treasure_hunt"
] | 3 | [
[
"max_non_adjacent_treasures",
"is_adjacent"
],
[
"solve_treasure_hunt",
"max_non_adjacent_treasures"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | bb286a6aa73de7da316da59555d5bac6d09b7f07 | 92419d2d3cf02d7f593b6333d430c909f0f8e3c1 | |||
v1.0 | complete | Taco | Taco_44923_C | def min_edges_to_connect_graph(test_cases):
""" Given multiple test cases of undirected graphs represented by a set of nodes and edges,
determine the minimum number of edges needed to add so that each graph becomes connected.
Args:
test_cases (List[Tuple[int, int, List[Tuple[int, int]]]]): A l... | def find_parent(parent, node):
if parent[node] != node:
parent[node] = find_parent(parent, parent[node])
return parent[node]
def union(parent, rank, node1, node2):
root1 = find_parent(parent, node1)
root2 = find_parent(parent, node2)
if root1 != root2:
if rank[root1] > rank... | from solution import min_edges_to_connect_graph
def test_example_cases():
assert min_edges_to_connect_graph([
(4, 2, [(1, 2), (3, 4)]),
(5, 3, [(1, 2), (2, 3), (4, 5)]),
(3, 0, [])
]) == [1, 1, 2]
def test_single_node_cases():
assert min_edges_to_connect_graph([
(1, 0, []),... | [
{
"docstring": null,
"function_declaration": "def find_parent(parent, node):",
"function_name": "find_parent",
"parameter_list": "(parent, node)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, node1, node2):",
"function_name": "union",
"parameter_list": ... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, x):\n if parent[x] != x:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\ndef union(parent, rank, x, y):\n rootX = find... | trial_gpt4o_1 | {
"original_instruction": "Given an undirected graph represented by a set of nodes and edges, determine the minimum number of edges needed to add so that the graph becomes connected. A graph is connected if there is a path between any pair of nodes.\n\nInput\n\nThe input consists of multiple test cases. The first lin... | 0.62806 | Taco_44923 | C | [
"find_parent",
"union",
"min_edges_to_connect_graph"
] | 3 | [
[
"min_edges_to_connect_graph",
"find_parent"
],
[
"min_edges_to_connect_graph",
"union"
],
[
"union",
"find_parent"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 4fa1cde8f251858e8935339be862582b8c3ed0a9 | c7b0ff108684065d11b092145753970fb491e508 | |||
v1.0 | complete | Taco | Taco_44905_C | from typing import List
def is_prime(num: int) -> bool:
""" Check if a number is prime.
>>> is_prime(2)
True
>>> is_prime(3)
True
>>> is_prime(4)
False
>>> is_prime(17)
True
>>> is_prime(18)
False
"""
pass
def nearest_smaller_prime(num: int) -> int:
""" Find the... | def is_prime(num):
""" Check if a number is prime. """
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def nearest_smaller_prime(num):
... | from solution import is_prime, nearest_smaller_prime, transform_list
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_nearest_smaller_prime():
assert nearest_smaller_prime(10... | [
{
"docstring": "Check if a number is prime. ",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Find the nearest smaller prime number less than the given number. ",
"function_declaration": "def nearest_smaller_prime(n... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n if ... | trial_gpt4o_2 | {
"original_instruction": "**Problem Statement:**\nAlice is teaching a class of young students the concept of prime numbers. She comes up with a fun exercise for the class. She provides each student with a list of numbers and asks them to replace each non-prime number in the list with the nearest smaller prime number... | 0.708264 | Taco_44905 | C | [
"is_prime",
"nearest_smaller_prime",
"transform_list"
] | 3 | [
[
"nearest_smaller_prime",
"is_prime"
],
[
"transform_list",
"is_prime"
],
[
"transform_list",
"nearest_smaller_prime"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 9a53ef07ac3c9f36dd5320c63afc0f20e69f1320 | f11338127b88a1eea5be48badfe69dc4d5bbd2e3 | |||
v1.0 | complete | Taco | Taco_44895_C | def unique_paths_with_obstacles(grid) -> int:
""" Determine the number of unique paths from the top-left corner to the bottom-right corner of the grid.
>>> unique_paths_with_obstacles([[0, 0, 0], [0, 1, 0], [0, 0, 0]])
2
>>> unique_paths_with_obstacles([[0, 1], [1, 0]])
0
"""
def solve_number_o... | def unique_paths_with_obstacles(grid):
if not grid or grid[0][0] == 1 or grid[-1][-1] == 1:
return 0
R, C = len(grid), len(grid[0])
dp = [[0] * C for _ in range(R)]
dp[0][0] = 1
for r in range(R):
for c in range(C):
if grid[r][c] == 1:
dp[r][c] = 0
... | import pytest
from solution import process_input
def test_example_1():
raw_input = "2\n3 3\n0 0 0\n0 1 0\n0 0 0\n2 2\n0 1\n1 0\n"
result = process_input(raw_input)
assert result == [2, 0]
def test_no_obstacles():
raw_input = "1\n3 3\n0 0 0\n0 0 0\n0 0 0\n"
result = process_input(raw_input)
ass... | [
{
"docstring": null,
"function_declaration": "def unique_paths_with_obstacles(grid):",
"function_name": "unique_paths_with_obstacles",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve_number_of_unique_paths(test_cases):",
"function_name": "solve_n... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def unique_paths_with_obstacles(grid):\n if not grid or grid[0][0] == 1 or grid[-1][-1] == 1:\n return 0\n\n R, C = len(grid), len(grid[0])\n dp = ... | trial_gpt4o_0 | {
"original_instruction": "You are given a patch of rectangular tiles arranged in a grid with $R$ rows and $C$ columns. Each tile can either be plain (represented by 0) or have an obstacle (represented by 1). You need to start in the top-left corner of the grid and reach the bottom-right corner while navigating aroun... | 0.622398 | Taco_44895 | C | [
"unique_paths_with_obstacles",
"solve_number_of_unique_paths",
"parse_input",
"process_input"
] | 4 | [
[
"process_input",
"parse_input"
],
[
"process_input",
"solve_number_of_unique_paths"
],
[
"solve_number_of_unique_paths",
"unique_paths_with_obstacles"
]
] | 3 | [
"parse_input",
"process_input"
] | false | [] | false | pytest | true | [] | true | 060b4abc125f1ef921e7cbd394c6aa428dafe4a2 | 49f4c29c679609d4b3a6a211bb1384a850a51dc5 | |||
v1.0 | complete | Taco | Taco_44748_C | def max_trapped_water(grid, n, m):
""" Determine the maximum amount of water that can be trapped between the buildings after a rain on a grid of buildings.
Args:
grid: List[List[int]]: A n x m grid representing the height of the buildings.
n: int: The number of rows in the grid.
m: int: The number o... | def max_trapped_water(grid, n, m):
if n < 3 or m < 3:
return 0
left_max = [[0]*m for _ in range(n)]
right_max = [[0]*m for _ in range(n)]
top_max = [[0]*m for _ in range(n)]
bottom_max = [[0]*m for _ in range(n)]
for i in range(n):
left_max[i][0] = grid[i][0]
for j in r... | from solution import max_trapped_water, solve_trapped_water
def test_example1():
grid = [
[1, 2, 1],
[2, 1, 2],
[1, 1, 1]
]
n, m = 3, 3
assert max_trapped_water(grid, n, m) == 0
def test_example2():
grid = [
[3, 3, 3],
[3, 0, 3],
[3, 3, 3]
]
... | [
{
"docstring": null,
"function_declaration": "def max_trapped_water(grid, n, m):",
"function_name": "max_trapped_water",
"parameter_list": "(grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def solve_trapped_water(test_cases):",
"function_name": "solve_trapped_water",
... | [
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 calculate_trapped_water(n, m, grid):\n if n < 3 or m < 3:\n return 0\n\n left_max = [[0] * m for _ in range(n)]\n right_max = [[0] * m for _ in... | trial_gpt4o_9 | {
"original_instruction": "You are given a grid of size n x m where each cell contains a number representing the height of a building at that position. A water reservoir is placed over the grid that collects rainwater in the gaps between buildings. \n\nDetermine the maximum amount of water that can be trapped between... | 0.658233 | Taco_44748 | C | [
"max_trapped_water",
"solve_trapped_water",
"parse_input",
"main"
] | 4 | [
[
"solve_trapped_water",
"max_trapped_water"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 803070a4e0764893f9aa127ee2bd2afda620452c | 5967fd295cf5d2177aec0c76beeb5ce872336dc8 | |||
v1.0 | complete | Taco | Taco_45208_C | from math import factorial
from collections import Counter
def unique_permutations_count(s: str) -> int:
"""
Returns the number of unique permutations of the string s.
>>> unique_permutations_count("abc")
6
>>> unique_permutations_count("aab")
3
"""
pass
def process_test_cases(test_ca... | from math import factorial
from collections import Counter
def unique_permutations_count(s):
"""
Returns the number of unique permutations of the string s.
"""
char_count = Counter(s)
denominator = 1
for count in char_count.values():
denominator *= factorial(count)
return factorial(... | from solution import unique_permutations_count
def test_example_cases():
assert unique_permutations_count("abc") == 6
assert unique_permutations_count("aab") == 3
def test_single_character_case():
assert unique_permutations_count("a") == 1
def test_repeated_characters_case():
assert unique_permutatio... | [
{
"docstring": "Returns the number of unique permutations of the string s.",
"function_declaration": "def unique_permutations_count(s):",
"function_name": "unique_permutations_count",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def process_test_cases(test_cas... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import factorial\nfrom collections import Counter\n\ndef unique_permutations_count(s):\n \"\"\"\n Returns the number of unique permutations of the ... | trial_gpt4o_0 | {
"original_instruction": "Alice is interested in finding unique permutations of a given string. She wants to know the total number of unique permutations possible for her string. Given a string S which contains lowercase alphabets, find the number of unique permutations of the string.\n\nInput Format:\n\nThe first l... | 0.699821 | Taco_45208 | C | [
"unique_permutations_count",
"process_test_cases",
"gather_input",
"output_results"
] | 4 | [
[
"process_test_cases",
"unique_permutations_count"
]
] | 1 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 345ec6efd99d0f6cc8c8e28b0c4fd43302ba103d | 835bcdd439ab1a1d49dc6a3a6f26f3ef375c1fdb | |||
v1.0 | complete | Taco | Taco_44763_C | def find_central_logistics_center(n: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the optimal city to build the central logistics center.
The optimal city minimizes the total travel distance from this center to all other cities.
Args:
n (int): The number of cities (nodes).
... | import heapq
def dijkstra(graph, start, n):
"""
Perform Dijkstra's algorithm to find the shortest paths from start node to all other nodes in a weighted graph.
"""
distances = {i: float('inf') for i in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_q... | def test_solution():
from solution import find_central_logistics_center
# Test case 1
n = 4
edges = [(1, 2, 4), (1, 3, 2), (2, 3, 1), (3, 4, 7)]
assert find_central_logistics_center(n, edges) == 3
# Test case 2
n = 3
edges = [(1, 2, 1), (2, 3, 1), (1, 3, 2)]
assert find_central_log... | [
{
"docstring": "Perform Dijkstra's algorithm to find the shortest paths from start node to all other nodes in a weighted graph.",
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef optimal_city(N, M, routes):\n def dijkstra(source):\n dist = [float('inf')] * (N + 1)\n dist[source] = 0\n pq = [(0, so... | trial_gpt4o_1 | {
"original_instruction": "The planet of Zog has a unique network of inter-connected cities, each city represented as a node and each route between them as an edge with a certain distance. Aliens on Zog want to establish a central logistics center that minimizes the total travel distance from this center to all other... | 0.615149 | Taco_44763 | C | [
"dijkstra",
"find_central_logistics_center",
"solve"
] | 3 | [
[
"find_central_logistics_center",
"dijkstra"
],
[
"solve",
"find_central_logistics_center"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 5f3acf4e30e9a702d1a19f952dd5d41e8637757e | 1795bd7e1587dfde6b642999bfc762cdce24277f | |||
v1.0 | complete | Taco | Taco_45214_C | def num_islands(grid: List[List[str]]) -> int:
"""
Finds and returns the number of islands in the given grid.
>>> num_islands([['1', '1', '0', '0', '0'],
['1', '1', '0', '0', '0'],
['0', '0', '1', '0', '0'],
['0', '0', '0', '1', '1']]) == 3
>>> num_islands([['1', '1', '1'],
['0', '1', '... | def num_islands(grid):
"""
Finds and returns the number of islands in the given grid.
"""
if not grid:
return 0
n = len(grid)
m = len(grid[0])
visited = [[False for _ in range(m)] for _ in range(n)]
def dfs(x, y):
if x < 0 or y < 0 or x >= n or y >= m or grid[x]... | def test_num_islands_single():
assert islands_from_input('3 3\n111\n010\n111') == 1
def test_num_islands_multiple():
assert islands_from_input('4 5\n11000\n11000\n00100\n00011') == 3
def test_num_islands_none():
assert islands_from_input('3 3\n000\n000\n000') == 0
def test_num_islands_one_row():
asse... | [
{
"docstring": "Finds and returns the number of islands in the given grid.",
"function_declaration": "def num_islands(grid):",
"function_name": "num_islands",
"parameter_list": "(grid)"
},
{
"docstring": "Parses the input and returns the grid and consists of the main logic to calculate the 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": "def count_islands(grid):\n \"\"\"\n Returns the number of islands in the given grid.\n \"\"\"\n if not grid:\n return 0\n\n n = len(grid)\n ... | trial_gpt4o_1 | {
"original_instruction": "You are given a 2D grid of size 'n x m' representing a map where:\n\n- `'1'` represents land.\n- `'0'` represents water.\n\nAn island is formed by connecting adjacent lands horizontally or vertically. You must write a function that finds and returns the number of islands.\n\nInput\n\nThe fi... | 0.579004 | Taco_45214 | C | [
"num_islands",
"islands_from_input"
] | 2 | [
[
"islands_from_input",
"num_islands"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 64982fe9cceb251e3294f5a21d0cec96f810d7b8 | 5e17e42c92eae85647e26ad97c9722ef27139287 | |||
v1.0 | complete | Taco | Taco_45194_C | import itertools
from typing import List, Tuple
def manhattan_distance(x1: int, y1: int, x2: int, y2: int) -> int:
""" Calculate the Manhattan distance between two points."""
return abs(x1 - x2) + abs(y1 - y2)
def find_shortest_route(x0: int, y0: int, addresses: List[Tuple[int, int]]) -> int:
""" Find the... | import itertools
def manhattan_distance(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def find_shortest_route(x0, y0, addresses):
min_distance = float('inf')
address_permutations = itertools.permutations(addresses)
for perm in address_permutations:
current_distance = 0
curre... | from solution import find_shortest_route
def test_example_case():
x0, y0 = 0, 0
addresses = [(1, 1), (2, 2), (3, 3)]
assert find_shortest_route(x0, y0, addresses) == 12
def test_single_address():
x0, y0 = 0, 0
addresses = [(1, 1)]
assert find_shortest_route(x0, y0, addresses) == 4
def test_tw... | [
{
"docstring": null,
"function_declaration": "def manhattan_distance(x1, y1, x2, y2):",
"function_name": "manhattan_distance",
"parameter_list": "(x1, y1, x2, y2)"
},
{
"docstring": null,
"function_declaration": "def find_shortest_route(x0, y0, addresses):",
"function_name": "find_sh... | [
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": "from itertools import permutations\n\ndef manhattan_distance(p1, p2):\n return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])\n\ndef minimum_route_distance(warehouse, ... | trial_gpt4o_9 | {
"original_instruction": "A delivery company is working on optimizing its route planning system. The goal is to minimize the total distance covered while delivering packages to multiple addresses. The company operates in a grid-like city where each cell represents an address and the distance between any two cells is... | 0.639348 | Taco_45194 | C | [
"manhattan_distance",
"find_shortest_route"
] | 2 | [
[
"find_shortest_route",
"manhattan_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3199afb1acdb088f7a27c86734608b74d5a6e4bf | 717ae08229c72bee412ef366205e7b8108eb04eb | |||
v1.0 | complete | Taco | Taco_44675_C | def can_travel_and_min_flights(n: int, m: int, flights: List[Tuple[int, int]]) -> int:
""" Given n cities and m direct flights between them, determine if it is possible to travel between any two cities using only the given flights. If possible, compute the minimum number of flights required to visit all cities star... | def bfs(start, adj_list, visited):
"""
Perform BFS on the graph to mark all reachable nodes from the start node.
"""
queue = [start]
while queue:
node = queue.pop(0)
for neighbor in adj_list[node]:
if not visited[neighbor]:
visited[neighbor] = True
... | from solution import can_travel_and_min_flights
def test_case_1():
n = 4
m = 4
flights = [(1, 2), (2, 3), (3, 4), (4, 1)]
assert can_travel_and_min_flights(n, m, flights) == 3
def test_case_2():
n = 4
m = 2
flights = [(1, 2), (2, 3)]
assert can_travel_and_min_flights(n, m, flights) == ... | [
{
"docstring": "Perform BFS on the graph to mark all reachable nodes from the start node.",
"function_declaration": "def bfs(start, adj_list, visited):",
"function_name": "bfs",
"parameter_list": "(start, adj_list, visited)"
},
{
"docstring": null,
"function_declaration": "def can_travel... | [
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_min_flights(n, m, flights):\n from collections import defaultdict, deque\n \n if n == 1:\n return 0\n \n graph = defaultdict(list)\n... | trial_gpt4o_1 | {
"original_instruction": "Given n cities and m direct flights between them, find if it’s possible to travel between any two cities by only using these flights. If it is possible, determine the minimum number of flights required to visit all cities starting from any city.\n\nEach of the cities is numbered from 1 to n... | 0.721137 | Taco_44675 | C | [
"bfs",
"can_travel_and_min_flights"
] | 2 | [
[
"can_travel_and_min_flights",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9f6386a4512eb63db6779d9cda14032d29738a00 | 49cafe3b84551e8b5f829f988e6d430655630000 | |||
v1.0 | complete | Taco | Taco_45423_C | def count_paths(grid) -> int:
"""
Calculate the number of distinct paths from the top-left corner to the bottom-right corner of the grid, avoiding traps.
Args:
grid (List[List[str]]): MxN grid with '.' representing a free cell and '#' representing a trap.
Returns:
int: The number of d... | def count_paths(grid):
MOD = 10**9 + 7
M = len(grid)
N = len(grid[0])
# Create a dp array for storing number of ways to reach each cell
dp = [[0] * N for _ in range(M)]
# Start position always has one way to be reached
dp[0][0] = 1
for i in range(M):
for j in range... | def test_count_paths_example_1():
input_str = "3 3\n...\n.#.\n..."
assert solve(input_str) == 2
def test_count_paths_no_path():
input_str = "3 3\n.#.\n.#.\n.#."
assert solve(input_str) == 0
def test_count_paths_single_column():
input_str = "3 1\n.\n.\n."
assert solve(input_str) == 1
def tes... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid):",
"function_name": "count_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve(input_str):",
"function_name": "solve",
"parameter_list": "(input_str)"
}
] | [
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": "MOD = 10**9 + 7\n\ndef count_paths(m, n, grid):\n dp = [[0] * n for _ in range(m)]\n \n if grid[0][0] == '#':\n return 0\n \n dp[0][0] = 1\n ... | trial_gpt4o_4 | {
"original_instruction": "A group of treasure hunters is exploring an ancient temple, and they encountered a corridor guarded by a series of traps. Each trap is represented by a cell in a grid, and the corridor has exactly M rows and N columns. The hunters need to navigate from the top-left corner to the bottom-righ... | 0.715673 | Taco_45423 | C | [
"count_paths",
"solve"
] | 2 | [
[
"solve",
"count_paths"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 51dd2abf9c0e7f9953343804e55798217bef3af6 | a7988572916365622e2f58fd169a869b0e2e4dbd | |||
v1.0 | complete | Taco | Taco_45234_C | MOD = 10**9 + 7
def max_path_beauty(n, roads, A, B):
""" Determine the maximum beauty of any path from city A to city B in a tree of cities.
The roads are organized as a tree and each has a beauty index.
The function should return the maximum sum of beauty indices of the roads on the path from city A to ci... | MOD = 10**9 + 7
def dfs(graph, node, parent, target, path_sum, path):
if node == target:
return path_sum
for neighbor, weight in graph[node]:
if neighbor != parent:
result = dfs(graph, neighbor, node, target, path_sum + weight, path + [weight])
if result is not None... | from solution import max_path_beauty
def test_example_1():
n = 5
roads = [
(1, 2, 4),
(1, 3, 6),
(2, 4, 5),
(2, 5, 3)
]
A = 3
B = 4
assert max_path_beauty(n, roads, A, B) == 15
def test_small_tree():
n = 2
roads = [
(1, 2, 1)
]
A = 1
... | [
{
"docstring": null,
"function_declaration": "def dfs(graph, node, parent, target, path_sum, path):",
"function_name": "dfs",
"parameter_list": "(graph, node, parent, target, path_sum, path)"
},
{
"docstring": null,
"function_declaration": "def max_path_beauty(n, roads, A, B):",
"fun... | [
0,
0,
1,
0
] | 1 | hard | 0.25 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_path_beauty(n, roads, A, B):\n from collections import defaultdict, deque\n \n MOD = 10**9 + 7\n \n # Create an adjacency list to represent ... | trial_gpt4o_3 | {
"original_instruction": "In a country where roads are organized as a tree of cities (i.e., a connected acyclic graph), each road has a beauty index. The beauty index of a set of roads is defined as the sum of their indices mod 10^9 + 7. You are a tourist who wants to travel from city A to city B. To make your trave... | 0.648124 | Taco_45234 | C | [
"dfs",
"max_path_beauty"
] | 2 | [
[
"max_path_beauty",
"dfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 684ad3e827ab10c864c85b18c4a1f777c3eef435 | 6b49c02836429851593dc5c4148847160b2657a3 | |||
v1.0 | complete | Taco | Taco_45255_C | from typing import List
def is_prime(num: int) -> bool:
""" Returns True if the given number is prime, otherwise False.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
def find_sequence(k: int, n: int) -> List[int]:
""" Returns the first n elements of the sequence starting with k.
>>> f... | def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def find_sequence(k, n):
sequence = [k]
current_num = k + 1
while len(sequence) < n:
if is_prime(current_num):
sequence... | from solution import is_prime, find_sequence
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(11) == True
def test_find_sequence_case_1():
assert find_sequence(1, 5)... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def find_sequence(k, n):",
"function_name": "find_sequence",
"parameter_list": "(k, n)"
}
] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def generate_primes(up_to):\n \"\"\"\n Helper function to generate a list of prime numbers up to a specified number.\n \"\"\"\n primes = []\n candid... | trial_gpt4o_1 | {
"original_instruction": "There exists a unique sequence of integers a1, a2, ..., an that is subjected to the following iterative process:\n\n1. Initially, the sequence contains only one element a1 = k.\n2. For each subsequent element, ai = pi for i = 2 to n, where pi is the position of i-th prime number in the sequ... | 0.783444 | Taco_45255 | C | [
"is_prime",
"find_sequence"
] | 2 | [
[
"find_sequence",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | beada1e434351bb4250645eb358ec164e970f5a8 | fa842ae4bfa438107dd0d8af600f9c4360112a42 | |||
v1.0 | complete | Taco | Taco_45223_C | from typing import List, Tuple
def has_cycle_in_network(test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[str]:
""" Determine if there is a cycle in the communication network for each test case.
Args:
test_cases (List[Tuple[int, int, List[Tuple[int, int]]]]): A list of test cases, where eac... | from collections import defaultdict
def detect_cycle_util(v, visited, rec_stack, graph):
visited[v] = True
rec_stack[v] = True
for neighbor in graph[v]:
if not visited[neighbor]:
if detect_cycle_util(neighbor, visited, rec_stack, graph):
return True
elif rec... | from solution import has_cycle_in_network
def test_sample_input():
test_cases = [
(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)]),
(3, 2, [(1, 2), (2, 3)])
]
assert has_cycle_in_network(test_cases) == ["Yes", "No"]
def test_no_edges():
test_cases = [
(3, 0, []),
(5, 0, [])
... | [
{
"docstring": null,
"function_declaration": "def detect_cycle_util(v, visited, rec_stack, graph):",
"function_name": "detect_cycle_util",
"parameter_list": "(v, visited, rec_stack, graph)"
},
{
"docstring": null,
"function_declaration": "def detect_cycle(n, edges):",
"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": "from collections import defaultdict\n\ndef has_cycle(N, communications):\n adj_list = defaultdict(list)\n for x, y in communications:\n adj_list[x].ap... | trial_gpt4o_2 | {
"original_instruction": "In a distant future, machines have become capable of forming social groups. Machines in a group communicate with each other through a network. Interestingly, they maintain records of their communications. Each communication is represented as a message from machine X to machine Y. Given such... | 0.552442 | Taco_45223 | C | [
"detect_cycle_util",
"detect_cycle",
"has_cycle_in_network"
] | 3 | [
[
"detect_cycle",
"detect_cycle_util"
],
[
"has_cycle_in_network",
"detect_cycle"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 02ef4c93859984c024d54834ebb5b3128d58b9c2 | 54be30fdaaf98f42f8f24a1becdbf517b0afd467 | |||
v1.0 | complete | Taco | Taco_45490_C | from typing import List, Tuple
def minimize_max_distance(n: int, roads: List[Tuple[int, int, int]]) -> int:
""" Determine the optimal village to place the fountain so that the maximum distance any village has to travel to
get to the fountain is minimized.
Parameters:
n (int): The number of village... | from collections import defaultdict, deque
def find_furthest(node, n, graph):
dist = [-1] * (n + 1)
queue = deque([node])
dist[node] = 0
furthest_node, max_dist = node, 0
while queue:
curr = queue.popleft()
for nei, length in graph[curr]:
if dist[nei] == -1:
... | from solution import minimize_max_distance
def test_minimize_max_distance_basic():
assert minimize_max_distance(5, [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6)]) == 9
def test_minimize_max_distance_single_node():
assert minimize_max_distance(1, []) == 0
def test_minimize_max_distance_two_nodes():
assert m... | [
{
"docstring": null,
"function_declaration": "def find_furthest(node, n, graph):",
"function_name": "find_furthest",
"parameter_list": "(node, n, graph)"
},
{
"docstring": null,
"function_declaration": "def minimize_max_distance(n, roads):",
"function_name": "minimize_max_distance",
... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef bfs(start, n, adj):\n dist = [-1] * (n + 1)\n dist[start] = 0\n queue = deque([start])\n \n farthe... | trial_gpt4o_9 | {
"original_instruction": "The kingdom of Algorithmsland is composed of numerous villages, each connected by a series of roads. Villagers want to place a fountain in their kingdom such that it minimizes the longest distance any villager has to walk to get water.\n\nThe kingdom has $n$ villages and $n-1$ roads, making... | 0.631623 | Taco_45490 | C | [
"find_furthest",
"minimize_max_distance"
] | 2 | [
[
"minimize_max_distance",
"find_furthest"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f9097924ab42e2cc9ed24934b518ae3bcbabc2bb | f892ccbf7d3ab20327515075f8c5361a8dcbc072 | |||
v1.0 | complete | Taco | Taco_44956_C | from typing import List
def sieve(n: int) -> List[int]:
""" Generates a list of prime numbers up to n using the Sieve of Eratosthenes.
"""
primes = []
is_prime = [True] * (n + 1)
for p in range(2, n + 1):
if is_prime[p]:
primes.append(p)
for multiple in range(p * p, ... | def sieve(n):
primes = []
is_prime = [True] * (n + 1)
for p in range(2, n + 1):
if is_prime[p]:
primes.append(p)
for multiple in range(p * p, n + 1, p):
is_prime[multiple] = False
return primes
def generate_factors(n):
factors = [[] for _ in range(n +... | from solution import max_possible_sum
def test_sample_input_1():
assert max_possible_sum([12, 15, 7]) == 34
assert max_possible_sum([23, 10]) == 33
assert max_possible_sum([4, 6, 8, 9]) == 27
def test_large_number():
assert max_possible_sum([1000000]) == 1000000 # Since 1000000 has multiple factors, ... | [
{
"docstring": null,
"function_declaration": "def sieve(n):",
"function_name": "sieve",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def generate_factors(n):",
"function_name": "generate_factors",
"parameter_list": "(n)"
},
{
"docstring": null,... | [
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": "from typing import List, Tuple\n\ndef sieve(n):\n \"\"\"\n Sieve of Eratosthenes to generate prime factors for every number up to n.\n \"\"\"\n smalles... | trial_gpt4o_5 | {
"original_instruction": "Given an array B of M non-negative integers, find the maximum possible sum of elements you can obtain by modifying the array such that each element can only be either kept the same or replaced with any one of its prime factors. \n\n----- Input Format -----\n\n- The first line contains a sin... | 0.766516 | Taco_44956 | C | [
"sieve",
"generate_factors",
"max_possible_sum",
"process_test_cases",
"main"
] | 5 | [
[
"max_possible_sum",
"generate_factors"
],
[
"process_test_cases",
"max_possible_sum"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | ec99d5de1793aa025f3654237c26643f40c52afd | 9e4ad6cd1c710e7d0447d96986209963ee570281 | |||
v1.0 | complete | Taco | Taco_45573_C | def find_shortest_title(titles):
"""
Finds the shortest book title from a list of book titles.
Parameters:
titles (list): A list of book titles
Returns:
str: The shortest book title
>>> find_shortest_title(["The Great Gatsby", "A Tale of Two Cities", "Ulysses", "Don Quixote", ... | def find_shortest_title(titles):
"""
Finds the shortest book title from a list of book titles.
Parameters:
titles (list): A list of book titles
Returns:
str: The shortest book title
"""
if not titles:
return ""
shortest_title = titles[0]
shortest_length... | from solution import find_shortest_title
def test_find_shortest_title_single_title():
assert find_shortest_title(["The Great Gatsby"]) == "The Great Gatsby"
def test_find_shortest_title_same_length_titles():
assert find_shortest_title(["AA", "BB", "CC", "A"]) == "A"
def test_find_shortest_title_varied_length... | [
{
"docstring": "Finds the shortest book title from a list of book titles.\n\nParameters:\ntitles (list): A list of book titles\n\nReturns:\nstr: The shortest book title",
"function_declaration": "def find_shortest_title(titles):",
"function_name": "find_shortest_title",
"parameter_list": "(titles)"
... | [
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_shortest_title(titles):\n \"\"\"\n Finds the shortest book title from a list of book titles.\n \n Parameters:\n titles (list): A list of bo... | trial_gpt4o_0 | {
"original_instruction": "Lee has a task of organizing a list of book titles by their length. He wants to determine which book title in the list is the shortest.\n\nWrite a program that helps Lee find the shortest book title.\n\n------ Input Format ------ \n\n- The first line will contain an integer N - the number o... | 0.552704 | Taco_45573 | C | [
"find_shortest_title",
"process_book_titles"
] | 2 | [
[
"process_book_titles",
"find_shortest_title"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3ed4667d7ed28820e46b16ee0d2bb0b1485eae0b | 5ad548fffd828ccd72ec14571a63323b4e0ce43b | |||
v1.0 | complete | Taco | Taco_45487_C | def shortest_path_length(n: int, m: int, grid: List[List[str]]) -> int:
"""
A logistics company handles the delivery of packages in a city represented as a grid of size n x m.
Each cell in the grid either contains a delivery point (denoted as '*') or is empty (denoted as '.').
The company wants to find ... | from itertools import permutations
from collections import deque
import sys
import numpy as np
def bfs(start, grid, n, m):
"""
Perform BFS to find the shortest path from start to all delivery points.
"""
queue = deque([start])
distance = {start: 0}
while queue:
x, y = queue.popleft()
... | def test_example_case():
grid = [
['*', '.', '.'],
['.', '*', '.'],
['.', '.', '*']
]
assert shortest_path_length(3, 3, grid) == 8
def test_all_empty():
grid = [
['.', '.', '.'],
['.', '.', '.'],
['.', '.', '.']
]
assert shortest_path_length(3, 3,... | [
{
"docstring": "Perform BFS to find the shortest path from start to all delivery points.",
"function_declaration": "def bfs(start, grid, n, m):",
"function_name": "bfs",
"parameter_list": "(start, grid, n, m)"
},
{
"docstring": null,
"function_declaration": "def shortest_path_length(n, m... | [
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 itertools import permutations\nfrom collections import deque\n\ndef find_shortest_path_length(n, m, grid):\n # Extract all delivery point coordinates and a... | trial_gpt4o_3 | {
"original_instruction": "A logistics company handles the delivery of packages in a city which is represented as a grid of size n x m. Each cell in the grid either contains a delivery point (denoted as '*') or is empty (denoted as '.'). The company wants to find the shortest path that visits all the delivery points ... | 0.738906 | Taco_45487 | C | [
"bfs",
"shortest_path_length"
] | 2 | [
[
"shortest_path_length",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [
"numpy"
] | false | b125183a66473050aaf91593a0a46aa9304dd88e | 54f0a92ecb7d5a63955c1fc00dc36fab5280043d | |||
v1.0 | complete | Taco | Taco_45608_C | def can_collect_three_treasures(n, treasures):
""" Determine if Charlotte can collect exactly three treasures without entering overlapping magnetic fields.
Args:
n (int): The number of treasures.
treasures (List[Tuple[int, int, int]]): A list of tuples where each tuple contains the x, y coordinates and... | def can_collect_three_treasures(n, treasures):
import itertools
treasures.sort()
def are_fields_separate(t1, t2):
x1, y1, r1 = t1
x2, y2, r2 = t2
dx = x1 - x2
dy = y1 - y2
distance_squared = dx * dx + dy * dy
radius_sum_squared = (r1 + r2) * (r1 + r2... | def test_example_1(monkeypatch):
from io import StringIO
monkeypatch.setattr('sys.stdin', StringIO('5\n100 100 50\n800 800 40\n1500 1500 60\n300 300 30\n1200 1200 50\n'))
read_input_and_solve()
def test_example_2(monkeypatch):
from io import StringIO
monkeypatch.setattr('sys.stdin', StringIO('4\n50... | [
{
"docstring": null,
"function_declaration": "def can_collect_three_treasures(n, treasures):",
"function_name": "can_collect_three_treasures",
"parameter_list": "(n, treasures)"
},
{
"docstring": null,
"function_declaration": "def read_input_and_solve():",
"function_name": "read_inpu... | [
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 find_treasures(n, treasures):\n treasures.sort()\n \n def can_travel(treasures):\n selected = [treasures[0]]\n \n for i in range(... | trial_gpt4o_4 | {
"original_instruction": "A treasure map provides coordinates of treasures buried in a $2000 \\times 2000$ grid. Each treasure emits a magnetic field detectable within a certain radius. Charlotte must collect exactly three treasures while ensuring that she never passes through an area under the influence of more tha... | 0.539747 | Taco_45608 | C | [
"can_collect_three_treasures",
"read_input_and_solve"
] | 2 | [
[
"read_input_and_solve",
"can_collect_three_treasures"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | c37475c1a8b7589b955e45167c501444bd3ae8cd | 9c7ff05fd58c84ecd899d45d44c37beb7114f6ab | |||
v1.0 | complete | Taco | Taco_45018_C | def common_delivery_point(routes):
"""
Determines if all delivery routes have at least one common delivery point.
:param routes: List of lists, where each list contains delivery points for a specific route.
:return: 'yes' if there is at least one common delivery point, otherwise 'no'.
"""
pass
... | def common_delivery_point(routes):
"""
Determines if all delivery routes have at least one common delivery point.
:param routes: List of lists, where each list contains delivery points for a specific route.
:return: 'yes' if there is at least one common delivery point, otherwise 'no'.
"""
# Usin... | import pytest
from solution import common_delivery_point, solve, parse_input, format_output
def test_common_delivery_point():
assert common_delivery_point([[1, 2, 3], [2, 3, 4], [3, 4, 5]]) == "yes"
assert common_delivery_point([[1, 2, 3], [4, 5, 6]]) == "no"
assert common_delivery_point([[7, 8, 9, 10], [7... | [
{
"docstring": "Determines if all delivery routes have at least one common delivery point.\n:param routes: List of lists, where each list contains delivery points for a specific route.\n:return: 'yes' if there is at least one common delivery point, otherwise 'no'.",
"function_declaration": "def common_deliv... | [
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 common_delivery_point(test_cases):\n results = []\n \n for case in test_cases:\n n = case[0]\n routes = case[1:]\n \n # Ge... | trial_gpt4o_2 | {
"original_instruction": "A bakery likes to deliver fresh bread to its customers. The bakery delivery system operates on predefined delivery routes. Each delivery person has a specific route that they follow, and each route is marked by delivery points. A delivery person can only deliver bread to points on their rou... | 0.639815 | Taco_45018 | C | [
"common_delivery_point",
"solve",
"parse_input",
"format_output"
] | 4 | [
[
"solve",
"common_delivery_point"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | d4a69f6926ef9dbb9471c30c4eb830c2949b82ae | 2e9d4ffb28e63cdf8c8c26bed82bce0c7832e4f6 | |||
v1.0 | complete | Taco | Taco_45685_C | def solve(t: int, test_cases: List[int]) -> List[str]:
""" Determines if it is possible to arrange n magic stones in a special sequence for each test case.
>>> solve(3, [4, 5, 3])
["YES", "NO", "YES"]
>>> solve(4, [1, 2, 3, 6])
["YES", "YES", "YES", "NO"]
"""
def is_prime(num: int) -> bool:
... | 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 can_form_special_sequence(... | from solution import solve
def test_solve():
assert solve(3, [4, 5, 3]) == ["YES", "NO", "YES"]
# Add more specific tests related to prime checking and sequence validation
assert solve(4, [1, 2, 3, 6]) == ["YES", "YES", "YES", "NO"]
assert solve(2, [10, 7]) == ["NO", "NO"]
assert solve(5, [15, 2, 8... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def can_form_special_sequence(n):",
"function_name": "can_form_special_sequence",
"parameter_list": "(n)"
}... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Returns True if num is a prime number, otherwise False.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n... | trial_gpt4o_6 | {
"original_instruction": "In a faraway kingdom, there is a wizard named Merlin who has $n$ magic stones. Each stone has a unique positive integer written on it. Merlin loves to experiment with the stones by arranging them in different sequences. A sequence is considered special if for every pair of consecutive stone... | 0.551662 | Taco_45685 | C | [
"is_prime",
"can_form_special_sequence",
"solve"
] | 3 | [
[
"can_form_special_sequence",
"is_prime"
],
[
"solve",
"can_form_special_sequence"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 66b339c82f27eb29985b8b92fb949e4369b9f3c3 | 3177b3e712f6de8d963568d26fca99553ac428f1 | |||
v1.0 | complete | Taco | Taco_45447_C | def time_to_minutes(time_str: str) -> int:
"""
Convert a time string in HH:MM format to minutes since midnight.
"""
pass
def check_schedule_conflict(sessions: List[str]) -> str:
"""
Determine if there is any schedule conflict among the sessions.
Each session is represented by a start and en... | def time_to_minutes(time_str):
"""
Convert a time string in HH:MM format to minutes since midnight.
"""
hours, minutes = map(int, time_str.split(':'))
return hours * 60 + minutes
def check_schedule_conflict(sessions):
"""
Determine if there is any schedule conflict among the sessions.
E... | from solution import organize_workshop, check_schedule_conflict
def test_no_conflicts():
sessions = ["09:00-10:30", "10:45-12:00", "12:30-13:30"]
assert check_schedule_conflict(sessions) == "No conflicts"
def test_schedule_conflict():
sessions = ["09:00-10:30", "10:15-11:00", "11:00-12:30"]
assert che... | [
{
"docstring": "Convert a time string in HH:MM format to minutes since midnight.",
"function_declaration": "def time_to_minutes(time_str):",
"function_name": "time_to_minutes",
"parameter_list": "(time_str)"
},
{
"docstring": "Determine if there is any schedule conflict among the sessions.\n... | [
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 check_schedule_conflicts(t, test_cases):\n def time_to_minutes(time):\n hh, mm = map(int, time.split(':'))\n return hh * 60 + mm\n\n result... | trial_gpt4o_2 | {
"original_instruction": "Write a program that helps to organize a workshop by ensuring there is no schedule conflict between multiple sessions. Each session is represented by a start time and end time in the format HH:MM-HH:MM. Your task is to determine if any sessions overlap or if all sessions can be scheduled wi... | 0.542936 | Taco_45447 | C | [
"time_to_minutes",
"check_schedule_conflict",
"organize_workshop"
] | 3 | [
[
"check_schedule_conflict",
"time_to_minutes"
],
[
"organize_workshop",
"check_schedule_conflict"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | f953447f0479349335e3c1715b9bb5d19809ef1f | e27eb86bc6ad8b0cb7e5ac14c7282e577e50415c | |||
v1.0 | complete | Taco | Taco_45183_C | def numMatchingSubseq(s: str, words: List[str]) -> int:
"""
Given a string s and a list of words words[], return the number of words that are
a subsequence of s. A subsequence of a string is a new string generated from the
original string with some characters (can be none) deleted without changing th... | def is_subsequence(s, word):
"""
Helper function to determine if 'word' is a subsequence of 's'.
"""
it = iter(s)
return all(char in it for char in word)
def numMatchingSubseq(s, words):
"""
Returns the number of words that are a subsequence of s.
"""
count = 0
for word in words... | from solution import numMatchingSubseq
def test_num_matching_subseq_example():
assert numMatchingSubseq("abcde", ["a", "bb", "acd", "ace"]) == 3
def test_num_matching_subseq_empty_string():
assert numMatchingSubseq("", ["a", "bb", "acd", "ace"]) == 0
def test_num_matching_subseq_no_subsequences():
assert... | [
{
"docstring": "Helper function to determine if 'word' is a subsequence of 's'.",
"function_declaration": "def is_subsequence(s, word):",
"function_name": "is_subsequence",
"parameter_list": "(s, word)"
},
{
"docstring": "Returns the number of words that are a subsequence of s.",
"functi... | [
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 numMatchingSubseq(s, words):\n \"\"\"\n Returns the number of words that are a subsequence of s.\n \"\"\"\n from collections import defaultdict\n ... | trial_gpt4o_1 | {
"original_instruction": "Given a string s and a list of words words[], return the number of words that are a subsequence of s. A subsequence of a string is a new string generated from the original string with some characters(can be none) deleted without changing the relative order of the remaining characters.\n\nEx... | 0.703857 | Taco_45183 | C | [
"is_subsequence",
"numMatchingSubseq"
] | 2 | [
[
"numMatchingSubseq",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 93713f768e784889b18bfed8d39b4223df053b92 | 86b4bc90eadd658472c72972b6f86a95c0bf9e3f | |||
v1.0 | complete | Taco | Taco_44685_C | def exists_in_grid(grid, word):
""" Determines if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cells, where "adjacent" cells are those horizontally or vertically neighboring. The same cell may not be used twice in the construction of the word.
>>> exis... | def exists_in_grid(grid, word):
rows = len(grid)
cols = len(grid[0])
word_len = len(word)
def dfs(x, y, index):
if index == word_len:
return True
if x < 0 or x >= rows or y < 0 or y >= cols or grid[x][y] != word[index]:
return False
temp = grid[x][y]
... | def test_exists_in_grid():
grid1 = [['a', 'b', 'c', 'e'], ['s', 'f', 'c', 's'], ['a', 'd', 'e', 'e']]
word1 = "abcced"
assert exists_in_grid(grid1, word1) == True
grid2 = [['a', 'b', 'c', 'e'], ['s', 'f', 'c', 's'], ['a', 'd', 'e', 'e']]
word2 = "see"
assert exists_in_grid(grid2, word2) == True... | [
{
"docstring": null,
"function_declaration": "def exists_in_grid(grid, word):",
"function_name": "exists_in_grid",
"parameter_list": "(grid, word)"
},
{
"docstring": null,
"function_declaration": "def word_exists_in_grids(grids):",
"function_name": "word_exists_in_grids",
"parame... | [
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 word_exists_in_grid(grid, word):\n m, n = len(grid), len(grid[0])\n \n def dfs(x, y, word):\n if not word:\n return True\n if... | trial_gpt4o_2 | {
"original_instruction": "Given a grid of letters and a word, your task is to determine if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where \"adjacent\" cells are those horizontally or vertically neighboring. The same cell may not be used twice in the constr... | 0.640945 | Taco_44685 | C | [
"exists_in_grid",
"word_exists_in_grids",
"parse_input",
"main"
] | 4 | [
[
"word_exists_in_grids",
"exists_in_grid"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | ed8e06171e7994b9fa2053a7ca1d8a07480623d8 | c28fd007ba9eb46a0927d662b5e2d343b25f8090 | |||
v1.0 | complete | Taco | Taco_45723_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def has_path_sum_any(root: TreeNode, A: int, B: int) -> bool:
"""
Return True if there exists a root-to-leaf path in the binary tree where the sum of the node values ... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def has_path_sum(root, target_sum):
"""
Return True if there exists a root-to-leaf path in the binary tree where the sum of the node values is equal to target_sum.
... | from solution import TreeNode, has_path_sum_any
def test_has_path_sum_any_example1():
root = TreeNode(5)
root.left = TreeNode(4)
root.right = TreeNode(8)
root.left.left = TreeNode(11)
root.left.left.left = TreeNode(7)
root.left.left.right = TreeNode(2)
root.right.left = TreeNode(13)
roo... | [] | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef has_pat... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree and two integers, `A` and `B`. Write a function that determines whether there is a path from the root of the tree to a leaf such that the sum of the node values along the path equals `A` or `B`. Assume all node values are non-negative integers.\n\nInput\n- The in... | 0.662765 | Taco_45723 | C | [
"has_path_sum",
"has_path_sum_any"
] | 2 | [
[
"has_path_sum_any",
"has_path_sum"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | b85fe99aec814e2983bfb6b5eac12ff605a38a58 | 30e2c2a0ab6168e3c59827a1582800246af87956 | |||
v1.0 | complete | Taco | Taco_45518_C | from typing import List, Tuple
def min_knights_required(t: int, cases: List[Tuple[Tuple[int, int], List[str]]]) -> List[int]:
"""
Determine the minimum number of knights required to ensure that every empty cell
is reachable by at least one knight. If it is not possible, return -1.
Parameters:
... | from collections import deque
def bfs(n, m, grid, start):
visited = [[False] * m for _ in range(n)]
queue = deque([start])
visited[start[0]][start[1]] = True
while queue:
x, y = queue.popleft()
# Traverse in all 4 possible directions (up, down, left, right)
for nx, ny in [(x-1,... | def test_min_knights_required_initial_knight_sufficient():
cases = [
((3, 3), [
'K.#',
'.#.',
'...'
])
]
assert min_knights_required(1, cases) == [1]
def test_min_knights_required_additional_knight_needed():
cases = [
((2, 4), [
'K... | [
{
"docstring": null,
"function_declaration": "def bfs(n, m, grid, start):",
"function_name": "bfs",
"parameter_list": "(n, m, grid, start)"
},
{
"docstring": null,
"function_declaration": "def min_knights_required(t, cases):",
"function_name": "min_knights_required",
"parameter_l... | [
0,
0,
0,
0,
0,
0,
0,
0,
1
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def bfs(grid, start, N, M):\n queue = [start]\n reachable = set([start])\n directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n while queue:\n ... | trial_gpt4o_9 | {
"original_instruction": "In a far land, King Arthur has several knights who are tasked with patrolling the kingdom. The kingdom is represented as a grid of size `N x M`. Each cell in the grid can either contain a knight, be empty, or be an impassable obstacle. The goal is to ensure that all empty cells in the grid ... | 0.620959 | Taco_45518 | C | [
"bfs",
"min_knights_required"
] | 2 | [
[
"min_knights_required",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | e4bde2f92b9a27a7da94985f507d3beb3179849a | 2eebf150a08ec371b5ebbf920b56e0379c0a8ceb | |||
v1.0 | complete | Taco | Taco_45123_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(level_order):
if not level_order or level_order[0] == -1:
return None
root = TreeNode(level_order[0])
queue = [(root, 0)]
front = 0
... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def build_tree(level_order):
if not level_order or level_order[0] == -1:
return None
root = TreeNode(level_order[0])
queue = [(root, 0)]
front = 0
... | def test_teardrop_forest_height():
input_str = "2\n9\n1 2 3 -1 -1 4 5 -1 -1 -1 -1 6 7\n7\n1 2 3 -1 4 -1 5"
expected_output = [4, 3]
assert main(input_str) == expected_output
def test_single_node():
input_str = "1\n1\n5"
expected_output = [1]
assert main(input_str) == expected_output
def test_a... | [] | [
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": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef build_tree(level_order):\n ... | trial_gpt4o_6 | {
"original_instruction": "Sophie is a wildlife photographer, and she wants to capture images of a rare species of bird that nest in a particular type of tree. She has discovered that these trees are always part of a unique type of forest spread known as teardrop forests. A teardrop forest can be represented as a bin... | 0.546782 | Taco_45123 | C | [
"build_tree",
"tree_height",
"teardrop_forest_height",
"main"
] | 4 | [
[
"teardrop_forest_height",
"build_tree"
],
[
"teardrop_forest_height",
"tree_height"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | d96349b1ca57c70f6b450a1320c1898671cd5cec | c044fa9e0a9131d5519c3378f58dc8d04062c95d | |||
v1.0 | complete | Taco | Taco_45697_C | def sum_of_interior_angles(n: int) -> int:
""" Calculate the total sum of the interior angles of a simple polygon with n sides.
>>> sum_of_interior_angles(3) 180
>>> sum_of_interior_angles(4) 360
>>> sum_of_interior_angles(5) 540
"""
def sum_of_interior_angles_for_polygons(sides: List[int]) -> ... | def sum_of_interior_angles(n):
"""
Calculate the total sum of the interior angles of a simple polygon with n sides.
Args:
n (int): Number of sides of the polygon
Returns:
int: Total sum of the interior angles in degrees
"""
return (n - 2) * 180
def sum_of_interior_angles_for_p... | from solution import sum_of_interior_angles, sum_of_interior_angles_for_polygons
def test_sum_of_interior_angles():
assert sum_of_interior_angles(3) == 180
assert sum_of_interior_angles(4) == 360
assert sum_of_interior_angles(5) == 540
assert sum_of_interior_angles(6) == 720
def test_sum_of_interior_a... | [
{
"docstring": "Calculate the total sum of the interior angles of a simple polygon with n sides.\n\nArgs:\nn (int): Number of sides of the polygon\n\nReturns:\nint: Total sum of the interior angles in degrees",
"function_declaration": "def sum_of_interior_angles(n):",
"function_name": "sum_of_interior_a... | [
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 sum_of_interior_angles(n):\n \"\"\"\n Returns the sum of the interior angles of a polygon with n sides.\n \"\"\"\n if n < 3:\n return 0\n ... | trial_gpt4o_2 | {
"original_instruction": "Create a program that calculates the total sum of the interior angles of a simple polygon with `n` sides. The provided input consists of several datasets, where each dataset supplied as an integer `n` which represents the number of sides of the polygon. Your program should continue to proce... | 0.503684 | Taco_45697 | C | [
"sum_of_interior_angles",
"sum_of_interior_angles_for_polygons"
] | 2 | [
[
"sum_of_interior_angles_for_polygons",
"sum_of_interior_angles"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 17557b90bd3043e1f1b11b2f1a987ea2d09277d5 | e2ff95893ac10c988a5d02ad53e6b4654ef07b90 | |||
v1.0 | complete | Taco | Taco_46027_C | def park_rides(R, ride_capacities, V, visitors_preferences):
"""
Determine if it's possible to assign each visitor to a ride based on their preferences and the ride capacities.
Parameters:
R : int : number of rides
ride_capacities : List[int] : List of integers denoting capacities of each ride
... | def assign_rides(ride_capacities, visitors_preferences):
R = len(ride_capacities)
V = len(visitors_preferences)
# Initial ride allocation
rides_allocation = [0] * R
for preferences in visitors_preferences:
assigned = False
for pref in preferences:
if rides_alloc... | from solution import park_rides
def test_example_case_1():
R = 3
ride_capacities = [2, 1, 3]
V = 4
visitors_preferences = [
[1, 3],
[1, 2],
[2, 3],
[1, 3]
]
assert park_rides(R, ride_capacities, V, visitors_preferences) == "Yes"
def test_example_case_2():
R ... | [
{
"docstring": null,
"function_declaration": "def assign_rides(ride_capacities, visitors_preferences):",
"function_name": "assign_rides",
"parameter_list": "(ride_capacities, visitors_preferences)"
},
{
"docstring": "R - number of rides\nride_capacities - List of integers denoting capacities... | [
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 assign_rides(ride_capacities, visitors_preferences):\n R = len(ride_capacities)\n V = len(visitors_preferences)\n \n # Initial ride allocation\n ... | trial_gpt4o_0 | {
"original_instruction": "An amusement park has several roller coaster rides. The park owners want to assign each visitor to a ride such that the number of visitors on any single ride does not exceed its capacity and each visitor enjoys a ride that they are satisfied with. Each visitor has a list of rides that they ... | 0.573288 | Taco_46027 | C | [
"assign_rides",
"park_rides"
] | 2 | [
[
"park_rides",
"assign_rides"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 870e1e68e8534bf8e1464718d87fecbca11b6fa6 | 78b9a9033f082a5e76ebf5d30d11819cd5b3abbd | |||
v1.0 | complete | Taco | Taco_45984_C | def fibonacci(n):
"""Returns the nth Fibonacci number."""
pass
def preprocess_fibonacci(elements):
"""Precompute the Fibonacci number for each element in the list to handle queries efficiently."""
pass
def precompute_sums(elements, fib_cache):
"""Precompute prefix sum of Fibonacci numbers of the e... | def fibonacci(n):
"""Returns the nth Fibonacci number."""
if n == 0:
return 0
elif n == 1:
return 1
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return b
def preprocess_fibonacci(elements):
"""Precompute the Fibonacci number for each element in the list to ... | def test_fibonacci():
assert fibonacci(0) == 0
assert fibonacci(1) == 1
assert fibonacci(2) == 1
assert fibonacci(3) == 2
assert fibonacci(4) == 3
assert fibonacci(5) == 5
assert fibonacci(6) == 8
assert fibonacci(10) == 55
def test_process_queries():
n = 5
elements = [3, 1, 4, ... | [
{
"docstring": "Returns the nth Fibonacci number.",
"function_declaration": "def fibonacci(n):",
"function_name": "fibonacci",
"parameter_list": "(n)"
},
{
"docstring": "Precompute the Fibonacci number for each element in the list to handle queries efficiently.",
"function_declaration": ... | [
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 fib(n, memo={0: 0, 1: 1}):\n \"\"\"\n Returns the Fibonacci number of n using memoization.\n \"\"\"\n if n not in memo:\n memo[n] = fib(n-1,... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of n elements and a series of m queries. Each query consists of two integers l and r, which represents a subarray of the list. You are required to answer the queries with the sum of the Fibonacci numbers from the elements in the specified subarray.\n\nWrite a program th... | 0.743879 | Taco_45984 | C | [
"fibonacci",
"preprocess_fibonacci",
"precompute_sums",
"sum_of_fibonacci_in_range",
"process_queries"
] | 5 | [
[
"preprocess_fibonacci",
"fibonacci"
],
[
"process_queries",
"precompute_sums"
],
[
"process_queries",
"preprocess_fibonacci"
],
[
"process_queries",
"sum_of_fibonacci_in_range"
]
] | 4 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | fa846381457d667716ead6c0e9f1b2e24b83924e | fb6679a4a2a3a12e70a34f3804ba3bc96dab22e5 | |||
v1.0 | complete | Taco | Taco_46136_C | def n_trees_ways(n: int) -> int:
""" Given the dimensions of a garden, determine the number of ways to plant
exactly one tree in each row and column such that no two trees are in the
same row, column, or diagonal.
>>> n_trees_ways(1)
1
>>> n_trees_ways(2)
0
>>> n_trees_ways(3)
... | def is_valid(board, row, col, n):
"""
Function to check if a tree can be planted at board[row][col].
"""
for i in range(row):
if board[i] == col or abs(board[i] - col) == abs(i - row):
return False
return True
def solve_n_trees(n, row, board, solutions):
"""
Function to ... | from solution import n_trees_ways
def test_n_trees_ways_1():
assert n_trees_ways(1) == 1
def test_n_trees_ways_2():
assert n_trees_ways(2) == 0
def test_n_trees_ways_3():
assert n_trees_ways(3) == 0
def test_n_trees_ways_4():
assert n_trees_ways(4) == 2
def test_n_trees_ways_5():
assert n_trees... | [
{
"docstring": "Function to check if a tree can be planted at board[row][col].",
"function_declaration": "def is_valid(board, row, col, n):",
"function_name": "is_valid",
"parameter_list": "(board, row, col, n)"
},
{
"docstring": "Function to recursively solve the n-trees problem by backtrac... | [
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_safe(board, row, col, n):\n # Check this row on left side and above\n for i in range(col):\n if board[row][i] == 1:\n return False\n... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular garden with rows and columns. The gardener wants to plant trees in the garden such that no two trees are in the same row, column, or diagonal. Given the dimensions of the garden, determine the number of ways the gardener can plant exactly one tree in each row and... | 0.612338 | Taco_46136 | C | [
"is_valid",
"solve_n_trees",
"n_trees_ways"
] | 3 | [
[
"n_trees_ways",
"solve_n_trees"
],
[
"solve_n_trees",
"is_valid"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | d668b055f664c2a5656c98c273bcd0b1ecc6991c | 1da043dd58f993736e38eeacabf1de614d928ddd | |||
v1.0 | complete | Taco | Taco_45306_C | def find(parent, u):
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
root_u = find(parent, u)
root_v = find(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_u
elif rank[r... | def find(parent, u):
if parent[u] != u:
parent[u] = find(parent, parent[u])
return parent[u]
def union(parent, rank, u, v):
root_u = find(parent, u)
root_v = find(parent, v)
if root_u != root_v:
if rank[root_u] > rank[root_v]:
parent[root_v] = root_u
elif rank[r... | def test_example_1():
input_data = """5 6\n1 2 3\n2 3 2\n3 4 4\n4 5 1\n1 3 5\n2 5 6"""
assert main(input_data) == "2\n10"
def test_example_2():
input_data = """4 5\n1 2 3\n1 3 2\n3 4 4\n2 4 1\n2 3 5"""
assert main(input_data) == "2\n6"
def test_minimum_case():
input_data = """2 1\n1 2 1"""
ass... | [
{
"docstring": null,
"function_declaration": "def find(parent, u):",
"function_name": "find",
"parameter_list": "(parent, u)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, u, v):",
"function_name": "union",
"parameter_list": "(parent, rank, u, v)"
},
... | [
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 kruskal(n, edges):\n # Helper function to find the root of a node\n def find(parent, x):\n if parent[x] != x:\n parent[x] = find(parent... | trial_gpt4o_2 | {
"original_instruction": "In a remote village, the residents decided to construct a series of underground tunnels connecting various important locations like the town hall, market, school, and hospital. The tunnels are represented as a graph where nodes are the important locations and edges are the tunnels with thei... | 0.553469 | Taco_45306 | C | [
"find",
"union",
"remove_redundant_tunnels",
"main"
] | 4 | [
[
"remove_redundant_tunnels",
"find"
],
[
"remove_redundant_tunnels",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 741f4faf2fa173bcbfde6c26e027574d0efc43cc | 6ab59bc18ef431c5a85d4d0b2152009f8072679c | |||
v1.0 | complete | Taco | Taco_46118_C | def hiking_journey(n: int, m: int, trails: List[Tuple[int, int, int]]) -> int:
""" Find the minimum possible value of the maximum difficulty rating on the path from peak 1 to peak n.
Args:
n (int): Number of peaks.
m (int): Number of trails.
trails (List[Tuple[int, int, int]]): List of trails w... | import heapq
def find_min_max_difficulty(n, m, trails):
def dijkstra(src, des, adj_list):
max_difficulty = [float('inf')] * (n + 1)
max_difficulty[src] = 0
pq = [(0, src)]
while pq:
curr_difficulty, u = heapq.heappop(pq)
for v, d in adj_... | from solution import hiking_journey
def test_hiking_journey_basic():
n, m = 4, 5
trails = [
(1, 2, 5),
(1, 3, 6),
(2, 3, 2),
(2, 4, 3),
(3, 4, 4)
]
assert hiking_journey(n, m, trails) == 5
def test_hiking_journey_minimum():
n, m = 2, 1
trails = [
... | [
{
"docstring": null,
"function_declaration": "def find_min_max_difficulty(n, m, trails):",
"function_name": "find_min_max_difficulty",
"parameter_list": "(n, m, trails)"
},
{
"docstring": null,
"function_declaration": "def hiking_journey(n, m, trails):",
"function_name": "hiking_jour... | [
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 defaultdict, deque\n\ndef can_reach_with_max_difficulty(graph, n, max_difficulty):\n \"\"\"\n Determines if there is a path from node... | trial_gpt4o_2 | {
"original_instruction": "You are planning a journey across a mountainous region with a group of hikers. There are several trails that connect different peaks, and each trail has a difficulty rating. To ensure the group's safety, you need to find a route from the starting peak to the destination peak that minimizes ... | 0.629995 | Taco_46118 | C | [
"find_min_max_difficulty",
"hiking_journey"
] | 2 | [
[
"hiking_journey",
"find_min_max_difficulty"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 20f0edcfea668c322c7698a9573c3b0a772c0ffe | 1119baaa1d4fc3394c339928e2478fe22a78f5f7 | |||
v1.0 | complete | Taco | Taco_46336_C | from typing import List
def largest_alliance_size(n: int, strengths: List[int]) -> int:
"""
Find the largest possible size of an alliance that can be formed among the creatures.
Args:
n (int): the number of different types of creatures.
strengths (List[int]): the strengths of the creatures.
... | from math import gcd
from itertools import combinations
def is_coprime(x, y):
return gcd(x, y) == 1
def largest_alliance_size(n, strengths):
max_alliance_size = 1
for r in range(2, n+1):
for subset in combinations(strengths, r):
if all(is_coprime(pair[0], pair[1]) for pair in combinati... | from solution import largest_alliance_size
def test_example_1():
assert largest_alliance_size(6, [2, 3, 5, 7, 11, 14]) == 5
def test_example_2():
assert largest_alliance_size(5, [4, 6, 8, 10, 12]) == 1
def test_single_creature():
assert largest_alliance_size(1, [10]) == 1
def test_all_coprime():
ass... | [
{
"docstring": null,
"function_declaration": "def is_coprime(x, y):",
"function_name": "is_coprime",
"parameter_list": "(x, y)"
},
{
"docstring": null,
"function_declaration": "def largest_alliance_size(n, strengths):",
"function_name": "largest_alliance_size",
"parameter_list": ... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import math\nfrom itertools import combinations\n\ndef largest_alliance(n, strengths):\n def are_coprime(a, b):\n return math.gcd(a, b) == 1\n \n m... | trial_gpt4o_2 | {
"original_instruction": "In a magical forest, there are n different types of magical creatures identified by unique integer IDs from 1 to n. Each of these creatures has a specific strength, represented as an integer. Creatures with higher strength display dominance over those with lower strength, but the relationsh... | 0.537542 | Taco_46336 | C | [
"is_coprime",
"largest_alliance_size"
] | 2 | [
[
"largest_alliance_size",
"is_coprime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 1b127c2bf43026ccdead9fb3397b2f1151529f79 | c121f0fe8c21baa17e328c70533334cb256c5160 | |||
v1.0 | complete | Taco | Taco_46196_C | def is_palindrome(s: str) -> bool:
""" Checks if the given string is a palindrome.
>>> is_palindrome("a") == True
>>> is_palindrome("aa") == True
>>> is_palindrome("ab") == False
>>> is_palindrome("aba") == True
>>> is_palindrome("abc") == False
"""
pass
def min_palindromic_substrings(s... | def is_palindrome(s):
"""
Checks if the given string is a palindrome.
"""
return s == s[::-1]
def min_palindromic_substrings(s):
"""
Returns the minimum number of contiguous substrings that can be
formed from s such that each substring is a palindrome.
"""
if is_palindrome(s):
... | from solution import is_palindrome, min_palindromic_substrings
def test_is_palindrome():
assert is_palindrome("a") == True
assert is_palindrome("aa") == True
assert is_palindrome("ab") == False
assert is_palindrome("aba") == True
assert is_palindrome("abc") == False
def test_min_palindromic_substr... | [
{
"docstring": "Checks if the given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns the minimum number of contiguous substrings that can be \nformed from s such that each substring... | [
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 min_palindrome_substrings(s):\n \"\"\"\n Returns the minimum number of contiguous substrings that are all palindromes.\n \"\"\"\n if s == s[::-1]:\... | trial_gpt4o_4 | {
"original_instruction": "----Input----\n\nThe input consists of a single string s containing only lowercase English letters (1 ≤ |s| ≤ 100).\n\n----Output----\n\nOutput a single integer representing the minimum number of contiguous substrings that can be formed from s such that each substring is a palindrome.\n\n--... | 0.820884 | Taco_46196 | C | [
"is_palindrome",
"min_palindromic_substrings"
] | 2 | [
[
"min_palindromic_substrings",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0174717e33a78b0f4225b832f48417cc1f1dda09 | d94e232d5de411f19fac4c74fb0e3c22b4911554 | |||
v1.0 | complete | Taco | Taco_46269_C | def solve(t: int, cases: List[Tuple[int, List[Tuple[int, int]]]]) -> List[int]:
"""
Determines the longest path between any two nodes in a tree (the diameter of the tree).
Args:
t (int): Number of test cases.
cases (List[Tuple[int, List[Tuple[int, int]]]]): For each test case, an integer N (number... | from collections import deque, defaultdict
def find_farthest_node(start, n, graph):
visited = [-1] * (n + 1)
max_distance = 0
farthest_node = start
queue = deque([(start, 0)])
visited[start] = 1
while queue:
node, dist = queue.popleft()
for neighbor in graph[node]:
... | from solution import solve
def test_case_1():
t = 2
cases = [
(4, [(1, 2), (2, 3), (2, 4)]),
(5, [(1, 2), (1, 3), (3, 4), (3, 5)])
]
expected = [2, 3]
assert solve(t, cases) == expected
def test_case_2():
t = 1
cases = [
(3, [(1, 2), (2, 3)])
]
expected = [2... | [
{
"docstring": null,
"function_declaration": "def find_farthest_node(start, n, graph):",
"function_name": "find_farthest_node",
"parameter_list": "(start, n, graph)"
},
{
"docstring": null,
"function_declaration": "def tree_diameter(n, edges):",
"function_name": "tree_diameter",
... | [
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, defaultdict\n\ndef find_farthest_node(start, n, graph):\n visited = [-1] * (n + 1)\n max_distance = 0\n farthest_node = sta... | trial_gpt4o_0 | {
"original_instruction": "You are given a tree with N nodes (numbered from 1 to N) and (N-1) edges. Your task is to determine the longest path between any two nodes in the tree. This is known as finding the diameter of the tree.\n\nThe diameter of a tree is defined as the maximum distance between any pair of nodes i... | 0.713161 | Taco_46269 | C | [
"find_farthest_node",
"tree_diameter",
"solve"
] | 3 | [
[
"solve",
"tree_diameter"
],
[
"tree_diameter",
"find_farthest_node"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 9af3ff866e37a2b1ee8556431aca0f97d76c2285 | 9ca6599c442293c529e6999b972b92011f9bd517 | |||
v1.0 | complete | Taco | Taco_46291_C | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def printLevel(root: TreeNode, target: int) -> List[int]:
""" Given a Binary Tree and a node, print the entire level of the Binary Tree in which the given node is present.
>>> root = TreeNode(... | class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def find_level(root, target, level):
if root is None:
return 0
if root.val == target:
return level
downlevel = find_level(root.left, target, level + 1)
if downlevel != ... | import pytest
from solution import TreeNode, printLevel
def test_example_1():
root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(3)
root.left.left = TreeNode(4)
root.left.right = TreeNode(5)
root.right.left = TreeNode(6)
root.right.right = TreeNode(7)
root.left.left.left =... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class Node:\n def __init__(self, key):\n self.data = key\n self.left = None\n self.right = None\n\nfrom collections import deque\n\ndef get... | trial_gpt4o_2 | {
"original_instruction": "Given a Binary Tree and a node, your task is to print the entire level of the Binary Tree in which the given node is present.\n\nExample 1:\nInput:\n 1\n / \\\n 2 3\n / \\ / \\\n 4 5 6 7\n /\n 8\nTarget Node: 5\n\nOutput: 4 5 6 7\nExplanation:... | 0.542558 | Taco_46291 | C | [
"find_level",
"printGivenLevel",
"printLevel"
] | 3 | [
[
"printLevel",
"find_level"
],
[
"printLevel",
"printGivenLevel"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 7ac162282c89f021906d242f97a2068d4a6e2800 | 745508ff0b19f00b5099bb96f7dd1726214c75c3 | |||
v1.0 | complete | Taco | Taco_46276_C | from typing import List, Tuple
def longest_parking_vehicle(n: int, entries: List[Tuple[str, str, str]]) -> str:
""" Determine the vehicle that has stayed the longest in the parking lot among a provided set of vehicle entries.
>>> longest_parking_vehicle(5, [("ABC123", "08:00", "09:30"), ("XYZ789", "07:00", "09... | from datetime import datetime
def calculate_duration(entry_time, exit_time):
format = "%H:%M"
entry = datetime.strptime(entry_time, format)
exit = datetime.strptime(exit_time, format)
duration = exit - entry
return duration.total_seconds()
def longest_parking_vehicle(n, entries):
max_duration ... | from solution import longest_parking_vehicle
def test_example_case():
n = 5
entries = [
("ABC123", "08:00", "09:30"),
("XYZ789", "07:00", "09:00"),
("LMN456", "10:15", "12:00"),
("DEF000", "09:45", "11:30"),
("GHI111", "07:30", "08:45")
]
assert longest_parking_v... | [
{
"docstring": null,
"function_declaration": "def calculate_duration(entry_time, exit_time):",
"function_name": "calculate_duration",
"parameter_list": "(entry_time, exit_time)"
},
{
"docstring": null,
"function_declaration": "def longest_parking_vehicle(n, entries):",
"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": "def parse_time(time_str):\n hours, minutes = map(int, time_str.split(':'))\n return hours * 60 + minutes\n\ndef find_longest_parked_vehicle(entries):\n lo... | trial_gpt4o_2 | {
"original_instruction": "You are tasked with developing software that processes and analyzes vehicle parking data. Each vehicle entry is logged with the following attributes: license plate number, entry time, and exit time. The challenge is to determine the vehicle that has stayed the longest in the parking lot amo... | 0.596406 | Taco_46276 | C | [
"calculate_duration",
"longest_parking_vehicle"
] | 2 | [
[
"longest_parking_vehicle",
"calculate_duration"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f96b2fd535af3a025b526a13e026ddb6e2e3f3e7 | 40299b8ae13176f1bcf3b5c1d5700ac53f03a9e8 | |||
v1.0 | complete | Taco | Taco_46499_C | from typing import List
def transform_to_palindrome(test_cases: List[str]) -> List[str]:
"""
Determines if it is possible to rearrange the given string into a palindrome.
For possible cases, output "YES" followed by the rearranged palindrome.
For impossible cases, output "NO".
>>> transform_to_pali... | from collections import Counter
def can_form_palindrome(s):
"""
Checks if the string can form a palindrome.
"""
count = Counter(s)
odd_count = sum(1 for c in count.values() if c % 2 != 0)
# A string can be rearranged to a palindrome if at most one character has an odd count
return odd_count... | def test_transform_to_palindrome():
test_cases = [
("aabb", ("YES", "abba")),
("racecar", ("YES", "racecar")),
("abcd", ("NO",))
]
for case in test_cases:
assert transform_to_palindrome([case[0]]) == list(case[1])
def test_single_character():
assert transform_to_palindro... | [
{
"docstring": "Checks if the string can form a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Rearranges the string into a palindrome if possible.",
"function_declaration": "def rear... | [
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 collections import Counter\n\ndef can_form_palindrome(s):\n \"\"\"\n Determines if a given string can be rearranged to form a palindrome.\n If possib... | trial_gpt4o_4 | {
"original_instruction": "Polycarp received a job of transforming a given string into a palindrome by rearranging its characters. A palindrome is a sequence of characters which reads the same backwards as forwards. Polycarp can perform the following operation as many times as needed: Select any two characters of the... | 0.75853 | Taco_46499 | C | [
"can_form_palindrome",
"rearrange_to_palindrome",
"transform_to_palindrome"
] | 3 | [
[
"transform_to_palindrome",
"can_form_palindrome"
],
[
"transform_to_palindrome",
"rearrange_to_palindrome"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | b514384512b7eec9ef032ac995f139dea8a8a6b9 | 693f6b46b3be5764cbdcd2ae6381ef226fdcfac4 | |||
v1.0 | complete | Taco | Taco_46207_C | def process_operations(n: int, s: str, operations: List[Tuple[int, int, int, int]]) -> List[int]:
"""
Perform given Q operations on the string S.
Type 1: Rotate the substring S[L:R] to the left by K positions.
Type 2: Query the number of distinct characters in the substring S[L:R].
Args:
... | def rotate_left(s, k):
return s[k:] + s[:k]
def process_operations(n, s, operations):
s = list(s)
result = []
for op in operations:
if op[0] == 1:
L, R, K = op[1], op[2], op[3]
L, R = L - 1, R - 1 # convert to 0-indexed
K = K % (R - L + 1)
s... | from solution import process_operations
def test_example_case():
n = 7
s = "abacaba"
operations = [
(2, 1, 3),
(1, 2, 5, 2),
(2, 1, 3),
(1, 1, 7, 3),
(2, 4, 6)
]
expected_output = [2, 2, 2]
assert process_operations(n, s, operations) == expected_output
d... | [
{
"docstring": null,
"function_declaration": "def rotate_left(s, k):",
"function_name": "rotate_left",
"parameter_list": "(s, k)"
},
{
"docstring": null,
"function_declaration": "def process_operations(n, s, operations):",
"function_name": "process_operations",
"parameter_list": ... | [
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 rotate_left(s, L, R, K):\n substring = s[L-1:R]\n K %= len(substring)\n rotated = substring[K:] + substring[:K]\n return s[:L-1] + rotated + s[R:]\... | trial_gpt4o_2 | {
"original_instruction": "Problem:\n\nYou are given a string S of length N consisting of lowercase alphabets ('a' - 'z'). You need to perform Q operations on this string, which can be of two types:\n\nType 1: 1 L R K: Rotate the substring S[L:R] (inclusive) to the left by K positions.\nType 2: 2 L R: Query the numbe... | 0.666749 | Taco_46207 | C | [
"rotate_left",
"process_operations"
] | 2 | [
[
"process_operations",
"rotate_left"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2b5b6b2ceb57bdb131e793908bebbdf046c11b37 | 32b45caec65ff17441e988ad828b988dce99811b | |||
v1.0 | complete | Taco | Taco_46119_C | class TreeNode:
def __init__(self, key):
self.data = key
self.left = None
self.right = None
class DoubleListNode:
def __init__(self, key):
self.data = key
self.prev = None
self.next = None
def bToDLL(root):
""" Given a binary tree, convert it into a ... | class TreeNode:
def __init__(self, key):
self.data = key
self.left = None
self.right = None
class DoubleListNode:
def __init__(self, key):
self.data = key
self.prev = None
self.next = None
def bToDLL(root):
if not root:
return None
# Ini... | def test_tree_to_dll_list_case1():
# Constructing the tree:
# 10
# / \
# 12 15
# / \ /
# 25 30 36
root = TreeNode(10)
root.left = TreeNode(12)
root.right = TreeNode(15)
root.left.left = TreeNode(25)
root.left.right = TreeNode(30)
root.ri... | [] | [
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 Node:\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right = None\n\ndef bToDLL(root):\n \"\"\"\n Con... | trial_gpt4o_2 | {
"original_instruction": "Given a binary tree, convert it into a Doubly Linked List (DLL) in such a way that the order of the DLL is the same as the Inorder traversal of the binary tree. The left and right pointers in nodes are to be used as previous and next pointers respectively in the converted DLL. The head poin... | 0.470999 | Taco_46119 | C | [
"bToDLL",
"tree_to_dll_list"
] | 2 | [
[
"tree_to_dll_list",
"bToDLL"
]
] | 1 | [] | false | [
"TreeNode",
"DoubleListNode"
] | true | pytest | false | [] | true | bc0c9e510293bea4d0caad2baddd345e63d0e914 | 404515fcfe0a142dc4ea72a6f63efafbc2857bde | |||
v1.0 | complete | Taco | Taco_46526_C | from typing import List
def char_value(c: str) -> int:
""" Return the alphabetical value of the character c.
"""
return ord(c) - ord('a') + 1
def max_value_for_alice(S: str) -> int:
""" Calculate the maximum value Alice can obtain from string S.
"""
def max_values_for_test_cases(T: int, test_... | def char_value(c):
"""
Return the alphabetical value of the character c.
"""
return ord(c) - ord('a') + 1
def max_value_for_alice(S):
"""
Calculate the maximum value Alice can obtain.
"""
# Convert each character to its corresponding value
letter_values = [char_value(c) for c in S]
... | from solution import max_values_for_test_cases
def test_example_cases():
assert max_values_for_test_cases(2, ["abc", "defg"]) == [4, 12]
def test_single_character():
assert max_values_for_test_cases(1, ["a"]) == [1]
def test_same_character():
assert max_values_for_test_cases(1, ["aaa"]) == [2] # Alice p... | [
{
"docstring": "Return the alphabetical value of the character c.",
"function_declaration": "def char_value(c):",
"function_name": "char_value",
"parameter_list": "(c)"
},
{
"docstring": "Calculate the maximum value Alice can obtain.",
"function_declaration": "def max_value_for_alice(S):... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_value_alice_can_obtain(T, test_cases):\n \"\"\"\n Returns a list of maximum values Alice can obtain for each test case.\n \n :param T: int, num... | trial_gpt4o_6 | {
"original_instruction": "Alice and Bob are playing a game with a string `S` that only consists of lowercase letters. The game rules are simple:\n- Alice starts first and picks a letter from the string.\n- Bob then picks another letter from the remaining string.\n- This process continues, alternating between Alice a... | 0.65706 | Taco_46526 | C | [
"char_value",
"max_value_for_alice",
"max_values_for_test_cases"
] | 3 | [
[
"max_value_for_alice",
"char_value"
],
[
"max_values_for_test_cases",
"max_value_for_alice"
]
] | 2 | [
"max_values_for_test_cases"
] | false | [] | false | pytest | true | [] | true | 85354e22dba81d137c1826fa1f836935b266cb29 | 264453ceefbd13a465c315e55bdc3f92760ea793 | |||
v1.0 | complete | Taco | Taco_46273_C | def locate_books(n: int, m: int, q: int, edges: List[Tuple[int, int, int]], start: int, book_shelves: List[int]) -> List[int]:
"""Given the library structure and starting position, find the shortest path times to locate a series of books.
Args:
n - The number of shelves.
m - The number of direct pa... | import heapq
def dijkstra(graph, start, n):
# Initialize distances with infinity
distances = {i: float('inf') for i in range(1, n + 1)}
distances[start] = 0
priority_queue = [(0, start)]
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
if cur... | from solution import locate_books
def test_case_1():
n, m, q = 5, 7, 3
edges = [
(1, 2, 3),
(2, 3, 4),
(1, 3, 8),
(1, 4, 7),
(4, 5, 2),
(5, 3, 1),
(2, 5, 5)
]
start = 1
book_shelves = [3, 5, 4]
assert locate_books(n, m, q, edges, start, bo... | [
{
"docstring": null,
"function_declaration": "def dijkstra(graph, start, n):",
"function_name": "dijkstra",
"parameter_list": "(graph, start, n)"
},
{
"docstring": null,
"function_declaration": "def locate_books(n, m, q, edges, start, book_shelves):",
"function_name": "locate_books",... | [
0,
0,
0,
0,
0,
0,
1,
1,
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 heapq\n\ndef find_shortest_paths(n, m, q, edges, s, books):\n # Create adjacency list for graph\n graph = {i: [] for i in range(1, n + 1)}\n for u,... | trial_gpt4o_9 | {
"original_instruction": "Library Book Locator\n\nSophia is a librarian responsible for managing and organizing books in a large library. Each book in the library has a unique identifier and is placed on a particular shelf. A book can only be located on a specific shelf number. The library uses an advanced inventory... | 0.638131 | Taco_46273 | C | [
"dijkstra",
"locate_books"
] | 2 | [
[
"locate_books",
"dijkstra"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 86c880af945e14e9c6318c55128450673771569e | 68194ca0d4081da137f161a96dff92077fc7ed81 | |||
v1.0 | complete | Taco | Taco_46703_C | def is_palindrome(n):
""" Checks if a given integer n is a palindrome.
>>> is_palindrome(121) True
>>> is_palindrome(12321) True
>>> is_palindrome(123) False
>>> is_palindrome(9009) True
>>> is_palindrome(10) False
"""
def largest_palindrome_product():
""" Returns the largest palind... | def is_palindrome(n):
"""
Checks if a given integer n is a palindrome.
"""
return str(n) == str(n)[::-1]
def largest_palindrome_product():
"""
Returns the largest palindrome made from the product of two 3-digit numbers.
"""
max_palindrome = 0
for i in range(999, 99, -1):
for... | from solution import largest_palindrome_product, is_palindrome
def test_is_palindrome():
assert is_palindrome(121) == True
assert is_palindrome(12321) == True
assert is_palindrome(123) == False
assert is_palindrome(9009) == True
assert is_palindrome(10) == False
def test_largest_palindrome_product... | [
{
"docstring": "Checks if a given integer n is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Returns the largest palindrome made from the product of two 3-digit numbers.",
"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 is_palindrome(n):\n \"\"\"\n Check if a given number is a palindrome.\n \"\"\"\n s = str(n)\n return s == s[::-1]\n\ndef largest_palindrome_prod... | trial_gpt4o_2 | {
"original_instruction": "Palindrome Products\n\nA palindrome is a number that reads the same forward and backward. The largest palindrome made from the product of two 2-digit numbers is 9009 (= 91 × 99). Develop a function that finds the largest palindrome made from the product of two 3-digit numbers.\n\nTask:\nWri... | 0.695377 | Taco_46703 | C | [
"is_palindrome",
"largest_palindrome_product"
] | 2 | [
[
"largest_palindrome_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ae5d683f90c494385e0394acc86e41f7b0ca647d | 3ee91519810daca796b9728d3cbe9f9e15b21c6b | |||
v1.0 | complete | Taco | Taco_46580_C | def evaluate_rpn_expression(expression: str) -> int:
""" Evaluate a single RPN expression and return the result.
>>> evaluate_rpn_expression("3 4 +")
7
>>> evaluate_rpn_expression("5 1 2 + 4 * + 3 -")
14
>>> evaluate_rpn_expression("15 7 1 1 + - / 3 * 2 1 1 + + -")
5
"""
pass
def ev... | def evaluate_rpn_expression(expression):
stack = []
tokens = expression.split()
for token in tokens:
if token in "+-*/":
b = stack.pop()
a = stack.pop()
if token == '+':
stack.append(a + b)
elif token == '-':
stack.... | from solution import evaluate_rpn_expression, evaluate_multiple_rpn
def test_evaluate_rpn_expression():
assert evaluate_rpn_expression("3 4 +") == 7
assert evaluate_rpn_expression("5 1 2 + 4 * + 3 -") == 14
assert evaluate_rpn_expression("15 7 1 1 + - / 3 * 2 1 1 + + -") == 5
assert evaluate_rpn_expres... | [
{
"docstring": null,
"function_declaration": "def evaluate_rpn_expression(expression):",
"function_name": "evaluate_rpn_expression",
"parameter_list": "(expression)"
},
{
"docstring": null,
"function_declaration": "def evaluate_multiple_rpn(expressions):",
"function_name": "evaluate_... | [
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 evaluate_rpn(expressions):\n def eval_rpn(tokens):\n stack = []\n for token in tokens:\n if token in '+-*/':\n b = s... | trial_gpt4o_2 | {
"original_instruction": "You are given a list of strings, each representing an expression in Reverse Polish Notation (RPN). Write a program to evaluate each of these expressions and return the result for each.\n\nRPN is a mathematical notation in which every operator follows all of its operands. It does not need an... | 0.545432 | Taco_46580 | C | [
"evaluate_rpn_expression",
"evaluate_multiple_rpn"
] | 2 | [
[
"evaluate_multiple_rpn",
"evaluate_rpn_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 54ec9f65a2dfc311f145f081667caa76ba968152 | 5149c78595399ee670f47a358d32e70454eb8405 | |||
v1.0 | complete | Taco | Taco_46709_C | def electric_car_battery_management(T: int, test_cases: List[Tuple[int, int, List[int]]]) -> List[int]:
"""
Simulate the energy consumption over multiple trips and determine the maximum number of complete trips the car can make.
Each trip requires energy E. After completing a trip, the remaining energy in t... | def max_complete_trips(E, N, energies):
total_energy = sum(energies)
return total_energy // E
def process_test_cases(T, test_cases):
results = []
for case in test_cases:
E, N, energies = case
results.append(max_complete_trips(E, N, energies))
return results
def electric_car_battery... | from solution import electric_car_battery_management
def test_example_case1():
T = 2
test_cases = [
(5, 3, [4, 3, 2]),
(10, 5, [5, 6, 7, 8, 9])
]
assert electric_car_battery_management(T, test_cases) == [1, 3]
def test_only_one_trip_possible():
T = 1
test_cases = [
(10,... | [
{
"docstring": null,
"function_declaration": "def max_complete_trips(E, N, energies):",
"function_name": "max_complete_trips",
"parameter_list": "(E, N, energies)"
},
{
"docstring": null,
"function_declaration": "def process_test_cases(T, test_cases):",
"function_name": "process_test... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_complete_trips(E, N, energies):\n total_energy = sum(energies)\n return total_energy // E\n\ndef process_test_cases(T, test_cases):\n results = []... | trial_gpt4o_0 | {
"original_instruction": "-----Electric Car Battery Management-----\n\nA company is developing a software to manage the battery usage of their electric cars. Each car's battery can be represented as a sequence of battery cells stored in an array. Each cell has a certain amount of energy, represented by a positive in... | 0.588248 | Taco_46709 | C | [
"max_complete_trips",
"process_test_cases",
"electric_car_battery_management"
] | 3 | [
[
"electric_car_battery_management",
"process_test_cases"
],
[
"process_test_cases",
"max_complete_trips"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 6864364aa8fd578b63088485e7498eca5a1338c5 | 1baf385b9b33161db5b843c5fb2c1ad10545cce4 | |||
v1.0 | complete | Taco | Taco_46670_C | def checkHammingDistance(n: int, arr: List[int], threshold: int, queries: List[Tuple[int, int]]) -> List[bool]:
""" Check if the Hamming distance between consecutive elements in subarrays remains below a given threshold.
Parameters:
n (int) : Size of the array.
arr (List[int]) : Array of integers.
t... | def hamming_distance(a, b):
return bin(a ^ b).count('1')
def checkHammingDistance(n, arr, threshold, queries):
results = []
for L, R in queries:
meets_criteria = True
for i in range(L, R):
if hamming_distance(arr[i], arr[i+1]) > threshold:
meets_criteria = False
... | from solution import checkHammingDistance
def test_example_1():
n = 5
arr = [1, 4, 3, 6, 7]
threshold = 2
queries = [(0, 2), (2, 4)]
assert checkHammingDistance(n, arr, threshold, queries) == [False, True]
def test_single_element_subarray():
n = 4
arr = [1, 2, 3, 4]
threshold = 1
q... | [
{
"docstring": null,
"function_declaration": "def hamming_distance(a, b):",
"function_name": "hamming_distance",
"parameter_list": "(a, b)"
},
{
"docstring": null,
"function_declaration": "def checkHammingDistance(n, arr, threshold, queries):",
"function_name": "checkHammingDistance"... | [
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 hamming_distance(a, b):\n return bin(a ^ b).count('1')\n\ndef checkHammingDistance(n, arr, threshold, queries):\n results = []\n for L, R in queries:\... | trial_gpt4o_0 | {
"original_instruction": "You are given an array of integers. Your task is to check if Hamming distance between consecutive elements in a subarray remains below a given threshold or not for multiple queries. The Hamming distance between two integers is the number of positions at which the corresponding bits are diff... | 0.662721 | Taco_46670 | C | [
"hamming_distance",
"checkHammingDistance"
] | 2 | [
[
"checkHammingDistance",
"hamming_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d91d41fee88e4244eef991204597e694d73ef26b | 4697f1fb58654af4600ee3c96a250663beb25f35 | |||
v1.0 | complete | Taco | Taco_46755_C | from typing import List
def find_largest_divisor(n: int, arr: List[int]) -> int:
"""
Given an array with `n` unique integers, find an integer `k` such that all elements
in the array can be divided by `k` without a remainder. `k` should be the largest possible divisor.
Args:
n (int): the number of ... | import math
from functools import reduce
def find_gcd(x, y):
"""
Returns the greatest common divisor (GCD) of x and y using the Euclidean algorithm.
"""
while y:
x, y = y, x % y
return x
def largest_divisor(arr):
"""
Finds the largest integer k such that all elements in the array c... | from solution import find_largest_divisor
def test_single_element():
assert find_largest_divisor(1, [10]) == 10
assert find_largest_divisor(1, [25]) == 25
def test_multiple_elements():
assert find_largest_divisor(3, [6, 9, 15]) == 3
assert find_largest_divisor(4, [12, 15, 21, 27]) == 3
assert find... | [
{
"docstring": "Returns the greatest common divisor (GCD) of x and y using the Euclidean algorithm.",
"function_declaration": "def find_gcd(x, y):",
"function_name": "find_gcd",
"parameter_list": "(x, y)"
},
{
"docstring": "Finds the largest integer k such that all elements in the array can ... | [
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 gcd_of_list(nums):\n \"\"\"\n Returns the greatest common divisor (GCD) of a list of numbers.\n \"\"\"\n return math.gcd(*nums)\n\nd... | trial_gpt4o_2 | {
"original_instruction": "Description\nGiven an array with `n` unique integers, write a program to find an integer `k` such that all elements in the array can be divided by `k` without a remainder. `k` should be the largest possible divisor.\n\nThe first line of input denotes the value of `n` (1 <= n <= 100). The se... | 0.862403 | Taco_46755 | C | [
"find_gcd",
"largest_divisor",
"find_largest_divisor"
] | 3 | [
[
"find_largest_divisor",
"largest_divisor"
],
[
"largest_divisor",
"find_gcd"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 83bc1917d8f65903179a07b12dfd9351f5e412a5 | 590fae6b1b9857b3592ab6322a9a29a9baa36d94 | |||
v1.0 | complete | Taco | Taco_46812_C | def handle_booking_requests(n: int, requests: List[Tuple[int, int]]) -> List[str]:
"""
This function takes the number of booking requests and a list of booking requests.
Each request is a tuple (start, end).
It returns a list of strings "Yes" or "No" based on whether the booking request is granted or d... | def handle_booking_requests(n, requests):
"""
This function takes the number of booking requests and a list of booking requests.
Each request is a tuple (start, end).
It returns a list of strings "Yes" or "No" based on whether the booking request is granted or denied.
"""
bookings = []
resul... | from solution import handle_booking_requests
def test_single_request():
assert handle_booking_requests(1, [(1, 3)]) == ["Yes"]
def test_non_overlapping_requests():
assert handle_booking_requests(2, [(1, 3), (4, 5)]) == ["Yes", "Yes"]
def test_overlapping_requests():
assert handle_booking_requests(2, [(1,... | [
{
"docstring": "This function takes the number of booking requests and a list of booking requests.\nEach request is a tuple (start, end).\nIt returns a list of strings \"Yes\" or \"No\" based on whether the booking request is granted or denied.",
"function_declaration": "def handle_booking_requests(n, reque... | [
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 manage_bookings(N, requests):\n \"\"\"\n Manages booking requests for a single study room.\n \n Parameters:\n N (int): Number of booking request... | trial_gpt4o_1 | {
"original_instruction": "A university library wishes to automate the process of booking study rooms. Each study room can be booked for a specific period and cannot be double-booked. Students can request a study room for a certain period, and if the room is available for the entire requested period, the request is g... | 0.53442 | Taco_46812 | C | [
"handle_booking_requests",
"read_input_and_process"
] | 2 | [
[
"read_input_and_process",
"handle_booking_requests"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cd34a5101be979911f21451a2a032cea6bea803d | fb3845250c7c59f9d56ba98e6b93b2affe4ce71c | |||
v1.0 | complete | Taco | Taco_46644_C | def max_subarray_sum(arr):
"""
Returns the maximum sum of a contiguous subarray within the given integer array arr.
Parameters:
arr (List[int]): An array of integers.
Returns:
int: The maximum sum of a contiguous subarray.
>>> max_subarray_sum([1, 2, 3, 4, -10])
10
>>> max_subarra... | def max_subarray_sum(arr):
"""
Returns the maximum sum of a contiguous subarray within the given integer array arr.
"""
max_sum = float('-inf')
current_sum = 0
for num in arr:
current_sum = max(num, current_sum + num)
max_sum = max(max_sum, current_sum)
return m... | def test_max_subarray_sum():
assert max_subarray_sum([1, 2, 3, 4, -10]) == 10
assert max_subarray_sum([-1, -2, -3, -4]) == -1
assert max_subarray_sum([5, 4, -1, 7, 8]) == 23
def test_process_input():
input_data = "3\n5\n1 2 3 4 -10\n4\n-1 -2 -3 -4\n6\n5 4 -1 7 8\n"
assert process_input(input_data) ... | [
{
"docstring": "Returns the maximum sum of a contiguous subarray within the given integer array arr.",
"function_declaration": "def max_subarray_sum(arr):",
"function_name": "max_subarray_sum",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def process_input(i... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_subarray_sum(T, test_cases):\n results = []\n for case in test_cases:\n n, A = case\n max_sum = float('-inf')\n current_sum = 0\... | trial_gpt4o_1 | {
"original_instruction": "Write a function to determine the maximum sum of a contiguous subarray within a given integer array A of length n.\n\n------ Input ------ \n\nThe first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows.\n\nThe first line of e... | 0.721926 | Taco_46644 | C | [
"max_subarray_sum",
"process_input",
"solve"
] | 3 | [
[
"process_input",
"max_subarray_sum"
],
[
"solve",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 7ce3fef426d518810c6189412ecca4a2e1ab878e | 0acdc910b67c95011fecb019cf7937cb7e4cea10 | |||
v1.0 | complete | Taco | Taco_46713_C | def is_magic_number(n: int) -> str:
"""
Check if the number is a magic number.
A "Magic Number" is defined as an integer that satisfies the following conditions:
1. The sum of its digits is a prime number.
2. The number contains at least one digit '7'.
Args:
n (int): The input int... | def is_prime(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num**0.5) + 1, 2):
if num % i == 0:
return False
return True
def is_magic_number(n):
digits = [int(d) for d in str(n)]
digit_... | from solution import is_magic_number
def test_magic_with_prime_sum_and_seven():
assert is_magic_number(719) == "MAGIC!"
def test_not_magic_due_to_non_prime_sum():
assert is_magic_number(37) == "NOT MAGIC!"
def test_not_magic_without_seven():
assert is_magic_number(233) == "NOT MAGIC!"
def test_magic_pri... | [
{
"docstring": null,
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def is_magic_number(n):",
"function_name": "is_magic_number",
"parameter_list": "(n)"
}
] | [
0,
0,
0,
0,
0,
0,
1,
1,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n for i in range(2, int(n... | trial_gpt4o_6 | {
"original_instruction": "Vijay loves numbers and patterns. He has recently stumbled upon a peculiar property of integers and wants to explore it further. He defines a \"Magic Number\" as an integer that satisfies the following conditions:\n\n1. The sum of its digits is a prime number.\n2. The number contains at lea... | 0.60092 | Taco_46713 | C | [
"is_prime",
"is_magic_number"
] | 2 | [
[
"is_magic_number",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 6e56c7ce616bdc3375aaf116c3518189495e1c5e | e312e807bddefc51d4b25e6d93ac7b4fe0c58b46 | |||
v1.0 | complete | Taco | Taco_46825_C | from typing import List, Tuple
def precompute_prefix_sums(array: List[int]) -> List[int]:
"""
Precompute the prefix sums of the input array.
>>> precompute_prefix_sums([1, 2, 3, 4, 5])
[0, 1, 3, 6, 10, 15]
"""
pass
def range_sum(prefix_sums: List[int], L: int, R: int) -> int:
"""
Calc... | def precompute_prefix_sums(array):
"""
Precompute the prefix sums of the input array.
"""
prefix_sums = [0] * (len(array) + 1)
for i in range(1, len(array) + 1):
prefix_sums[i] = prefix_sums[i - 1] + array[i - 1]
return prefix_sums
def range_sum(prefix_sums, L, R):
"""
Calculate... | def test_precompute_prefix_sums():
array = [1, 2, 3, 4, 5]
expected_prefix_sums = [0, 1, 3, 6, 10, 15]
assert precompute_prefix_sums(array) == expected_prefix_sums
def test_range_sum():
prefix_sums = [0, 1, 3, 6, 10, 15]
assert range_sum(prefix_sums, 1, 3) == 6
assert range_sum(prefix_sums, 2, ... | [
{
"docstring": "Precompute the prefix sums of the input array.",
"function_declaration": "def precompute_prefix_sums(array):",
"function_name": "precompute_prefix_sums",
"parameter_list": "(array)"
},
{
"docstring": "Calculate the sum of the range [L, R] using the prefix sums array.\nNote: L... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_prefix_sums(A):\n \"\"\"\n Precompute the prefix sums for array A.\n \"\"\"\n N = len(A)\n prefix_sums = [0] * (N + 1)\n for i in ... | trial_gpt4o_2 | {
"original_instruction": "Given a set of $N$ integers and $Q$ range queries, your task is to compute the sum of the integers in given ranges efficiently.\n\nYou will be provided with an array $A$ of $N$ integers, followed by $Q$ queries. Each query will specify a range $[L, R]$ (1-based index) and you need to return... | 0.603698 | Taco_46825 | C | [
"precompute_prefix_sums",
"range_sum",
"process_queries"
] | 3 | [
[
"process_queries",
"precompute_prefix_sums"
],
[
"process_queries",
"range_sum"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | 37c410b5f24833a7dfd38509ed27f2155a4a6ec9 | a3940b3cb79a6dc7aab26d54cedb8d0f5a29af0e | |||
v1.0 | complete | Taco | Taco_46848_C | from typing import List
def rob(nums: List[int]) -> int:
"""
Calculate the maximum amount of money that can be robbed without robbing two consecutive houses.
>>> rob([1, 2, 3, 1]) 4
>>> rob([2, 7, 9, 3, 1]) 12
>>> rob([]) 0
>>> rob([5]) 5
"""
def max_money_robbed(test_cases: List[List[int]... | def rob(nums):
"""
Calculate the maximum amount of money that can be robbed without robbing two consecutive houses.
"""
if not nums:
return 0
if len(nums) == 1:
return nums[0]
prev1 = 0
prev2 = 0
for num in nums:
temp = prev1
prev1 = max(prev2 + num, prev... | from solution import rob, max_money_robbed, parse_input
def test_rob_no_houses():
assert rob([]) == 0
def test_rob_one_house():
assert rob([5]) == 5
def test_rob_two_houses():
assert rob([3, 7]) == 7
def test_rob_multiple_houses():
assert rob([1, 2, 3, 1]) == 4
assert rob([2, 7, 9, 3, 1]) == 12
... | [
{
"docstring": "Calculate the maximum amount of money that can be robbed without robbing two consecutive houses.",
"function_declaration": "def rob(nums):",
"function_name": "rob",
"parameter_list": "(nums)"
},
{
"docstring": null,
"function_declaration": "def max_money_robbed(test_cases... | [
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 rob(nums):\n \"\"\"\n Returns the maximum amount of money that can be robbed without robbing adjacent houses.\n \"\"\"\n if not nums:\n retu... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of non-negative integers which represents the amount of money of n houses aligned in a row. A thief wants to rob these houses, but he cannot rob adjacent houses because the security systems will alert the police. Given the list of amounts, determine the maximum amount o... | 0.556265 | Taco_46848 | C | [
"rob",
"max_money_robbed",
"parse_input"
] | 3 | [
[
"max_money_robbed",
"rob"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 8f2e132becd1d22c437407f2a16200d1965d8684 | 3338a70311a0fde016f2108616996544735d0b7c | |||
v1.0 | complete | Taco | Taco_46658_C | def is_convex_polygon(points):
""" Determine if a given set of points form a convex polygon.
Args:
points (List[Tuple[int, int]]): List of tuples representing the coordinates of the points.
Returns:
bool: True if the points form a convex polygon, False otherwise.
Examples:
>>> i... | def is_convex_polygon(points):
def cross_product(p1, p2, p3):
return (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])
n = len(points)
if n < 3:
return False
last_product_sign = 0
for i in range(n):
p1 = points[i]
p2 = points[(i + 1) % n]
... | def test_parse_input():
input_str = '2\n4 0 0 0 1 1 1 1 0\n5 0 0 2 2 4 0 3 3 1 3'
expected = [
[(0, 0), (0, 1), (1, 1), (1, 0)],
[(0, 0), (2, 2), (4, 0), (3, 3), (1, 3)]
]
assert parse_input(input_str) == expected
def test_is_convex_polygon():
assert is_convex_polygon([(0, 0), (0, 1... | [
{
"docstring": null,
"function_declaration": "def is_convex_polygon(points):",
"function_name": "is_convex_polygon",
"parameter_list": "(points)"
},
{
"docstring": null,
"function_declaration": "def check_convex_polygons(test_cases):",
"function_name": "check_convex_polygons",
"p... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_convex_polygon(points):\n def cross_product(p1, p2, p3):\n return (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])\n\n n =... | trial_gpt4o_0 | {
"original_instruction": "Determine if a given set of points form a convex polygon. \n\nYou will be given a list of points in 2D plane and you need to determine if these points form a convex polygon or not. A polygon is convex if all its internal angles are less than 180 degrees.\n\nConstraints\n\n* 3 ≤ n ≤ 100\n* -... | 0.532408 | Taco_46658 | C | [
"is_convex_polygon",
"check_convex_polygons",
"parse_input",
"solution"
] | 4 | [
[
"check_convex_polygons",
"is_convex_polygon"
],
[
"solution",
"check_convex_polygons"
],
[
"solution",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 44a51b6d2149c643b6db7f874d03671932b746a8 | 7c0417b89528d7c1645dcd2c8ec47569142b33c7 | |||
v1.0 | complete | Taco | Taco_46939_C | def minimal_time_to_pick_mushrooms(m: int, n: int, k: int, mushrooms: List[Tuple[int, int]]) -> int:
""" Computes the minimal time required for Adil and Bera to pick all mushrooms and return to the starting position.
m : int : the number of rows in the forest grid
n : int : the number of columns in the... | from collections import deque
import itertools
def bfs(grid, start, m, n):
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
queue = deque([(start[0], start[1], 0)])
visited = [[False]*n for _ in range(m)]
visited[start[0]][start[1]] = True
distances = [[float('inf')]*n for _ in range(m)]
distanc... | from solution import minimal_time_to_pick_mushrooms
def test_case_1():
assert minimal_time_to_pick_mushrooms(4, 4, 3, [(1, 2), (2, 1), (3, 3)]) == 12
def test_case_2():
assert minimal_time_to_pick_mushrooms(3, 3, 2, [(1, 1), (2, 2)]) == 8
def test_case_3():
assert minimal_time_to_pick_mushrooms(1, 1, 0, ... | [
{
"docstring": null,
"function_declaration": "def bfs(grid, start, m, n):",
"function_name": "bfs",
"parameter_list": "(grid, start, m, n)"
},
{
"docstring": null,
"function_declaration": "def minimal_time_to_pick_mushrooms(m, n, k, mushrooms):",
"function_name": "minimal_time_to_pic... | [
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 deque\nimport itertools\n\ndef bfs(grid, start, m, n):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n queue = deque([(start[0], ... | trial_gpt4o_0 | {
"original_instruction": "Kekoland is famous for its delicious mushrooms. Adil and Bera are on a mushroom picking expedition in the enchanted Kekoland forest. The forest can be represented as a rectangular grid of size m x n. Each cell in the grid either contains a mushroom or is empty. Adil and Bera start at the to... | 0.602342 | Taco_46939 | C | [
"bfs",
"minimal_time_to_pick_mushrooms"
] | 2 | [
[
"minimal_time_to_pick_mushrooms",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b847ef0e6c136c066754d0dc3dc0fe115680e1d5 | ab59b38c2eb5d65bf39d5b2221338084c65ed6fa | |||
v1.0 | complete | Taco | Taco_46837_C | def update_stream(stream, index, value):
""" Update the value at a specific position in the stream.
"""
pass
def find_frequency_in_range(stream, left, right, value):
""" Find the frequency of a given integer in a specified range of the stream.
"""
pass
def process_queries(n, q, stream, queries... | def update_stream(stream, index, value):
stream[index - 1] = value
def find_frequency_in_range(stream, left, right, value):
return stream[left-1:right].count(value)
def process_queries(n, q, stream, queries):
results = []
for query in queries:
if query[0] == 1:
_, index, value = qu... | def test_update_stream():
stream = [1, 2, 1, 3, 2, 1]
update_stream(stream, 3, 2)
assert stream == [1, 2, 2, 3, 2, 1]
def test_find_frequency_in_range():
stream = [1, 2, 2, 3, 2, 1]
assert find_frequency_in_range(stream, 1, 6, 1) == 2
assert find_frequency_in_range(stream, 1, 4, 2) == 2
ass... | [
{
"docstring": null,
"function_declaration": "def update_stream(stream, index, value):",
"function_name": "update_stream",
"parameter_list": "(stream, index, value)"
},
{
"docstring": null,
"function_declaration": "def find_frequency_in_range(stream, left, right, value):",
"function_... | [
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 process_queries(n, q, a, queries):\n results = []\n \n for query in queries:\n if query[0] == 1:\n i, x = query[1] - 1, query[2]\n ... | trial_gpt4o_9 | {
"original_instruction": "Rebecca has recently started exploring the exciting world of data streams and is fascinated by the complex operations that can be performed on them in real-time. She came across a challenging problem related to the frequency of elements in a stream that she couldn't solve herself and has tu... | 0.569507 | Taco_46837 | C | [
"update_stream",
"find_frequency_in_range",
"process_queries"
] | 3 | [
[
"process_queries",
"find_frequency_in_range"
],
[
"process_queries",
"update_stream"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | false | [] | true | d1a824f33350c4b61114f25b84cddcd9d77e278a | 954aa004189f92258fb6217b481df68b1801f140 | |||
v1.0 | complete | Taco | Taco_47106_C | def zeckendorf_representation(n: int) -> List[int]:
"""
Given an integer n, decompose it into a sum of distinct non-consecutive Fibonacci numbers
following Zeckendorf's theorem.
Parameters:
- n: A positive integer (1 ≤ n ≤ 10^18)
Returns:
- A list of Fibonacci numbers in descending order t... | def generate_fibonacci_until(n):
"""
Generates all Fibonacci numbers up to n.
"""
fibs = [1, 2] # Since Zeckendorf representation avoids two consecutive Fibonacci numbers, start from the second Fibonacci number
while True:
next_fib = fibs[-1] + fibs[-2]
if next_fib > n:
... | from solution import zeckendorf_representation
def test_primary_examples():
assert zeckendorf_representation(28) == [21, 5, 2]
assert zeckendorf_representation(100) == [89, 8, 3]
def test_zero_case():
assert zeckendorf_representation(1) == [1]
assert zeckendorf_representation(2) == [2]
def test_large... | [
{
"docstring": "Generates all Fibonacci numbers up to n.",
"function_declaration": "def generate_fibonacci_until(n):",
"function_name": "generate_fibonacci_until",
"parameter_list": "(n)"
},
{
"docstring": "Returns the Zeckendorf representation of the number n,\nwhich is a sum of distinct no... | [
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 fibonacci_decomposition(n):\n # Generate Fibonacci sequence up to n\n fibs = [1, 2]\n while fibs[-1] <= n:\n fibs.append(fibs[-1] + fibs[-2])\n... | trial_gpt4o_3 | {
"original_instruction": "Bernie is learning about Fibonacci sequences and their properties. He read that Fibonacci sequences can be used to compose any positive integer uniquely by summing distinct Fibonacci numbers, where no two consecutive Fibonacci numbers are used. This is known as Zeckendorf's theorem.\n\nIntr... | 0.636926 | Taco_47106 | C | [
"generate_fibonacci_until",
"zeckendorf_representation"
] | 2 | [
[
"zeckendorf_representation",
"generate_fibonacci_until"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7ff9d20e21a8de283ec41f72af68bf2bb922e025 | 8ca4bd65fabdb66176c1850c28177fc3b9da6883 | |||
v1.0 | complete | Taco | Taco_46897_C | def count_paths(grid: List[List[int]], N: int) -> int:
""" Calculate the number of distinct paths to reach (N,N) from (1,1) in a grid.
The grid contains obstacles, marked as `1`, and traversable cells, marked as `0`.
The only allowed movements are to the right and downward.
Args:
grid (List[List[in... | def count_paths(grid, N):
# DP table for the number of paths to each cell
dp = [[0] * N for _ in range(N)]
# if starting cell has obstacle, immediately return 0 paths
if grid[0][0] == 1:
return 0
# Initial position (1,1) -> (0,0) in zero-based index
dp[0][0] = 1
# Fill... | def test_count_paths():
grid1 = [
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
]
assert count_paths(grid1, 3) == 2
grid2 = [
[0, 1, 0],
[0, 1, 0],
[0, 0, 0]
]
assert count_paths(grid2, 3) == 1
grid3 = [
[0, 0],
[1, 0]
]
assert coun... | [
{
"docstring": null,
"function_declaration": "def count_paths(grid, N):",
"function_name": "count_paths",
"parameter_list": "(grid, N)"
},
{
"docstring": null,
"function_declaration": "def calculate_paths(test_cases):",
"function_name": "calculate_paths",
"parameter_list": "(test... | [
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_paths(test_cases):\n results = []\n for N, grid in test_cases:\n if grid[0][0] == 1 or grid[N-1][N-1] == 1:\n # No path if start ... | trial_gpt4o_4 | {
"original_instruction": "Samir loves playing games. One of his favorites involves moving on a 2D grid. The grid is an $N \\times N$ matrix, and Samir starts in the top-left corner at (1,1). The goal is to reach the bottom-right corner at (N,N).\n\nHowever, there are certain cells in the grid through which Samir can... | 0.707763 | Taco_46897 | C | [
"count_paths",
"calculate_paths",
"process_input",
"main"
] | 4 | [
[
"calculate_paths",
"count_paths"
]
] | 1 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | b86df8ec4094af0723b7f3cfbfdd30f0e4f6284c | 0e5fc71a8c36bb4ce9743842cf2bd8ef8387b957 | |||
v1.0 | complete | Taco | Taco_47183_C | def library_organizer(input_str: str) -> str:
""" Simulates the librarian’s organizing process, ensuring that each compartment adheres to the rules.
>>> library_organizer("5\n1 5\n2 3\n1 2\n3 7\n2 4\n0")
"1\n2\n5\n\n2\n3\n4\n\n3\n7"
>>> library_organizer("1\n1 5\n0")
"1\n5"
""" | def organize_scrolls(datasets):
result = []
for dataset in datasets:
N = dataset[0]
scrolls = dataset[1:]
# Grouping scrolls by topic
scroll_dict = {}
for scroll in scrolls:
topic, length = scroll
if topic not in scroll_dict:
... | from solution import library_organizer
def test_example_case():
input_data = """5
1 5
2 3
1 2
3 7
2 4
6
1 3
1 6
2 3
2 6
3 3
3 6
0"""
expected_output = """1
2
5
2
3
4
3
7
1
3
6
2
3
6
3
3
6"""
assert library_organizer(input_data) == expected_output
def test_single_scroll():
input_data = "... | [
{
"docstring": null,
"function_declaration": "def organize_scrolls(datasets):",
"function_name": "organize_scrolls",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_str):",
"function_name": "parse_input",
"parameter_list": "(i... | [
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 organize_scrolls(datasets):\n results = []\n for dataset in datasets:\n scrolls = {}\n N = dataset[0]\n for i in range(1, N + 1):\n ... | trial_gpt4o_2 | {
"original_instruction": "In a land far away, there exists a peculiar library system managed by the diligent Librarian Lais. The library contains a fascinating collection of scrolls, each categorized by a unique topic. To facilitate efficient study sessions, the librarian has devised a unique way of organizing the s... | 0.494538 | Taco_47183 | C | [
"organize_scrolls",
"parse_input",
"parse_output",
"library_organizer"
] | 4 | [
[
"library_organizer",
"organize_scrolls"
],
[
"library_organizer",
"parse_input"
],
[
"library_organizer",
"parse_output"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 3cb5a43f39b4b83295b147a372551a358e21db4f | 42e2c8c1fc56b777864fbe9bfc4aa88168f1687d | |||
v1.0 | complete | Taco | Taco_47265_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def sorted_array_to_bst(nums):
"""
Convert a sorted array to a balanced binary search tree.
"""
pass
def inorder_traversal(root):
"""
Perform an in-... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def sorted_array_to_bst(nums):
"""
Convert a sorted array to a balanced binary search tree.
"""
if not nums:
return None
mid = len(nums) // 2
... | from solution import sorted_array_to_bst, inorder_traversal, process_test_cases
def test_sorted_array_to_bst_case1():
array = [-10, -3, 0, 5, 9]
bst_root = sorted_array_to_bst(array)
assert inorder_traversal(bst_root) == array
def test_sorted_array_to_bst_case2():
array = [1, 2, 3, 4, 5, 6, 7]
bst... | [] | [
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 sorted_... | trial_gpt4o_2 | {
"original_instruction": "A balanced binary tree is a special type of binary tree in which the depth of the two subtrees of every node never differ by more than 1. Write a function to convert a sorted array into a balanced binary tree.\n\nYou are given a sorted array of distinct integers. Your task is to create a ba... | 0.576023 | Taco_47265 | C | [
"sorted_array_to_bst",
"inorder_traversal",
"process_test_cases"
] | 3 | [
[
"process_test_cases",
"inorder_traversal"
],
[
"process_test_cases",
"sorted_array_to_bst"
]
] | 2 | [
"process_test_cases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 2da965f3f2a5abb0d42de3ac7c32231d123bf5b5 | 6a18eca2cfcfa34f0a9ee51d0d43fe767213e674 | |||
v1.0 | complete | Taco | Taco_47277_C | def is_prime(num: int) -> bool:
""" Returns True if num is a prime number, else False.
>>> is_prime(2)
True
>>> is_prime(1)
False
>>> is_prime(13)
True
"""
pass
def count_powerful_spells(spells: List[str]) -> int:
""" Counts how many spells are powerful, i.e., have a prime numbe... | def is_prime(num):
"""
Returns True if num is a prime number, else False.
"""
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:
retu... | 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
def test_count_powerful_spells():
assert count_powerful_spells(['abc', 'abb', 'abcde']) == 3
assert c... | [
{
"docstring": "Returns True if num is a prime number, else False.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": "Counts how many spells are powerful, i.e., have a prime number of distinct characters.",
"function_... | [
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 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_5 | {
"original_instruction": "Dr. Strange has a list of spells, each represented by a string of lowercase letters. A spell is considered powerful if the number of distinct characters in it is a prime number. Your task is to count the number of powerful spells in the given list.\n\nInput\nFirst line contains an integer T... | 0.627648 | Taco_47277 | C | [
"is_prime",
"count_powerful_spells",
"main"
] | 3 | [
[
"count_powerful_spells",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7045f2b0917cc9217549751df768034783eff837 | 81b9db64284ae89cb7df298883a6126fd6578940 | |||
v1.0 | complete | Taco | Taco_46984_C | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(index, nodes):
"""
Helper function to build the binary tree from node list.
"""
pass # Implement build_tree function here
def pre_order... | class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_tree(index, nodes):
value = nodes[index][0]
left = nodes[index][1]
right = nodes[index][2]
node = TreeNode(value)
if left is not... | from solution import decrypt_binary_tree
def test_decrypt_binary_tree_case1():
n = 5
nodes = [
(1, 1, 2),
(2, None, None),
(3, 3, 4),
(4, None, None),
(5, None, None)
]
assert decrypt_binary_tree(n, nodes) == [1, 2, 3, 4, 5, 2, 1, 4, 3, 5, 2, 4, 5, 3, 1]
def tes... | [] | [
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": "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 \nd... | trial_gpt4o_6 | {
"original_instruction": "One day, Danny the Detective is hired to solve a mysterious case. During his investigation, he discovers a crucial piece of evidence in the form of a sequence of numbers. However, the sequence is encrypted using a special mechanism.\n\nDanny needs your help to decipher the code, which is hi... | 0.541699 | Taco_46984 | C | [
"build_tree",
"pre_order_traversal",
"in_order_traversal",
"post_order_traversal",
"decrypt_binary_tree"
] | 5 | [
[
"decrypt_binary_tree",
"build_tree"
],
[
"decrypt_binary_tree",
"in_order_traversal"
],
[
"decrypt_binary_tree",
"post_order_traversal"
],
[
"decrypt_binary_tree",
"pre_order_traversal"
]
] | 4 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | a33b1885dade7ab1b23c4acab7db489a26aa9076 | fcffe1f0059d1cc197f54e009feda637c95a424c | |||
v1.0 | complete | Taco | Taco_47382_C | def decode_messages(messages: list) -> list:
""" Decodes multiple messages and returns the results as a list of integers.
Each integer in the message corresponds to a position in the English alphabet (1 = 'a', 2 = 'b', ..., 26 = 'z').
Integers may form a pair to represent a two-digit number which also ... | def num_decodings(s: str) -> int:
"""
Returns the number of ways to decode a given string of digits.
"""
if not s or s[0] == '0':
return 0
n = len(s)
dp = [0] * (n + 1)
dp[0], dp[1] = 1, 1 # An empty string has one way to decode, base case
for i in range(2, n + 1):... | import pytest
from solution import decode_messages
def test_case_123():
messages = ["123"]
assert decode_messages(messages) == [3]
def test_case_226():
messages = ["226"]
assert decode_messages(messages) == [3]
def test_case_06():
messages = ["06"]
assert decode_messages(messages) == [0]
def... | [
{
"docstring": "Returns the number of ways to decode a given string of digits.",
"function_declaration": "def num_decodings(s):",
"function_name": "num_decodings",
"parameter_list": "(s)"
},
{
"docstring": "Decodes multiple messages and returns the results as a list of integers.",
"funct... | [
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_decoding_ways(message: str) -> int:\n \"\"\"\n This function computes the number of ways a given sequence of integers can be decoded \n into val... | trial_gpt4o_2 | {
"original_instruction": "A mysterious ancient text has been discovered, and it is made up of several encrypted messages. Each message is a sequence of integers. Archaeologists have learned that these integers can be decoded into words by following these steps:\n\n1. Each integer corresponds to a position in the Eng... | 0.672415 | Taco_47382 | C | [
"num_decodings",
"decode_messages"
] | 2 | [
[
"decode_messages",
"num_decodings"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ebd0f68613bcc8b382646cee4dcc1f161870ac80 | ec3629c90b30d2cce551b968c0ecb336f081184f | |||
v1.0 | complete | Taco | Taco_47032_C | from typing import List
def find_longest_word(s: str, dictionary: List[str]) -> str:
""" Given a string S and a dictionary of words D, find the longest word in D that can be formed
by deleting some characters of S without reordering the remaining characters. If there are multiple
possible results, return... | def can_form_by_deleting(s, word):
it = iter(s)
return all(char in it for char in word)
def find_longest_word(s, dictionary):
longest_word = ""
for word in dictionary:
if can_form_by_deleting(s, word):
if len(word) > len(longest_word) or (len(word) == len(longest_word) and word < lo... | from solution import find_longest_word
def test_example1():
s = "abpcplea"
dictionary = ["ale", "apple", "monkey"]
assert find_longest_word(s, dictionary) == "apple"
def test_example2():
s = "abpcplea"
dictionary = ["a", "b", "c"]
assert find_longest_word(s, dictionary) == "a"
def test_no_mat... | [
{
"docstring": null,
"function_declaration": "def can_form_by_deleting(s, word):",
"function_name": "can_form_by_deleting",
"parameter_list": "(s, word)"
},
{
"docstring": null,
"function_declaration": "def find_longest_word(s, dictionary):",
"function_name": "find_longest_word",
... | [
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_subsequence(s, word):\n \"\"\"\n Check if `word` is a subsequence of `s`.\n \"\"\"\n it = iter(s)\n return all(char in it for char in word)\n... | trial_gpt4o_2 | {
"original_instruction": "Given a string S and a dictionary of words D, find the longest word in D that can be formed by deleting some characters of S without reordering the remaining characters. If there are multiple possible results, return the longest word with the smallest lexicographical order. If there is no p... | 0.787845 | Taco_47032 | C | [
"can_form_by_deleting",
"find_longest_word"
] | 2 | [
[
"find_longest_word",
"can_form_by_deleting"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 5bd562d1ec27b72c93f86bde5e11683b8a502bb4 | 4ba999528d44a0e77af3528786d2f25e064a0958 | |||
v1.0 | complete | Taco | Taco_47482_C | def conference_workshops(data: str) -> List[int]:
"""Determine the maximum number of non-overlapping workshops John can attend.
>>> conference_workshops("3\n1 3\n2 4\n3 5\n4\n1 2\n3 4\n0 6\n5 7\n4\n1 4\n4 5\n5 6\n4 10\n0\n")
[2, 3, 3]
>>> conference_workshops("1\n1 2\n0\n")
[1]
>>> conference_wo... | def max_non_overlapping_workshops(datasets):
results = []
for dataset in datasets:
n, workshops = dataset
workshops.sort(key=lambda x: x[1]) # Sort by end times
count = 0
last_end_time = 0
for s, e in workshops:
if s >= last_end_time:
count +... | from solution import conference_workshops
def test_example_case():
data = "3\n1 3\n2 4\n3 5\n4\n1 2\n3 4\n0 6\n5 7\n4\n1 4\n4 5\n5 6\n4 10\n0\n"
expected = [2, 3, 3]
assert conference_workshops(data) == expected
def test_single_dataset_single_workshop():
data = "1\n1 2\n0\n"
expected = [1]
ass... | [
{
"docstring": null,
"function_declaration": "def max_non_overlapping_workshops(datasets):",
"function_name": "max_non_overlapping_workshops",
"parameter_list": "(datasets)"
},
{
"docstring": null,
"function_declaration": "def parse_input(data):",
"function_name": "parse_input",
... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_non_overlapping_workshops(datasets):\n results = []\n \n for workshops in datasets:\n # Sort workshops based on their end times\n so... | trial_gpt4o_2 | {
"original_instruction": "John is organizing a series of workshops for a local tech conference. Each workshop has a specific start and end time. John wants to participate in as many workshops as possible, but the workshops may overlap. Your task is to write a program that helps John find the maximum number of non-ov... | 0.564399 | Taco_47482 | C | [
"max_non_overlapping_workshops",
"parse_input",
"conference_workshops"
] | 3 | [
[
"conference_workshops",
"max_non_overlapping_workshops"
],
[
"conference_workshops",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 627c551b065276ddd5515dd52c83c161fc045316 | 8afbcf26396d84990e8ec9231a3a96b4ffed9057 | |||
v1.0 | complete | Taco | Taco_47024_C | from typing import List, Tuple
from collections import defaultdict, deque
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if n is prime, False otherwise.
"""
pass
def largest_pri... | from collections import defaultdict, deque
def is_prime(n):
"""
Helper function to check if a number is prime.
"""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2... | from solution import largest_prime_subgraph
def test_example_1():
N, M = 5, 4
roads = [(1, 2), (1, 3), (3, 4), (4, 5)]
assert largest_prime_subgraph(N, M, roads) == 5
def test_example_2():
N, M = 6, 5
roads = [(1, 2), (2, 3), (2, 4), (3, 5), (4, 6)]
assert largest_prime_subgraph(N, M, roads) =... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Given the number of cities N, number of roads M, and list of bidirectional roads, \nreturn the number of cities... | [
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.222 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return ... | trial_gpt4o_8 | {
"original_instruction": "A company is organizing a conference in a country. The country consists of $N$ cities numbered $1$ through $N$, with $M$ bidirectional roads connecting them. We will use the following terms:\n- A path is a sequence of roads in which each road starts in the city the preceding road ended in.\... | 0.585548 | Taco_47024 | C | [
"is_prime",
"largest_prime_subgraph"
] | 2 | [
[
"largest_prime_subgraph",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e4f25b8c9dd2feefcb4c6c5bc755b44ca8ec93e0 | 835c136cdc62920b0b3fa49f521dbfaac2ec9342 | |||
v1.0 | complete | Taco | Taco_47740_C | def is_prime(num: int) -> bool:
""" Helper function to check if a number is prime. """
pass # Implement this function
def construct_permutation(n: int) -> list:
""" Given a positive integer 'n', construct a permutation 'p' of integers from 1 to n,
such that for any two consecutive integers i and ... | def is_prime(num):
"""
Helper function to check if a number is prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i + 2) == 0:
return F... | import pytest
from solution import construct_permutation, is_prime
def test_single_element():
assert construct_permutation(1) == [1]
def test_two_elements():
assert construct_permutation(2) == []
def test_three_elements():
assert construct_permutation(3) == []
def test_four_elements():
permutation =... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(num):",
"function_name": "is_prime",
"parameter_list": "(num)"
},
{
"docstring": null,
"function_declaration": "def construct_permutation(n):",
"function_name": "construct_permutati... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\" Returns True if n is a prime number, False otherwise. \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return Tru... | trial_gpt4o_1 | {
"original_instruction": "Given a positive integer `n`, you need to construct a permutation `p` of integers from 1 to n, such that for any two consecutive integers i and j in the permutation, the sum `i + j` is not a prime number. If there are multiple valid permutations, output any one of them. If no valid permutat... | 0.701949 | Taco_47740 | C | [
"is_prime",
"construct_permutation"
] | 2 | [
[
"construct_permutation",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 9e21a3e00ba280748ca16ebf18d8f1f6060a01e1 | f768c3b6a6b748c023a509b7b578f6b27f163c6e | |||
v1.0 | complete | Taco | Taco_47604_C | def is_mirrored_string(S: str) -> bool:
"""
Determine whether the given string S is a mirrored string, considering only alphabets and ignoring case.
Args:
S : str : the string to be tested
Returns:
bool : True if the string is a mirrored string, False otherwise.
Examples:
... | def is_mirrored_string(S):
"""
Determine whether the given string S is a mirrored string, considering only alphabets and ignoring case.
"""
filtered_chars = [char.lower() for char in S if char.isalpha()]
return filtered_chars == filtered_chars[::-1]
def mirrored_strings(N, strings):
"""
... | from solution import is_mirrored_string, mirrored_strings
def test_is_mirrored_string():
assert is_mirrored_string("A man a plan a canal Panama") == True
assert is_mirrored_string("Was it a car or a cat I saw") == True
assert is_mirrored_string("No lemon no melon") == True
assert is_mirrored_string("He... | [
{
"docstring": "Determine whether the given string S is a mirrored string, considering only alphabets and ignoring case.",
"function_declaration": "def is_mirrored_string(S):",
"function_name": "is_mirrored_string",
"parameter_list": "(S)"
},
{
"docstring": "Determine for each string in stri... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_mirrored_string(s):\n \"\"\"\n Determine if the given string is a mirrored string, ignoring case and non-alphabet characters.\n \"\"\"\n # Proce... | trial_gpt4o_2 | {
"original_instruction": "You are given a special string problem to solve. Your task is to determine whether a given string is a \"mirrored\" string or not. A mirrored string is one where the string reads the same backward as forward. However, the twist here is that you need to ignore case-sensitivity and only consi... | 0.64173 | Taco_47604 | C | [
"is_mirrored_string",
"mirrored_strings"
] | 2 | [
[
"mirrored_strings",
"is_mirrored_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c4265a2f24cfeccb72cb3960ed84573ddf5245d0 | 6496684543de795b527e1d56813f112ed7b54608 | |||
v1.0 | complete | Taco | Taco_47541_C | def gcd(x, y):
while y:
x, y = y, x % y
return x
def count_pairs(n):
"""
Given an integer n, return the count of pairs (a, b) such that
gcd(a, b) = lcm(a, b) / (a + b).
"""
count = 0
for a in range(1, n + 1):
for b in range(1, n + 1):
if a == b:
... | def count_pairs(n):
"""
Given an integer n, return the count of pairs (a, b) such that
gcd(a, b) = lcm(a, b) / (a + b).
"""
count = 0
for a in range(1, n + 1):
for b in range(1, n + 1):
if a == b:
count += 1
else:
lcm_ab = (a * b) /... | from solution import number_of_pairs
def test_sample_1():
assert number_of_pairs([1]) == [1]
def test_sample_2():
assert number_of_pairs([2]) == [2]
def test_sample_3():
assert number_of_pairs([4]) == [4]
def test_large_number():
assert number_of_pairs([10]) == [10]
assert number_of_pairs([100])... | [
{
"docstring": "Given an integer n, return the count of pairs (a, b) such that\ngcd(a, b) = lcm(a, b) / (a + b).",
"function_declaration": "def count_pairs(n):",
"function_name": "count_pairs",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def gcd(x, y):",
... | [
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 count_pairs(n):\n \"\"\"\n Function to find the number of pairs (a, b) such that \n gcd(a, b) = lcm(a, b) / (a + b) for a given n.\n \"\"\"\n pa... | trial_gpt4o_9 | {
"original_instruction": "Alice and Bob are fond of puzzles, and while taking a break from their games, they stumbled upon a mathematical challenge. Given a number n, they are curious to find out how many pairs of positive integers (a, b) such that the greatest common divisor (gcd) of a and b is equal to their least... | 0.648494 | Taco_47541 | C | [
"count_pairs",
"gcd",
"number_of_pairs"
] | 3 | [
[
"count_pairs",
"gcd"
],
[
"number_of_pairs",
"count_pairs"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 24ccd2c90428aca271ec442b18d655699b8bde82 | 4a6f7d084f9d642d94ea38f4e8b0d4664b2e9f84 | |||
v1.0 | complete | Taco | Taco_46956_C | def minimum_energy_cost(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]]]]) -> List[int]:
""" Determine the minimum total energy cost to ensure all planets are connected.
Parameters:
T (int): The number of test cases.
test_cases (List[Tuple[int, int, List[Tuple[int, int, int]]]])... | def find_parent(parent, i):
if parent[i] == i:
return i
else:
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_... | def test_minimum_energy_cost():
T = 2
test_cases = [
(4, 5, [
(1, 2, 3),
(2, 3, 4),
(3, 4, 5),
(4, 1, 6),
(1, 3, 2)
]),
(3, 3, [
(1, 2, 1),
(2, 3, 2),
(3, 1, 3)
])
]
expe... | [
{
"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... | [
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 return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n root_x = find(parent, x)\... | trial_gpt4o_2 | {
"original_instruction": "In a far-off galaxy, there exists a highly advanced civilization that uses a unique system of teleportation networks to travel between planets. Each planet in the galaxy is represented as a node, and each teleportation path between two planets is represented as an edge with a positive integ... | 0.623343 | Taco_46956 | C | [
"find_parent",
"union",
"kruskal_mst",
"minimum_energy_cost"
] | 4 | [
[
"kruskal_mst",
"find_parent"
],
[
"kruskal_mst",
"union"
],
[
"minimum_energy_cost",
"kruskal_mst"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | e9d40eadb264a05a77f873e02ca08e8ac018df84 | 2048256ffe6bbcb2df51f32ec85ba1127fe72b7d | |||
v1.0 | complete | Taco | Taco_47607_C | def quickselect(arr, k):
"""
Return the k-th smallest element in the array using Quickselect.
"""
if len(arr) == 1:
return arr[0]
pivot = arr[len(arr) // 2]
lows = [el for el in arr if el < pivot]
highs = [el for el in arr if el > pivot]
pivots = [el for el in arr if el == pivo... | def quickselect(arr, k):
"""
Return the k-th smallest element in the array using Quickselect.
"""
if len(arr) == 1:
return arr[0]
pivot = arr[len(arr) // 2]
lows = [el for el in arr if el < pivot]
highs = [el for el in arr if el > pivot]
pivots = [el for el in arr if el == pivo... | from solution import kth_smallest_element
def test_kth_smallest_element():
assert kth_smallest_element(6, [7, 10, 4, 3, 20, 15], 3) == 7
assert kth_smallest_element(5, [1, 2, 3, 4, 5], 1) == 1
assert kth_smallest_element(5, [1, 2, 3, 4, 5], 5) == 5
assert kth_smallest_element(7, [7, 10, 4, 3, 20, 15, 6... | [
{
"docstring": "Return the k-th smallest element in the array using Quickselect.",
"function_declaration": "def quickselect(arr, k):",
"function_name": "quickselect",
"parameter_list": "(arr, k)"
},
{
"docstring": null,
"function_declaration": "def kth_smallest_element(n, arr, k):",
... | [
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 random\n\ndef partition(arr, low, high):\n pivot = arr[high]\n i = low\n for j in range(low, high):\n if arr[j] <= pivot:\n arr[i... | trial_gpt4o_1 | {
"original_instruction": "Implement a function that finds the k-th smallest element in a given list of integers. You should solve this problem using the Quickselect algorithm.\n\nInput Format \n\nThe first line contains an integer n, representing the number of elements in the list. \nThe second line contains n space... | 0.584445 | Taco_47607 | C | [
"quickselect",
"kth_smallest_element"
] | 2 | [
[
"kth_smallest_element",
"quickselect"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 659779024ad4e467653153b49e9a4f2472bbbefa | 4d03327950c60d55b49972b0c3ed574688da7f6b | |||
v1.0 | complete | Taco | Taco_47880_C | from typing import List
def minimizeMaxSum(arr: List[int], k: int) -> int:
""" Partition the list into k contiguous subarrays such that the maximum sum of the subarrays is minimized.
>>> minimizeMaxSum([7, 2, 5, 10, 8], 2)
18
>>> minimizeMaxSum([1, 2, 3, 4], 4)
4
""" | def canPartition(arr, k, maxSum):
currentSum = 0
requiredPartitions = 1
for num in arr:
currentSum += num
if currentSum > maxSum:
requiredPartitions += 1
currentSum = num
if requiredPartitions > k:
return False
return True
def mini... | from solution import minimizeMaxSum
def test_minimizeMaxSum_sample():
assert minimizeMaxSum([7, 2, 5, 10, 8], 2) == 18
def test_minimizeMaxSum_single_element_subarrays():
assert minimizeMaxSum([1, 2, 3, 4], 4) == 4
def test_minimizeMaxSum_entire_array_as_one_subarray():
assert minimizeMaxSum([1, 2, 3, 4]... | [
{
"docstring": null,
"function_declaration": "def canPartition(arr, k, maxSum):",
"function_name": "canPartition",
"parameter_list": "(arr, k, maxSum)"
},
{
"docstring": null,
"function_declaration": "def minimizeMaxSum(arr, k):",
"function_name": "minimizeMaxSum",
"parameter_lis... | [
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 canPartition(arr, k, maxSum):\n currentSum = 0\n requiredPartitions = 1\n\n for num in arr:\n currentSum += num\n\n if currentSum > maxS... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of integers $arr$ and an integer $k$. Your task is to partition the list into $k$ contiguous subarrays such that the maximum sum of the subarrays is minimized. Return the minimized maximum sum.\n\nFor example, given $arr=[7,2,5,10,8]$ and $k=2$, the best partition would... | 0.691903 | Taco_47880 | C | [
"canPartition",
"minimizeMaxSum"
] | 2 | [
[
"minimizeMaxSum",
"canPartition"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | d3d4098737495201bb65046559fd97902576e14a | 072731560ad08594a493e1a4b76776450042b168 | |||
v1.0 | complete | Taco | Taco_47818_C | def find_core(s):
"""
Returns the core of the string s, which is the longest contiguous substring
that contains either only letters or only digits. If multiple substrings
of the same maximum length exist, returns the leftmost one.
>>> find_core("AB12C34DE") "AB"
>>> find_core("1234AB56") "1234... | def find_core(s):
"""
Returns the core of the string s, which is the longest contiguous substring
that contains either only letters or only digits. If multiple substrings
of the same maximum length exist, returns the leftmost one.
"""
max_len = 0
max_core = ""
current_core = s[0]
... | from solution import find_core, process_strings
def test_find_core():
assert find_core("AB12C34DE") == "AB"
assert find_core("1234AB56") == "1234"
assert find_core("ABCDE123") == "ABCDE"
assert find_core("1000A5B67") == "1000"
assert find_core("A") == "A"
assert find_core("1") == "1"
assert... | [
{
"docstring": "Returns the core of the string s, which is the longest contiguous substring \nthat contains either only letters or only digits. If multiple substrings \nof the same maximum length exist, returns the leftmost one.",
"function_declaration": "def find_core(s):",
"function_name": "find_core"... | [
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_core(s):\n \"\"\"\n Returns the core of the string s, which is the longest contiguous substring \n that contains either only letters or only digi... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of strings, each consisting of uppercase English letters and digits. We define the \"core\" of a string as the longest contiguous substring that contains either only letters or only digits. If there are multiple substrings of the same maximum length, the leftmost one is... | 0.651849 | Taco_47818 | C | [
"find_core",
"process_strings"
] | 2 | [
[
"process_strings",
"find_core"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6e57eebe53dcaa6c7cd164f6e230b2a8fac1060 | d67d4234e5ef2babed9aa0b4d116fad3f5498e28 | |||
v1.0 | complete | Taco | Taco_47834_C | def find_longest_word(s: str, words: List[str]) -> str:
""" Finds the longest word that can be formed by deleting some characters of `s`
from the list of words, where the longest word is the lexicographically smallest.
>>> find_longest_word("abpcplea", ["apple", "apply", "ale", "plea"]) "apple"
>>>... | def is_subsequence(x, y):
"""
Check if string x is a subsequence of string y.
"""
it = iter(y)
return all(char in it for char in x)
def find_longest_word(s, words):
"""
Finds the longest word that can be formed by deleting some characters of s
from the list of words, where the longest w... | from solution import find_longest_word
def test_example_1():
assert find_longest_word("abpcplea", ["apple", "apply", "ale", "plea"]) == "apple"
def test_example_2():
assert find_longest_word("abc", ["a", "b", "c", "abc"]) == "abc"
def test_no_possible_word():
assert find_longest_word("abc", ["d", "e", "f... | [
{
"docstring": "Check if string x is a subsequence of string y.",
"function_declaration": "def is_subsequence(x, y):",
"function_name": "is_subsequence",
"parameter_list": "(x, y)"
},
{
"docstring": "Finds the longest word that can be formed by deleting some characters of s\nfrom the list of... | [
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 findLongestWord(s, words):\n def is_subsequence(x):\n it = iter(s)\n return all(c in it for c in x)\n\n words.sort(key=lambda x: (-len(x), ... | trial_gpt4o_1 | {
"original_instruction": "In a given list of words, your task is to find the longest word that can be formed by deleting some characters of another given string `s`.\n\nA word `w` from the list can be formed by deleting some characters of `s` if without reordering the remaining characters of `s`, they match the char... | 0.792534 | Taco_47834 | C | [
"is_subsequence",
"find_longest_word"
] | 2 | [
[
"find_longest_word",
"is_subsequence"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | bae175709c64ccf440a59c844fcadb0063eec67f | 9c6ff4500e1322df95c5a68bfa27c2b8f450f702 | |||
v1.0 | complete | Taco | Taco_47619_C | from collections import Counter
from typing import List, Tuple
def prime_factors(n: int) -> Counter:
"""
Returns a Counter (hashmap) of prime factors of n with their powers.
>>> prime_factors(18)
Counter({2: 1, 3: 2})
>>> prime_factors(25)
Counter({5: 2})
>>> prime_factors(49)
Counter({... | from collections import Counter
from math import gcd
from functools import reduce
def prime_factors(n):
"""Returns a Counter (hashmap) of prime factors of n with their powers."""
i = 2
factors = Counter()
while i * i <= n:
while (n % i) == 0:
factors[i] += 1
n //= i
... | def test_prime_factors():
assert prime_factors(18) == Counter({2: 1, 3: 2})
assert prime_factors(25) == Counter({5: 2})
assert prime_factors(49) == Counter({7: 2})
def test_min_operations_to_perfect_square():
assert min_operations_to_perfect_square(3, [2, 2, 3]) == 1
assert min_operations_to_perfec... | [
{
"docstring": "Returns a Counter (hashmap) of prime factors of n with their powers.",
"function_declaration": "def prime_factors(n):",
"function_name": "prime_factors",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def min_operations_to_perfect_square(n, integ... | [
0,
0,
0,
0,
0,
0,
1,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import Counter\nfrom math import isqrt\n\ndef min_operations_to_perfect_square(t, test_cases):\n def factor_count(n):\n count = Counter(... | trial_gpt4o_7 | {
"original_instruction": "Simon has a collection of $n$ integers that he likes to play around with. He wants to transform his collection in such a way that the product of all the integers becomes a perfect square. Simon can multiply any integer in the collection by any positive integer (including 1) as many times as... | 0.764884 | Taco_47619 | C | [
"prime_factors",
"min_operations_to_perfect_square",
"solve"
] | 3 | [
[
"min_operations_to_perfect_square",
"prime_factors"
],
[
"solve",
"min_operations_to_perfect_square"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 6f179efd0e6a6d019fe5799ee6c087f462adfbd1 | 5d61b75c8eefa6f939be61c0f0c1a4cdcab2e616 | |||
v1.0 | complete | Taco | Taco_47678_C | def max_non_overlapping_activities(test_cases):
"""
Determines the maximum number of non-overlapping activities John can attend for each test case.
:param test_cases: List of test cases, where each test case is a list of tuples representing activities with start and end times.
:return: List of inte... | def max_non_overlapping_activities(test_cases):
"""
Determines the maximum number of non-overlapping activities John can attend for each test case.
:param test_cases: List of test cases, where each test case is a list of tuples representing activities with start and end times.
:return: List of inte... | from solution import max_non_overlapping_activities, process_input, solution
def test_max_non_overlapping_activities():
test_cases = [
[(1, 3), (2, 4), (3, 5)],
[(1, 2), (2, 3), (3, 4), (4, 5)]
]
expected = [2, 4]
result = max_non_overlapping_activities(test_cases)
assert result == ... | [
{
"docstring": "Determines the maximum number of non-overlapping activities John can attend for each test case.\n\n:param test_cases: List of test cases, where each test case is a list of tuples representing activities with start and end times.\n:return: List of integers representing the maximum number of non-o... | [
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 max_activities(test_cases):\n \"\"\"\n Determines the maximum number of non-overlapping activities John can attend for each test case.\n \n Paramet... | trial_gpt4o_3 | {
"original_instruction": "John has a list of activities that he needs to complete by the end of the day. Each activity has a start time and an end time. John wants to complete as many activities as possible, but no two activities can overlap in time.\n\nDesign an algorithm that helps John determine the maximum numbe... | 0.569555 | Taco_47678 | C | [
"max_non_overlapping_activities",
"process_input",
"solution"
] | 3 | [
[
"solution",
"max_non_overlapping_activities"
],
[
"solution",
"process_input"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | 57dcc2678f7a6b2bf005a93a24694496a4467892 | a0c4311261bb7a25061b99d35d3fb92a48867243 | |||
v1.0 | complete | Taco | Taco_48053_C | def is_prime(n):
"""Helper function to check if a number is prime."""
# Implement the is_prime function here
def find_prime_pairs(N):
"""Function to find and print all pairs of prime numbers (p1, p2) such that their sum is equal to N.
Parameters:
N (int): The target sum for pairs of prime numb... | def is_prime(n):
"""Helper function to check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
re... | from solution import is_prime, find_prime_pairs
def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(29) == True
assert is_prime(97) == True
assert is_prime(100) == False
def test_find_prime_pairs_10(capsys):
find_prime_pair... | [
{
"docstring": "Helper function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Function to find all pairs of prime numbers (p1, p2) such that their sum is equal to N.",
"function_declara... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n ... | trial_gpt4o_1 | {
"original_instruction": "Given a positive integer \\(N\\), your task is to find and print all pairs of prime numbers \\((p1, p2)\\) such that their sum is equal to \\(N\\).\n\nA prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 2, 3, 5, 7, and 11 are... | 0.717495 | Taco_48053 | C | [
"is_prime",
"find_prime_pairs"
] | 2 | [
[
"find_prime_pairs",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 51e201f1fa11d744b2dc9dc6fa23a1a5fda8f2de | e03dd19e8b216e756cacd4004753235e9af19eb9 | |||
v1.0 | complete | Taco | Taco_47901_C | MOD = 1000000_007
def num_paths(grid):
""" Count the number of distinct paths from the top-left to the bottom-right cell in the grid,
avoiding impassable cells ('#') and considering only movements to the right or down.
The result is returned modulo 1,000,000,007.
>>> num_paths([
... ['.', '.',... | MOD = 1000000_007
def num_paths(grid):
R = len(grid)
C = len(grid[0])
# DP table to store the number of ways to reach each cell
dp = [[0] * C for _ in range(R)]
# Starting point
if grid[0][0] == '.':
dp[0][0] = 1
# Fill the DP table
for i in range(R):
for ... | from solution import num_paths
def test_example_1():
grid = [
['.', '.', '.'],
['.', '#', '.'],
['.', '.', '.']
]
assert num_paths(grid) == 2
def test_example_2():
grid = [
['#', '#', '#'],
['.', '#', '.'],
['.', '.', '.']
]
assert num_paths(grid... | [
{
"docstring": null,
"function_declaration": "def num_paths(grid):",
"function_name": "num_paths",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def solve():",
"function_name": "solve",
"parameter_list": "()"
}
] | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def distinct_paths(grid):\n MOD = 1000000007\n R = len(grid)\n C = len(grid[0])\n \n # Create a 2D dp array filled with 0\n dp = [[0] * C for _ i... | trial_gpt4o_4 | {
"original_instruction": "You are given a grid with R rows and C columns. Each cell in the grid can either be passable ('.') or impassable ('#'). You start in the top-left cell (1, 1) and want to reach the bottom-right cell (R, C). You can only move to the right or down at each step. Your task is to count the number... | 0.724208 | Taco_47901 | C | [
"num_paths",
"solve"
] | 2 | [
[
"solve",
"num_paths"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 71ea23bfa17f74ca0fb3f314d7257deaf2f27663 | 6aba00e825070ae2c1f426d75aeea805b453affc | |||
v1.0 | complete | Taco | Taco_47909_C | def count_unique_arrays(N, K, M):
""" Given the size of the array N, the number of elements to keep K, and the range limit for replacement M,
determine the number of unique arrays that can be formed by keeping exactly K elements and replacing the rest with any integer from 1 to M (inclusive).
>>> count_uniq... | def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
def binomial_coefficient(n, k):
return factorial(n) // (factorial(k) * factorial(n - k))
def count_unique_arrays(N, K, M):
return binomial_coefficient(N, K) * (M ** (N - K))
def process_test_cases(test_cases):
res... | from solution import count_unique_arrays, process_test_cases
def test_count_unique_arrays():
assert count_unique_arrays(5, 2, 5) == 1250
assert count_unique_arrays(3, 1, 3) == 27
def test_process_test_cases():
test_cases = [
((5, 2, 5), [2, 3, 1, 4, 5]),
((3, 1, 3), [7, 8, 9])
]
re... | [
{
"docstring": null,
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def binomial_coefficient(n, k):",
"function_name": "binomial_coefficient",
"parameter_list": "(n, k)"
},
{
... | [
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": "from math import comb\n\ndef count_unique_arrays(n, k, m):\n \"\"\"\n Count the number of unique arrays by keeping exactly k elements and replacing the rest ... | trial_gpt4o_5 | {
"original_instruction": "Given an integer array $A$ of size $N$, and two integers $K$ and $M$, determine the number of unique arrays you can form by keeping exactly $K$ elements and replacing the rest with any integer from $1$ to $M$ (inclusive). Two arrays are considered unique if they are different in at least on... | 0.620914 | Taco_47909 | C | [
"factorial",
"binomial_coefficient",
"count_unique_arrays",
"process_test_cases",
"main"
] | 5 | [
[
"binomial_coefficient",
"factorial"
],
[
"count_unique_arrays",
"binomial_coefficient"
],
[
"process_test_cases",
"count_unique_arrays"
]
] | 3 | [
"process_test_cases"
] | false | [] | false | pytest | true | [] | true | 1a6ec8888e60675f8dea763a756a174d88bf81de | a831f1326d3042a8f7f9b7faccb9e692cbcc66a5 | |||
v1.0 | complete | Taco | Taco_47730_C | from typing import List, Tuple
def is_prime(n: int) -> bool:
""" Check if a number is a prime number.
>>> is_prime(2)
True
>>> is_prime(4)
False
"""
pass
def longest_increasing_prime_subsequence_length(sequence: List[int]) -> int:
""" Find the length of the longest subsequence that is ... | def is_prime(n):
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def longest_increasing_prime_subsequence_length(sequence):
primes = [num for num in sequence if is_prime(num)]
if not primes:
return 0
... | def test_is_prime():
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(4) == False
assert is_prime(17) == True
assert is_prime(18) == False
def test_longest_increasing_prime_subsequence_length():
assert longest_increasing_prime_subsequence_length([2, 3, 5, 7, 11, 13]) == 6
... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def longest_increasing_prime_subsequence_length(sequence):",
"function_name": "longest_increasing_prime_subsequence_l... | [
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 if n < 2:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n... | trial_gpt4o_0 | {
"original_instruction": "You are given a sequence of integers. You want to find the length of the longest subsequence that is strictly increasing and consists only of prime numbers.\n\nInput:\nThe first line contains the number of test cases T. T test cases follow. Each test case contains two lines.\nThe first line... | 0.662152 | Taco_47730 | C | [
"is_prime",
"longest_increasing_prime_subsequence_length",
"find_longest_increasing_prime_subsequence"
] | 3 | [
[
"find_longest_increasing_prime_subsequence",
"longest_increasing_prime_subsequence_length"
],
[
"longest_increasing_prime_subsequence_length",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 3490c30584e529fa1fcebdd549fba78bcdae0f1a | a03cffee67d1c2b604069c2a14661745161fb21d | |||
v1.0 | complete | Taco | Taco_47216_C | class FenwickTree:
def __init__(self, size):
self.size = size
self.tree = [0] * (size + 1)
def update(self, index, value):
while index <= self.size:
self.tree[index] += value
index += index & -index
def query(self, index):
sum = 0... | class FenwickTree:
def __init__(self, size):
self.size = size
self.tree = [0] * (size + 1)
def update(self, index, value):
while index <= self.size:
self.tree[index] += value
index += index & -index
def query(self, index):
sum = 0... | def test_fenwick_tree_operations_single_update():
n = 5
array = [2, 1, 5, 3, 4]
queries = [
(1, 2, 4, 2), # Increase a[2, 3, 4] by 2
]
assert process_queries(n, array, queries) == []
def test_fenwick_tree_operations_single_sum():
n = 5
array = [2, 1, 5, 3, 4]
queries = [
... | [] | [
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": "class NumArray:\n def __init__(self, nums):\n self.nums = nums\n self.n = len(nums)\n self.seg_tree = [0] * (4 * self.n)\n self.buil... | trial_gpt4o_4 | {
"original_instruction": "You are given an array of n integers. You need to perform two types of operations on this array:\n\n1. 1 l r x — Increase every element a[i] (l ≤ i ≤ r) by x.\n2. 2 l r — Output the sum of all elements a[i] (l ≤ i ≤ r).\n\nYou have to process q queries of the above types in an efficient man... | 0.498995 | Taco_47216 | C | [
"range_update",
"prefix_sum",
"range_sum",
"process_queries"
] | 4 | [
[
"process_queries",
"range_sum"
],
[
"process_queries",
"range_update"
],
[
"range_sum",
"prefix_sum"
]
] | 3 | [
"process_queries"
] | false | [
"FenwickTree"
] | true | pytest | false | [] | true | 4ffbedb90d1a633adc81bfaa08ad318b00fd498d | a60b16b54a6b70c4fd32173c8a42294d103e91ef | |||
v1.0 | complete | Taco | Taco_48057_C | def largest_sum_submatrix(matrix: List[List[int]]) -> int:
""" Returns the largest sum of any submatrix within the given matrix.
>>> largest_sum_submatrix([
... [1, -2, 3],
... [-4, 5, -6],
... [7, 8, 9]
... ]) == 24
>>> largest_sum_submatrix([
... [-1, -2],
... [-3, -... | def largest_sum_submatrix(matrix):
"""
Returns the largest sum of any submatrix within the given matrix.
"""
import numpy as np
M = len(matrix)
N = len(matrix[0])
max_sum = -float('inf')
for left in range(N):
row_sum = [0] * M
for right in range(left, N):
... | from solution import largest_sum_submatrix
def test_largest_sum_submatrix():
matrix = [
[1, -2, 3],
[-4, 5, -6],
[7, 8, 9]
]
assert largest_sum_submatrix(matrix) == 24
def test_largest_sum_submatrix_all_negative():
matrix = [
[-1, -2],
[-3, -4]
]
assert ... | [
{
"docstring": "Returns the largest sum of any submatrix within the given matrix.",
"function_declaration": "def largest_sum_submatrix(matrix):",
"function_name": "largest_sum_submatrix",
"parameter_list": "(matrix)"
},
{
"docstring": "Helper function to find the maximum sum subarray using K... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def max_submatrix_sum(matrix):\n def get_kadane(arr):\n max_current = max_global = arr[0]\n for x in arr[1:]:\n max_current = max(x, ma... | trial_gpt4o_2 | {
"original_instruction": "Tim and Jane are participating in a collaborative coding competition. They have to solve a problem that involves working with a matrix of integers. Given an $M \\times N$ matrix, they need to find the largest sum of any submatrix within the given matrix. A submatrix is defined as any contig... | 0.627498 | Taco_48057 | C | [
"largest_sum_submatrix",
"max_subarray_sum"
] | 2 | [
[
"largest_sum_submatrix",
"max_subarray_sum"
]
] | 1 | [] | false | [] | false | pytest | true | [
"numpy"
] | false | decaf804b8457ac9c1faa6db5d9d1dd6e89d3091 | d5f396f16ea4d93bb643453999ac7739d3ddee75 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.