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_56033_C | def compute_prefix_sum_array(A):
"""
Computes the prefix sum array for a given array A.
"""
P = [0] * len(A)
P[0] = A[0]
for i in range(1, len(A)):
P[i] = P[i-1] + A[i]
return P
def sum_of_unique_prefix_sums(A):
"""
Computes the sum of all unique values in the prefix sum arr... | def compute_prefix_sum_array(A):
"""
Computes the prefix sum array for a given array A.
"""
P = [0] * len(A)
P[0] = A[0]
for i in range(1, len(A)):
P[i] = P[i-1] + A[i]
return P
def sum_of_unique_prefix_sums(A):
"""
Computes the sum of all unique values in the prefix sum arr... | def test_compute_prefix_sum_array():
assert compute_prefix_sum_array([1, 2, 3, 4, 5]) == [1, 3, 6, 10, 15]
assert compute_prefix_sum_array([1, 1, 1, 1]) == [1, 2, 3, 4]
assert compute_prefix_sum_array([5, 5, 5, 5]) == [5, 10, 15, 20]
def test_sum_of_unique_prefix_sums():
assert sum_of_unique_prefix_sum... | [
{
"docstring": "Computes the prefix sum array for a given array A.",
"function_declaration": "def compute_prefix_sum_array(A):",
"function_name": "compute_prefix_sum_array",
"parameter_list": "(A)"
},
{
"docstring": "Computes the sum of all unique values in the prefix sum array.",
"funct... | [
0,
0,
0,
0,
0,
0,
0,
1,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def prefix_sum_unique(arr):\n \"\"\"\n Given an array of integers, computes the prefix sum array and returns the sum of all unique values in it.\n \"\"\"\... | trial_gpt4o_8 | {
"original_instruction": "Given an integer array A of length N, compute the prefix sum array P where P[i] denotes the sum of elements from the start of the array up to the i-th element, inclusive. Then, find the sum of all unique values in the prefix sum array P.\n\n------ Input Format ------\n\n- The first line con... | 0.600117 | Taco_56033 | C | [
"compute_prefix_sum_array",
"sum_of_unique_prefix_sums",
"process_test_cases",
"main"
] | 4 | [
[
"process_test_cases",
"sum_of_unique_prefix_sums"
],
[
"sum_of_unique_prefix_sums",
"compute_prefix_sum_array"
]
] | 2 | [
"process_test_cases"
] | false | [] | false | pytest | false | [] | true | 94f439cbb9a01c640216541493c2cfee47ee6281 | d46bcd0df18d78356233f0ff06f761144f06c6d0 | |||
v1.0 | complete | Taco | Taco_55833_C | def calculate_relation_score(p1, p2):
""" Calculate the relation score between two paintings based on the given criteria:
- 3 points for same artist
- 2 points for same year
- 1 point for same type
>>> calculate_relation_score(["MonaLisa", "LeonardoDaVinci", "1503", "Portrait"], ["StarryNight", "Van... | from itertools import permutations
def calculate_relation_score(p1, p2):
score = 0
if p1[1] == p2[1]: # same artist
score += 3
if p1[2] == p2[2]: # same year
score += 2
if p1[3] == p2[3]: # same type
score += 1
return score
def can_arrange_paintings(f, paintings):
if... | from solution import can_arrange_paintings, calculate_relation_score
def test_calculate_relation_score():
painting1 = ["MonaLisa", "LeonardoDaVinci", "1503", "Portrait"]
painting2 = ["StarryNight", "VanGogh", "1889", "Landscape"]
painting3 = ["GirlWithAPearlEarring", "Vermeer", "1665", "Portrait"]
ass... | [
{
"docstring": null,
"function_declaration": "def calculate_relation_score(p1, p2):",
"function_name": "calculate_relation_score",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def can_arrange_paintings(f, paintings):",
"function_name": "can_arrange_pa... | [
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 itertools import permutations\n\ndef calculate_relation_score(p1, p2):\n score = 0\n if p1[1] == p2[1]: # same artist\n score += 3\n if p1[2]... | trial_gpt4o_0 | {
"original_instruction": "Alice loves her art collection and wants to display her paintings in a unique way. She has a collection of 10 unique paintings and she wants to hang them in a hallway that has a series of picture frames arranged in a linear sequence. The constraints are such that neighboring picture frames ... | 0.484851 | Taco_55833 | C | [
"calculate_relation_score",
"can_arrange_paintings",
"read_input"
] | 3 | [
[
"can_arrange_paintings",
"calculate_relation_score"
]
] | 1 | [
"read_input"
] | false | [] | false | pytest | true | [] | true | c1ab3285d666de13ddb5e4f3c5dc69089f603395 | cb168f5086bffd424434b4190b7dd3877177a247 | |||
v1.0 | complete | Taco | Taco_56344_C | def find_matches(n, m, pairs):
"""
Determine if it's possible to schedule matches where each team plays exactly one match.
Parameters:
n (int): The number of teams.
m (int): The number of pairs of teams that can play against each other.
pairs (list): A list of tuples where each tuple (a, b)... | def find_matches(n, m, pairs):
from collections import defaultdict
import networkx as nx
if n % 2 == 1:
return -1
graph = defaultdict(list)
for a, b in pairs:
graph[a].append(b)
graph[b].append(a)
matching = []
visited = set()
def dfs(node, match):
... | from solution import find_matches, schedule_matches
def test_example1():
n = 4
m = 3
pairs = [(1, 2), (2, 3), (3, 4)]
result = find_matches(n, m, pairs)
assert result == [(1, 2), (3, 4)]
def test_example2():
n = 3
m = 2
pairs = [(1, 2), (2, 3)]
result = find_matches(n, m, pairs... | [
{
"docstring": null,
"function_declaration": "def find_matches(n, m, pairs):",
"function_name": "find_matches",
"parameter_list": "(n, m, pairs)"
},
{
"docstring": null,
"function_declaration": "def schedule_matches(n, m, pair_list):",
"function_name": "schedule_matches",
"parame... | [
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_matches(n, m, pairs):\n from collections import defaultdict\n import networkx as nx\n\n if n % 2 == 1:\n return -1\n\n graph = defaultd... | trial_gpt4o_0 | {
"original_instruction": "Tommy is organizing a sports league with `n` distinct teams labeled from 1 to `n`. He wants to schedule matches such that each team plays with exactly one other team. However, due to various constraints, not all teams can play against each other. Tommy seeks your help to find if it's possib... | 0.63468 | Taco_56344 | C | [
"find_matches",
"schedule_matches"
] | 2 | [
[
"schedule_matches",
"find_matches"
]
] | 1 | [] | false | [] | false | pytest | true | [
"networkx"
] | false | f3b2ad122600b449cfa9df3bbb940ee5617d46d2 | 520805f5001a9ee61f83902860ac91082ce8234e | |||
v1.0 | complete | Taco | Taco_56698_C | def allocate_books(books, k):
"""
Allocate books to students in a way that the maximum number of pages assigned to a student is minimized.
:param books: List[int] - An array of integers representing the number of pages in each book.
:param k: int - The number of students.
:return: int - Th... | def can_allocate_books(books, n, k, max_pages):
"""
Helper function to check if it's possible to allocate books such that
the maximum number of pages assigned to a student is less than or equal to max_pages.
"""
students_required = 1
current_pages = 0
for pages in books:
if curr... | from solution import allocate_books
def test_allocate_books_example():
assert allocate_books([12, 34, 67, 90], 2) == 113
def test_allocate_books_single_book_per_student():
assert allocate_books([12, 34, 67, 90], 4) == 90
def test_allocate_books_single_student():
assert allocate_books([12, 34, 67, 90], 1)... | [
{
"docstring": "Helper function to check if it's possible to allocate books such that\nthe maximum number of pages assigned to a student is less than or equal to max_pages.",
"function_declaration": "def can_allocate_books(books, n, k, max_pages):",
"function_name": "can_allocate_books",
"parameter_... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_distribution(books, n, k, max_pages):\n students_required = 1\n current_sum = 0\n\n for pages in books:\n if current_sum + pages > max... | trial_gpt4o_2 | {
"original_instruction": "# Task\nYou are given a list of `n` integers, where each integer represents the number of pages in a particular book. You are also given `k` number of students. Your task is to allocate books to each student in such a way that the maximum number of pages assigned to a student is minimized. ... | 0.65015 | Taco_56698 | C | [
"can_allocate_books",
"allocate_books"
] | 2 | [
[
"allocate_books",
"can_allocate_books"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f450faa613ee1b76e194680524b58509ece34dfe | f2285bd290815d66673a7e00006dd025e4adb89e | |||
v1.0 | complete | Taco | Taco_56395_C | def average_primes(numbers: List[int]) -> float:
""" Returns the average of all the prime numbers in the list.
If there are no prime numbers, returns 0.
>>> average_primes([2, 3, 4, 5, 6, 7, 8, 9]) -> 4.25
>>> average_primes([10, 15, 20, 25, 30]) -> 0.0
>>> average_primes([11, 13, 17, 19]) -> 1... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise returns False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
de... | from solution import average_primes
def test_average_primes_with_mixed_numbers():
assert average_primes([2, 3, 4, 5, 6, 7, 8, 9]) == 4.25
def test_average_primes_with_no_primes():
assert average_primes([10, 15, 20, 25, 30]) == 0.0
def test_average_primes_with_all_primes():
assert average_primes([11, ... | [
{
"docstring": "Returns True if n is a prime number, otherwise returns False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the average of all the prime numbers in the list.\nIf there are no prime numbers, return... | [
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 \"\"\"A helper function to check if a number is prime.\"\"\"\n if num <= 1:\n return False\n if num == 2:\n return True... | trial_gpt4o_2 | {
"original_instruction": "**DESCRIPTION:**\n\nA software company is developing a new data processing software that takes lists of integers and performs certain operations on them. One feature they want to include is a function that, given a list of integers, returns the average of all the prime numbers within the li... | 0.618165 | Taco_56395 | C | [
"is_prime",
"average_primes"
] | 2 | [
[
"average_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7e2c5a165b559450bc47cae0156f482e14c0dd20 | 7dba4d874a17e191dba621d4ffc1371133f6c8c7 | |||
v1.0 | complete | Taco | Taco_56796_C | def are_there_super_anagrams(list1: List[str], list2: List[str]) -> str:
""" Determine if there exists at least one pair of super anagrams
in two lists of words.
>>> are_there_super_anagrams(["listen", "apple", "silent"], ["enlist", "banana", "tinsel"])
"YES"
>>> are_there_super_anagrams(["hello"], ... | def is_super_anagram(word1, word2):
"""
Helper function to check if two words are super anagrams.
"""
if sorted(word1) == sorted(word2) and sum(ord(char) for char in word1) == sum(ord(char) for char in word2):
return True
return False
def are_there_super_anagrams(list1, list2):
"""
... | def test_are_there_super_anagrams():
assert are_there_super_anagrams(["listen", "apple", "silent"], ["enlist", "banana", "tinsel"]) == "YES"
assert are_there_super_anagrams(["hello"], ["world"]) == "NO"
assert are_there_super_anagrams(["abc"], ["cba"]) == "YES"
assert are_there_super_anagrams(["anagram"... | [
{
"docstring": "Helper function to check if two words are super anagrams.",
"function_declaration": "def is_super_anagram(word1, word2):",
"function_name": "is_super_anagram",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Function to check if there exists at least one pair of super a... | [
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_super_anagram(word1, word2):\n \"\"\"\n Determines if two words are super anagrams.\n \"\"\"\n return sorted(word1) == sorted(word2) and sum(map... | trial_gpt4o_1 | {
"original_instruction": "You've encountered a situation where you need to compare two lists of words to find if they are anagrams at the level of individual characters as well as the sums of their ASCII values. Specifically, two words are considered anagrams if they contain the same characters in any order. If the ... | 0.557191 | Taco_56796 | C | [
"is_super_anagram",
"are_there_super_anagrams"
] | 2 | [
[
"are_there_super_anagrams",
"is_super_anagram"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 8a7b4fcee79cfd8f352144ac972d6fa2c778b9c8 | b7f402268834469030a5758034aa7fbabccd6527 | |||
v1.0 | complete | Taco | Taco_56500_C | from typing import List, Tuple
def find_plots(M: int, D: int) -> List[Tuple[int, int]]:
"""
Function to find possible coordinates for D vegetable plots in an MxM grid.
Each plot is a 1x1 square, no two plots share a row or a column, and the Manhattan distance
between any two plots is at least 3.
... | def find_plots(M, D):
"""
Function to find possible coordinates for D vegetable plots in an MxM grid.
"""
if D > M:
return "This arrangement is not possible"
plots = []
for i in range(D):
plots.append((i, i))
return plots
def vegetable_garden(test_cases):
... | def test_find_plots():
# test case 1
assert find_plots(4, 3) == [(0, 0), (1, 1), (2, 2)]
# test case 2
assert find_plots(5, 5) == [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]
# test case 3 - expecting impossible
assert find_plots(5, 6) == "This arrangement is not possible"
# test ... | [
{
"docstring": "Function to find possible coordinates for D vegetable plots in an MxM grid.",
"function_declaration": "def find_plots(M, D):",
"function_name": "find_plots",
"parameter_list": "(M, D)"
},
{
"docstring": null,
"function_declaration": "def vegetable_garden(test_cases):",
... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def plot_vegetable_garden(T, test_cases):\n results = []\n \n for M, D in test_cases:\n if D > (M + 1) // 2:\n results.append(\"This arr... | trial_gpt4o_6 | {
"original_instruction": "Quentin is planning his vegetable garden!\nHe starts with two integers \\(M\\) and \\(D\\). His goal is to determine if it's possible to arrange \\(D\\) vegetable plots in a grid of size \\(M \\times M\\), such that:\n- Each plot is a 1x1 square.\n- No two plots share a row or a column.\n- ... | 0.584526 | Taco_56500 | C | [
"find_plots",
"vegetable_garden"
] | 2 | [
[
"vegetable_garden",
"find_plots"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 04c26ef47637955624bf477268edc2d36a1f7e28 | 0cf8185fe53b0ee982708432b7cea1f2e2af5cd6 | |||
v1.0 | complete | Taco | Taco_56590_C | from typing import List
def isFile(path: str) -> bool:
"""
Mock `isFile` function definition.
This function should determine whether the given path is a file.
It's expected to return `True` if the path is a file, `False` if it's a directory.
"""
pass
def listFiles(path: str) -> List[str]:
... | from typing import List
# This would be a mock function for the example
def isFile(path: str) -> bool:
"""
Mock `isFile` function definition.
This function should determine whether the given path is a file.
It's expected to return `True` if the path is a file, `False` if it's a directory.
"""
f... | from solution import listFiles
def test_list_files_root():
result = listFiles("/")
assert sorted(result) == sorted(["/file4.txt", "/folder1/file1.txt", "/folder1/folder2/file2.txt", "/folder1/folder3/file3.txt"])
def test_list_files_folder1():
result = listFiles("/folder1/")
assert sorted(result) == s... | [
{
"docstring": "Mock `isFile` function definition.\nThis function should determine whether the given path is a file.\nIt's expected to return `True` if the path is a file, `False` if it's a directory.",
"function_declaration": "def isFile(path):",
"function_name": "isFile",
"parameter_list": "(path)... | [
0,
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List\n\n# Helper functions provided for the solution\ndef isFile(path: str) -> bool:\n file_system = {\n \"/\": False,\n \"/fol... | trial_gpt4o_6 | {
"original_instruction": "Given a file system represented as a tree rooted at the directory \"/\", you need to implement a function to list all files under a given directory path. Each file or directory is represented as a string. Directories are represented as paths ending with a slash (\"/\"). Your task is to writ... | 0.747361 | Taco_56590 | C | [
"isFile",
"listFiles"
] | 2 | [
[
"listFiles",
"isFile"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 2394e59111fd32499312498847b6c94fdc2fb1a7 | e588de6182d8871d921fba8e74455379c4431719 | |||
v1.0 | complete | Taco | Taco_56229_C | def minimum_effort_path(elevation: List[List[int]]) -> int:
""" Find the minimum effort path from the top-left to the bottom-right of the grid.
The effort of a path is defined as the maximum absolute difference in elevations
between two consecutive cells in the path.
>>> minimum_effort_path([[1, 2, 2],... | from heapq import heappop, heappush
import sys
def minimum_effort_path(elevation):
N, M = len(elevation), len(elevation[0])
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# Using a priority queue to track cells to visit, starting with the top-left corner (0,0)
pq = [(0, 0, 0)] # (effort, row, co... | from solution import main
def test_example_case():
input_string = "3\n3 3\n1 2 2\n3 8 2\n5 3 5\n2 2\n1 2\n3 4\n4 4\n1 2 2 3\n3 8 2 7\n5 8 5 9\n6 3 4 1\n"
expected_output = "2\n2\n3"
assert main(input_string) == expected_output
def test_single_cell():
input_string = "1\n1 1\n0\n"
expected_output = ... | [
{
"docstring": null,
"function_declaration": "def minimum_effort_path(elevation):",
"function_name": "minimum_effort_path",
"parameter_list": "(elevation)"
},
{
"docstring": null,
"function_declaration": "def solve_minimum_effort_path(test_cases):",
"function_name": "solve_minimum_ef... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef minimum_effort_path(elevation_map):\n \"\"\"\n Function to find the minimum effort path from top-left to bottom-right of the grid.\n \... | trial_gpt4o_2 | {
"original_instruction": "You are given a rectangular grid of size N x M where each cell contains a non-negative integer representing an elevation map. The task is to find the minimum effort path from the top-left cell (0, 0) to the bottom-right cell (N-1, M-1).\n\nA path is defined as a sequence of adjacent cells i... | 0.637044 | Taco_56229 | C | [
"minimum_effort_path",
"solve_minimum_effort_path",
"parse_input",
"format_output",
"main"
] | 5 | [
[
"solve_minimum_effort_path",
"minimum_effort_path"
]
] | 1 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | e1c3255ef93e76ee818c193d06f162fb2d4478b0 | 1780a4379cd8c61b17a4372e536561ecff04bd01 | |||
v1.0 | complete | Taco | Taco_56935_C | from typing import List
def validate_email_addresses(email_addresses: List[str]) -> List[bool]:
"""
Takes a list of email addresses and returns a list of booleans indicating whether each email address is valid or not.
>>> validate_email_addresses(["john.doe@example.com", "jane_doe@domain.co.uk"])
... | import re
def validate_email_addresses(email_addresses):
"""
Takes a list of email addresses and returns a list of booleans indicating whether each email address is valid or not.
"""
validations = []
for email in email_addresses:
if is_valid_email(email):
validations.append(True... | from solution import validate_email_addresses
def test_valid_emails():
emails = ["john.doe@example.com", "jane_doe@domain.co.uk"]
assert validate_email_addresses(emails) == [True, True]
def test_invalid_emails():
emails = ["invalid-email-@example..com", "_invalid@example.com"]
assert validate_email_ad... | [
{
"docstring": "Takes a list of email addresses and returns a list of booleans indicating whether each email address is valid or not.",
"function_declaration": "def validate_email_addresses(email_addresses):",
"function_name": "validate_email_addresses",
"parameter_list": "(email_addresses)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import re\n\ndef validate_email_addresses(email_addresses):\n \"\"\"\n Validates a list of email addresses based on the given rules.\n \n Parameters:\n... | trial_gpt4o_1 | {
"original_instruction": "Sam is working on a system that requires validating email addresses. An email address consists of a local part, an \"@\" symbol, and a domain part. The local part may contain alphanumeric characters, dots ('.'), underscores ('_'), and hyphens ('-'), but it must start and end with an alphanu... | 0.560266 | Taco_56935 | C | [
"validate_email_addresses",
"is_valid_email"
] | 2 | [
[
"validate_email_addresses",
"is_valid_email"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 16872b0a5d8608c0062b6146ee6e1e3265600d40 | 25dafa36715f0194aa54edc564732b56c204263d | |||
v1.0 | complete | Taco | Taco_56709_C | def is_prime(n: int) -> bool:
""" Utility function to 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
"""
# Implementation here
def is_mystic_number(x: int) -> bool:
""" Func... | def is_prime(n):
"""Utility 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
r... | from solution import is_prime, is_mystic_number, mystic_numbers
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_is_mystic_number():
assert is_mystic_number(6) == True # bin... | [
{
"docstring": "Utility function to check if a number is prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Function to determine if a number is a Mystic Number.",
"function_declaration": "def is_mystic_number(x):"... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n retur... | trial_gpt4o_4 | {
"original_instruction": "In a faraway land, there is a special sequence of numbers known as \"Mystic Numbers.\" Mystic Numbers follow a unique rule based on binary representation of numbers. Let's understand the special property of these numbers.\n\nA number N is called a Mystic Number if the count of '1's in its b... | 0.677145 | Taco_56709 | C | [
"is_prime",
"is_mystic_number",
"mystic_numbers"
] | 3 | [
[
"is_mystic_number",
"is_prime"
],
[
"mystic_numbers",
"is_mystic_number"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 122e84e8ed3da61c88b761e75266f4384373fc9c | 4367367b26589322cbd5906397bd4d7dd413c886 | |||
v1.0 | complete | Taco | Taco_56623_C | def longest_subsequence_with_perfect_square_product(arr: List[int]) -> int:
""" Returns the length of the longest subsequence such that
when sorted, every pair of adjacent elements have a product
that is a perfect square.
>>> longest_subsequence_with_perfect_square_product([1, 4, 16, 9, 25]) == 5
>>... | def is_perfect_square(num):
"""
Checks if a number is a perfect square.
"""
root = int(num**0.5)
return root * root == num
def longest_subsequence_with_perfect_square_product(arr):
"""
Returns the length of the longest subsequence such that
when sorted, every pair of adjacent elements h... | from solution import longest_subsequence_with_perfect_square_product
def test_example_1():
assert longest_subsequence_with_perfect_square_product([1, 4, 16, 9, 25]) == 5
def test_example_2():
assert longest_subsequence_with_perfect_square_product([2, 3, 5, 7, 11, 13]) == 1
def test_single_element():
asse... | [
{
"docstring": "Checks if a number is a perfect square.",
"function_declaration": "def is_perfect_square(num):",
"function_name": "is_perfect_square",
"parameter_list": "(num)"
},
{
"docstring": "Returns the length of the longest subsequence such that\nwhen sorted, every pair of adjacent ele... | [
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_perfect_square(num):\n \"\"\"\n Checks if a number is a perfect square.\n \"\"\"\n root = int(num**0.5)\n return root * root == num\n\ndef lo... | trial_gpt4o_0 | {
"original_instruction": "You are given a list of integers, and you have to determine the length of the longest subsequence such that when sorted, every pair of adjacent elements have a product that is a perfect square.\n\nA perfect square is an integer that can be expressed as the square of another integer. For exa... | 0.660873 | Taco_56623 | C | [
"is_perfect_square",
"longest_subsequence_with_perfect_square_product"
] | 2 | [
[
"longest_subsequence_with_perfect_square_product",
"is_perfect_square"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7c36a2de1027c46811339b662081ae030b93456b | 50b54c320dcbe5d65d2856c7bd084d3528392fce | |||
v1.0 | complete | Taco | Taco_56849_C | def prime_factors_count(n):
"""
Returns the number of distinct prime factors of n.
>>> prime_factors_count(10) == 2
>>> prime_factors_count(15) == 2
>>> prime_factors_count(21) == 2
>>> prime_factors_count(23) == 1
>>> prime_factors_count(35) == 2
>>> prime_factors_count(1) == 0
"""
... | def prime_factors_count(n):
"""
Returns the number of distinct prime factors of n.
"""
distinct_primes = set()
factor = 2
while n % factor == 0:
distinct_primes.add(factor)
n //= factor
factor = 3
while factor * factor <= n:
while n % factor == 0:
dist... | import pytest
from solution import satisfaction_scores, prime_factors_count
def test_prime_factors_count():
assert prime_factors_count(10) == 2
assert prime_factors_count(15) == 2
assert prime_factors_count(21) == 2
assert prime_factors_count(23) == 1
assert prime_factors_count(35) == 2
assert ... | [
{
"docstring": "Returns the number of distinct prime factors of n.",
"function_declaration": "def prime_factors_count(n):",
"function_name": "prime_factors_count",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of satisfaction scores for each calorie count in calorie_counts.",
... | [
0,
0,
0,
0,
1,
1,
1,
1,
1
] | 5 | medium | 0.556 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import isqrt\n\ndef prime_factors_count(n):\n \"\"\"\n Return the number of distinct prime factors of n.\n \"\"\"\n count = 0\n if n % 2 =... | trial_gpt4o_9 | {
"original_instruction": "Robin is a food blogger and he always takes note of how satisfied he is with the dishes he tries. Recently, he decided to calculate a satisfaction score for each meal. The satisfaction score is the number of distinct prime factors of the meal's calorie count.\n\nRobin has a list of calorie ... | 0.588762 | Taco_56849 | C | [
"prime_factors_count",
"satisfaction_scores"
] | 2 | [
[
"satisfaction_scores",
"prime_factors_count"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 3fdc6f9cdbebfad4448340c8ea78b1b8d4455c97 | ff86f64bad7b491e2088f65fc12e800b5dbb561f | |||
v1.0 | complete | Taco | Taco_56357_C | class TreeNode:
def __init__(self, key):
self.val = key
self.left = None
self.right = None
def deleteNode(root, key):
""" Delete the node with the given key from the BST and return the new root.
>>> root = TreeNode(5)
>>> root.left = TreeNode(3)
>>> root.right = TreeNod... | class TreeNode:
def __init__(self, key):
self.val = key
self.left = None
self.right = None
def deleteNode(root, key):
if not root:
return root
if key < root.val:
root.left = deleteNode(root.left, key)
elif key > root.val:
root.right = deleteNode(root.rig... | import pytest
from solution import TreeNode, deleteNode, inorderTraversal
def test_delete_node_case1():
root = TreeNode(5)
root.left = TreeNode(3)
root.right = TreeNode(7)
root.left.left = TreeNode(2)
root.left.right = TreeNode(4)
root.right.left = TreeNode(6)
root.right.right = TreeNode(8)... | [] | [
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": "class TreeNode:\n def __init__(self, key):\n self.val = key\n self.left = None\n self.right = None\n\ndef deleteNode(root, key):\n if no... | trial_gpt4o_0 | {
"original_instruction": "Given a Binary Search Tree and an integer key. The task is to delete the node with the given key from the BST and return the new root. \n\nExample 1:\nInput:\n 5\n / \\\n 3 7\n / \\ / \\\n 2 4 6 8\nKey: 3\nOutput:\n 5\n / ... | 0.590374 | Taco_56357 | C | [
"deleteNode",
"minValueNode",
"inorderTraversal"
] | 3 | [
[
"deleteNode",
"minValueNode"
]
] | 1 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 05a3f0869f4dfaf98f1c600de2314d4a9353f906 | ed0589d2dd4b7cd70831ecd7c29e3395b0f3cb08 | |||
v1.0 | complete | Taco | Taco_56945_C | def separate_cities(n: int, m: int, edges: List[Tuple[int, int]]) -> str:
""" Given an undirected graph with n vertices and m edges, determine if you can separate the
graph into two disjoint sets such that no two vertices in the same set are connected by an edge.
Args:
n (int): Number of vertices ... | from collections import deque
def is_bipartite(n, edges):
# Create an adjacency list
adj = [[] for _ in range(n + 1)]
for u, v in edges:
adj[u].append(v)
adj[v].append(u)
# Array to store the color of each vertex (0: not colored, 1: color 1, 2: color 2)
color = [0] * (n + 1)
#... | def test_case_1():
output = separate_cities(4, 4, [(1, 2), (2, 3), (3, 4), (4, 1)])
assert output == "YES\n1 2 1 2"
def test_case_2():
output = separate_cities(3, 3, [(1, 2), (2, 3), (1, 3)])
assert output == "NO"
def test_case_3():
output = separate_cities(5, 4, [(1, 2), (2, 3), (4, 5)])
poss... | [
{
"docstring": null,
"function_declaration": "def is_bipartite(n, edges):",
"function_name": "is_bipartite",
"parameter_list": "(n, edges)"
},
{
"docstring": null,
"function_declaration": "def separate_cities(n, m, edges):",
"function_name": "separate_cities",
"parameter_list": "... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_bipartite(n, edges):\n from collections import deque\n\n # Build the adjacency list\n adj_list = [[] for _ in range(n + 1)]\n for u, v in edges:... | trial_gpt4o_2 | {
"original_instruction": "Given an undirected graph with $n$ vertices and $m$ edges, each vertex representing a city and each edge representing a bidirectional road connecting two cities, you need to determine whether you can separate the graph into two disjoint sets such that no two cities in the same set are conne... | 0.581747 | Taco_56945 | C | [
"is_bipartite",
"separate_cities"
] | 2 | [
[
"separate_cities",
"is_bipartite"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 4f4da1e8c889c9129a9fec59e954aedc251e4727 | ecc14743ecf64ad6407d58e0d9c30e38ca516715 | |||
v1.0 | complete | Taco | Taco_57011_C | from collections import Counter
def can_form_palindrome(s: str) -> bool:
"""
Check if it is possible to rearrange the string s into a palindrome.
"""
count = Counter(s)
odd_count = sum(1 for val in count.values() if val % 2 != 0)
# A palindrome can have at most one character with an odd count
... | from collections import Counter
def can_form_palindrome(s):
"""
Check if it is possible to rearrange the string s into a palindrome.
"""
count = Counter(s)
odd_count = sum(1 for val in count.values() if val % 2 != 0)
# A palindrome can have at most one character with an odd count
return odd... | from solution import rearrange_to_palindrome
def test_palindrome_even_length():
assert rearrange_to_palindrome("aabb") in {"abba", "baab"}
assert rearrange_to_palindrome("ccbb") in {"bccb", "cbbc"}
def test_palindrome_odd_length():
assert rearrange_to_palindrome("aabbc") in {"abcba", "bacab", "cabac"}
de... | [
{
"docstring": "Check if it is possible to rearrange the string s into a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def rearrange_to_palindrome(s):",... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def can_form_palindrome(s):\n from collections import Counter\n count = Counter(s)\n odd_count = sum(1 for c in count if count[c] % 2 != 0)\n return od... | trial_gpt4o_4 | {
"original_instruction": "You are given a string `s` of length `n`. Your task is to transform this string into a palindrome by rearranging its characters, while making the minimum possible number of swaps between any two characters. If it is not possible to rearrange the characters of the string to form a palindrome... | 0.78719 | Taco_57011 | C | [
"can_form_palindrome",
"rearrange_to_palindrome"
] | 2 | [
[
"rearrange_to_palindrome",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 240f4f45691964897d6cae85fc5a1eef962a928f | 639cac8bf61c3e12368514cee30cf1488487f27b | |||
v1.0 | complete | Taco | Taco_56792_C | from typing import List
def maxInteger(arr: List[int]) -> str:
""" Given an array of positive integers, rearrange the elements to form the maximum possible integer and return that integer as a string.
>>> maxInteger([3, 30, 34, 5, 9])
'9534330'
>>> maxInteger([1, 10, 2])
'2110'
"""
from functo... | from functools import cmp_to_key
def compare(x, y):
"""
Compare two elements by their possible concatenations in both orders.
"""
if x + y > y + x:
return -1
elif x + y < y + x:
return 1
else:
return 0
def maxInteger(arr):
"""
Given an array of positive integers... | from solution import maxInteger
def test_example_1():
assert maxInteger([3, 30, 34, 5, 9]) == "9534330"
def test_example_2():
assert maxInteger([1, 10, 2]) == "2110"
def test_single_element():
assert maxInteger([5]) == "5"
def test_all_same_digits():
assert maxInteger([11, 11, 11]) == "111111"
def ... | [
{
"docstring": "Compare two elements by their possible concatenations in both orders.",
"function_declaration": "def compare(x, y):",
"function_name": "compare",
"parameter_list": "(x, y)"
},
{
"docstring": "Given an array of positive integers, rearrange the elements to form the maximum poss... | [
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 functools import cmp_to_key\n\ndef compare_numbers(x, y):\n # Custom comparator for sorting the numbers\n if x + y > y + x:\n return -1\n elif... | trial_gpt4o_2 | {
"original_instruction": "Given an array of positive integers, rearrange the elements to form the maximum possible integer and return that integer.\n\nExample 1:\nInput: arr = [3, 30, 34, 5, 9]\nOutput: 9534330\nExplanation: By arranging elements in descending order, you will form 9534330 which is the largest possib... | 0.681823 | Taco_56792 | C | [
"compare",
"maxInteger"
] | 2 | [
[
"maxInteger",
"compare"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 545b8ce614ced841323343f286d6dc03d13d881b | c4ec70a1cd0eb7dfed37955f203bb2d448301c87 | |||
v1.0 | complete | Taco | Taco_56278_C | def findAnagrams(s: str, p: str) -> List[int]:
"""
Given a string s and a pattern p, return all starting indices of p's anagrams in s.
>>> findAnagrams("cbaebabacd", "abc")
[0, 6]
>>> findAnagrams("af", "be")
[]
"""
pass
def checkInclusion(s: str, p: str) -> bool:
"""
Given a ... | def findAnagrams(s: str, p: str):
from collections import Counter
len_s, len_p = len(s), len(p)
if len_p > len_s:
return []
p_count = Counter(p)
s_count = Counter()
result = []
for i in range(len_s):
s_count[s[i]] += 1
if i >= len_p:
if s_count[s[i - l... | from solution import findAnagrams, checkInclusion
def test_example_1():
s = "cbaebabacd"
p = "abc"
assert findAnagrams(s, p) == [0, 6]
assert checkInclusion(s, p) == True
def test_example_2():
s = "af"
p = "be"
assert findAnagrams(s, p) == []
assert checkInclusion(s, p) == False
def t... | [
{
"docstring": null,
"function_declaration": "def findAnagrams(s, p):",
"function_name": "findAnagrams",
"parameter_list": "(s, p)"
},
{
"docstring": null,
"function_declaration": "def checkInclusion(s, p):",
"function_name": "checkInclusion",
"parameter_list": "(s, p)"
}
] | [
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 findAnagrams(s: str, p: str):\n from collections import Counter\n\n len_s, len_p = len(s), len(p)\n if len_p > len_s:\n return []\n\n p_coun... | trial_gpt4o_0 | {
"original_instruction": "Given a string S. The task is to check if it contains any anagram of a pattern P by completing the functions findAnagrams() and checkInclusion(). The function checkInclusion() should return `true` if the pattern's anagram is found as a substring within the given string, and `false` otherwis... | 0.683684 | Taco_56278 | C | [
"findAnagrams",
"checkInclusion"
] | 2 | [
[
"checkInclusion",
"findAnagrams"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | f71e74dd092bafa6cd8fdf3979f3a26a7497c68c | 670e009e210a3176da7a2c22586a8908823d8d54 | |||
v1.0 | complete | Taco | Taco_57094_C | def is_palindrome(n: int) -> bool:
""" Check if a number is a palindrome.
>>> is_palindrome(9009) True
>>> is_palindrome(12321) True
>>> is_palindrome(12345) False
>>> is_palindrome(1) True
"""
def largest_palindrome_product() -> int:
""" Find the largest palindrome made from the produc... | def is_palindrome(n):
"""
Check if a number is a palindrome.
"""
return str(n) == str(n)[::-1]
def largest_palindrome_product():
"""
Find the largest palindrome made from the product of two 3-digit numbers.
"""
max_palindrome = 0
for i in range(999, 99, -1):
for j in range(i... | from solution import largest_palindrome_product, is_palindrome
def test_is_palindrome():
assert is_palindrome(9009) == True
assert is_palindrome(12321) == True
assert is_palindrome(12345) == False
assert is_palindrome(1) == True
def test_largest_palindrome_product():
assert largest_palindrome_prod... | [
{
"docstring": "Check if a number is a palindrome.",
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": "Find the largest palindrome made from the product of two 3-digit numbers.",
"function_declaration": "def larg... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a number is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef largest_palindrome_product():\n ... | trial_gpt4o_0 | {
"original_instruction": "A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is `9009` = `91` × `99`. A useful property to note is that for a number to be palindromic, its reverse must be equal to itself.\n\nYour task is to find the largest palindrome m... | 0.656056 | Taco_57094 | C | [
"is_palindrome",
"largest_palindrome_product"
] | 2 | [
[
"largest_palindrome_product",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dc7724869bdf74ea37ab3a9d6392c2bffbc1939e | e90883613a91b5cfca8eaf5f6fd1212041975928 | |||
v1.0 | complete | Taco | Taco_56977_C | from typing import List, Tuple
def max_flow(N: int, M: int, S: int, T: int, edges: List[Tuple[int, int, int]]) -> int:
""" Determine the maximum number of commuters that can be routed from the starting intersection to the destination intersection.
This function takes the number of intersections (N), the numbe... | from collections import deque
def bfs_capacity(graph, capacity, source, sink, parent):
visited = [False] * len(graph)
queue = deque([source])
visited[source] = True
while queue:
node = queue.popleft()
for adj, cap in graph[node]:
if not visited[adj] and capacity[node][adj]... | def test_case_1():
N = 4
M = 5
S = 1
T = 4
edges = [
(1, 2, 40),
(1, 3, 20),
(2, 3, 10),
(2, 4, 30),
(3, 4, 20)
]
assert max_flow(N, M, S, T, edges) == 50
def test_case_2():
N = 3
M = 3
S = 1
T = 3
edges = [
(1, 2, 5),
... | [
{
"docstring": null,
"function_declaration": "def bfs_capacity(graph, capacity, source, sink, parent):",
"function_name": "bfs_capacity",
"parameter_list": "(graph, capacity, source, sink, parent)"
},
{
"docstring": null,
"function_declaration": "def max_flow(N, M, S, T, edges):",
"f... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef bfs(capacity, source, sink, parent):\n visited = set()\n queue = deque([source])\n visited.add(source)\n\n while q... | trial_gpt4o_2 | {
"original_instruction": "A city is planning to introduce a new public transit route and wants to maximize the number of commuters that can utilize this route efficiently. The city map consists of $N$ intersections connected by $M$ bidirectional streets. Each street between the intersections has a capacity, which is... | 0.656248 | Taco_56977 | C | [
"bfs_capacity",
"max_flow"
] | 2 | [
[
"max_flow",
"bfs_capacity"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 7798a1a6a0cd2d800ccf31f4f90402e073486e91 | 98f87faa17e05c0056a725c7252ed3ded2e1cecc | |||
v1.0 | complete | Taco | Taco_57098_C | def is_balanced(s: str) -> bool:
""" Determine if a string is balanced, meaning every character
in the string appears the same number of times.
>>> is_balanced("aabbcc")
True
>>> is_balanced("aaabbc")
False
>>> is_balanced("abcdab")
False
>>> is_balanced("aaaa")
True
>>> is_... | def is_balanced(s):
from collections import Counter
char_counts = Counter(s)
values = list(char_counts.values())
return all(val == values[0] for val in values)
def process_strings(strings):
results = []
for s in strings:
if s == "*":
break
results.append("YES" i... | from solution import is_balanced, process_strings
def test_is_balanced():
assert is_balanced("aabbcc") == True
assert is_balanced("aaabbc") == False
assert is_balanced("abcdab") == False
assert is_balanced("aaaa") == True
assert is_balanced("") == True
assert is_balanced("x" * 100) == True
def... | [
{
"docstring": null,
"function_declaration": "def is_balanced(s):",
"function_name": "is_balanced",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def process_strings(strings):",
"function_name": "process_strings",
"parameter_list": "(strings)"
}
] | [
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_balanced(s):\n from collections import Counter\n \n char_counts = Counter(s)\n values = list(char_counts.values())\n return all(val == values... | trial_gpt4o_0 | {
"original_instruction": "A string is called “balanced” if every character in the string appears the same number of times. For example, the string \"aabbcc\" is balanced because each character appears twice, while the string \"aaabbc\" is not balanced because 'a' appears three times, 'b' appears twice, and 'c' appea... | 0.651971 | Taco_57098 | C | [
"is_balanced",
"process_strings"
] | 2 | [
[
"process_strings",
"is_balanced"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 67bf25ee331d80a540c2eb0b9d6ad75f7f6a16d7 | a73d772c09231035f592b9fbbb8111300e49ac1e | |||
v1.0 | complete | Taco | Taco_56856_C | from typing import List
def levenshtein_distance(word1: str, word2: str) -> int:
""" Compute the Levenshtein distance between two words.
>>> levenshtein_distance("apple", "appl") == 1
>>> levenshtein_distance("kitten", "sitting") == 3
"""
def spell_check(dictionary: List[str], document: List[str]) -> ... | def levenshtein_distance(word1, word2):
"""
Compute the Levenshtein distance between two words.
"""
len1, len2 = len(word1), len(word2)
dp = [[0] * (len2 + 1) for _ in range(len1 + 1)]
for i in range(len1 + 1):
dp[i][0] = i
for j in range(len2 + 1):
dp[0][j] = j
for i i... | from solution import levenshtein_distance, spell_check
def test_levenshtein_distance():
assert levenshtein_distance("apple", "apple") == 0
assert levenshtein_distance("appl", "apple") == 1
assert levenshtein_distance("apple", "aple") == 1
assert levenshtein_distance("apple", "appli") == 1
assert le... | [
{
"docstring": "Compute the Levenshtein distance between two words.",
"function_declaration": "def levenshtein_distance(word1, word2):",
"function_name": "levenshtein_distance",
"parameter_list": "(word1, word2)"
},
{
"docstring": "Check each word in the document and suggest the closest 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 levenshtein_distance(s1, s2):\n \"\"\"\n Compute the Levenshtein distance between two strings.\n \"\"\"\n len_s1, len_s2 = len(s1), len(s2)\n \n... | trial_gpt4o_2 | {
"original_instruction": "You are working on developing a spell checking application. Your task is to determine if each word in a document is spelled correctly based on a given dictionary. The dictionary contains a list of correctly spelled words.\n\nAdditionally, you are required to suggest the closest possible wor... | 0.631215 | Taco_56856 | C | [
"levenshtein_distance",
"spell_check"
] | 2 | [
[
"spell_check",
"levenshtein_distance"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a97b90ee9d5ca60968645134702766b18ff14737 | 40c55136ac759f4e45790688e009217fbc3197b6 | |||
v1.0 | complete | Taco | Taco_56863_C | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(n, edges, values):
"""
Build a binary tree from the given edges and values.
"""
pass
def maximum_path_sum(root):
"""
Calculate the maximum path sum in the... | class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def build_tree(n, edges, values):
if n == 0:
return None
nodes = [TreeNode(value) for value in values]
from collections import defaultdict
children = defaultdic... | def test_example_1():
n = 5
edges = [(1, 2), (1, 3), (3, 4), (3, 5)]
values = [10, 2, 10, 20, 1]
assert find_max_sum_path(n, edges, values) == 42
def test_example_2():
n = 3
edges = [(1, 2), (1, 3)]
values = [5, 7, 8]
assert find_max_sum_path(n, edges, values) == 20
def test_single_nod... | [] | [
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 TreeNode:\n def __init__(self, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef c... | trial_gpt4o_4 | {
"original_instruction": "You are given a binary tree where each node contains a positive integer value. Your task is to find the maximum sum path from any node to any node in the tree. The path must contain at least one node and does not need to pass through the root.\n\nConstraints\n\n* The number of nodes in the ... | 0.548107 | Taco_56863 | C | [
"build_tree",
"maximum_path_sum",
"find_max_sum_path"
] | 3 | [
[
"find_max_sum_path",
"build_tree"
],
[
"find_max_sum_path",
"maximum_path_sum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 0464a6da5ae3a9221b092eb7986862abf85e29ac | d45527bac30df6f98e8304c853dd51dd96cb6f16 | |||
v1.0 | complete | Taco | Taco_57177_C | def min_operations_to_equal_elements(arr):
"""
Calculate the minimum number of operations needed to make all elements in the array equal.
>>> min_operations_to_equal_elements([2, 3, 5])
2
>>> min_operations_to_equal_elements([1, 1, 1, 1])
0
"""
def process_input(input_data):
"""
... | def min_operations_to_equal_elements(arr):
"""
Calculate the minimum number of operations needed to make all elements in the array equal.
"""
from collections import Counter
frequency = Counter(arr)
max_frequency = max(frequency.values())
return len(arr) - max_frequency
def process_inp... | from solution import min_operations_to_equal_elements, process_input, min_operations
def test_case_1():
assert min_operations_to_equal_elements([2, 3, 5]) == 2
def test_case_2():
assert min_operations_to_equal_elements([1, 1, 1, 1]) == 0
def test_case_3():
assert min_operations_to_equal_elements([0, 0, 0... | [
{
"docstring": "Calculate the minimum number of operations needed to make all elements in the array equal.",
"function_declaration": "def min_operations_to_equal_elements(arr):",
"function_name": "min_operations_to_equal_elements",
"parameter_list": "(arr)"
},
{
"docstring": "Process the inp... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_operations_to_equal_elements(n, arr):\n \"\"\"\n Returns the minimum number of operations to make all elements in the array equal.\n \"\"\"\n f... | trial_gpt4o_2 | {
"original_instruction": "Given an integer array \\(A\\) of length \\(N\\).\n\nFind the minimum number of operations to make all elements of \\(A\\) equal, where each operation consists of choosing two distinct elements \\(A_i\\) and \\(A_j\\) (1 ≤ i, j ≤ N) and one of the following:\n1. Add the value of \\(A_i\\) t... | 0.658608 | Taco_57177 | C | [
"min_operations_to_equal_elements",
"process_input",
"min_operations"
] | 3 | [
[
"min_operations",
"process_input"
],
[
"process_input",
"min_operations_to_equal_elements"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d6d93ad7f162f6573c219a5f9ae90c45188e8db6 | 90dab975dd487b3bf427e352d389659f861203af | |||
v1.0 | complete | Taco | Taco_57382_C | def is_good_sequence(sequence):
""" Determines if the sequence can be made such that all elements are equal
through a series of right circular shifts followed by reversing the sequence
and performing right circular shifts again.
"""
pass
def check_sequences(sequences):
""" Determine if each seq... | def is_good_sequence(sequence):
"""
Determines if the sequence can be made such that all elements are equal
through a series of right circular shifts followed by reversing the sequence
and performing right circular shifts again.
"""
unique_elements = set(sequence)
return len(unique_elements)... | def test_is_good_sequence():
assert is_good_sequence([4, 1, 2, 3]) == False
assert is_good_sequence([1, 1, 1]) == True
assert is_good_sequence([2, 4, 4, 2, 2]) == True
def test_check_sequences():
assert check_sequences([[4, 1, 2, 3], [1, 1, 1], [2, 4, 4, 2, 2]]) == ["NO", "YES", "YES"]
def test_proces... | [
{
"docstring": "Determines if the sequence can be made such that all elements are equal\nthrough a series of right circular shifts followed by reversing the sequence\nand performing right circular shifts again.",
"function_declaration": "def is_good_sequence(sequence):",
"function_name": "is_good_sequen... | [
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_good_sequence(sequence):\n \"\"\"\n Determine if a sequence can be made all equal through a series of \n right circular shifts and possibly reversi... | trial_gpt4o_2 | {
"original_instruction": "Dreamoon loves sequences and shifting operations. Let’s define a right circular shift operation on a sequence a as follows: moving the last element to the beginning of the sequence while shifting all other elements one position to the right.\n\nFor example, applying a right circular shift t... | 0.692016 | Taco_57382 | C | [
"is_good_sequence",
"check_sequences",
"process_input"
] | 3 | [
[
"check_sequences",
"is_good_sequence"
],
[
"process_input",
"check_sequences"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | ef728734833dcb0f6f1177b165865e70b04dd2bb | 0597bb8b6ab61f96f9aac572ffd63a815b33fb8c | |||
v1.0 | complete | Taco | Taco_57272_C | def is_valid_constellation(points):
"""
Determine if the points can form a valid constellation (no three points are collinear).
Args:
points (List[Tuple[int, int]]): List of points represented as tuples of coordinates (x, y).
Returns:
str: 'YES' if points form a valid constellation, 'NO' otherw... | def is_valid_constellation(points):
"""
Returns 'YES' if given points can form a valid constellation,
otherwise 'NO'
"""
n = len(points)
def are_collinear(p1, p2, p3):
"""
Check if three points are collinear.
"""
return (p2[1] - p1[1]) * (p3[0] - p1[0]) == (p3[1... | import pytest
from solution import is_valid_constellation, parse_and_solve
def test_is_valid_constellation_collinear():
points = [(1, 1), (2, 2), (3, 3), (4, 4)]
assert is_valid_constellation(points) == 'NO'
def test_is_valid_constellation_not_collinear():
points = [(0, 0), (1, 2), (2, 3), (3, 1), (4, 4)]... | [
{
"docstring": "Returns 'YES' if given points can form a valid constellation, \notherwise 'NO'",
"function_declaration": "def is_valid_constellation(points):",
"function_name": "is_valid_constellation",
"parameter_list": "(points)"
},
{
"docstring": "Process multiple test cases and returns t... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_constellation(points):\n def are_collinear(p1, p2, p3):\n # Check if the area of the triangle formed by points (p1, p2, p3) is zero\n ... | trial_gpt4o_2 | {
"original_instruction": "James, an astronomy student, loves to study star constellations represented by coordinate points in a 2D space. He defines a constellation as a set of points where no three points are collinear. Given a set of points, he wants to determine if they can form a valid constellation.\n\nThe inpu... | 0.58754 | Taco_57272 | C | [
"is_valid_constellation",
"process_input",
"parse_and_solve"
] | 3 | [
[
"parse_and_solve",
"process_input"
],
[
"process_input",
"is_valid_constellation"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | true | [] | true | d02c5211ede06c08a2d514f461bb4d7133e8b58d | 8be461e57973a2949775145e50b5e6fbafb12a86 | |||
v1.0 | complete | Taco | Taco_57009_C | def largestGrassRectangle(N: int, M: int, field: List[List[str]]) -> int:
""" Find the largest rectangular section of the field that contains only grass and no rocks.
>>> largestGrassRectangle(4, 5, [
... ['G', '.', 'G', 'G', 'G'],
... ['.', 'G', '.', '.', '.'],
... ['G', 'G', 'G', 'R',... | def maximalRectangle(matrix):
if not matrix:
return 0
max_area = 0
heights = [0] * len(matrix[0])
for row in matrix:
for i in range(len(row)):
if row[i] == 'G':
heights[i] += 1
else:
heights[i] = 0
max_area = max(max_area,... | def test_largest_grass_rectangle():
assert largestGrassRectangle(4, 5, [
['G', '.', 'G', 'G', 'G'],
['.', 'G', '.', '.', '.'],
['G', 'G', 'G', 'R', 'R'],
['G', 'G', 'G', 'G', 'G']
]) == 6
assert largestGrassRectangle(4, 5, [
['G', 'G', 'G', 'G', 'G'],
['G', '... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
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 maximalRectangleArea(field):\n if not field:\n return 0\n\n n = len(field)\n m = len(field[0])\n \n # Heights will store the continuous h... | trial_gpt4o_1 | {
"original_instruction": "Farmer John has a rectangular field, represented as a grid of size NxM where each cell can either be empty, contain grass, or contain a rock. Farmer John wants to plant a special type of crop that requires a clear and rectangular section of land. He needs your help to find the largest recta... | 0.539553 | Taco_57009 | C | [
"maximalRectangle",
"largestRectangleArea",
"largestGrassRectangle"
] | 3 | [
[
"largestGrassRectangle",
"maximalRectangle"
],
[
"maximalRectangle",
"largestRectangleArea"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | 00b483745f20f31d23de8f3c67f14d9015e34d18 | 18fb50ce0b45e9c63259927baa662069c57c3cc2 | |||
v1.0 | complete | Taco | Taco_57286_C | def project_management_tool(N, D, dependencies):
"""
Determines the order of project completions based on dependencies.
Args:
N : int : Number of projects
D : int : Number of dependencies
dependencies : list of tuples : List containing tuples of dependencies (A, B)
Returns:
str... | from collections import defaultdict, deque
def find_project_order(N, D, dependencies):
"""
Determines the order of project completions based on dependencies.
Args:
N : int : Number of projects
D : int : Number of dependencies
dependencies : list of tuples : List containing tuples of depend... | import pytest
from solution import project_management_tool
def test_single_valid_order():
N, D = 4, 3
dependencies = [(1, 2), (2, 3), (3, 4)]
assert project_management_tool(N, D, dependencies) == "1 2 3 4"
def test_impossible_due_to_cycle():
N, D = 4, 4
dependencies = [(1, 2), (2, 3), (3, 1), (3, ... | [
{
"docstring": "Determines the order of project completions based on dependencies.\n\nArgs:\nN : int : Number of projects\nD : int : Number of dependencies\ndependencies : list of tuples : List containing tuples of dependencies (A, B)\n\nReturns:\nstr : A space-separated sequence of N integers representing vali... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef find_project_order(N, D, dependencies):\n \"\"\"\n Determines a valid order to complete the projects given ... | trial_gpt4o_2 | {
"original_instruction": "You are building a new project management tool to help a company track its ongoing projects and their dependencies. Each project can depend on one or more other projects that must be completed first. The company wants to determine the order in which they should complete the projects to resp... | 0.465512 | Taco_57286 | C | [
"find_project_order",
"project_management_tool"
] | 2 | [
[
"project_management_tool",
"find_project_order"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 8c6026c01ed66a51008b43cbf932b8e1e1de004d | 4ef3b6fd77abc3643f5800eb24f4823643dd545d | |||
v1.0 | complete | Taco | Taco_56703_C | def minimum_total_travel_cost(N: int, M: int, roads: List[Tuple[int, int, int]]) -> int:
"""
Determine the minimum total travel cost required to connect all cities.
Args:
N : int : the number of cities
M : int : the number of roads
roads : List[Tuple[int, int, int]] : a list of tuples where... | def find(parent, i):
if parent[i] == i:
return i
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[yroot] = xroot
e... | def test_minimum_total_travel_cost():
# Test Sample Input
N, M = 4, 5
roads = [
(1, 2, 5),
(2, 3, 3),
(1, 3, 7),
(4, 3, 2),
(4, 1, 6)
]
assert minimum_total_travel_cost(N, M, roads) == 10
# Test Larger Input
N, M = 3, 3
roads = [
(1, 2, 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,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n \ndef union(parent, rank, x, y):\n xroot ... | trial_gpt4o_2 | {
"original_instruction": "A kingdom consists of N cities and M bidirectional roads that connect pairs of cities. Each road has a certain travel cost associated with it. The king wants to construct a network where every citizen can travel between any two cities with the minimum total travel cost. The king decided to ... | 0.766505 | Taco_56703 | C | [
"find",
"union",
"minimum_total_travel_cost"
] | 3 | [
[
"minimum_total_travel_cost",
"find"
],
[
"minimum_total_travel_cost",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 677fdbc78b3d0da8d03ea1c47d172ce58b3c3892 | f59177aec2c0831b2f8eef333ccfd01c0916c741 | |||
v1.0 | complete | Taco | Taco_57100_C | from typing import List, Tuple
def merge_layers(layers: List[List[List[int]]], merge_operations: List[Tuple[int, int]]):
""" Merge the given layers as per the given merge operations.
>>> layers = [
... [[1, 2], [3, 4]],
... [[5, 6], [7, 8]],
... [[1, 2], [3, 4]]]
>>> merge_operations = [(1, 2),... | def merge_layers(layers, merge_operations):
N, M = len(layers), len(layers[0])
def merge(A, B):
for i in range(M):
for j in range(M):
layers[A][i][j] = max(layers[A][i][j], layers[B][i][j])
for A, B in merge_operations:
merge(A - 1, B - 1)
def query_layer(l... | def test_merge_layers():
layers = [
[
[1, 2],
[3, 4]
],
[
[5, 6],
[7, 8]
],
[
[1, 2],
[3, 4]
]
]
merge_operations = [(1, 2), (2, 3), (1, 3)]
expected_layers = [
[
[... | [
{
"docstring": null,
"function_declaration": "def merge_layers(layers, merge_operations):",
"function_name": "merge_layers",
"parameter_list": "(layers, merge_operations)"
},
{
"docstring": null,
"function_declaration": "def query_layer(layers, L, R, C):",
"function_name": "query_lay... | [
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 merge_layers(N, M, K, Q, layers, merges, queries):\n for a, b in merges:\n a -= 1 # Convert to zero-indexed\n b -= 1 # Convert to zero-index... | trial_gpt4o_2 | {
"original_instruction": "In a computer graphics software, layers of images are manipulated in various ways. One common operation is to merge a series of layers together into a single image. The merging process involves combining the pixel values of each layer in a specific order, usually by a given set of pairwise ... | 0.501257 | Taco_57100 | C | [
"merge_layers",
"query_layer",
"process_graphics_merging"
] | 3 | [
[
"process_graphics_merging",
"merge_layers"
],
[
"process_graphics_merging",
"query_layer"
]
] | 2 | [] | false | [] | false | pytest | false | [] | true | d75909ce88313ea9dac8d563408f7c944c1419bd | 9332be919aa2fa4cdf0f668baf8672f7b989eca9 | |||
v1.0 | complete | Taco | Taco_56888_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(parent_array):
nodes = [TreeNode(i) for i in range(len(parent_array))]
root = None
for i, p in enumerate(parent_array):
if p == -1:
root = nodes[i]
e... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def build_tree(parent_array):
nodes = [TreeNode(i) for i in range(len(parent_array))]
root = None
for i, p in enumerate(parent_array):
if p == -1:
root = nodes[i]
e... | def test_flatten_binary_tree():
# Test case 1
T = 2
test_cases = [
(5, [-1, 0, 0, 1, 1]),
(3, [-1, 0, 1]),
]
assert process_test_cases(T, test_cases) == [
[0, 1, 3, 4, 2],
[0, 1, 2],
]
def test_single_node():
T = 1
test_cases = [
(1, [-1]),
]
... | [] | [
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):\n self.val = val\n self.left = None\n self.right = None\n\ndef flatten_tree(A):\n if not A:\n... | trial_gpt4o_1 | {
"original_instruction": "You are given a binary tree represented by an array A of length N, where each element at index i (0-based) indicates the parent of node i. The root of the binary tree will always be represented by -1, which means node i is the root if A[i] = -1.\n\nYou need to flatten this binary tree into ... | 0.601094 | Taco_56888 | C | [
"build_tree",
"flatten_binary_tree_util",
"flatten_binary_tree",
"preorder_traversal",
"process_test_cases",
"solve"
] | 6 | [
[
"flatten_binary_tree",
"flatten_binary_tree_util"
],
[
"process_test_cases",
"build_tree"
],
[
"process_test_cases",
"flatten_binary_tree"
],
[
"process_test_cases",
"preorder_traversal"
],
[
"solve",
"process_test_cases"
]
] | 5 | [
"process_test_cases"
] | false | [
"TreeNode"
] | true | pytest | false | [] | true | ebe1a14360b893e386ca110cf8642fb1cea6cd46 | 3afc1cfdf7322e93105fa1d6ae3f7688e74798fa | |||
v1.0 | complete | Taco | Taco_57340_C | from typing import List
def is_palindrome(num: int) -> bool:
""" Check if the given number is a palindrome.
>>> is_palindrome(121)
True
>>> is_palindrome(131)
True
>>> is_palindrome(123)
False
>>> is_palindrome(1)
True
>>> is_palindrome(0)
True
"""
def is_prime(num: ... | def is_palindrome(num):
"""
Check if the given number is a palindrome.
"""
return str(num) == str(num)[::-1]
def is_prime(num):
"""
Check if the given number is a prime.
"""
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
... | from solution import is_palindrome, is_prime, smallest_palindromic_prime
def test_is_palindrome():
assert is_palindrome(121)
assert is_palindrome(131)
assert not is_palindrome(123)
assert is_palindrome(1)
assert is_palindrome(0)
def test_is_prime():
assert is_prime(2)
assert is_prime(3)
... | [
{
"docstring": "Check if the given number is a palindrome.",
"function_declaration": "def is_palindrome(num):",
"function_name": "is_palindrome",
"parameter_list": "(num)"
},
{
"docstring": "Check if the given number is a prime.",
"function_declaration": "def is_prime(num):",
"functi... | [
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_prime(num):\n \"\"\" Check if a number is prime. \"\"\"\n if num < 2:\n return False\n if num in (2, 3):\n return True\n if num % ... | trial_gpt4o_2 | {
"original_instruction": "Alice is interested in prime numbers, and she recently learned that palindromic prime numbers are quite fascinating. Palindromic prime numbers are prime numbers that remain the same when their digits are reversed. For example, 101 is a palindromic prime number since it is prime and reads th... | 0.726623 | Taco_57340 | C | [
"is_palindrome",
"is_prime",
"smallest_palindromic_prime"
] | 3 | [
[
"smallest_palindromic_prime",
"is_palindrome"
],
[
"smallest_palindromic_prime",
"is_prime"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 39a1b1bd0f9d83909064b09c1921d515b8ce2848 | 45601d7234dd95a5e324f2c8d327771e0353341f | |||
v1.0 | complete | Taco | Taco_57413_C | def maximalRectangle(matrix: List[str]) -> int:
""" Given a grid of '*' and '.' characters, determine the maximum area of rectangles consisting solely of '.' characters in the grid.
>>> maximalRectangle([
... "******",
... "*...**",
... "*.*.**",
... "*.*.**",
... "**.***"
... ]) 3
>... | def maximalRectangle(matrix):
if not matrix:
return 0
n = len(matrix)
m = len(matrix[0])
heights = [0] * m
max_area = 0
for i in range(n):
for j in range(m):
if matrix[i][j] == '.':
heights[j] += 1
else:
heights[j] = 0
... | def test_maximalRectangle_small():
grid = [
"******",
"*...**",
"*.*.**",
"*.*.**",
"**.***"
]
assert maximalRectangle(grid) == 3
def test_maximalRectangle_empty():
grid = [
"*"
]
assert maximalRectangle(grid) == 0
def test_maximalRectangle_one_r... | [
{
"docstring": null,
"function_declaration": "def maximalRectangle(matrix):",
"function_name": "maximalRectangle",
"parameter_list": "(matrix)"
},
{
"docstring": null,
"function_declaration": "def largestRectangleArea(heights):",
"function_name": "largestRectangleArea",
"paramete... | [
1,
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 maximalRectangle(matrix):\n if not matrix:\n return 0\n n = len(matrix)\n m = len(matrix[0])\n heights = [0] * m\n max_area = 0\n \n ... | trial_gpt4o_0 | {
"original_instruction": "Given a grid of '*' and '.' characters, your task is to determine the maximum area of rectangles consisting solely of '.' characters in the grid. A rectangle of size r x c is defined as r consecutive rows and c consecutive columns.\n\nFor example, consider the following grid:\n```\n ... | 0.659949 | Taco_57413 | C | [
"maximalRectangle",
"largestRectangleArea"
] | 2 | [
[
"maximalRectangle",
"largestRectangleArea"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 935058656a1f2bc50fff5fed24c946d2673b4282 | 83519641e432f3c4f075735e7c41f12081c07248 | |||
v1.0 | complete | Taco | Taco_57579_C | def extract_primes(int_str: str) -> str:
"""
Takes a string containing a list of space-separated integers and returns a string
with only the prime numbers from the list, separated by commas.
>>> extract_primes("2 3 5 7 11")
'2,3,5,7,11'
>>> extract_primes("4 6 8 10 12")
''
... | def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def extract_primes(int_str):
"""
Takes a string containing a list of space-s... | from solution import extract_primes
def test_extract_primes_all_primes():
assert extract_primes("2 3 5 7 11") == "2,3,5,7,11"
def test_extract_primes_no_primes():
assert extract_primes("4 6 8 10 12") == ""
def test_extract_primes_mixed():
assert extract_primes("23 4 15 29 17 8") == "23,29,17"
def test_e... | [
{
"docstring": null,
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Takes a string containing a list of space-separated integers and\nreturns a string of the prime numbers, separated by commas.",
"function_declaration":... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Helper function to determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n ret... | trial_gpt4o_2 | {
"original_instruction": "Write a function that takes a string containing a list of space-separated integers and returns a string with only the prime numbers from the list, separated by commas. For example:\n\n```\nInput: \"23 4 15 29 17 8\"\nOutput: \"23,29,17\"\n```\n\nReturn the result as a single string. \n\nYou... | 0.639685 | Taco_57579 | C | [
"is_prime",
"extract_primes"
] | 2 | [
[
"extract_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | ca642ce27b46e8e1e6ec83660ab4052db6a96990 | e72e713aaeb82c1dc44df4de04be372b00c1943b | |||
v1.0 | complete | Taco | Taco_57658_C | def minimum_cost_to_connect_agents(N: int, M: int, connections: List[Tuple[int, int, int]]) -> int:
""" Find the minimum cost to connect all agents such that every agent can communicate with every other agent either directly or indirectly using a Minimum Spanning Tree (MST) approach.
>>> minimum_cost_to_connect... | def find(parent, x):
if parent[x] != x:
parent[x] = find(parent, parent[x])
return parent[x]
def union(parent, rank, x, y):
root_x = find(parent, x)
root_y = find(parent, y)
if root_x != root_y:
if rank[root_x] > rank[root_y]:
parent[root_y] = root_x
elif ra... | def test_minimum_cost_to_connect_agents():
assert minimum_cost_to_connect_agents(4, 5, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (2, 4, 5)]) == 6
assert minimum_cost_to_connect_agents(4, 2, [(1, 2, 1), (3, 4, 2)]) == -1
assert minimum_cost_to_connect_agents(3, 3, [(1, 2, 1), (2, 3, 2), (1, 3, 4)]) == 3
... | [
{
"docstring": null,
"function_declaration": "def find(parent, x):",
"function_name": "find",
"parameter_list": "(parent, x)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class UnionFind:\n def __init__(self, size):\n self.root = list(range(size))\n self.rank = [1] * size\n\n def find(self, x):\n if self.r... | trial_gpt4o_1 | {
"original_instruction": "You are tasked with creating a safe communication network for a group of secret agents. Each agent can securely communicate with others through a direct communication link represented as an undirected and weighted edge between two vertices in a graph. The vertices represent agents, and the ... | 0.660473 | Taco_57658 | C | [
"find",
"union",
"minimum_cost_to_connect_agents"
] | 3 | [
[
"minimum_cost_to_connect_agents",
"find"
],
[
"minimum_cost_to_connect_agents",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 23289a6e4ce1c5f5854d8e0a062cf82d45165d4d | b67b05ddffccb4a42ad42cfc304824a4d51f8f8e | |||
v1.0 | complete | Taco | Taco_57729_C | def minSwapsToPalindrome(s: str) -> int:
"""
Returns the minimum number of adjacent character swaps required to transform `s` into a palindrome.
If it cannot be transformed into a palindrome, return -1.
Arguments:
s: a string of lowercase English letters
Returns:
The minimum number... | def minSwapsToPalindrome(s):
"""
Returns the minimum number of adjacent character swaps required to transform the
string `s` into a palindrome. If it's not possible, returns -1.
"""
if not canFormPalindrome(s):
return -1
s = list(s)
n = len(s)
swap_count = 0
for i ... | from solution import minSwapsToPalindrome
def test_example_1():
assert minSwapsToPalindrome("mamad") == 3
def test_example_2():
assert minSwapsToPalindrome("asflkj") == -1
def test_example_3():
assert minSwapsToPalindrome("abcbca") == 1
def test_single_character():
assert minSwapsToPalindrome("a") =... | [
{
"docstring": "Returns the minimum number of adjacent character swaps required to transform the \nstring `s` into a palindrome. If it's not possible, returns -1.",
"function_declaration": "def minSwapsToPalindrome(s):",
"function_name": "minSwapsToPalindrome",
"parameter_list": "(s)"
},
{
"... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def minSwapsToPalindrome(s):\n \"\"\"\n Returns the minimum number of adjacent character swaps required to transform the \n string `s` into a palindrome. ... | trial_gpt4o_0 | {
"original_instruction": "A palindrome is a string that reads the same forward and backward. Given a string, you need to determine the minimum number of adjacent character swaps required to transform it into a palindrome. If it cannot be transformed into a palindrome, return -1.\n\nFunction Description\n\nComplete t... | 0.802545 | Taco_57729 | C | [
"minSwapsToPalindrome",
"canFormPalindrome"
] | 2 | [
[
"minSwapsToPalindrome",
"canFormPalindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | cfb18ab1eaff54219dea0bf8e71f86335539bfac | 22fe39712a1c73238e8e9d15109a76c670f46fae | |||
v1.0 | complete | Taco | Taco_57482_C | def minimum_new_connections_required(N: int, M: int, connections: List[Tuple[int, int, int]]) -> int:
"""
This function returns the minimum number of new connections required
to make the entire system fully connected.
"""
# Implementation here...
def solve(T: int, test_cases: List[Tuple[int, int, ... | def find_parent(parent, i):
"""
A utility function to find the set of an element i
"""
if parent[i] == i:
return i
else:
return find_parent(parent, parent[i])
def union(parent, rank, x, y):
"""
A utility function to do union of two subsets x and y
"""
xroot = find_pa... | def test_minimum_new_connections_required():
test_cases = [
(5, 3, [(1, 2, 1), (2, 3, 2), (4, 5, 3)]), # Expected output: 1
(4, 5, [(1, 2, 1), (1, 3, 2), (3, 4, 1)]), # Expected output: 0
]
assert solve(2, test_cases) == [1, 0]
def test_single_server():
test_cases = [
(1,... | [
{
"docstring": "A utility function to find the set of an element i",
"function_declaration": "def find_parent(parent, i):",
"function_name": "find_parent",
"parameter_list": "(parent, i)"
},
{
"docstring": "A utility function to do union of two subsets x and y",
"function_declaration": "... | [
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_root(parent, i):\n if parent[i] == i:\n return i\n else:\n return find_root(parent, parent[i])\n\ndef union(parent, rank, x, y):\n ... | trial_gpt4o_2 | {
"original_instruction": "Miyuki, a renowned software engineer, has recently enrolled in a top-secret development program. As part of her training, she has been assigned the challenge of managing a distributed data storage system. The system consists of `N` servers, indexed from 1 to `N`, and `M` bidirectional netwo... | 0.592734 | Taco_57482 | C | [
"find_parent",
"union",
"minimum_new_connections_required",
"solve"
] | 4 | [
[
"minimum_new_connections_required",
"find_parent"
],
[
"minimum_new_connections_required",
"union"
],
[
"solve",
"minimum_new_connections_required"
],
[
"union",
"find_parent"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 52488beba49dd6d5714ae329e48e5ad27781ae95 | cffe5b6c4ce9a2f20ec990db13ecf7bc4fb245cb | |||
v1.0 | complete | Taco | Taco_57545_C | def process_optimization(n: int, edges: List[Tuple[int, int]], k: int) -> int:
""" Determine the minimum value of the maximum delivery distance for any warehouse to main hubs after direct routes are added between the main hubs.
Parameters:
n (int): The number of warehouses.
edges (List[Tuple[int, i... | import heapq
from collections import deque, defaultdict
def bfs_farthest_node(graph, start):
"""
Perform BFS to find the farthest node and its distance from the starting node.
"""
queue = deque([(start, 0)])
visited = set([start])
farthest_node = start
max_dist = 0
while queue:
... | import pytest
from solution import process_optimization
def test_basic_case():
assert process_optimization(6, [(1, 2), (1, 3), (3, 4), (3, 5), (5, 6)], 2) == 2
def test_single_hub():
assert process_optimization(4, [(1, 2), (2, 3), (3, 4)], 1) == 2
def test_hubs_equal_to_warehouses():
assert process_optim... | [
{
"docstring": "Perform BFS to find the farthest node and its distance from the starting node.",
"function_declaration": "def bfs_farthest_node(graph, start):",
"function_name": "bfs_farthest_node",
"parameter_list": "(graph, start)"
},
{
"docstring": null,
"function_declaration": "def m... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef find_farthest_node(start_node, adjacency_list):\n \"\"\"\n Returns the farthest node and its distance from the start_nod... | trial_gpt4o_1 | {
"original_instruction": "A company is planning to optimize their delivery routes. They have a network of $n$ warehouses, described as an unweighted, connected undirected graph. Each warehouse is connected by a road to other warehouses.\n\nYou must analyze the network and determine key strategic locations that will ... | 0.604348 | Taco_57545 | C | [
"bfs_farthest_node",
"min_max_delivery_distance",
"process_optimization"
] | 3 | [
[
"min_max_delivery_distance",
"bfs_farthest_node"
],
[
"process_optimization",
"min_max_delivery_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | ac6e04b820680b895c59a3a4178fb69c665be015 | 166e624cf0182f7e600a3332bb20a8b82a453f2b | |||
v1.0 | complete | Taco | Taco_57101_C | from typing import List, Tuple
def are_isomorphic(edges1: List[Tuple[int, int]], edges2: List[Tuple[int, int]]) -> str:
""" Determines whether two rooted trees are isomorphic.
>>> are_isomorphic([(1, 2), (1, 3)], [(1, 2), (1, 3)]) "Yes"
>>> are_isomorphic([(1, 2), (2, 3), (3, 4)], [(1, 2), (1, 3), (1, 4)])... | from collections import defaultdict
from typing import List, Tuple
def hash_tree(children, root, parent):
"""
Helper function to recursively generate hash representation of the tree
"""
primes = [31, 29, 23, 19, 17]
subtree_hash = []
for child in children[root]:
if child != parent:
... | def test_process_input():
input_data = '''2
3
1 2
1 3
3
1 2
1 3
4
1 2
2 3
3 4
4
1 2
1 3
1 4'''
expected_output = ["Yes", "No"]
assert process_input(input_data) == expected_output
def test_are_isomorphic_identical_trees():
edges1 = [(1, 2), (1, 3)]
edges2 = [(1, 2), (1, 3)]
assert are_isomorphic... | [
{
"docstring": "Helper function to recursively generate hash representation of the tree",
"function_declaration": "def hash_tree(children, root, parent):",
"function_name": "hash_tree",
"parameter_list": "(children, root, parent)"
},
{
"docstring": null,
"function_declaration": "def are_... | [
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\n\ndef build_tree(edges, n):\n tree = defaultdict(list)\n for u, v in edges:\n tree[u].append(v)\n tree[v].... | trial_gpt4o_2 | {
"original_instruction": "Wandering Trees\n\nStory\n\nIn a small village surrounded by a vast forest, the villagers have a unique problem. The trees in the forest often wander around during the night, leading to a different configuration of the forest every morning. The villagers decided to map the forest every day.... | 0.489738 | Taco_57101 | C | [
"hash_tree",
"are_isomorphic",
"process_input"
] | 3 | [
[
"are_isomorphic",
"hash_tree"
],
[
"process_input",
"are_isomorphic"
]
] | 2 | [
"process_input"
] | false | [] | false | pytest | false | [] | true | 33d497b755a7f2c5a5ce5b5e54f63c3bc94a48d6 | 98483db5db86923e499e86ef65ba51b09809677a | |||
v1.0 | complete | Taco | Taco_57660_C | def bubble_sort(arr):
"""
Sorts an array using the Bubble Sort algorithm.
Parameters:
- arr: list of integers
Returns:
- Sorted list of integers
"""
n = len(arr)
for i in range(n):
# Last i elements are already in place
for j in range(0, n - i - 1):
... | def bubble_sort(arr):
"""
Sorts an array using the Bubble Sort algorithm.
Parameters:
- arr: list of integers
Returns:
- Sorted list of integers
"""
n = len(arr)
for i in range(n):
# Last i elements are already in place
for j in range(0, n - i - 1):
... | from solution import sort_input
def test_sort_input_example_1():
assert sort_input(5, [64, 34, 25, 12, 22]) == [12, 22, 25, 34, 64]
def test_sort_input_example_2():
assert sort_input(4, [4, 3, 2, 1]) == [1, 2, 3, 4]
def test_sort_input_sorted():
assert sort_input(3, [1, 2, 3]) == [1, 2, 3]
def test_sort... | [
{
"docstring": "Sorts an array using the Bubble Sort algorithm.\n\nParameters:\n- arr: list of integers\n\nReturns:\n- Sorted list of integers",
"function_declaration": "def bubble_sort(arr):",
"function_name": "bubble_sort",
"parameter_list": "(arr)"
},
{
"docstring": "Sorts the elements 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 bubble_sort(arr):\n \"\"\"\n Perform bubble sort on the given array.\n \"\"\"\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i... | trial_gpt4o_2 | {
"original_instruction": "Your task is to write a program that helps to arrange the elements of an array in ascending order using the Bubble Sort algorithm. Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The... | 0.667953 | Taco_57660 | C | [
"bubble_sort",
"sort_input"
] | 2 | [
[
"sort_input",
"bubble_sort"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0d2bcf4d822862a110820d227db0f431a262ce5a | 6a924454156d22abe5b92b82c626c149d789c694 | |||
v1.0 | complete | Taco | Taco_57929_C | def solution(input_text: str) -> str:
"""
Determines if it is possible to rearrange the grid such that no two adjacent
cells contain the same value for each test case in the input.
>>> solution("2\n3 3\n010\n101\n010\n3 3\n000\n111\n000")
"YES\nNO"
>>> solution("1\n2 2\n01\n10")
"YES"
... | def is_possible_to_rearrange(grid):
n = len(grid)
m = len(grid[0])
# Generate the checkerboard pattern grids for comparison
checkerboard_1 = [[(i + j) % 2 for j in range(m)] for i in range(n)]
checkerboard_2 = [[(i + j + 1) % 2 for j in range(m)] for i in range(n)]
def is_matching(grid, pa... | import pytest
from solution import solution
def test_case_1():
input_text = "2\n3 3\n010\n101\n010\n3 3\n000\n111\n000"
expected_output = "YES\nNO"
assert solution(input_text) == expected_output
def test_case_2():
input_text = "1\n2 2\n01\n10"
expected_output = "YES"
assert solution(input_text... | [
{
"docstring": null,
"function_declaration": "def is_possible_to_rearrange(grid):",
"function_name": "is_possible_to_rearrange",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def possible_rearrangement(test_cases):",
"function_name": "possible_rearrangem... | [
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_possible_to_rearrange(n, m, grid):\n \"\"\"\n Determines if it is possible to rearrange the grid such that \n no two adjacent cells (horizontally o... | trial_gpt4o_2 | {
"original_instruction": "In a small village, children play a game using a grid of size n × m. Initially, each cell of the grid contains either a '0' or a '1'. A child is allowed to select any one cell and flip its value (change '0' to '1' or '1' to '0'). They can do this operation as many times as they like on any ... | 0.683712 | Taco_57929 | C | [
"is_possible_to_rearrange",
"possible_rearrangement",
"parser",
"solution"
] | 4 | [
[
"possible_rearrangement",
"is_possible_to_rearrange"
],
[
"solution",
"parser"
],
[
"solution",
"possible_rearrangement"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 71ceba4e5d6c26055f259c58ac3013e59d4d5070 | 58668ad6c997216280eeee1b1e7d267f56ed9eda | |||
v1.0 | complete | Taco | Taco_57883_C | def max_path_sum(grid: List[List[int]]) -> int:
""" Determine the maximum sum of any path from the top-left corner to the bottom-right corner of the grid, where you can only move right or down at each step.
If the input is not a grid or if the grid contains non-positive integers, return None.
... | def is_valid_grid(grid):
if not isinstance(grid, list):
return False
for row in grid:
if not isinstance(row, list):
return False
for cell in row:
if not isinstance(cell, int) or cell <= 0:
return False
return True
def max_path_sum(grid):
... | from solution import max_path_sum
def test_valid_grid():
grid = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert max_path_sum(grid) == 12
def test_single_cell_grid():
grid = [
[5]
]
assert max_path_sum(grid) == 5
def test_not_a_grid():
assert max_path_sum("not a ... | [
{
"docstring": null,
"function_declaration": "def is_valid_grid(grid):",
"function_name": "is_valid_grid",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def max_path_sum(grid):",
"function_name": "max_path_sum",
"parameter_list": "(grid)"
}
] | [
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 max_path_sum(grid):\n \"\"\"\n Returns the maximum sum of any path from the top-left corner to the bottom-right corner \n of the grid, where you can o... | trial_gpt4o_1 | {
"original_instruction": "You are given a grid of size `m x n` represented by a list of lists, where each cell contains a positive integer. Your task is to determine the maximum sum of any path from the top-left corner to the bottom-right corner of the grid, where you can only move right or down at each step. Implem... | 0.665571 | Taco_57883 | C | [
"is_valid_grid",
"max_path_sum"
] | 2 | [
[
"max_path_sum",
"is_valid_grid"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | e37ce6813a77f5ca445f01342f9120911fa62e2f | 9471cd72a87125db2d73c9f789d167a0cd4c0271 | |||
v1.0 | complete | Taco | Taco_58096_C | from typing import List
def generate_palindromic_permutations(s: str) -> List[str]:
"""
Given a string S, determine if S can be rearranged into a palindrome.
Return all possible palindromic arrangements in any order.
If no palindromic arrangement exists, return an empty list.
>>> generate_pali... | from collections import Counter
from itertools import permutations
def can_form_palindrome(s):
"""
Check if the input string can be rearranged into a palindrome.
"""
count = Counter(s)
odd_count = sum(1 for c in count if count[c] % 2 != 0)
return odd_count <= 1
def generate_palindromic_permuta... | from solution import generate_palindromic_permutations
def test_generate_palindromic_permutations_example1():
result = generate_palindromic_permutations("aabb")
expected = sorted(["abba", "baab"])
assert sorted(result) == expected
def test_generate_palindromic_permutations_example2():
result = generat... | [
{
"docstring": "Check if the input string can be rearranged into a palindrome.",
"function_declaration": "def can_form_palindrome(s):",
"function_name": "can_form_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Return all palindromic permutations of the input string.",
"function_... | [
0,
0,
0,
0,
0,
0,
0,
1,
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 itertools import permutations\n\ndef can_form_palindrome(s):\n \"\"\"\n Function to determine if the string s can be re... | trial_gpt4o_8 | {
"original_instruction": "Given a string S, determine if S can be rearranged into a palindrome. Return all possible palindromic arrangements in any order. If no palindromic arrangement exists, return an empty list.\n\nExample 1:\nInput: \"aabb\"\nOutput: [\"abba\", \"baab\"]\n\nExample 2:\nInput: \"abc\"\nOutput: []... | 0.7063 | Taco_58096 | C | [
"can_form_palindrome",
"generate_palindromic_permutations"
] | 2 | [
[
"generate_palindromic_permutations",
"can_form_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a348baa5591996c52998bbb50ff6b29850f54970 | b0058eaa6abde5dc1b37c5d18c679a5603dac96c | |||
v1.0 | complete | Taco | Taco_58136_C | def minimum_possible_total_magical_value(n: int, m: int, bridges: List[Tuple[int, int, int]]) -> int:
""" Determine the minimum possible total magical value of the bridges that can be chosen to ensure that all islands are connected.
>>> minimum_possible_total_magical_value(4, 5, [(1, 2, 1), (1, 3, 4), (1, 4, 3)... | def find(parent, i):
if parent[i] == i:
return i
else:
return find(parent, parent[i])
def union(parent, rank, x, y):
xroot = find(parent, x)
yroot = find(parent, y)
if rank[xroot] < rank[yroot]:
parent[xroot] = yroot
elif rank[xroot] > rank[yroot]:
parent[yr... | from solution import minimum_possible_total_magical_value
def test_example1():
n = 4
m = 5
bridges = [
(1, 2, 1),
(1, 3, 4),
(1, 4, 3),
(2, 3, 2),
(3, 4, 5)
]
assert minimum_possible_total_magical_value(n, m, bridges) == 6
def test_example2():
n = 3
... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n rootX = find(parent, x)\n... | trial_gpt4o_2 | {
"original_instruction": "In a kingdom far away, there are n islands connected by m bidirectional bridges. Each bridge has a certain magical value associated with it. The wizard of the kingdom decided to organize a transportation network such that people can travel from one island to any other island. To accomplish ... | 0.671609 | Taco_58136 | C | [
"find",
"union",
"kruskal",
"minimum_possible_total_magical_value"
] | 4 | [
[
"kruskal",
"find"
],
[
"kruskal",
"union"
],
[
"minimum_possible_total_magical_value",
"kruskal"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | true | [] | true | 076f36259ce0b6f942e3bd70949afef602f8ca5c | da12cd82358691ab1986ab79b26a24141ec9a9a5 | |||
v1.0 | complete | Taco | Taco_57593_C | def number_of_paths(n: int, m: int, grid: str) -> int:
"""
Alice is working with a grid-based game where she can move her character on a 2D grid from the top-left corner (1, 1) to the bottom-right corner (n, m). The grid has some obstacles, which she cannot pass through. Alice can only move right or down at an... | def num_paths_with_obstacles(grid):
n = len(grid)
m = len(grid[0])
MOD = 1000000007
if grid[0][0] == '#' or grid[n-1][m-1] == '#':
return 0
dp = [[0] * m for _ in range(n)]
dp[0][0] = 1
for i in range(n):
for j in range(m):
if grid[i][j] == '#':
... | def test_example_case_1():
n, m = 3, 3
grid = "...\n.#.\n..."
assert number_of_paths(n, m, grid) == 2
def test_example_case_2():
n, m = 3, 3
grid = "...\n.#.\n..#"
assert number_of_paths(n, m, grid) == 0
def test_corner_case_starting_point_blocked():
n, m = 3, 3
grid = "#..\n.#.\n..."
... | [
{
"docstring": null,
"function_declaration": "def num_paths_with_obstacles(grid):",
"function_name": "num_paths_with_obstacles",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def number_of_paths(n, m, grid):",
"function_name": "number_of_paths",
"par... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "MOD = 1000000007\n\ndef uniquePaths(n, m, grid):\n if grid[0][0] == '#' or grid[n-1][m-1] == '#':\n return 0\n \n dp = [[0] * m for _ in range(n)]\... | trial_gpt4o_2 | {
"original_instruction": "Alice is working with a grid-based game where she can move her character on a 2D grid from the top-left corner (1, 1) to the bottom-right corner (n, m). The grid has some obstacles, which she cannot pass through. Alice can only move right or down at any step.\n\nAlice wants to know the numb... | 0.695905 | Taco_57593 | C | [
"num_paths_with_obstacles",
"number_of_paths"
] | 2 | [
[
"number_of_paths",
"num_paths_with_obstacles"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a4cb02d794a3509f0d6c33f9f38295ee866c64a0 | 81de9ffb3ecdcefca4303301d0e889536e5e6e2e | |||
v1.0 | complete | Taco | Taco_58117_C | def gcd(a, b):
"""
Helper function to compute the greatest common divisor of a and b using Euclid's algorithm.
>>> gcd(12, 18) 6
>>> gcd(100, 75) 25
>>> gcd(7, 13) 1
"""
def common_divisors_count(n, m):
"""
Returns the number of common divisors between two numbers n and m.
>>> commo... | def gcd(a, b):
"""
Helper function to compute the greatest common divisor of a and b using Euclid's algorithm.
"""
while b:
a, b = b, a % b
return a
def common_divisors_count(n, m):
"""
Returns the number of common divisors between two numbers n and m.
"""
common_gcd = gcd(n... | from solution import gcd, common_divisors_count, solve
def test_gcd():
assert gcd(12, 18) == 6
assert gcd(100, 75) == 25
assert gcd(7, 13) == 1
assert gcd(0, 18) == 18
assert gcd(18, 0) == 18
def test_common_divisors_count():
assert common_divisors_count(12, 18) == 4
assert common_divisors... | [
{
"docstring": "Helper function to compute the greatest common divisor of a and b using Euclid's algorithm.",
"function_declaration": "def gcd(a, b):",
"function_name": "gcd",
"parameter_list": "(a, b)"
},
{
"docstring": "Returns the number of common divisors between two numbers n and m.",
... | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b.\n \"\"\"\n while b:\n a, b = b, a % b\n return a\n\ndef common_divi... | trial_gpt4o_2 | {
"original_instruction": "Two integers N and M are given as inputs. Write a program to find the number of common divisors of N and M.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of test cases. Then, T lines follow, each line containing two integers N and M. \n\n-----Output-----\nDisp... | 0.758207 | Taco_58117 | C | [
"gcd",
"common_divisors_count",
"solve"
] | 3 | [
[
"common_divisors_count",
"gcd"
],
[
"solve",
"common_divisors_count"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | fde61af44d3c1e1a0679e31af807fb97c9fbdc6c | cb35f1129e1588c5efaee5a318d143c6fb2b7cee | |||
v1.0 | complete | Taco | Taco_57954_C | def check_palindrome_substrings(test_cases):
"""
Given a list of test cases, check each one to see if there exists a contiguous substring
in any row or column that reads the same forward and backward (i.e., is a palindrome).
Parameters:
test_cases (List[Tuple[List[str], int, int]]): List of tu... | def is_palindrome(s):
return s == s[::-1]
def contains_palindrome(grid, n, m):
# Check each row for palindromes
for row in grid:
for k in range(2, m+1): # Minimum palindrome length is 2
for i in range(m - k + 1):
if is_palindrome(row[i:i+k]):
return ... | from solution import check_palindrome_substrings
def test_single_case_yes():
test_cases = [
([
"abc",
"aba",
"xyz"
], 3, 3)]
assert check_palindrome_substrings(test_cases) == ["YES"]
def test_single_case_no():
test_cases = [
([
"abc",
... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": null,
"function_declaration": "def contains_palindrome(grid, n, m):",
"function_name": "contains_palindrome",
"parameter_list": "(grid... | [
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(s):\n return s == s[::-1]\n\ndef has_palindromic_substring(grid, n, m):\n for row in grid:\n for length in range(2, m+1):\n ... | trial_gpt4o_2 | {
"original_instruction": "Given a rectangular grid of characters, check whether there exists a contiguous substring in any row or column that reads the same forward and backward (i.e., is a palindrome).\n\n-----Input-----\n\nThe first line contains an integer $t$ ($1 \\le t \\le 100$) — the number of test cases. The... | 0.736828 | Taco_57954 | C | [
"is_palindrome",
"contains_palindrome",
"check_palindrome_substrings"
] | 3 | [
[
"check_palindrome_substrings",
"contains_palindrome"
],
[
"contains_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 869a22ca82c8350581fc6003d5073c95fd15ba21 | b81a132f8f10f55d204f5f2479fd1bbe281671f3 | |||
v1.0 | complete | Taco | Taco_57572_C | def length_of_lis(arr):
"""
Function to find the length of the Longest Increasing Subsequence (LIS) in the given array.
"""
pass
def check_subsequence(N, Q, arr, queries):
"""
For each query, determine if there exists a subsequence of length K that is strictly increasing.
Return a list of "... | def length_of_lis(arr):
"""
Function to find the length of the Longest Increasing Subsequence (LIS) in the given array.
"""
if not arr:
return 0
n = len(arr)
lis = [1] * n
for i in range(1, n):
for j in range(i):
if arr[i] > arr[j] and lis[i] < lis[j] + 1:
... | from solution import length_of_lis, check_subsequence
def test_length_of_lis():
assert length_of_lis([9, 1, 3, 7, 5, 6, 20]) == 5
assert length_of_lis([1, 1, 1, 1, 1]) == 1
assert length_of_lis([]) == 0
assert length_of_lis([10, 20, 30, 40, 50]) == 5
assert length_of_lis([50, 40, 30, 20, 10]) == 1
... | [
{
"docstring": "Function to find the length of the Longest Increasing Subsequence (LIS) in the given array.",
"function_declaration": "def length_of_lis(arr):",
"function_name": "length_of_lis",
"parameter_list": "(arr)"
},
{
"docstring": "For each query, determine if there exists a subseque... | [
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 lis(array):\n \"\"\"\n Helper function to compute the length of the Longest Increasing Subsequence (LIS).\n \"\"\"\n if not array:\n return ... | trial_gpt4o_1 | {
"original_instruction": "Tina enjoys exploring various subsequences within arrays.\n\nShe is particularly interested in finding the length of the Longest Increasing Subsequence (LIS) in a given array.\n\nYou are given an array of size N and a positive integer Q.\n\nEach Q query contains one integer K, and you need ... | 0.631301 | Taco_57572 | C | [
"length_of_lis",
"check_subsequence"
] | 2 | [
[
"check_subsequence",
"length_of_lis"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 12188d3b4efe136d873ecc62b280d8ff6ce25031 | a7f43bbe2bb52c576723423dcff6ec534cfbcd6a | |||
v1.0 | complete | Taco | Taco_57802_C | def calculate_minutes(time1: str, time2: str) -> int:
"""Calculate the minutes between two timestamps in "HH:MM" format.
>>> calculate_minutes("09:00", "12:00") 180
>>> calculate_minutes("13:00", "17:00") 240
>>> calculate_minutes("08:30", "12:45") 255
>>> calculate_minutes("14:15", "15:30") 75
... | def calculate_minutes(time1, time2):
"""
Calculate the minutes between two time stamps in "HH:MM" format
"""
h1, m1 = map(int, time1.split(':'))
h2, m2 = map(int, time2.split(':'))
return (h2 - h1) * 60 + (m2 - m1)
def total_minutes_present(test_cases):
results = []
for case in test_cas... | from solution import calculate_minutes, total_minutes_present, parse_input
def test_calculate_minutes():
assert calculate_minutes("09:00", "12:00") == 180
assert calculate_minutes("13:00", "17:00") == 240
assert calculate_minutes("08:30", "12:45") == 255
assert calculate_minutes("14:15", "15:30") == 75... | [
{
"docstring": "Calculate the minutes between two time stamps in \"HH:MM\" format",
"function_declaration": "def calculate_minutes(time1, time2):",
"function_name": "calculate_minutes",
"parameter_list": "(time1, time2)"
},
{
"docstring": null,
"function_declaration": "def total_minutes_... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def calculate_total_minutes(timestamps):\n \"\"\"\n Calculate the total minutes active given check-in and check-out times.\n \n Parameters:\n timest... | trial_gpt4o_4 | {
"original_instruction": "A company has a system that tracks employee check-ins and check-outs throughout the day via timestamps in a given format. Given a list of check-in and check-out timestamps for a day, your task is to determine the total number of minutes an employee was present in the office during that day.... | 0.554108 | Taco_57802 | C | [
"calculate_minutes",
"total_minutes_present",
"parse_input"
] | 3 | [
[
"total_minutes_present",
"calculate_minutes"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 2cd3e92c94df395d3010b3dda3048b1958770273 | debd746c7f210a36c2219adabe45c8d1f6667ed2 | |||
v1.0 | complete | Taco | Taco_57586_C | def can_place_tree(grid, x, y, w, h):
""" Check if a tree can be placed in the grid at position (x, y) with width w and height h.
>>> grid = [
>>> ['.', '.', '.'],
>>> ['.', '.', '.'],
>>> ['.', '.', '.']
>>> ]
>>> can_place_tree(grid, 0, 0, 2, 2)
True
>>> grid = [
>... | def can_place_tree(grid, x, y, w, h):
for i in range(h):
for j in range(w):
if grid[x + i][y + j] != '.':
return False
return True
def place_tree(grid, x, y, w, h):
for i in range(h):
for j in range(w):
grid[x + i][y + j] = 'T'
def remove_tree(grid, ... | def test_can_place_tree_true():
grid = [
['.', '.', '.'],
['.', '.', '.'],
['.', '.', '.']
]
assert can_place_tree(grid, 0, 0, 2, 2) == True
def test_can_place_tree_false():
grid = [
['.', '.', '.'],
['.', '#', '.'],
['.', '.', '.']
]
assert can_p... | [
{
"docstring": null,
"function_declaration": "def can_place_tree(grid, x, y, w, h):",
"function_name": "can_place_tree",
"parameter_list": "(grid, x, y, w, h)"
},
{
"docstring": null,
"function_declaration": "def place_tree(grid, x, y, w, h):",
"function_name": "place_tree",
"par... | [
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 can_place_tree(grid, n, m, x, y, w, h):\n if x + h > n or y + w > m:\n return False\n for i in range(h):\n for j in range(w):\n ... | trial_gpt4o_2 | {
"original_instruction": "Suppose you are helping a farmer to plant trees in an orchard. The orchard is represented as a 2D grid of size n x m. Each cell can either be empty or contain an obstacle. You are given a list of tree saplings, each specifying the type of tree and its desired growth area in the shape of a r... | 0.60914 | Taco_57586 | C | [
"can_place_tree",
"place_tree",
"remove_tree",
"max_trees_planted",
"main"
] | 5 | [
[
"max_trees_planted",
"can_place_tree"
],
[
"max_trees_planted",
"place_tree"
],
[
"max_trees_planted",
"remove_tree"
]
] | 3 | [] | false | [] | false | pytest | false | [] | true | 7516fc874731e4049b22fdac37f0cd6c49c6e7c8 | a22aac94b6cb72cf376e49c1281fc880cf82e378 | |||
v1.0 | complete | Taco | Taco_58107_C | from typing import List
def can_form_sequence(strings: List[str]) -> bool:
"""
Determine if the given list of strings can be rearranged to form a sequence
such that each successive string differs from the previous one by exactly one character.
>>> can_form_sequence(["abc", "bbc", "bac"])
True... | from itertools import permutations
def differ_by_one_char(s1, s2):
"""
Check if two strings differ by exactly one character.
"""
count_diff = 0
for a, b in zip(s1, s2):
if a != b:
count_diff += 1
if count_diff > 1:
return False
return count_diff == 1
def... | from solution import can_form_sequence
def test_example_true():
assert can_form_sequence(["abc", "bbc", "bac"]) == True
def test_example_false():
assert can_form_sequence(["abc", "def", "ghi"]) == False
def test_single_string():
assert can_form_sequence(["abc"]) == True
def test_two_strings_one_char_dif... | [
{
"docstring": "Check if two strings differ by exactly one character.",
"function_declaration": "def differ_by_one_char(s1, s2):",
"function_name": "differ_by_one_char",
"parameter_list": "(s1, s2)"
},
{
"docstring": "Determine if the given list of strings can be rearranged to form a sequenc... | [
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 itertools import permutations\n\ndef differ_by_one_char(s1, s2):\n \"\"\"\n Check if two strings differ by exactly one character.\n \"\"\"\n count... | trial_gpt4o_0 | {
"original_instruction": "You have been tasked with developing a method to determine if a given list of strings can be rearranged to form a sequence such that each successive string differs from the previous one by exactly one character. Two strings are considered to differ by one character if they are the same leng... | 0.735765 | Taco_58107 | C | [
"differ_by_one_char",
"can_form_sequence"
] | 2 | [
[
"can_form_sequence",
"differ_by_one_char"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 39c3643798d647eb459b93274c874df4e855c3e1 | e9ca5a63fcdda2065876a1369a389c1ec81fa5e2 | |||
v1.0 | complete | Taco | Taco_58224_C | MOD = 10**9 + 7
def compute_prefix_products(arr):
"""Compute prefix products for the array.
>>> compute_prefix_products([1, 2, 3, 4, 5])
[1, 1, 2, 6, 24, 120]
"""
prefix_products = [1] * (len(arr) + 1)
def range_product(L, R, prefix_products):
"""Compute range product from index L to R usi... | MOD = 10**9 + 7
def compute_prefix_products(arr):
prefix_products = [1] * (len(arr) + 1)
for i in range(1, len(arr) + 1):
prefix_products[i] = (prefix_products[i-1] * arr[i-1]) % MOD
return prefix_products
def range_product(L, R, prefix_products):
return (prefix_products[R] * pow(prefix_produc... | from solution import process_queries
def test_single_element():
assert process_queries(1, [5], 1, [(1, 1)]) == [5 % (10**9 + 7)]
def test_entire_range():
assert process_queries(5, [1, 2, 3, 4, 5], 1, [(1, 5)]) == [120 % (10**9 + 7)]
def test_partial_ranges():
assert process_queries(5, [1, 2, 3, 4, 5], 3,... | [
{
"docstring": null,
"function_declaration": "def compute_prefix_products(arr):",
"function_name": "compute_prefix_products",
"parameter_list": "(arr)"
},
{
"docstring": null,
"function_declaration": "def range_product(L, R, prefix_products):",
"function_name": "range_product",
"... | [
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": "MOD = 10**9 + 7\n\ndef preprocess_product(arr):\n \"\"\"\n Preprocesses the input array to calculate prefix products modulo (10^9 + 7).\n \"\"\"\n n = ... | trial_gpt4o_2 | {
"original_instruction": "Alice is given a list of $N$ integers and a list of $Q$ queries. Each query consists of two integers $L$ and $R$ and asks for the product of all integers in the sublist from index $L$ to index $R$ (inclusive). Since the product can be very large, return the result modulo $(10^9+7)$.\n\nCan ... | 0.630674 | Taco_58224 | C | [
"compute_prefix_products",
"range_product",
"process_queries"
] | 3 | [
[
"process_queries",
"compute_prefix_products"
],
[
"process_queries",
"range_product"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | 57e9de80e6405c776970d31b62f31c6bcd603edb | 5035575a41ed948e769cb7ae9c643993030a16d8 | |||
v1.0 | complete | Taco | Taco_58244_C | def word_search(m: int, n: int, grid: List[List[str]], word: str) -> str:
""" Determine if the word exists in the grid in specified directions.
>>> word_search(3, 4, [
... ['A', 'B', 'C', 'E'],
... ['S', 'F', 'C', 'S'],
... ['A', 'D', 'E', 'E']], "ABCCED")
"YES"
>>> word_search(3, 4, [
.... | def exist(board, word):
def dfs(board, word, i, j, m, n, index):
if index == len(word):
return True
if i < 0 or i >= m or j < 0 or j >= n or board[i][j] != word[index]:
return False
# temporarily mark the board cell as visited to avoid revisiting
temp, board[i... | def test_word_search_example_1():
grid = [
['A', 'B', 'C', 'E'],
['S', 'F', 'C', 'S'],
['A', 'D', 'E', 'E']
]
word = "ABCCED"
assert word_search(3, 4, grid, word) == "YES"
def test_word_search_example_2():
grid = [
['A', 'B', 'C', 'E'],
['S', 'F', 'C', 'S'],
... | [
{
"docstring": null,
"function_declaration": "def exist(board, word):",
"function_name": "exist",
"parameter_list": "(board, word)"
},
{
"docstring": null,
"function_declaration": "def word_search(m, n, grid, word):",
"function_name": "word_search",
"parameter_list": "(m, n, grid... | [
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 exist(board, word):\n def dfs(board, word, i, j, m, n, index):\n if index == len(word):\n return True\n if i < 0 or i >= m or j < 0... | trial_gpt4o_0 | {
"original_instruction": "In a grid of size `m x n` consisting of characters, word search is a challenge where a word can be constructed from the left-right, right-left, down-up, up-down, and diagonal directions. We are given a grid of characters and a word. The task is to determine if the word exists in the grid.\n... | 0.609779 | Taco_58244 | C | [
"exist",
"word_search"
] | 2 | [
[
"word_search",
"exist"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 5452c576316f769cb28d61cf1ba7a045f04a2b7e | 89440bb9cab17175b7adea025efe7424e25fd204 | |||
v1.0 | complete | Taco | Taco_58150_C | def sieve_of_eratosthenes(n: int) -> List[bool]:
""" Helper function to generate a list of booleans representing primality of numbers from 0 to n """
pass
def find_sum_of_primes(N: int):
""" Given an integer N, determine if it can be expressed as the sum of two prime numbers.
If it can, return any pair... | def sieve_of_eratosthenes(n):
is_prime = [True] * (n + 1)
p = 2
while p * p <= n:
if is_prime[p]:
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
is_prime[0] = is_prime[1] = False
return is_prime
def find_sum_of_primes(N):
if N < 4:
... | from solution import find_sum_of_primes
def test_small_prime_sum():
result = find_sum_of_primes(4)
assert result == (2, 2) or result == (2, 2), "Test for N=4 failed."
def test_valid_prime_sum_34():
result = find_sum_of_primes(34)
valid_results = [(3, 31), (5, 29), (11, 23), (17, 17)]
assert re... | [
{
"docstring": null,
"function_declaration": "def sieve_of_eratosthenes(n):",
"function_name": "sieve_of_eratosthenes",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def find_sum_of_primes(N):",
"function_name": "find_sum_of_primes",
"parameter_list": "... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return Tru... | trial_gpt4o_1 | {
"original_instruction": "Given an integer N, determine if it can be expressed as the sum of two prime numbers. If it can, return any pair of such prime numbers. If not, return -1.\n\n-----Constraints-----\n- 4 ≦ N ≦ 10^6\n\n-----Input-----\nThe input is given from Standard Input in the following format:\nN\n\n-----... | 0.662427 | Taco_58150 | C | [
"sieve_of_eratosthenes",
"find_sum_of_primes"
] | 2 | [
[
"find_sum_of_primes",
"sieve_of_eratosthenes"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 05c6973775e51a7a3638071d2bf329c6006d66c4 | 9b1669e93d7ac681c4647f5d924ec2421d21d7ad | |||
v1.0 | complete | Taco | Taco_58056_C | def max_path_sum(n: int, vals: List[int], edges: List[Tuple[int, int]]) -> int:
"""
Given a tree with N nodes where each node has a value, returns the maximum possible sum of values
of the nodes that can be collected by visiting nodes on exactly one simple path.
Args:
n: An integer, the number... | import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
def dfs(node, parent, values, adj_list):
max1 = max2 = 0
for neighbor in adj_list[node]:
if neighbor == parent:
continue
current_sum = dfs(neighbor, node, values, adj_list)
if current_sum > max1:
... | def test_max_path_sum():
assert max_path_sum(
5,
[1, 2, 3, 4, 5],
[(1, 2), (1, 3), (3, 4), (3, 5)]
) == 12
def test_simple_case():
assert max_path_sum(
2,
[1, 2],
[(1, 2)]
) == 3
def test_line_tree():
assert max_path_sum(
4,
[1, ... | [
{
"docstring": null,
"function_declaration": "def dfs(node, parent, values, adj_list):",
"function_name": "dfs",
"parameter_list": "(node, parent, values, adj_list)"
},
{
"docstring": null,
"function_declaration": "def max_path_sum(n, vals, edges):",
"function_name": "max_path_sum",
... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import sys\nfrom collections import defaultdict\n\nsys.setrecursionlimit(200000)\n\ndef dfs(node, parent, values, adj_list):\n max1 = max2 = 0\n for neighbor... | trial_gpt4o_0 | {
"original_instruction": "Consider a tree (connected acyclic graph) consisting of N nodes, where each node i has an integer value v_i. You are given the task of finding the maximum possible sum of values of the nodes that can be collected by visiting nodes on exactly one simple path.\n\nA simple path is a path that ... | 0.686849 | Taco_58056 | C | [
"dfs",
"max_path_sum",
"parse_input"
] | 3 | [
[
"max_path_sum",
"dfs"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | ddb610090bf9ad4daf045ad33d8c7f6d9450c923 | 21d7529c21940bc2bb56ed5a5e8b6c9e55306564 | |||
v1.0 | complete | Taco | Taco_58280_C | def palindromic_sequence_steps(test_cases: List[int]) -> List[Union[int, str]]:
"""Given a list of integers, determines the number of steps it takes for each integer to become a palindrome.
A palindrome is generated by reversing and adding the original integer. If the integer does not become a palindrome
... | def is_palindrome(n):
return str(n) == str(n)[::-1]
def steps_to_palindrome(n):
step_count = 0
while step_count < 1000:
if is_palindrome(n):
return step_count
n = n + int(str(n)[::-1])
step_count += 1
return "FAIL"
def palindromic_sequence_steps(test_cases):
res... | from solution import palindromic_sequence_steps
def test_single_input():
assert palindromic_sequence_steps([23]) == [1]
def test_multiple_input():
assert palindromic_sequence_steps([23, 87, 196]) == [1, 4, "FAIL"]
def test_large_input():
assert palindromic_sequence_steps([89]) == [24] # Number of steps ... | [
{
"docstring": null,
"function_declaration": "def is_palindrome(n):",
"function_name": "is_palindrome",
"parameter_list": "(n)"
},
{
"docstring": null,
"function_declaration": "def steps_to_palindrome(n):",
"function_name": "steps_to_palindrome",
"parameter_list": "(n)"
},
{
... | [
0,
0,
0,
1,
1
] | 2 | medium | 0.4 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a given integer n is a palindrome.\n \"\"\"\n return str(n) == str(n)[::-1]\n\ndef reverse_and_add(n):\n \... | trial_gpt4o_4 | {
"original_instruction": "Given a series of integers that follow the rules of a Palindromic sequence, where each integer is a palindrome and is generated by reversing and adding the original integer (e.g., 23 becomes 23 + 32 = 55). The sequence continues until it becomes a palindrome.\n\nWrite a program that takes a... | 0.709529 | Taco_58280 | C | [
"is_palindrome",
"steps_to_palindrome",
"palindromic_sequence_steps"
] | 3 | [
[
"palindromic_sequence_steps",
"steps_to_palindrome"
],
[
"steps_to_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 3dd251e211fe192a06380b0fab13fcbaabe82ebf | 69af119a327cb4784028662be969d7d01fc9d750 | |||
v1.0 | complete | Taco | Taco_58219_C | from typing import List
def is_valid_expression(exp: str) -> bool:
"""
Checks if the expression is valid according to the rules specified.
>>> is_valid_expression("3 + 5 - 2") == True
>>> is_valid_expression("3 + -5") == False
>>> is_valid_expression("10 + 15 - 5") == True
>>> is_valid_expressi... | def is_valid_expression(exp):
"""
Checks if the expression is valid according to the rules specified.
"""
tokens = exp.strip().split()
if len(tokens) < 3:
return False
# Check if first and last tokens are integers.
if not tokens[0].isdigit() or not tokens[-1].isdigit():
... | from solution import is_valid_expression, evaluate_expressions
def test_is_valid_expression():
assert is_valid_expression("3 + 5 - 2") == True
assert is_valid_expression("3 + -5") == False
assert is_valid_expression("10 + 15 - 5") == True
assert is_valid_expression("3-5") == False
assert is_valid_e... | [
{
"docstring": "Checks if the expression is valid according to the rules specified.",
"function_declaration": "def is_valid_expression(exp):",
"function_name": "is_valid_expression",
"parameter_list": "(exp)"
},
{
"docstring": "Evaluates valid mathematical expressions from the input list and... | [
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 evaluate_expressions(expressions):\n \"\"\"\n Evaluates only valid mathematical expressions involving integers, addition (+), and subtraction (-).\n A... | trial_gpt4o_2 | {
"original_instruction": "Write a function that takes a list of strings containing valid and invalid mathematical expressions involving integers, addition (+), and subtraction (-). The goal is to evaluate only the valid expressions and return a list with the results of those evaluations.\n\nA valid expression must:\... | 0.638602 | Taco_58219 | C | [
"is_valid_expression",
"evaluate_expressions"
] | 2 | [
[
"evaluate_expressions",
"is_valid_expression"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 458312f82e1965a3dabbca9c556836ba50c0cf13 | 3841d7856a71a8aea32c474f9f8f6bb942417564 | |||
v1.0 | complete | Taco | Taco_58157_C | from typing import List, Tuple
def min_cost_to_connect_houses(N: int, M: int, connections: List[Tuple[int, int, int]]) -> int:
"""
Find the minimum construction cost required to connect all the houses.
Args:
N (int): The number of houses.
M (int): The number of possible pipe connections.
conn... | def find(parent, i):
# This function finds the parent of a node i
if parent[i] == i:
return i
else:
parent[i] = find(parent, parent[i])
return parent[i]
def union(parent, rank, x, y):
# This function unions the sets containing x and y
rootX = find(parent, x)
rootY = find... | from solution import min_cost_to_connect_houses
def test_case_1():
N = 4
M = 5
connections = [
(1, 2, 10),
(1, 3, 15),
(2, 3, 5),
(2, 4, 20),
(3, 4, 10)
]
assert min_cost_to_connect_houses(N, M, connections) == 25
def test_case_2():
N = 3
M = 1
c... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, rank, x, y):",
"function_name": "union",
"parameter_list": "(parent, rank, x, y)"
},
... | [
1,
0,
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 # This function finds the parent of a node i\n if parent[i] == i:\n return i\n else:\n parent[i] = find(parent, paren... | trial_gpt4o_0 | {
"original_instruction": "In a small village, there is a need to build a water supply network that connects all the houses. The village consists of N houses numbered from 1 to N, and M possible pipe connections between them. Each pipe connection i connects houses a_i and b_i and has a construction cost of c_i. The v... | 0.583972 | Taco_58157 | C | [
"find",
"union",
"min_cost_to_connect_houses",
"main"
] | 4 | [
[
"min_cost_to_connect_houses",
"find"
],
[
"min_cost_to_connect_houses",
"union"
],
[
"union",
"find"
]
] | 3 | [] | false | [] | false | pytest | true | [] | true | 8d73a33b6f3ee787775ae3dbc357e5acf8f130d2 | e582c81317a072d35632309b64521e238ae08d2e | |||
v1.0 | complete | Taco | Taco_58355_C | def min_energy_required(N: int, M: int, grid: List[List[int]]) -> int:
""" Calculate the minimum energy required to move from the top-left to the bottom-right corner of the grid.
Parameters:
N (int): Number of rows in the grid.
M (int): Number of columns in the grid.
grid (List[List[int]]): 2D ... | def min_energy_path(grid):
"""
Returns the minimum energy required to move from
the top-left to the bottom-right corner of the grid.
"""
N = len(grid)
M = len(grid[0])
# Create a 2D dp array to store the minimum energy required to reach each cell
dp = [[0]*M for _ in range(N)]
... | from solution import min_energy_required
def test_min_energy_simple():
grid = [
[1, 3, 1],
[1, 5, 1],
[4, 2, 1]
]
assert min_energy_required(3, 3, grid) == 7
def test_min_energy_single_row():
grid = [
[1, 2, 3, 4]
]
assert min_energy_required(1, 4, grid) == 10
... | [
{
"docstring": "Returns the minimum energy required to move from \nthe top-left to the bottom-right corner of the grid.",
"function_declaration": "def min_energy_path(grid):",
"function_name": "min_energy_path",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "... | [
0,
0,
0,
0,
0,
1,
0,
0,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_energy(N, M, grid):\n \"\"\"\n Calculate the minimum energy required for the organism to reach the bottom-right corner of the grid.\n \n :param... | trial_gpt4o_9 | {
"original_instruction": "A group of scientists has discovered a new type of organism that exhibits interesting behavior in terms of movement. The organisms live on a 2D grid and can move from one grid cell to another based on specific movement rules. The grid is of size N x M, with each cell having a respective val... | 0.656525 | Taco_58355 | C | [
"min_energy_path",
"min_energy_required"
] | 2 | [
[
"min_energy_required",
"min_energy_path"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 327f672f599381a6f34b830836e70f5767c2b345 | beea736c80468cdea5569f9df82dab4981f62159 | |||
v1.0 | complete | Taco | Taco_58247_C | def update(array, x, y):
""" Updates the element at position x in the array to y.
>>> array = [1, 5, 2, 6, 3, 4]
>>> update(array, 3, 7)
>>> array
[1, 5, 7, 6, 3, 4]
"""
pass
def kth_one(array, l, r, k):
""" Returns the k-th smallest element in the subarray from index l to r inclusive.
... | def update(array, x, y):
"""
Updates the element at position x in the array to y.
"""
array[x-1] = y
def kth_one(array, l, r, k):
"""
Returns the k-th smallest element in the subarray from index l to r inclusive.
"""
subarray = array[l-1:r]
subarray.sort()
return subarray[k-1]
... | from solution import update, kth_one, process_queries
def test_update():
array = [1, 5, 2, 6, 3, 4]
update(array, 3, 7)
assert array == [1, 5, 7, 6, 3, 4]
def test_kth_one():
array = [1, 5, 7, 6, 3, 4]
result = kth_one(array, 2, 5, 3)
assert result == 6
result = kth_one(array, 1, 6, 4)
... | [
{
"docstring": "Updates the element at position x in the array to y.",
"function_declaration": "def update(array, x, y):",
"function_name": "update",
"parameter_list": "(array, x, y)"
},
{
"docstring": "Returns the k-th smallest element in the subarray from index l to r inclusive.",
"fun... | [
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 SegmentTree:\n def __init__(self, data):\n self.n = len(data)\n self.data = data[:]\n self.tree = [[] for _ in range(4 * self.n)]\n ... | trial_gpt4o_4 | {
"original_instruction": "Given an array of integers, you are required to perform 'Q' queries of two types on it:\n\n1. `update(x, y)`: Update the element at position 'x' of the array to 'y'.\n2. `kth_one(l, r, k)`: Find the k-th smallest element in the subarray from index 'l' to 'r' inclusive.\n\nImplement a progra... | 0.591998 | Taco_58247 | C | [
"update",
"kth_one",
"process_queries"
] | 3 | [
[
"process_queries",
"kth_one"
],
[
"process_queries",
"update"
]
] | 2 | [
"process_queries"
] | false | [] | false | pytest | true | [] | true | c7cbdc7080a3e9067a488a6ce32012deefad62bf | 7a76714c663de8e72735498b4a8230f557fdfb50 | |||
v1.0 | complete | Taco | Taco_58320_C | from typing import List, Tuple
def min_steps_each_robot(N: int, M: int, grid: List[str], robots: List[Tuple[int, int, int, int]]) -> List[int]:
"""
Determine the minimum steps required for each robot to reach its end position from its start position, or -1 if it is impossible.
Args:
N (int): The numb... | from collections import deque
def bfs(grid, start, end, N, M):
sx, sy = start
ex, ey = end
if grid[sx][sy] == '#' or grid[ex][ey] == '#':
return -1
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = [[False] * M for _ in range(N)]
queue = deque([(sx, sy, 0)]) # (row, col, steps... | from solution import min_steps_each_robot
def test_min_steps_basic():
N, M = 5, 5
grid = [
".....",
".###.",
".#.#.",
".###.",
"....."
]
robots = [(0, 0, 4, 4), (2, 2, 0, 0)]
expected = [8, -1]
assert min_steps_each_robot(N, M, grid, robots) == expected
... | [
{
"docstring": null,
"function_declaration": "def bfs(grid, start, end, N, M):",
"function_name": "bfs",
"parameter_list": "(grid, start, end, N, M)"
},
{
"docstring": null,
"function_declaration": "def min_steps_each_robot(N, M, grid, robots):",
"function_name": "min_steps_each_robo... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\ndef min_steps_to_reach(grid, start, end):\n rows, cols = len(grid), len(grid[0])\n visited = [[False] * cols for _ in range(... | trial_gpt4o_2 | {
"original_instruction": "You are given a grid of size N x M. Each cell in the grid can be either passable or blocked. You are also given a list of robot start positions and their respective end positions. Each robot can only move vertically or horizontally, one cell at a time, and cannot move into blocked cells.\n\... | 0.646464 | Taco_58320 | C | [
"bfs",
"min_steps_each_robot"
] | 2 | [
[
"min_steps_each_robot",
"bfs"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 50d410b9c6d7e32c73a2427c36fca2af32edc15d | 794fda25787a59e3c510ab8e4f1de6ad0bc1fa13 | |||
v1.0 | complete | Taco | Taco_58398_C | from typing import List, Tuple
def preprocess_grid(grid: List[List[int]]) -> List[List[int]]:
"""
Preprocess the grid to create a prefix sum matrix.
"""
pass
def query_sum(prefix_sum: List[List[int]], x1: int, y1: int, x2: int, y2: int) -> int:
"""
Query the sum of the sub-grid defined by (x1,... | def preprocess_grid(grid):
"""
Preprocess the grid to create a prefix sum matrix.
"""
n = len(grid)
m = len(grid[0])
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = (grid[i-1][j-1] +
... | def test_preprocess_grid():
grid = [
[1, 2, 4],
[8, 16, 32],
[64, 128, 256]
]
expected_prefix_sum = [
[0, 0, 0, 0],
[0, 1, 3, 7],
[0, 9, 27, 63],
[0, 73, 219, 511]
]
assert preprocess_grid(grid) == expected_prefix_sum
def test_query_sum():
... | [
{
"docstring": "Preprocess the grid to create a prefix sum matrix.",
"function_declaration": "def preprocess_grid(grid):",
"function_name": "preprocess_grid",
"parameter_list": "(grid)"
},
{
"docstring": "Query the sum of the sub-grid defined by (x1, y1) to (x2, y2).\nAdjust indices to 1-bas... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def preprocess_prefix_sum(grid):\n n = len(grid)\n m = len(grid[0])\n prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]\n \n for i in range(1, n + ... | trial_gpt4o_1 | {
"original_instruction": "You are given a 2D grid of dimensions n x m filled with non-negative integers. Your task is to handle q queries, each described by four integers x1, y1, x2, and y2 (1-based indices), which define a sub-grid. For each query, calculate the sum of all the elements within the specified sub-grid... | 0.585307 | Taco_58398 | C | [
"preprocess_grid",
"query_sum",
"handle_queries"
] | 3 | [
[
"handle_queries",
"preprocess_grid"
],
[
"handle_queries",
"query_sum"
]
] | 2 | [
"handle_queries"
] | false | [] | false | pytest | false | [] | true | 3678b57c91d7d9da725eabf2fc8ed9902676a526 | 1c6ce032e6a0167ebf070cd0afff502546dfc238 | |||
v1.0 | complete | Taco | Taco_58470_C | from typing import List, Tuple
def is_valid(x: int, y: int, n: int = 8) -> bool:
""" Check if the given position (x, y) is within the bounds of the chessboard. """
pass
def knight_moves(start_x: int, start_y: int, target_x: int, target_y: int) -> int:
""" Find the minimum number of moves a knight needs to... | from collections import deque
def is_valid(x, y, n=8):
return 1 <= x <= n and 1 <= y <= n
def knight_moves(start_x, start_y, target_x, target_y):
if (start_x, start_y) == (target_x, target_y):
return 0
directions = [
(2, 1), (2, -1), (-2, 1), (-2, -1),
(1, 2), (1, -2), (-1, 2)... | from solution import knight_moves, solve_knight_moves
def test_knight_moves_same_position():
assert knight_moves(1, 1, 1, 1) == 0
def test_knight_moves_basic():
assert knight_moves(1, 1, 8, 8) == 6
def test_knight_moves_short_distance():
assert knight_moves(1, 1, 2, 2) == 4
assert knight_moves(3, 3, ... | [
{
"docstring": null,
"function_declaration": "def is_valid(x, y, n=8):",
"function_name": "is_valid",
"parameter_list": "(x, y, n=8)"
},
{
"docstring": null,
"function_declaration": "def knight_moves(start_x, start_y, target_x, target_y):",
"function_name": "knight_moves",
"param... | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import deque\n\n# Possible knight moves\nmoves = [(2, 1), (1, 2), (-1, 2), (-2, 1), \n (-2, -1), (-1, -2), (1, -2), (2, -1)]\n\ndef is_wit... | trial_gpt4o_1 | {
"original_instruction": "Write a program that simulates the traversal of a knight in a chessboard and finds the minimum number of moves required to reach from a starting position to a target position. The knight moves in an \"L\" shape: two squares in one direction and then one square perpendicular, or one square i... | 0.643435 | Taco_58470 | C | [
"is_valid",
"knight_moves",
"solve_knight_moves",
"main"
] | 4 | [
[
"knight_moves",
"is_valid"
],
[
"solve_knight_moves",
"knight_moves"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 1011f6a9843c77ed149d214e92d3acdb35bbfc71 | 5e1622fadb530ec1cc6cf17425973f422628add3 | |||
v1.0 | complete | Taco | Taco_58419_C | def find(parent, i):
if parent[i] == -1:
return i
else:
return find(parent, parent[i])
def union(parent, x, y):
# Perform union of two subsets x and y
x_set = find(parent, x)
y_set = find(parent, y)
if x_set != y_set:
parent[x_set] = y_set
def is_fully_connected(num_... | def find(parent, i):
if parent[i] == -1:
return i
else:
return find(parent, parent[i])
def union(parent, x, y):
x_set = find(parent, x)
y_set = find(parent, y)
if x_set != y_set:
parent[x_set] = y_set
def is_fully_connected(num_cities, roads):
parent = [-1] * num_cities... | def test_check_fully_connected():
test_cases = [
(3, 3, [(1, 2), (2, 3), (3, 1)]),
(4, 2, [(1, 2), (3, 4)]),
(5, 4, [(1, 2), (2, 3), (3, 4), (4, 5)]),
(5, 3, [(1, 2), (2, 3), (3, 4)]),
(6, 6, [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 1)]),
(1, 0, []),
]
ex... | [
{
"docstring": null,
"function_declaration": "def find(parent, i):",
"function_name": "find",
"parameter_list": "(parent, i)"
},
{
"docstring": null,
"function_declaration": "def union(parent, x, y):",
"function_name": "union",
"parameter_list": "(parent, x, y)"
},
{
"doc... | [
0,
1,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def check_fully_connected(T, test_cases):\n \"\"\"\n Returns whether the network of cities in each test case is fully connected or not.\n \"\"\"\n def ... | trial_gpt4o_2 | {
"original_instruction": "In a country far away, there are N cities connected by M bidirectional roads. The government wants to improve transportation by adding new roads so that all cities are easily accessible from each other. They need your help to determine if the network of cities is already fully connected. \n... | 0.581075 | Taco_58419 | C | [
"find",
"union",
"is_fully_connected",
"check_fully_connected"
] | 4 | [
[
"check_fully_connected",
"is_fully_connected"
],
[
"is_fully_connected",
"find"
],
[
"is_fully_connected",
"union"
],
[
"union",
"find"
]
] | 4 | [] | false | [] | false | pytest | false | [] | true | 224c2b00171a0794fec4fee094f2e9fa4670b61e | d3947f023c9edf08911696a474a13a613e425688 | |||
v1.0 | complete | Taco | Taco_58702_C | def transform_string(s: str) -> str:
"""
Transforms each character in the string to the next character in the alphabet.
The alphabet is considered cyclic, so 'z' becomes 'a'.
>>> transform_string("abc") "bcd"
>>> transform_string("xyz") "yza"
>>> transform_string("hello") "ifmmp"
>>> transfo... | def transform_string(s):
"""
Transforms each character in the string to the next character in the alphabet.
The alphabet is considered cyclic, so 'z' becomes 'a'.
"""
transformed = []
for char in s:
if char == 'z':
transformed.append('a')
else:
transformed... | from solution import transform_string, transform_input
def test_transform_string():
assert transform_string("abc") == "bcd"
assert transform_string("xyz") == "yza"
assert transform_string("hello") == "ifmmp"
assert transform_string("z") == "a"
assert transform_string("az") == "ba"
assert transf... | [
{
"docstring": "Transforms each character in the string to the next character in the alphabet.\nThe alphabet is considered cyclic, so 'z' becomes 'a'.",
"function_declaration": "def transform_string(s):",
"function_name": "transform_string",
"parameter_list": "(s)"
},
{
"docstring": "Takes a... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def transform_string(s):\n \"\"\"\n Transforms a string where each character is replaced with the next character\n in the English alphabet. The alphabet i... | trial_gpt4o_2 | {
"original_instruction": "There is a mysterious island where people speak a unique dialect. The dialect consists entirely of transformations of words based on specific rules. One of the local scholars has a fascination with creating and solving puzzles using this dialect. The scholar presents you with a challenge in... | 0.637082 | Taco_58702 | C | [
"transform_string",
"transform_input"
] | 2 | [
[
"transform_input",
"transform_string"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b4cff7ff08da3ac5c16cf3cf86deb2c5b75af889 | 47e6a6d59437588c415f59447671e9dee74d0f07 | |||
v1.0 | complete | Taco | Taco_58637_C | def feedback(secret, guess):
"""
Function to provide feedback on the guess based on the secret code.
Returns a tuple (correct_position, correct_value).
>>> feedback("1234", "1234")
(4, 0)
>>> feedback("1234", "5678")
(0, 0)
>>> feedback("1234", "1243")
(2, 2)
>>> feedback("1234"... | def feedback(secret, guess):
"""
Function to provide feedback on the guess based on the secret code.
Returns a tuple (correct_position, correct_value).
"""
correct_position = 0
correct_value = 0
secret_used = [False] * len(secret)
guess_used = [False] * len(guess)
# First pass: coun... | def test_feedback_exact_match():
assert feedback("1234", "1234") == (4, 0)
def test_feedback_no_match():
assert feedback("1234", "5678") == (0, 0)
def test_feedback_partial_match():
assert feedback("1234", "1243") == (2, 2)
def test_feedback_same_digits_different_positions():
assert feedback("1234", ... | [
{
"docstring": "Function to provide feedback on the guess based on the secret code.\nReturns a tuple (correct_position, correct_value).",
"function_declaration": "def feedback(secret, guess):",
"function_name": "feedback",
"parameter_list": "(secret, guess)"
},
{
"docstring": "Simulates the ... | [
0,
0,
0,
0,
0,
0,
0,
1,
0,
1
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def mastermind(L, K, C, guesses):\n \"\"\"\n Simulates the Mastermind game between the system and the guesser.\n \n L: length of the secret code\n K... | trial_gpt4o_9 | {
"original_instruction": "H: Mastermind / Code-breaker\n\n### story\n\nMastermind is a classic code-breaking game for two players. One player sets a secret code, and the other tries to guess it. The code-setter gives feedback on how many guesses are correct in both color and position and how many are correct in colo... | 0.608582 | Taco_58637 | C | [
"feedback",
"mastermind_game"
] | 2 | [
[
"mastermind_game",
"feedback"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 25f7ab31bcb698ff34dc81324f0b442a78869d84 | 1044496441ef1109f4df183a748ff6dc0fb3c05a | |||
v1.0 | complete | Taco | Taco_58994_C | def check_nested_palindromes(T, test_cases):
""" Determine if each string in the test cases is a nested palindrome.
Args:
T (int): The number of test cases.
test_cases (List[str]): List of strings to be checked.
Returns:
List[str]: List of "YES" or "NO" for each test case.
>>> ch... | def is_palindrome(s):
"""
Check if a string s is a palindrome.
"""
return s == s[::-1]
def is_nested_palindrome(s):
"""
Check if a string s is a nested palindrome.
"""
if not is_palindrome(s):
return False
n = len(s)
# Base case for single character or empty string.... | from solution import check_nested_palindromes
def test_check_nested_palindromes():
assert check_nested_palindromes(3, ["abba", "abcba", "xyz"]) == ["YES", "YES", "NO"]
assert check_nested_palindromes(2, ["aaa", "abc"]) == ["YES", "NO"]
assert check_nested_palindromes(1, ["a"]) == ["YES"]
assert check_n... | [
{
"docstring": "Check if a string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Check if a string s is a nested palindrome.",
"function_declaration": "def is_nested_palindrome(s):",
"... | [
1,
0
] | 1 | medium | 0.5 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def is_palindrome(s):\n \"\"\"\n Check if a string s is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef is_nested_palindro... | trial_gpt4o_1 | {
"original_instruction": "Nested Palindrome\n\nAlice is fascinated by palindromes. She defines a string \\( S \\) as a \"nested palindrome\" if every palindrome within \\( S \\) can be decomposed into smaller palindromes, including single-character palindromes.\n\nGiven a string \\( S \\) of length \\( N \\), determ... | 0.721714 | Taco_58994 | C | [
"is_palindrome",
"is_nested_palindrome",
"check_nested_palindromes"
] | 3 | [
[
"check_nested_palindromes",
"is_nested_palindrome"
],
[
"is_nested_palindrome",
"is_palindrome"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 30e779c3fd3bbfb5c0cf18fc8d5baa5bff109f38 | 6a3e82ddb27c4df2511b8e044c9d4254327bbdf4 | |||
v1.0 | complete | Taco | Taco_58917_C | def is_palindrome(s: str) -> bool:
"""
Check if the string s is a palindrome.
"""
return s == s[::-1]
def min_palindromic_partitions(s: str) -> int:
"""
Returns the minimum number of palindromic substrings the string 's' can be partitioned into.
>>> min_palindromic_partitions("aab")
1
... | def is_palindrome(s):
"""
Check if the string s is a palindrome.
"""
return s == s[::-1]
def min_palindromic_partitions(s):
"""
Returns the minimum number of palindromic substrings the string 's' can be partitioned into.
"""
n = len(s)
dp = [0] * (n+1)
for i in range(n-1, -1, -1... | from solution import min_palindromic_partitions
def test_single_character():
assert min_palindromic_partitions("a") == 0
def test_two_characters_palindrome():
assert min_palindromic_partitions("aa") == 0
def test_two_characters_non_palindrome():
assert min_palindromic_partitions("ab") == 1
def test_thre... | [
{
"docstring": "Check if the string s is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns the minimum number of palindromic substrings the string 's' can be partitioned into.",
"function_... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def min_palindrome_partitions(s):\n \"\"\"\n Returns the minimum number of palindromic substrings s can be partitioned into.\n \"\"\"\n\n n = len(s)\n ... | trial_gpt4o_2 | {
"original_instruction": "-----Problem-----\n\nA string is called beautiful if it can be partitioned into one or more contiguous substrings such that each substring is a palindrome. Given a string s, determine the minimum number of palindromic substrings it can be partitioned into to make it beautiful.\n\n-----Input... | 0.773648 | Taco_58917 | C | [
"is_palindrome",
"min_palindromic_partitions"
] | 2 | [
[
"min_palindromic_partitions",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 0bb91cce9ad30d7b1e2d0a5088676ecafcd15d49 | 7f99d1443db63b00b331382bba342bd5dfa9b1a7 | |||
v1.0 | complete | Taco | Taco_58765_C | def complete_grid(matrix: List[List[int]]) -> Union[List[List[int]], int]:
""" Given a partially filled 3x3 grid, complete it to form a magic square if possible, otherwise return -1.
>>> complete_grid([
... [8, 1, 6],
... [3, 0, 0],
... [0, 0, 0]
... ])
[[8, 1, 6], [3, 5, 7]... | def is_magic_square(matrix):
"""
Check whether a 3x3 matrix is a magic square.
"""
s = sum(matrix[0])
for i in range(3):
if sum(matrix[i]) != s or sum(matrix[j][i] for j in range(3)) != s:
return False
if sum(matrix[i][i] for i in range(3)) != s or sum(matrix[i][2-i] for i in... | from solution import complete_grid
def test_complete_grid_example():
input_grid = [
[8, 1, 6],
[3, 0, 0],
[0, 0, 0]
]
output_grid = [
[8, 1, 6],
[3, 5, 7],
[4, 9, 2]
]
assert complete_grid(input_grid) == output_grid
def test_complete_grid_another():
... | [
{
"docstring": "Check whether a 3x3 matrix is a magic square.",
"function_declaration": "def is_magic_square(matrix):",
"function_name": "is_magic_square",
"parameter_list": "(matrix)"
},
{
"docstring": "Try to complete the 3x3 grid to form a magic square.",
"function_declaration": "def ... | [
0,
0,
0,
0,
1
] | 1 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_magic(square):\n # Check rows, columns and diagonals for equal sum\n target_sum = sum(square[0])\n for row in square:\n if sum(row) != targe... | trial_gpt4o_4 | {
"original_instruction": "In a fantasy land called Gridlandia, the king has a peculiar interest in magic square matrices. A magic square matrix is a square grid filled with distinct positive integers such that the sum of the integers in each row, each column, and both main diagonals are the same.\n\nGiven a 3x3 grid... | 0.588555 | Taco_58765 | C | [
"is_magic_square",
"fill_grid",
"complete_grid"
] | 3 | [
[
"complete_grid",
"fill_grid"
],
[
"fill_grid",
"is_magic_square"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 90ddbe91eb4b7312d8534262f10db142625d0fbd | d9c52a247f65bb9827d8798651007a41c8fcf7a0 | |||
v1.0 | complete | Taco | Taco_58823_C | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def create_tree(node_tuples):
if not node_tuples:
return None
nodes = {}
for val, left, right in node_tuples:
if val not in nodes:
nodes[val] = TreeNode(val)
... | class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def create_tree(node_tuples):
if not node_tuples:
return None
nodes = {}
for val, left, right in node_tuples:
if val not in nodes:
nodes[val] = TreeNode(v... | from solution import check_if_bst
def test_balanced_bst():
input_data = [(8, 3, 10), (3, 1, 6), (1, None, None), (6, 4, 7), (4, None, None), (7, None, None), (10, None, 14), (14, 13, None), (13, None, None)]
assert check_if_bst(input_data) == "YES"
def test_unbalanced_non_bst():
input_data = [(5, 1, 4), (... | [] | [
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, value=0, left=None, right=None):\n self.value = value\n self.left = left\n self.right = right\n\ndef i... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree where each node has a value. Your task is to determine if the tree is a Binary Search Tree (BST).\n\nA Binary Search Tree is a tree in which for every node, the following properties hold:\n\n1. The left subtree of a node contains only nodes with values less than ... | 0.62363 | Taco_58823 | C | [
"create_tree",
"is_bst",
"check_if_bst"
] | 3 | [
[
"check_if_bst",
"create_tree"
],
[
"check_if_bst",
"is_bst"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | ee6c8b49d4b4d5e56a5e49cad43e9587b1710f99 | 4e8d38c90d02ba92837cbeae2d5caedb5b026788 | |||
v1.0 | complete | Taco | Taco_58610_C | import os
import joblib
def train_model(training_path: str):
"""
Train sentiment analysis model using data at the specified training path.
Args:
training_path (str): The path containing training directories ('positive', 'negative', 'neutral')
Returns:
None
Notes:
Saves t... | import os
import string
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
import joblib
def load_training_data(training_path):
texts, labels = [], []
for sentiment in ['positive', 'negative', 'neutral']:
... | import pytest
import os
from solution import train_model, load_model, predict_sentiment
def setup_module(module):
# Ensure the training directory exists and contains files
if not os.path.exists('train_sent'):
os.makedirs('train_sent/positive')
os.makedirs('train_sent/negative')
os.maked... | [
{
"docstring": null,
"function_declaration": "def load_training_data(training_path):",
"function_name": "load_training_data",
"parameter_list": "(training_path)"
},
{
"docstring": null,
"function_declaration": "def train_model(training_path):",
"function_name": "train_model",
"pa... | [
1,
0,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import os\nimport string\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn.pipeline import ... | trial_gpt4o_0 | {
"original_instruction": "You've been tasked with creating a tool to help classify reviews by sentiment. Each review can either be positive, negative, or neutral. You must write a program that predicts the sentiment based on the text of the review.\n\nYou'll receive a training set of reviews to develop your sentimen... | 0.574413 | Taco_58610 | C | [
"load_training_data",
"train_model",
"load_model",
"predict_sentiment",
"main"
] | 5 | [
[
"train_model",
"load_training_data"
]
] | 1 | [] | false | [] | false | pytest | true | [
"joblib",
"sklearn"
] | false | 8264aa971ea28462f0a7a7ca3df91a674a698c97 | a639bf38b664bf75773c2228553bf08cc0388dba | |||
v1.0 | complete | Taco | Taco_58657_C | from typing import List
def is_unique(grid: List[List[int]], top: int, left: int, size: int) -> bool:
""" Check if sub-square of given size starting at (top, left) is unique """
pass
def largest_unique_subsquare(grid: List[List[int]], n: int) -> int:
""" Return the size of the largest unique sub-square. "... | def is_unique(grid, top, left, size):
""" Check if sub-square starting at (top, left) of given size is unique """
seen = set()
for i in range(top, top + size):
for j in range(left, left + size):
if grid[i][j] in seen:
return False
seen.add(grid[i][j])
retu... | def test_is_unique():
grid = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
assert is_unique(grid, 0, 0, 4) == True
assert is_unique(grid, 0, 0, 2) == True
assert is_unique(grid, 1, 1, 2) == True
grid_with_duplicates = [
[1, 2, 3, 4],
... | [
{
"docstring": "Check if sub-square starting at (top, left) of given size is unique ",
"function_declaration": "def is_unique(grid, top, left, size):",
"function_name": "is_unique",
"parameter_list": "(grid, top, left, size)"
},
{
"docstring": "Return the size of the largest unique sub-squar... | [
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_unique(grid, top, left, size):\n \"\"\" Check if sub-square starting at (top, left) of given size is unique \"\"\"\n seen = set()\n for i in range(... | trial_gpt4o_0 | {
"original_instruction": "### Problem Description\nYou are given an NxN grid filled with positive integers. Your task is to find the size of the largest sub-square which contains all unique values.\n\nA sub-square is defined as a square sub-grid within the NxN grid.\n\n### Constraints\n* 1 \\leq N \\leq 100\n* The v... | 0.593411 | Taco_58657 | C | [
"is_unique",
"largest_unique_subsquare"
] | 2 | [
[
"largest_unique_subsquare",
"is_unique"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | a015859949cd0ceda6ff514285cc4ab40058d4d2 | 2b293155293b0ebc9a5f7d49572012abe4ef9fbb | |||
v1.0 | complete | Taco | Taco_59283_C | from typing import List, Tuple
def optimize_route(points: List[Tuple[int, int]]) -> List[Tuple[int, int]]:
"""
Returns the optimal path for visiting all points exactly once and returning to the starting point,
employing a naive approach algorithm.
>>> optimize_route([(0, 0), (1, 1), (1, 0), (0, 1)])... | from typing import List, Tuple
from itertools import permutations
def euclidean_distance(point1: Tuple[int, int], point2: Tuple[int, int]) -> float:
"""
Returns the Euclidean distance between two points in 2D plane.
"""
return ((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) ** 0.5
def to... | from solution import optimize_route
def test_optimize_route_four_points():
assert optimize_route([(0, 0), (1, 1), (1, 0), (0, 1)]) == [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)] or \
optimize_route([(0, 0), (1, 1), (1, 0), (0, 1)]) == [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]
def test_optimize_route_two_po... | [
{
"docstring": "Returns the Euclidean distance between two points in 2D plane.",
"function_declaration": "def euclidean_distance(point1, point2):",
"function_name": "euclidean_distance",
"parameter_list": "(point1, point2)"
},
{
"docstring": "Returns the total distance of the given route, in... | [
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 itertools\nfrom typing import List, Tuple\n\ndef calculate_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float:\n \"\"\"\n Calculates the Eucl... | trial_gpt4o_2 | {
"original_instruction": "Design a function named `optimize_route` that takes in a list of points representing locations on a 2D plane and returns the optimal path for visiting all points exactly once and returning to the starting point, employing a naive approach algorithm.\n\n### Input\nA list of tuples, where eac... | 0.667404 | Taco_59283 | C | [
"euclidean_distance",
"total_route_distance",
"optimize_route"
] | 3 | [
[
"optimize_route",
"total_route_distance"
],
[
"total_route_distance",
"euclidean_distance"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | 8042990b01cff998cc50127116aab82def5ca6e3 | 575262cba2507bc77049e1698592394d75f1b584 | |||
v1.0 | complete | Taco | Taco_58985_C | def get_prefix_sum_matrix(matrix, n, m):
""" Helper function to compute prefix sum matrix for efficient submatrix sum queries """
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = matrix[i-1][j-1] + prefix_sum[i-1][j... | def get_prefix_sum_matrix(matrix, n, m):
""" Helper function to compute prefix sum matrix for efficient submatrix sum queries """
prefix_sum = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, m + 1):
prefix_sum[i][j] = matrix[i-1][j-1] + prefix_sum[i-1][j... | from solution import submatrix_sum
def test_single_submatrix():
n, m, q = 3, 3, 1
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
queries = [(1, 1, 3, 3)]
assert submatrix_sum(n, m, q, matrix, queries) == [45]
def test_multiple_submatrices():
n, m, q = 3, 3, 3
matrix =... | [
{
"docstring": "Helper function to compute prefix sum matrix for efficient submatrix sum queries ",
"function_declaration": "def get_prefix_sum_matrix(matrix, n, m):",
"function_name": "get_prefix_sum_matrix",
"parameter_list": "(matrix, n, m)"
},
{
"docstring": "Main function to handle mult... | [
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 get_prefix_sum_matrix(matrix, n, m):\n \"\"\" Helper function to compute prefix sum matrix for efficient submatrix sum queries \"\"\"\n prefix_sum = [[0]... | trial_gpt4o_0 | {
"original_instruction": "On a strange rectangular grid (NxM), each cell contains either a positive integer or zero. You are given Q queries and your task is to find the sum of the elements in a specified submatrix for each query. A submatrix is defined by its top-left and bottom-right corners.\n\n**Input:**\nThe fi... | 0.539886 | Taco_58985 | C | [
"get_prefix_sum_matrix",
"submatrix_sum"
] | 2 | [
[
"submatrix_sum",
"get_prefix_sum_matrix"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 97b4d05adb77c50da712f7baf431f7a004626f68 | fb348bbfe726cdf055bf51f7068df52eb02c221e | |||
v1.0 | complete | Taco | Taco_59359_C | def lexicographicRank(S: str) -> int:
""" Calculate the lexicographic rank of string S among all its permutations sorted in alphabetical order.
>>> lexicographicRank("abc") 1
>>> lexicographicRank("cba") 6
""" | def factorial(n):
"""
Returns the factorial of n.
"""
return 1 if n == 0 or n == 1 else n * factorial(n - 1)
def lexicographicRank(S):
"""
Returns the lexicographic rank of string S.
"""
n = len(S)
rank = 1
mul = factorial(n)
for i in range(n):
mul //= (n - i)
... | from solution import lexicographicRank
def test_lexicographicRank_example1():
assert lexicographicRank("abc") == 1
def test_lexicographicRank_example2():
assert lexicographicRank("cba") == 6
def test_lexicographicRank_single_character():
assert lexicographicRank("a") == 1
def test_lexicographicRank_two_... | [
{
"docstring": "Returns the factorial of n.",
"function_declaration": "def factorial(n):",
"function_name": "factorial",
"parameter_list": "(n)"
},
{
"docstring": "Returns the lexicographic rank of string S.",
"function_declaration": "def lexicographicRank(S):",
"function_name": "lex... | [
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 factorial(n):\n if n == 0 or n == 1:\n return 1\n fact = 1\n for i in range(2, n + 1):\n fact *= i\n return fact\n\ndef lexicographic... | trial_gpt4o_2 | {
"original_instruction": "Given a string S, calculate its lexicographic rank among all its possible permutations sorted in alphabetical order. Assume that all characters in the string are distinct.\n\nExample 1:\nInput: S = \"abc\"\nOutput: 1\nExplanation: All permutations of \"abc\" in lexicographic order are [\"ab... | 0.650376 | Taco_59359 | C | [
"factorial",
"lexicographicRank"
] | 2 | [
[
"lexicographicRank",
"factorial"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 224a8dc5ebf7fabb06820d1d6eda23c3f6368d2f | 89143a5b1b6632f4bcea73b1a014b12869b8cb2f | |||
v1.0 | complete | Taco | Taco_58870_C | def compute_minimum_rope_length(input_string: str) -> str:
""" Compute the minimum total rope length required to connect all the lanterns.
>>> input_data = '3\n0 2 3\n2 0 1\n3 1 0\n0\n'
>>> compute_minimum_rope_length(input_data)
'3'
>>> input_data = '4\n0 5 9 4\n5 0 1 3\n9 1 0 2\n4 3 2 0\... | import sys
import heapq
def prim_mst(n, dist_matrix):
min_cost = [sys.maxsize] * n
min_cost[0] = 0
visited = [False] * n
pq = [(0, 0)] # (cost, vertex)
total_cost = 0
while pq:
cost, u = heapq.heappop(pq)
if visited[u]:
continue
visited[u] = True
... | from solution import compute_minimum_rope_length
def test_case1():
input_data = '3\n0 2 3\n2 0 1\n3 1 0\n0\n'
expected_output = '3'
assert compute_minimum_rope_length(input_data) == expected_output
def test_case2():
input_data = '4\n0 5 9 4\n5 0 1 3\n9 1 0 2\n4 3 2 0\n0\n'
expected_output = '7'
... | [
{
"docstring": null,
"function_declaration": "def prim_mst(n, dist_matrix):",
"function_name": "prim_mst",
"parameter_list": "(n, dist_matrix)"
},
{
"docstring": null,
"function_declaration": "def minimal_rope_length(test_cases):",
"function_name": "minimal_rope_length",
"paramet... | [
1,
0,
1
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "import heapq\n\ndef compute_min_rope_length(matrix):\n n = len(matrix)\n min_heap = [(0, 0)] # (cost, vertex)\n visited = [False] * n\n total_cost = 0... | trial_gpt4o_2 | {
"original_instruction": "In a small village, there is a fascinating tradition where the villagers light lanterns during the festival, and each lantern is connected to every other lantern by a rope which has a certain length associated with it. However, due to the festival's popularity, the villagers want to minimiz... | 0.590076 | Taco_58870 | C | [
"prim_mst",
"minimal_rope_length",
"parse_input",
"format_output",
"compute_minimum_rope_length"
] | 5 | [
[
"compute_minimum_rope_length",
"format_output"
],
[
"compute_minimum_rope_length",
"minimal_rope_length"
],
[
"compute_minimum_rope_length",
"parse_input"
],
[
"minimal_rope_length",
"prim_mst"
]
] | 4 | [
"parse_input",
"format_output"
] | false | [] | false | pytest | true | [] | true | e5f9cae16251f41ea3a7878fe6caceb1e92b5f59 | 3b45f2574d90d3a4882e763aabf3aaafa36d8f93 | |||
v1.0 | complete | Taco | Taco_59188_C | def is_prime(n):
"""Helper function to check if a number is a prime."""
pass
def twisted_primes(L, R):
""" Returns a list of all 'Twisted Primes' in the range [L, R].
A number is 'Twisted Prime' if reversing its digits also results in a prime number.
The reversed number must be different from the ... | def is_prime(n):
"""Helper function to check if a number is a prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
... | from solution import twisted_primes
def test_twisted_primes_range_10_to_100():
assert twisted_primes(10, 100) == [13, 17, 31, 37, 71, 73, 79, 97]
def test_twisted_primes_range_200_to_300():
assert twisted_primes(200, 300) == [-1]
def test_twisted_primes_range_prime_reversal():
# Range with primes that re... | [
{
"docstring": "Helper function to check if a number is a prime.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of all 'Twisted Primes' in the range [L, R].",
"function_declaration": "def twisted_primes... | [
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 \"\"\"Helper function to check if a number is a prime.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n ... | trial_gpt4o_0 | {
"original_instruction": "Alice loves numbers and she recently discovered a very interesting property about some special numbers. She calls a number 'Twisted Prime' if reversing its digits also results in a prime number. Note that the reversed number must be different from the original number to be considered 'Twist... | 0.756373 | Taco_59188 | C | [
"is_prime",
"twisted_primes"
] | 2 | [
[
"twisted_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 42ca0348bce4281ec933b3def68b268f912acb93 | 7e1e15f983d4db7f6bddb2fd31a02362da2a85f2 | |||
v1.0 | complete | Taco | Taco_59143_C | def prime_ranges(n):
"""
Generates a list of tuples representing ranges of consecutive prime numbers less than or equal to n.
A range (tuple) is defined as the largest contiguous sequence of prime numbers where each prime number
in the range is separated from the next prime number by exactly 2.
... | def is_prime(n):
"""Check if a number is a prime number."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
... | from solution import prime_ranges
def test_prime_ranges_basic():
assert prime_ranges(13) == [(3, 5, 7), (11, 13)]
def test_prime_ranges_up_to_20():
assert prime_ranges(20) == [(3, 5, 7), (11, 13), (17, 19)]
def test_prime_ranges_up_to_30():
assert prime_ranges(30) == [(3, 5, 7), (11, 13), (17, 19), (29,)... | [
{
"docstring": "Check if a number is a prime number.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns a list of tuples representing ranges of consecutive primes less than or equal to n,\nwhere each prime number in t... | [
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 \"\"\"Check if a number is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == ... | trial_gpt4o_0 | {
"original_instruction": "Design a function `prime_ranges(n)` that generates a list of tuples representing ranges of consecutive prime numbers less than or equal to `n`. A range (tuple) is defined as the largest contiguous sequence of prime numbers where each prime number in the range is separated from the next prim... | 0.67952 | Taco_59143 | C | [
"is_prime",
"prime_ranges"
] | 2 | [
[
"prime_ranges",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a720392136551218637a0a79f3e7a78f04cf5e79 | 6c765c47265464dca75c9d1c25d94903e5581450 | |||
v1.0 | complete | Taco | Taco_59261_C | from typing import List
def is_prime(n: int) -> bool:
"""
Returns True if n is a prime number, otherwise returns False.
"""
pass
def check_primes(numbers: List[int]) -> List[str]:
"""
For each number in 'numbers' list, determine if it is prime,
and return a list of strings "Prime" or "Not ... | def is_prime(n):
"""
Returns True if n is a prime number, otherwise returns False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
sq_root = int(n**0.5) + 1
for i in range(3, sq_root, 2):
if n % i == 0:
return Fal... | from solution import is_prime, check_primes
def test_is_prime():
# Testing known prime numbers
assert is_prime(2) == True
assert is_prime(3) == True
assert is_prime(5) == True
assert is_prime(11) == True
assert is_prime(13) == True
# Testing known non-prime numbers
assert is_prime(1) =... | [
{
"docstring": "Returns True if n is a prime number, otherwise returns False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "For each number in 'numbers' list, determine if it is prime,\nand return a list of strings \"Pri... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise returns False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n... | trial_gpt4o_1 | {
"original_instruction": "You are given a list of integers. You need to determine for each integer whether it is a prime number or not. A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself. If a number is prime, print \"Prime\"; otherwise, print \"Not Prim... | 0.849324 | Taco_59261 | C | [
"is_prime",
"check_primes"
] | 2 | [
[
"check_primes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | c15a1a1bb2bde8c81e48c08419146a76bc001236 | 00813bd92d5fb03919818fc511f82b062f8f6bcb | |||
v1.0 | complete | Taco | Taco_59332_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def find_max_path_sum(tree_str: str) -> int:
""" Find the maximum path sum in a binary tree represented
by a serialized string of nodes in level order traversal.
... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def maxPathSum(root):
def helper(node):
nonlocal max_sum
if not node:
return 0
# Calculate the maximum path sum with respect to curre... | from solution import find_max_path_sum
def test_find_max_path_sum_simple():
assert find_max_path_sum("1 2 3") == 6
def test_find_max_path_sum_with_negatives():
assert find_max_path_sum("-10 9 20 null null 15 7") == 42
def test_find_max_path_sum_single_node():
assert find_max_path_sum("5") == 5
def test_... | [] | [
0,
0,
1
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from typing import List, Optional\n\n# Definition for a binary tree node.\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val... | trial_gpt4o_2 | {
"original_instruction": "You are given a binary tree. Your task is to find the maximum path sum. The path may start and end at any node in the tree and must move downward (traveling only from parent nodes to child nodes).\n\nA path sum is the sum of the values of nodes in a specific path.\n\nInput\n\nThe input cons... | 0.5576 | Taco_59332 | C | [
"maxPathSum",
"deserialize",
"find_max_path_sum"
] | 3 | [
[
"find_max_path_sum",
"deserialize"
],
[
"find_max_path_sum",
"maxPathSum"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | fc44f5a367c8cae9e9289deaf7de223d5864a09e | 1cf72260f3bc7d09515d2a621d21fcd2598dc90d | |||
v1.0 | complete | Taco | Taco_59121_C | def k_consecutive_increasing_subsequence_exists(n: int, k: int, sequence: List[int]) -> str:
""" Determine if there exists a subsequence of at least k consecutive increasing numbers in the sequence.
Args:
n (int): Number of elements in the sequence
k (int): Minimum length of the increasing ... | def has_k_consecutive_increasing(nums, k):
if k == 1:
return "YES" if len(nums) > 0 else "NO"
n = len(nums)
count = 1
for i in range(1, n):
if nums[i] > nums[i - 1]:
count += 1
if count >= k:
return "YES"
else:
count = 1
re... | from solution import k_consecutive_increasing_subsequence_exists
def test_example_1():
assert k_consecutive_increasing_subsequence_exists(10, 3, [1, 2, 2, 3, 4, 5, 1, 1, 1, 6]) == "YES"
def test_example_2():
assert k_consecutive_increasing_subsequence_exists(5, 4, [5, 2, 4, 6, 1]) == "NO"
def test_k_is_1():
... | [
{
"docstring": null,
"function_declaration": "def has_k_consecutive_increasing(nums, k):",
"function_name": "has_k_consecutive_increasing",
"parameter_list": "(nums, k)"
},
{
"docstring": null,
"function_declaration": "def k_consecutive_increasing_subsequence_exists(n, k, sequence):",
... | [
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 has_k_consecutive_increasing(n, k, sequence):\n \"\"\"\n Check if there exists a subsequence of at least k consecutive increasing numbers in the sequence... | trial_gpt4o_1 | {
"original_instruction": "You are given a sequence of $n$ integers and a number $k$. You need to determine if there exists a subsequence of at least $k$ consecutive increasing numbers in the sequence. \n\n-----Input-----\n\nThe first line contains two integers $n$ and $k$ ($1 \\le n, k \\le 1000$). The second line c... | 0.664199 | Taco_59121 | C | [
"has_k_consecutive_increasing",
"k_consecutive_increasing_subsequence_exists"
] | 2 | [
[
"k_consecutive_increasing_subsequence_exists",
"has_k_consecutive_increasing"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 08797e10e1fe0bc1a557a48702b6caafa1ede80f | f3e579559cbfe6e58ee9e669cbd678b94a1bd324 | |||
v1.0 | complete | Taco | Taco_58863_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def isSymmetric(root):
"""
Check if a binary tree is symmetric around its center.
"""
def isMirror(t1, t2):
if not t1 and not t2:
return ... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def isSymmetric(root):
def isMirror(t1, t2):
if not t1 and not t2:
return True
if not t1 or not t2:
return False
return (t... | from solution import check_symmetry_of_trees
def test_symmetric_trees():
assert check_symmetry_of_trees(["1 2 2 3 4 4 3"]) == ["Yes"]
def test_asymmetric_trees():
assert check_symmetry_of_trees(["1 2 2 N 3 N 3"]) == ["No"]
def test_multiple_cases():
test_cases = ["1 2 2 3 4 4 3", "1 2 2 N 3 N 3", "1 2 2"... | [] | [
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 isSymme... | trial_gpt4o_2 | {
"original_instruction": "Given a binary tree, write a function isSymmetric() that checks if the tree is symmetric around its center. A binary tree is symmetric if the left and right subtrees are mirror images of each other. \n\nInput Format:\nThe input consists of a single integer T denoting the number of test case... | 0.637216 | Taco_58863 | C | [
"isSymmetric",
"buildTree",
"check_symmetry_of_trees"
] | 3 | [
[
"check_symmetry_of_trees",
"buildTree"
],
[
"check_symmetry_of_trees",
"isSymmetric"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | a1c6b7450aef6b5d1758c731ddfa30dc15476b48 | 589ad3ea5f19e6d4ca96977b4bd9cad801465916 | |||
v1.0 | complete | Taco | Taco_59376_C | def process_surgery_data(input_lines):
"""
Returns a list of minimum number of operating rooms required for each test case.
>>> process_surgery_data(["5", "1 4", "2 5", "6 7", "3 8", "8 9", "3", "2 3", "4 5", "6 7", "0"])
[3, 1]
>>> process_surgery_data(["1", "0 1000000", "0"])
[1]
""" | def min_operating_rooms(test_cases):
"""
Returns a list of minimum number of operating rooms required for each test case.
"""
results = []
for surgeries in test_cases:
events = []
for s, t in surgeries:
events.append((s, 'start'))
events.append((t, 'end'))
... | def test_min_operating_rooms():
input_lines = [
"5",
"1 4",
"2 5",
"6 7",
"3 8",
"8 9",
"3",
"2 3",
"4 5",
"6 7",
"0"
]
expected_output = [3, 1]
assert process_surgery_data(input_lines) == expected_output
... | [
{
"docstring": "Returns a list of minimum number of operating rooms required for each test case.",
"function_declaration": "def min_operating_rooms(test_cases):",
"function_name": "min_operating_rooms",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def... | [
1,
1
] | 2 | easy | 1 | {
"trial_gpt4o_0": null,
"trial_gpt4o_1": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared1_results_combined.jsonl",
"solution_code": "def min_operating_rooms(surgeries):\n \"\"\"\n Determine the minimum number of operating rooms required to schedule all the surgerie... | trial_gpt4o_2 | {
"original_instruction": "Imagine you are tasked with developing a new scheduling algorithm for a hospital. The hospital operates with a set number of operating rooms, and each surgery requires one room for its entire duration. Each surgery also cannot overlap with another surgery in the same room.\n\nThe hospital r... | 0.530307 | Taco_59376 | C | [
"min_operating_rooms",
"parse_input",
"process_surgery_data"
] | 3 | [
[
"process_surgery_data",
"min_operating_rooms"
],
[
"process_surgery_data",
"parse_input"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 874a4c91409a27fa6d55b8a66e852637eccca489 | 3e60a40c347f6a3cd70f2cd2d65183c5908fee68 | |||
v1.0 | complete | Taco | Taco_59486_C | from typing import List, Tuple
def shortest_route(points: List[Tuple[int, int]]) -> List[Tuple[int, int]]:
""" Determine the shortest possible round trip route that visits each point exactly once and returns to the starting point.
>>> shortest_route([(0, 0), (2, 2), (2, 0), (0, 2)])
[(0, 0), (2, 0), (2, 2... | from itertools import permutations
import math
from typing import List, Tuple
def euclidean_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float:
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def calculate_route_length(route: List[Tuple[int, int]]) -> float:
length = 0.0
for i in ra... | from solution import shortest_route
def test_shortest_route_simple_case():
points = [(0, 0), (2, 2), (2, 0), (0, 2)]
result = shortest_route(points)
assert result[0] == (0, 0) and result[-1] == (0, 0), "The route must start and end at the first point."
assert len(result) == 5, "The route must have the ... | [
{
"docstring": null,
"function_declaration": "def euclidean_distance(p1, p2):",
"function_name": "euclidean_distance",
"parameter_list": "(p1, p2)"
},
{
"docstring": null,
"function_declaration": "def calculate_route_length(route):",
"function_name": "calculate_route_length",
"pa... | [
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 itertools\nimport math\nfrom typing import List, Tuple\n\ndef calculate_distance(point1: Tuple[int, int], point2: Tuple[int, int]) -> float:\n \"\"\"\n ... | trial_gpt4o_1 | {
"original_instruction": "A logistics company is trying to optimize their delivery routes. They have multiple delivery points and want to determine the shortest possible round trip route that visits each point exactly once and returns to the starting point. Can you help them by writing an algorithm to solve this pro... | 0.657737 | Taco_59486 | C | [
"euclidean_distance",
"calculate_route_length",
"shortest_route"
] | 3 | [
[
"calculate_route_length",
"euclidean_distance"
],
[
"shortest_route",
"calculate_route_length"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | aa17c6127d5fba425eab8700559adf1124e49881 | e74e756db481ac9eb97bca379f6dd458612fca0a | |||
v1.0 | complete | Taco | Taco_58952_C | def lexicographically_smallest_array_after_gcd_operations(N: int, M: int, array: List[int]) -> List[int]:
"""
Given an array of N elements and M operations, this function returns
the lexicographically smallest possible array after performing
exactly M operations.
>>> lexicographically_smallest_arra... | from math import gcd
from functools import reduce
def calculate_gcd_of_array(arr):
"""
This function calculates the GCD of all elements in the array.
"""
return reduce(gcd, arr)
def lexicographically_smallest_array_after_gcd_operations(N, M, array):
"""
Given an array of N elements and M opera... | import pytest
from solution import lexicographically_smallest_array_after_gcd_operations
def test_example_1():
N = 5
M = 1
array = [12, 15, 9, 18, 24]
expected_output = [3, 3, 3, 3, 3]
assert lexicographically_smallest_array_after_gcd_operations(N, M, array) == expected_output
def test_example_2()... | [
{
"docstring": "This function calculates the GCD of all elements in the array.",
"function_declaration": "def calculate_gcd_of_array(arr):",
"function_name": "calculate_gcd_of_array",
"parameter_list": "(arr)"
},
{
"docstring": "Given an array of N elements and M operations, this function re... | [
0,
0,
0,
0,
0,
1,
0,
0,
0
] | 1 | hard | 0.111 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from math import gcd\nfrom functools import reduce\n\ndef smallest_array_after_operations(N, M, A):\n overall_gcd = reduce(gcd, A)\n \n if M >= N - 1:\n ... | trial_gpt4o_6 | {
"original_instruction": "Takahashi has an array of N integers. He will perform the following operation exactly M times:\n\n* Choose any two elements a and b from the array (not necessarily distinct), and replace both values with their greatest common divisor (GCD).\n* Note that multiple pairs of (a, b) can be chose... | 0.594726 | Taco_58952 | C | [
"calculate_gcd_of_array",
"lexicographically_smallest_array_after_gcd_operations"
] | 2 | [
[
"lexicographically_smallest_array_after_gcd_operations",
"calculate_gcd_of_array"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | dd010169721754128f4072392470153257ccaf7a | b899d33b747ba8ef3272ff859b1cdff7de3413fd | |||
v1.0 | complete | Taco | Taco_59631_C | def almost_palindrome(s: str) -> bool:
"""
Checks if a given string is almost a palindrome.
A string is considered almost a palindrome if it can be made into a palindrome
by removing exactly one character.
Args:
s (str): Input string
Returns:
bool: True if the input string is ... | def is_palindrome(s):
"""
Helper function to check if a given string is a palindrome.
"""
return s == s[::-1]
def almost_palindrome(s):
"""
Returns True if the given string is an almost palindrome.
A string is considered an almost palindrome if it can be made into a palindrome
by removi... | from solution import almost_palindrome
def test_almost_palindrome():
assert almost_palindrome("radkar") == True
assert almost_palindrome("raceecar") == True
assert almost_palindrome("abc") == False
assert almost_palindrome("Race, Car") == True # Removing , and space, then r gets removed
assert almo... | [
{
"docstring": "Helper function to check if a given string is a palindrome.",
"function_declaration": "def is_palindrome(s):",
"function_name": "is_palindrome",
"parameter_list": "(s)"
},
{
"docstring": "Returns True if the given string is an almost palindrome.\nA string is considered an alm... | [
0,
0,
0,
0,
0,
1,
0,
0,
1,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_palindrome(s: str) -> bool:\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef preproc... | trial_gpt4o_8 | {
"original_instruction": "Description\n\nA palindrome is a string that reads the same backward as forward. Write a function that checks if a given string is almost a palindrome. A string is considered almost a palindrome if it can be made into a palindrome by removing exactly one character.\n\nThe input is a string ... | 0.842082 | Taco_59631 | C | [
"is_palindrome",
"almost_palindrome"
] | 2 | [
[
"almost_palindrome",
"is_palindrome"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7630a8002567d4b88928fb9809a708fa0d159c4b | 3a268b2c3ab50eaee5cb82af1f95769c88ae77d7 | |||
v1.0 | complete | Taco | Taco_59732_C | from typing import List
def sumOfPrimes(numbers: List[int]) -> int:
"""Calculate the sum of all prime numbers in the list.
>>> sumOfPrimes([1, 2, 3, 4, 5])
10
>>> sumOfPrimes([10, 11, 12, 13, 14])
24
>>> sumOfPrimes([4, 6, 8, 10])
0
""" | def is_prime(n):
"""
Returns True if n is a prime number, else False.
"""
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
def sumOfPrimes... | from solution import sumOfPrimes
def test_with_primes():
assert sumOfPrimes([1, 2, 3, 4, 5]) == 10
assert sumOfPrimes([10, 11, 12, 13, 14]) == 24
assert sumOfPrimes([17, 19, 23]) == 59
def test_with_no_primes():
assert sumOfPrimes([4, 6, 8, 10]) == 0
assert sumOfPrimes([1, 1, 1]) == 0
assert s... | [
{
"docstring": "Returns True if n is a prime number, else False.",
"function_declaration": "def is_prime(n):",
"function_name": "is_prime",
"parameter_list": "(n)"
},
{
"docstring": "Returns the sum of all prime numbers in the list numbers.",
"function_declaration": "def sumOfPrimes(numb... | [
1,
1,
0
] | 2 | easy | 0.667 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n retur... | trial_gpt4o_0 | {
"original_instruction": "Given a list of integers, write a function that calculates the sum of all prime numbers in the list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example:\n\n```\nsumOfPrimes([1, 2, 3, 4, 5]) = 10 // 2 + 3 + 5\nsumOfPrimes([... | 0.684677 | Taco_59732 | C | [
"is_prime",
"sumOfPrimes"
] | 2 | [
[
"sumOfPrimes",
"is_prime"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a236bc1e49b53599bc86d7738e2e672729920768 | f095c2e9306ff4c290c510ed9be7285c4addff05 | |||
v1.0 | complete | Taco | Taco_59473_C | def generate_triangle(base_length):
"""
Generate a triangle pattern of numbers with the specified base length.
Args:
base_length (int): The base length and the height of the triangle.
Returns:
List[str]: A list of strings representing each row of the triangle.
"""
pass
def gen... | def generate_triangle(base_length):
"""
Generate a triangle pattern of numbers with the specified base length.
Args:
base_length (int): The base length and the height of the triangle.
Returns:
List[str]: A list of strings representing each row of the triangle.
"""
triangle = []... | from solution import generate_triangle, generate_patterns
def test_generate_triangle_base_2():
expected_output = ["12", "23"]
assert generate_triangle(2) == expected_output
def test_generate_triangle_base_3():
expected_output = ["123", "234", "345"]
assert generate_triangle(3) == expected_output
def ... | [
{
"docstring": "Generate a triangle pattern of numbers with the specified base length.\n\nArgs:\nbase_length (int): The base length and the height of the triangle.\n\nReturns:\nList[str]: A list of strings representing each row of the triangle.",
"function_declaration": "def generate_triangle(base_length):"... | [
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 generate_triangle_patterns(N, stones):\n \"\"\"\n Given N stones and their respective base lengths, generate the triangle patterns.\n \n Args:\n ... | trial_gpt4o_9 | {
"original_instruction": "A team of archaeologists is deciphering an ancient numeric code inscribed on stones found at a site. The code forms a unique triangle pattern based on a provided number. Your task is to help them generate this pattern.\n\n-----Input:-----\n- First line will contain an integer $N$, the numbe... | 0.594588 | Taco_59473 | C | [
"generate_triangle",
"generate_patterns"
] | 2 | [
[
"generate_patterns",
"generate_triangle"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 7db939e6818ffa1a10e5c4166c8ee192c4679f76 | 680d51a8bf363c8893b235c141d9363d89995a0c | |||
v1.0 | complete | Taco | Taco_59710_C | def mini_sudoku_solver(grid: List[List[int]]) -> str:
""" Determine if the given Mini Sudoku puzzle has at least one valid solution.
>>> mini_sudoku_solver([
... [0, 0, 3, 4],
... [3, 4, 0, 0],
... [0, 3, 4, 0],
... [4, 0, 0, 3]
... ]) "YES"
>>> mini_sudoku_solver([
.... | def is_valid(grid, row, col, num):
# Check if num is not in the given row
if num in grid[row]:
return False
# Check if num is not in the given column
if num in [grid[r][col] for r in range(4)]:
return False
# Check if num is not in the 2x2 sub-grid
start_row, start_col = 2 * (r... | from solution import mini_sudoku_solver
def test_sample_input():
grid = [
[0, 0, 3, 4],
[3, 4, 0, 0],
[0, 3, 4, 0],
[4, 0, 0, 3]
]
assert mini_sudoku_solver(grid) == "YES"
def test_no_solution():
grid = [
[1, 1, 2, 3],
[3, 4, 1, 0],
[2, 3, 4, 1],... | [
{
"docstring": null,
"function_declaration": "def is_valid(grid, row, col, num):",
"function_name": "is_valid",
"parameter_list": "(grid, row, col, num)"
},
{
"docstring": null,
"function_declaration": "def solve(grid):",
"function_name": "solve",
"parameter_list": "(grid)"
},
... | [
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_valid(board, r, c, num):\n for i in range(4):\n if board[r][i] == num or board[i][c] == num:\n return False\n \n startRow, startC... | trial_gpt4o_3 | {
"original_instruction": "Kevin loves to play all sorts of games, and one of his favorite types of puzzles is Sudoku. However, he has become bored of the classic 9x9 Sudoku and decided to create his own version called Mini Sudoku. In Mini Sudoku, the grid size is 4x4, and the standard rules of Sudoku apply: each row... | 0.528634 | Taco_59710 | C | [
"is_valid",
"solve",
"mini_sudoku_solver"
] | 3 | [
[
"mini_sudoku_solver",
"solve"
],
[
"solve",
"is_valid"
]
] | 2 | [] | false | [] | false | pytest | true | [] | true | c93e53cebf5b6643d034069bb3855be4353db06d | 952eaf8fc76d2c44d290833e2c8330e1c30c8c37 | |||
v1.0 | complete | Taco | Taco_59338_C | from typing import List, Tuple
def is_subsequence(treasure: str, clue: str) -> bool:
""" Determines if 'clue' is a subsequence of 'treasure'.
Args:
treasure (str): The treasure string.
clue (str): The clue string.
Returns:
bool: True if clue is a subsequence of treasure, False otherwi... | def is_subsequence(treasure, clue):
"""
Determines if 'clue' is a subsequence of 'treasure'.
"""
it = iter(treasure)
return all(char in it for char in clue)
def count_subsequences(T, test_cases):
"""
Counts the number of clues that are subsequences of the treasure strings for each test case... | from solution import is_subsequence, count_subsequences, parse_input
def test_is_subsequence():
assert is_subsequence("TREASURE", "TRE") == True
assert is_subsequence("TREASURE", "SURE") == True
assert is_subsequence("TREASURE", "ASTR") == False
assert is_subsequence("GDVANC", "GAC") == True
assert... | [
{
"docstring": "Determines if 'clue' is a subsequence of 'treasure'.",
"function_declaration": "def is_subsequence(treasure, clue):",
"function_name": "is_subsequence",
"parameter_list": "(treasure, clue)"
},
{
"docstring": "Counts the number of clues that are subsequences of the treasure st... | [
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_subsequence(treasure, clue):\n \"\"\"\n Helper function to check if clue is a subsequence of treasure.\n \"\"\"\n it = iter(treasure)\n retur... | trial_gpt4o_2 | {
"original_instruction": "A group of friends is planning a treasure hunt. Each treasure is represented by a string of length $N$, made up of uppercase English letters. They have a map that gives clues about the treasure's location. Each clue is a string of length $M$ which might contain a sequence of characters that... | 0.617927 | Taco_59338 | C | [
"is_subsequence",
"count_subsequences",
"parse_input"
] | 3 | [
[
"count_subsequences",
"is_subsequence"
]
] | 1 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | c26c3abaa1aa49cbbd79885a6553ab58a03482b7 | 93856ce15049bfd85bf121dbe8adc3e226f6fb3a | |||
v1.0 | complete | Taco | Taco_59534_C | from typing import List
def is_valid_sudoku(board: List[str]) -> bool:
""" Check if a given Sudoku puzzle is valid.
>>> is_valid_sudoku([
"53..7....",
"6..195...",
".98....6.",
"8...6...3",
"4..8.3..1",
"7...2...6",
".6....28.",
"...419..5",
... | def is_valid_sudoku(board):
def is_valid_unit(unit):
elements = [num for num in unit if num != '.']
return len(elements) == len(set(elements))
def get_subgrid(board, start_row, start_col):
return [board[row][col] for row in range(start_row, start_row + 3) for col in range(start_col,... | def test_is_valid_sudoku():
valid_puzzle = [
"53..7....",
"6..195...",
".98....6.",
"8...6...3",
"4..8.3..1",
"7...2...6",
".6....28.",
"...419..5",
"....8..79"
]
invalid_puzzle = [
"63..7....",
"6..895...",
".9... | [
{
"docstring": null,
"function_declaration": "def is_valid_sudoku(board):",
"function_name": "is_valid_sudoku",
"parameter_list": "(board)"
},
{
"docstring": null,
"function_declaration": "def validate_sudoku_puzzles(puzzles):",
"function_name": "validate_sudoku_puzzles",
"parame... | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def is_valid_sudoku(board):\n def is_valid_unit(unit):\n elements = [num for num in unit if num != '.']\n return len(elements) == len(set(elements... | trial_gpt4o_0 | {
"original_instruction": "Create a program to determine if a given Sudoku puzzle is valid. The program should check if the puzzle board contains valid digits from 1 to 9 and adheres to Sudoku rules: each row, each column, and each of the nine 3x3 sub-grids must contain all unique digits from 1 to 9 only once.\n\nInp... | 0.555567 | Taco_59534 | C | [
"is_valid_sudoku",
"validate_sudoku_puzzles"
] | 2 | [
[
"validate_sudoku_puzzles",
"is_valid_sudoku"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | 3dccf0ba4d792f932dcaa179378b10ae63af2a49 | 934500951fdae989b55e9ea85041299f601c31d8 | |||
v1.0 | complete | Taco | Taco_59679_C | from typing import List, Tuple
def parse_orders(input_data: str) -> List[List[Tuple[str, int, float]]]:
"""
Parses the input data and returns a list where each element is a list of tuples representing an order.
>>> input_data = "2\n3\nburger 2 5.00\nfries 1 2.50\ncola 1 1.25\n2\npizza 1 10.00\nwater ... | from typing import List, Tuple
def parse_orders(input_data: str) -> List[List[Tuple[str, int, float]]]:
"""
Parses the input data and returns a list where each element is a list of tuples representing an order.
"""
lines = input_data.strip().split('\n')
n = int(lines[0])
index = 1
orders = ... | import pytest
from solution import parse_orders, compute_order_cost, compute_total_cost
def test_parse_orders():
input_data = "2\n3\nburger 2 5.00\nfries 1 2.50\ncola 1 1.25\n2\npizza 1 10.00\nwater 2 1.00"
expected_output = [
[("burger", 2, 5.00), ("fries", 1, 2.50), ("cola", 1, 1.25)],
[("piz... | [
{
"docstring": "Parses the input data and returns a list where each element is a list of tuples representing an order.",
"function_declaration": "def parse_orders(input_data):",
"function_name": "parse_orders",
"parameter_list": "(input_data)"
},
{
"docstring": "Takes an order and returns th... | [
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 typing import List, Tuple\n\ndef parse_orders(input_data: str) -> List[List[Tuple[str, int, float]]]:\n \"\"\"\n Parses the input data and returns a lis... | trial_gpt4o_0 | {
"original_instruction": "You have been assigned the task of developing a new software system for managing orders in a restaurant. One of the functionalities is to compute the total cost of orders placed by customers.\n\nEach customer can place multiple orders, and each order consists of multiple items. Each item ha... | 0.571534 | Taco_59679 | C | [
"parse_orders",
"compute_order_cost",
"compute_total_cost"
] | 3 | [
[
"compute_total_cost",
"compute_order_cost"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | b451b207d95b3561508a115979585750a54b8c9b | fa578f5ce99aaff5af3f9c71c2aa9bb2101fc3b5 | |||
v1.0 | complete | Taco | Taco_59796_C | def largest_contiguous_area(grid: List[List[str]]) -> int:
""" Given a grid of tiles represented by their colors in uppercase English
letters, find the area of the largest rectangular subgrid where all tiles
have the same color.
>>> largest_contiguous_area(["AAA", "AAA", "AAA"])
9
>>> largest_co... | def largest_contiguous_area(grid):
R = len(grid)
C = len(grid[0]) if R > 0 else 0
max_area = 0
for row_start in range(R):
for col_start in range(C):
color = grid[row_start][col_start]
for row_end in range(row_start, R):
for col_end in range(col_start,... | def test_largest_contiguous_area_single_color_grid():
grid = [
"AAA",
"AAA",
"AAA"
]
assert largest_contiguous_area(grid) == 9
def test_largest_contiguous_area_mixed_colors():
grid = [
"ABAA",
"ABBB",
"ABBB",
"AAAA",
"BBBB"
]
asser... | [
{
"docstring": null,
"function_declaration": "def largest_contiguous_area(grid):",
"function_name": "largest_contiguous_area",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def check_uniform(grid, row_start, col_start, row_end, col_end, color):",
"functi... | [
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 largest_contiguous_area(grid):\n R = len(grid)\n C = len(grid[0]) if R > 0 else 0\n max_area = 0\n \n for row_start in range(R):\n for co... | trial_gpt4o_0 | {
"original_instruction": "A famous artist specializes in creating mosaic artwork using colorful square tiles. Each tile has a unique color, represented by an uppercase English letter (from 'A' to 'Z'). He arranges these tiles in a grid with R rows and C columns. The artist wants to know the largest contiguous rectan... | 0.645161 | Taco_59796 | C | [
"largest_contiguous_area",
"check_uniform",
"parse_input",
"solve"
] | 4 | [
[
"largest_contiguous_area",
"check_uniform"
],
[
"solve",
"largest_contiguous_area"
],
[
"solve",
"parse_input"
]
] | 3 | [
"parse_input"
] | false | [] | false | pytest | false | [] | true | 1ba34b4485f918e521db80d049573a277ed7c44f | 5e27c609d0474ef8a8b9b051a81225a9bd41b383 | |||
v1.0 | complete | Taco | Taco_59326_C | from collections import deque
from typing import List
def shortest_path_in_grid(M: int, N: int, Sx: int, Sy: int, Dx: int, Dy: int, grid: List[str]) -> int:
""" Computes the minimum number of steps required to move from the starting cell to the destination cell in a grid.
Parameters:
M (int): Number of ro... | from collections import deque
def shortest_path_in_grid(M, N, Sx, Sy, Dx, Dy, grid):
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
Sx -= 1
Sy -= 1
Dx -= 1
Dy -= 1
queue = deque([(Sx, Sy, 0)])
visited = set()
visited.add((Sx, Sy))
while queue:
x, y, steps = queue.pople... | def test_shortest_path_in_grid():
# Test Example 1
M = 5
N = 5
Sx = 1
Sy = 1
Dx = 5
Dy = 5
grid = [
".....",
"..#..",
"..#..",
"..#..",
"....."
]
assert shortest_path_in_grid(M, N, Sx, Sy, Dx, Dy, grid) == 8
# Test Example 2
M = 3
... | [
{
"docstring": null,
"function_declaration": "def shortest_path_in_grid(M, N, Sx, Sy, Dx, Dy, grid):",
"function_name": "shortest_path_in_grid",
"parameter_list": "(M, N, Sx, Sy, Dx, Dy, grid)"
},
{
"docstring": null,
"function_declaration": "def read_input_and_compute():",
"function... | [
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 collections import deque\n\ndef shortest_path_in_grid(M, N, Sx, Sy, Dx, Dy, grid):\n directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n Sx -= 1\n Sy -... | trial_gpt4o_0 | {
"original_instruction": "A group of friends is playing a game on a grid. The grid has M rows and N columns. Each cell in the grid can either be empty or contain a block. The friends move from one cell to another adjacent cell. Adjacent cells are those that share an edge either horizontally or vertically (not diagon... | 0.749383 | Taco_59326 | C | [
"shortest_path_in_grid",
"read_input_and_compute"
] | 2 | [
[
"read_input_and_compute",
"shortest_path_in_grid"
]
] | 1 | [] | false | [] | false | pytest | false | [] | true | d82ba87602aff41aac6bf527e655c349aea87701 | f458accc2da4b648ec8b06de1b161f0eec58b128 | |||
v1.0 | complete | Taco | Taco_59914_C | def solve(n, q, scores, edges, queries):
"""
A software company implements a system for monitoring user activities on its platform. The platform has a tree structure representing a hierarchy of different modules, where each module is connected to its parent module.
Each module has an associated activity s... | class TreeNode:
def __init__(self, index, score):
self.index = index
self.score = score
self.children = []
self.parent = None
def build_tree(n, scores, edges):
nodes = [TreeNode(i, scores[i-1]) for i in range(1, n+1)]
for u, v in edges:
nodes[u-1].children.appen... | def test_case_1():
n = 5
q = 3
scores = [1, 5, 3, 2, 4]
edges = [(1, 2), (1, 3), (2, 4), (2, 5)]
queries = [(1, 4), (4, 5), (3, 4)]
expected_result = [5, 5, 5]
assert solve(n, q, scores, edges, queries) == expected_result
def test_case_2():
n = 4
q = 2
scores = [8, 6, 7, 5]
... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "from collections import defaultdict, deque\n\ndef build_tree(n, edges):\n tree = defaultdict(list)\n for u, v in edges:\n tree[u].append(v)\n t... | trial_gpt4o_1 | {
"original_instruction": "A software company implements a system for monitoring user activities on its platform. The platform has a tree structure representing a hierarchy of different modules, where each module is connected to its parent module.\n\nEach module has an associated activity score which represents the u... | 0.653146 | Taco_59914 | C | [
"build_tree",
"preprocess_lca",
"query_max_score",
"solve"
] | 4 | [
[
"solve",
"build_tree"
],
[
"solve",
"preprocess_lca"
],
[
"solve",
"query_max_score"
]
] | 3 | [] | false | [
"TreeNode"
] | true | pytest | false | [] | true | 2a399a664788f1744867696794ffebf8e9f28209 | b43123548791d448e705e8d73889ef919037b5fd | |||
v1.0 | complete | Taco | Taco_59924_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def is_unival_tree(root):
"""
Determines if a binary tree is a uni-value tree.
"""
def deserialize(data):
"""
Deserializes a space-separated string input... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def is_unival_tree(root):
"""
Determines if a binary tree is a uni-value tree.
"""
if not root:
return True
val = root.val
def dfs(n... | from solution import is_unival_tree_from_str
def test_unival_tree():
assert is_unival_tree_from_str("1 1 1 1 1 null null") == True
assert is_unival_tree_from_str("2 2 2 null null 5 2") == False
assert is_unival_tree_from_str("1 1 1 1 1 1 1") == True
assert is_unival_tree_from_str("1") == True
asser... | [] | [
1,
1,
1
] | 3 | easy | 1 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef constru... | trial_gpt4o_1 | {
"original_instruction": "A binary tree is called a uni-value binary tree if all nodes of the tree have the same value. Given a binary tree, your task is to determine if it is a uni-value binary tree.\n\n### Constraints\n- The number of nodes in the tree will be in the range [1, 1000].\n- Each node will have a value... | 0.587853 | Taco_59924 | C | [
"is_unival_tree",
"deserialize",
"is_unival_tree_from_str"
] | 3 | [
[
"is_unival_tree_from_str",
"deserialize"
],
[
"is_unival_tree_from_str",
"is_unival_tree"
]
] | 2 | [] | false | [
"TreeNode"
] | true | pytest | true | [] | true | 1623362a8c9b2e51bcb78203291caed87d6ab2fa | 684dc53eb4accb91939e434cff49b38bc1911258 | |||
v1.0 | complete | Taco | Taco_59981_C | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def buildTree(levelOrder):
if not levelOrder or levelOrder[0] == -1:
return None
root = TreeNode(levelOrder[0])
queue = [root]
i = 1
whi... | class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def buildTree(levelOrder):
if not levelOrder or levelOrder[0] == -1:
return None
root = TreeNode(levelOrder[0])
queue = [root]
i = 1
whi... | from solution import findTreeHeight, evaluateTestCases
def test_basic_cases():
testCases = [
[3, 9, 20, -1, -1, 15, 7],
[1, -1, 2, -1, -1]
]
expected = [3, 2]
assert evaluateTestCases(testCases) == expected
def test_single_node():
testCases = [
[1]
]
expected = [1]
... | [] | [
0,
1,
0
] | 1 | medium | 0.333 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "class TreeNode:\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right = None\n\ndef findTreeHeight(root):\n if ... | trial_gpt4o_1 | {
"original_instruction": "Given a binary tree, your task is to complete the function findTreeHeight() which takes the root of the binary tree as input and returns the height of the tree.\nInput:\nThe input line contains T, denoting the number of test cases. Each test case contains a binary tree in level-order traver... | 0.567679 | Taco_59981 | C | [
"buildTree",
"findTreeHeight",
"evaluateTestCases"
] | 3 | [
[
"evaluateTestCases",
"buildTree"
],
[
"evaluateTestCases",
"findTreeHeight"
]
] | 2 | [
"evaluateTestCases"
] | false | [
"TreeNode"
] | true | pytest | true | [] | true | f88e91edf4835d4bfc709c5c3eedba9272a35409 | 08a971ca6df862974ce002a1bb608727a0fb4234 | |||
v1.0 | complete | Taco | Taco_60001_C | def will_birds_migrate(test_cases):
""" Determine if birds will migrate based on weather patterns.
Args:
test_cases: List of tuples, where each tuple contains:
N: Length of binary string (int)
L: Length of the subsequence (int)
binary_string: S... | def will_birds_migrate(test_cases):
results = []
for case in test_cases:
N, L, binary_string = case
found = False
for i in range(N - L + 1):
substring = binary_string[i:i + L]
if substring.count('1') > substring.count('0'):
found = True
... | import pytest
from solution import will_birds_migrate, parse_input, solution
def test_will_birds_migrate():
test_cases = [
(7, 3, '1011010'),
(5, 2, '01101'),
(6, 4, '000011')
]
expected = ["YES", "YES", "NO"]
assert will_birds_migrate(test_cases) == expected
def test_parse_in... | [
{
"docstring": null,
"function_declaration": "def will_birds_migrate(test_cases):",
"function_name": "will_birds_migrate",
"parameter_list": "(test_cases)"
},
{
"docstring": null,
"function_declaration": "def parse_input(input_data):",
"function_name": "parse_input",
"parameter_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 bird_migration(T, test_cases):\n results = []\n for i in range(T):\n N, L = test_cases[i][0]\n pattern = test_cases[i][1]\n \n ... | trial_gpt4o_2 | {
"original_instruction": "You are an environmental researcher studying the migration patterns of a special species of birds. Surprisingly, the birds' migratory habits are influenced by sequences of weather patterns. Your task is to write a program that can analyze the weather patterns to predict whether the birds wi... | 0.543947 | Taco_60001 | C | [
"will_birds_migrate",
"parse_input",
"solution"
] | 3 | [
[
"solution",
"parse_input"
],
[
"solution",
"will_birds_migrate"
]
] | 2 | [
"parse_input"
] | false | [] | false | pytest | true | [] | true | 72ca9e895e89491a30523279c5c5f8e098359d9d | 07df30949a51a833440190652495b077fce91f10 | |||
v1.0 | complete | Taco | Taco_60082_C | def is_palindromic(number):
"""
Returns True if the number is palindromic, False otherwise.
>>> is_palindromic(1) True
>>> is_palindromic(9) True
>>> is_palindromic(11) True
>>> is_palindromic(22) True
>>> is_palindromic(121) True
>>> is_palindromic(123) False
"""
def count_pal... | def is_palindromic(number):
"""
Returns True if the number is palindromic, False otherwise.
"""
return str(number) == str(number)[::-1]
def count_palindromic_numbers(a, b):
"""
Returns the count of palindromic numbers in the range [a, b] inclusive.
"""
count = 0
for number in range(... | from solution import is_palindromic, count_palindromic_numbers
def test_is_palindromic():
assert is_palindromic(1) == True
assert is_palindromic(9) == True
assert is_palindromic(11) == True
assert is_palindromic(22) == True
assert is_palindromic(121) == True
assert is_palindromic(123) == False
... | [
{
"docstring": "Returns True if the number is palindromic, False otherwise.",
"function_declaration": "def is_palindromic(number):",
"function_name": "is_palindromic",
"parameter_list": "(number)"
},
{
"docstring": "Returns the count of palindromic numbers in the range [a, b] inclusive.",
... | [
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 count_palindromic_numbers(a, b):\n \"\"\"\n Returns the number of palindromic numbers between a and b, inclusive.\n\n Parameters:\n a (int): The st... | trial_gpt4o_5 | {
"original_instruction": "Bob loves palindromic numbers. He finds them to be symmetrical and beautiful. Bob defines a number as palindromic if it reads the same backward as forward. Bob wants to know how many palindromic numbers exist in a given range [a, b].\n\nWrite a program to help Bob count the number of palind... | 0.752798 | Taco_60082 | C | [
"is_palindromic",
"count_palindromic_numbers"
] | 2 | [
[
"count_palindromic_numbers",
"is_palindromic"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | a6078d928a93c8ec0932f5dc9d1ba7568eeec40e | 2ec486427601a4074be3f49c57994bef6b798d8b | |||
v1.0 | complete | Taco | Taco_60047_C | def game_of_life(initial_state: List[List[int]], T: int) -> List[List[int]]:
""" Determine the state of the rectangular grid after a certain number of time steps.
>>> game_of_life([[0, 1, 0],[0, 0, 1],[1, 1, 1]], 1)
[[0, 0, 0], [1, 0, 1], [0, 1, 1]]
>>> game_of_life([[1, 1, 0],[1, 0, 1],[0, 1, 1]], 1)
... | def get_next_state(grid):
m, n = len(grid), len(grid[0])
next_grid = [[0] * n for _ in range(m)]
def count_live_neighbors(x, y):
directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
count = 0
for dx, dy in directions:
nx, ny = x + dx, y... | from solution import game_of_life
def test_game_of_life_1():
initial_state = [[0, 1, 0],
[0, 0, 1],
[1, 1, 1]]
T = 1
expected_state = [[0, 0, 0],
[1, 0, 1],
[0, 1, 1]]
assert game_of_life(initial_state, T) == expected... | [
{
"docstring": null,
"function_declaration": "def get_next_state(grid):",
"function_name": "get_next_state",
"parameter_list": "(grid)"
},
{
"docstring": null,
"function_declaration": "def game_of_life(initial_state, T):",
"function_name": "game_of_life",
"parameter_list": "(init... | [
0,
0,
0,
0,
0,
1,
1,
0,
0,
0
] | 2 | hard | 0.2 | {
"trial_gpt4o_0": {
"file_source": "CodeGen_instruction_taco-i2i_100000_1739866661_sanitized_prepared0_results_combined.jsonl",
"solution_code": "def get_neighbors_count(grid, row, col):\n \"\"\"\n Helper function to count populated neighbors of a cell in the grid.\n \"\"\"\n rows = len(grid)\n ... | trial_gpt4o_6 | {
"original_instruction": "# Task\nYou have a rectangular grid of cells with `m` rows and `n` columns. Each cell in the grid can be in one of two states: populated (represented by 1) or unpopulated (represented by 0). The grid evolves over discrete time steps according to the following rules:\n1. Any populated cell w... | 0.622782 | Taco_60047 | C | [
"get_next_state",
"game_of_life"
] | 2 | [
[
"game_of_life",
"get_next_state"
]
] | 1 | [] | false | [] | false | pytest | true | [] | true | 45606337a7c7278275c67ab773aa36814c64a69b | 6a732a6eca411441ec7d4cfef2cb805e0ee64e37 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.