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
Apps
Apps_4208_C
from typing import List def find_unique_subsets(arr: List[int]) -> List[List[int]]: """ Returns all unique subsets of the given list in lexicographical order. """ def format_subsets_for_output(subsets: List[List[int]]) -> str: """ Converts each subset into a string in the form of space-separated i...
def find_unique_subsets(arr): """ Returns all unique subsets of the given list in lexicographical order. """ def backtrack(start, path): result.append(path[:]) for i in range(start, len(arr)): if i > start and arr[i] == arr[i - 1]: continue path.ap...
from solution import find_unique_subsets, format_subsets_for_output, unique_subsets def test_find_unique_subsets_empty(): assert find_unique_subsets([]) == [[]] def test_find_unique_subsets_no_duplicates(): assert find_unique_subsets([1, 2, 3]) == [ [], [1], [1, 2], [1, 2, 3], ...
[ { "docstring": "Returns all unique subsets of the given list in lexicographical order.", "function_declaration": "def find_unique_subsets(arr):", "function_name": "find_unique_subsets", "parameter_list": "(arr)" }, { "docstring": "Converts each subset into a string in the form of space-separ...
[ 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from itertools import combinations\n\ndef unique_subsets(arr):\n \"\"\"\n Returns all unique subsets of the given list of integers.\n The subsets are retur...
trial_gpt4o_8
{ "original_instruction": "=====Problem Statement=====\nYou are given a list of integers which may contain some duplicate elements. Your task is to find and print all unique subsets of the given list.\n\nA subset is a collection of elements that can be derived from the list by deleting some or none of the elements wi...
0.616334
Apps_4208
C
[ "find_unique_subsets", "format_subsets_for_output", "unique_subsets" ]
3
[ [ "unique_subsets", "find_unique_subsets" ], [ "unique_subsets", "format_subsets_for_output" ] ]
2
[]
false
[]
false
pytest
true
[]
true
746845baeb543757259144665991ef5a0ae659d4
6ec4de83f774f5d1861db60cc9a415c0cad462bf
v1.0
complete
Apps
Apps_4452_C
def is_palindrome(x: int) -> bool: """ Helper function that checks if a given number x is a palindrome. """ return str(x) == str(x)[::-1] def next_palindrome(n: int) -> int: """ Takes a positive integer n and returns the smallest palindrome number larger than n. >>> next_palindrome(123) -> ...
def is_palindrome(x): """ Helper function that checks if a given number x is a palindrome. """ return str(x) == str(x)[::-1] def next_palindrome(n): """ Takes a positive integer n and returns the smallest palindrome number larger than n. """ n += 1 while not is_palindrome(n): ...
from solution import next_palindrome def test_next_palindrome(): assert next_palindrome(123) == 131 assert next_palindrome(489) == 494 assert next_palindrome(99) == 101 assert next_palindrome(999) == 1001 assert next_palindrome(12321) == 12421 assert next_palindrome(100) == 101 assert next_...
[ { "docstring": "Helper function that checks if a given number x is a palindrome.", "function_declaration": "def is_palindrome(x):", "function_name": "is_palindrome", "parameter_list": "(x)" }, { "docstring": "Takes a positive integer n and returns the smallest palindrome number larger than n...
[ 0, 1, 0, 1, 1, 0, 1, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(num):\n \"\"\"\n Helper function to check if a number is a palindrome.\n \"\"\"\n return str(num) == str(num)[::-1]\n\ndef next_palind...
trial_gpt4o_9
{ "original_instruction": "Write a function `next_palindrome(n)` that takes a positive integer `n` as input and returns the smallest palindrome number larger than `n`. A palindrome is a number that reads the same backwards as forwards.\n\nFor example:\n```\nnext_palindrome(123) -> 131\nnext_palindrome(489) -> 494\nne...
0.797487
Apps_4452
C
[ "is_palindrome", "next_palindrome" ]
2
[ [ "next_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
adca816eb29072c33c92b777360fc795500f6675
e9ce84392c47f841e5e58629fcc0e19bfdd95df0
v1.0
complete
Apps
Apps_2908_C
def largest_square_of_ones(grids): """ Find the size of the largest square containing only 1s in each grid. >>> largest_square_of_ones([(3, 3, [[1, 1, 1], [1, 1, 1], [1, 1, 1]]), (4, 5, [[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]])]) [3, 2] >>> largest_square_of_ones([(2, 2, [[0,...
def largest_square_of_ones(grids): def find_largest_square(grid, n, m): max_side = 0 dp = [[0] * m for _ in range(n)] for i in range(n): for j in range(m): if grid[i][j] == 1: if i == 0 or j == 0: dp[i][j] = 1 ...
def test_largest_square_of_ones(): input_data_1 = "2\n3 3\n1 1 1\n1 1 1\n1 1 1\n4 5\n1 0 1 0 0\n1 0 1 1 1\n1 1 1 1 1\n1 0 0 1 0" expected_output_1 = "3\n2" assert solve(input_data_1) == expected_output_1 input_data_2 = "1\n2 2\n0 0\n0 0" expected_output_2 = "0" assert solve(input_data_2) == exp...
[ { "docstring": null, "function_declaration": "def largest_square_of_ones(grids):", "function_name": "largest_square_of_ones", "parameter_list": "(grids)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name": "process_input", "parameter...
[ 1, 1, 1, 1, 0, 1, 1, 0, 0 ]
6
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_square(grid):\n \"\"\"\n This function receives a n x m grid of 0s and 1s and returns the size of the largest square containing only 1s.\n \"\"...
trial_gpt4o_7
{ "original_instruction": "You are given a 2D grid of size $n \\times m$. Each cell in the grid has a value, which is either 0 or 1. Your task is to find the size of the largest square containing only 1s.\n\n-----Input-----\n- The first line of the input contains an integer $T$ denoting the number of test cases. The ...
0.606733
Apps_2908
C
[ "largest_square_of_ones", "process_input", "solve" ]
3
[ [ "solve", "largest_square_of_ones" ], [ "solve", "process_input" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
4936fccdeff807950c802bf79b4b7acf1aefe244
95233e9756b3f66f499c0324cfc495f4d6b7a13c
v1.0
complete
Apps
Apps_3193_C
from typing import List, Tuple, Union def find(parent, i): """Function to find the parent of node i""" pass def union(parent, rank, x, y): """Function to perform union of two sets x and y""" pass def kruskal(n, edges): """Kruskal's algorithm to find the MST of a graph""" pass def minimum_spa...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
def test_example_case(): assert minimum_spanning_tree(4, 5, [(1, 2, 1), (1, 3, 4), (2, 3, 2), (3, 4, 3), (4, 2, 5)]) == 6 def test_no_edges(): assert minimum_spanning_tree(1, 0, []) == 0 assert minimum_spanning_tree(2, 0, []) == "IMPOSSIBLE" assert minimum_spanning_tree(3, 0, []) == "IMPOSSIBLE" def t...
[ { "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, 1, 1, 1, 1, 0, 1, 0 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.parent[u]...
trial_gpt4o_5
{ "original_instruction": "You are given an undirected graph with `n` nodes and `m` edges where each node is labeled from `1` to `n`. Each edge connects two nodes and has a weight associated with it. Your task is to find the Minimum Spanning Tree (MST) of the graph using Kruskal's algorithm and output its total weigh...
0.685082
Apps_3193
C
[ "find", "union", "kruskal", "minimum_spanning_tree" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_spanning_tree", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
baf27976e2a4380171c5ea4b778fbbfcdc10febf
bae5b4f63963777044159d4ae3625e453009b03d
v1.0
complete
Apps
Apps_3871_C
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def find_maximum_path_sum(root): """ Find the maximum sum of nodes for any path in a binary tree. >>> node_values = [4, -10, 3, 5, 2] >>> edges = [(1, 2), (1, 3), (3, 4), (3, 5)] ...
class TreeNode: def __init__(self, value=0): self.value = value self.left = None self.right = None def find_maximum_path_sum(root): def helper(node): nonlocal max_sum if not node: return 0 left_max = max(helper(node.left), 0) right_max = max(h...
from solution import max_sum_for_all_cases, build_tree_from_edges, find_maximum_path_sum def test_case_1(): num_cases = 2 cases = [ (5, [4, -10, 3, 5, 2], [(1, 2), (1, 3), (3, 4), (3, 5)]), (3, [1, 2, 3], [(1, 2), (1, 3)]) ] assert max_sum_for_all_cases(num_cases, cases) == [12, 6] def...
[]
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "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 maxPathS...
trial_gpt4o_5
{ "original_instruction": "Alex is learning about binary trees. He came across a problem where he needs to determine the maximum sum of nodes for any path in a binary tree. A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A path can start an...
0.625947
Apps_3871
C
[ "find_maximum_path_sum", "build_tree_from_edges", "max_sum_for_all_cases" ]
3
[ [ "max_sum_for_all_cases", "build_tree_from_edges" ], [ "max_sum_for_all_cases", "find_maximum_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
de3c3fac527cfd7ac8acdc1ffe51ddb4fbe54284
c90b5ece63a8cb25a41d33de308de60cdd36a3bd
v1.0
complete
Apps
Apps_4523_C
def sum_of_digits_is_prime(number: int) -> bool: """ Determines if the sum of the digits of a positive integer `number` is a prime number. >>> sum_of_digits_is_prime(113) == True >>> sum_of_digits_is_prime(123) == False >>> sum_of_digits_is_prime(0) == False >>> sum_of_digits_is_prime(7) == True ...
def is_prime(n): """ Determines if a given number `n` is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def sum_of_d...
from solution import sum_of_digits_is_prime def test_sum_of_digits_is_prime_example(): assert sum_of_digits_is_prime(113) == True # 1 + 1 + 3 = 5, which is prime def test_sum_of_digits_is_prime_not_prime(): assert sum_of_digits_is_prime(123) == False # 1 + 2 + 3 = 6, which is not prime def test_sum_of_digi...
[ { "docstring": "Determines if a given number `n` is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Determines if the sum of the digits of `number` is a prime number.", "function_declaration": "def sum_...
[ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return T...
trial_gpt4o_1
{ "original_instruction": "Write a function that determines whether the sum of the digits of a positive integer is a prime number.\n\nThe function should take a single integer argument and return `true` if the sum of its digits is a prime number, and `false` otherwise (`True` and `False` for Python). \n\nFor example:...
0.761562
Apps_4523
C
[ "is_prime", "sum_of_digits_is_prime" ]
2
[ [ "sum_of_digits_is_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c1cde1de681cadd827ac64ebbeff6f74f8096f5
c9dd7cbcab5e892b7efefcc70abfc453fccf520f
v1.0
complete
Apps
Apps_3309_C
def ordinal(num): """ Converts an integer to its ordinal representation. Args: num (int): The integer to convert. Returns: str: The ordinal representation of the integer. >>> ordinal(1), "1st" >>> ordinal(2), "2nd" >>> ordinal(3), "3rd" >>> ordinal(4), "4th" >>...
def ordinal(num): """ Converts an integer to its ordinal representation. Args: num (int): The integer to convert. Returns: str: The ordinal representation of the integer. """ if 11 <= num % 100 <= 13: suffix = 'th' else: suffixes = {1: 'st', 2: 'nd', 3: 'rd'...
def test_ordinal(): assert ordinal(1) == "1st" assert ordinal(2) == "2nd" assert ordinal(3) == "3rd" assert ordinal(4) == "4th" assert ordinal(11) == "11th" assert ordinal(21) == "21st" assert ordinal(22) == "22nd" assert ordinal(23) == "23rd" def test_nth_element(): assert nth_elem...
[ { "docstring": "Converts an integer to its ordinal representation.\n\nArgs:\nnum (int): The integer to convert.\n\nReturns:\nstr: The ordinal representation of the integer.", "function_declaration": "def ordinal(num):", "function_name": "ordinal", "parameter_list": "(num)" }, { "docstring": ...
[ 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def ordinal(n):\n \"\"\"\n Convert an integer into its corresponding ordinal representation.\n \"\"\"\n if 10 <= n % 100 <= 20:\n suffix = 'th'\n...
trial_gpt4o_8
{ "original_instruction": "=====Function Description=====\n.ordinal()\n\nThis operation converts an integer into its corresponding ordinal representation.\n\nExample\n\n>>> ordinal(1)\n'1st'\n>>> ordinal(2)\n'2nd'\n>>> ordinal(3)\n'3rd'\n>>> ordinal(4)\n'4th'\n>>> ordinal(11)\n'11th'\n>>> ordinal(21)\n'21st'\n>>> ord...
0.625911
Apps_3309
C
[ "ordinal", "nth_element", "find_ordinal_at_index" ]
3
[ [ "find_ordinal_at_index", "nth_element" ], [ "find_ordinal_at_index", "ordinal" ] ]
2
[]
false
[]
false
pytest
false
[]
true
4b5c1ebdd7d90e3bbbc9bfa12709c98904ac2689
035841ba8853f912475befe7ada7323d16a12dce
v1.0
complete
Apps
Apps_3617_C
from collections import deque, defaultdict from typing import List, Tuple def max_shortest_distance(n: int, roads: List[Tuple[int, int]]) -> int: """ Determine the maximum possible shortest distance between any pair of cities after adding exactly one new road >>> max_shortest_distance(5, [(1, 2), (1, 3), (3, 4...
from collections import deque, defaultdict def find_farthest_node(start, graph, n): visited = [False] * (n + 1) dist = [0] * (n + 1) queue = deque([start]) visited[start] = True farthest_node = start while queue: node = queue.popleft() for neighbor in graph[no...
def test_max_shortest_distance(): assert max_shortest_distance(5, [(1, 2), (1, 3), (3, 4), (3, 5)]) == 2 assert max_shortest_distance(4, [(1, 2), (2, 3), (3, 4)]) == 2 assert max_shortest_distance(3, [(1, 2), (1, 3)]) == 1 assert max_shortest_distance(2, [(1, 2)]) == 1 assert max_shortest_distance(6...
[ { "docstring": null, "function_declaration": "def find_farthest_node(start, graph, n):", "function_name": "find_farthest_node", "parameter_list": "(start, graph, n)" }, { "docstring": null, "function_declaration": "def max_shortest_distance(n, roads):", "function_name": "max_shortest...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(tree, start):\n n = len(tree)\n distance = [-1] * n\n distance[start] = 0\n queue = deque([start])\n while q...
trial_gpt4o_3
{ "original_instruction": "Linova has been inspired by the diverse landscapes in her kingdom and wants to create a unique way for her people to travel. The kingdom can be represented as a tree with `n` nodes (cities) and `n-1` edges (roads). A path between two cities is defined as the sequence of node visits starting...
0.686716
Apps_3617
C
[ "find_farthest_node", "max_shortest_distance" ]
2
[ [ "max_shortest_distance", "find_farthest_node" ] ]
1
[]
false
[]
false
pytest
false
[]
true
c539e55e94ce58d584c9c1473aaebbc5d6997255
85857007af8cd3d0c51a08328c814b637c2f1228
v1.0
complete
Apps
Apps_4131_C
def longest_prime_length_increasing_subsequence(signal_strengths: List[int]) -> int: """ Returns the length of the longest strictly increasing subsequence with a prime length. >>> longest_prime_length_increasing_subsequence([3, 2, 1, 2, 3, 5, 6, 4, 1, 2, 3]) 5 >>> longest_prime_length_incr...
def is_prime(n): """Check if an integer n is a prime number.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return T...
from solution import longest_prime_length_increasing_subsequence def test_longest_prime_length_increasing_subsequence(): assert longest_prime_length_increasing_subsequence([3, 2, 1, 2, 3, 5, 6, 4, 1, 2, 3]) == 5 assert longest_prime_length_increasing_subsequence([1, 2, 3, 4, 5, 6, 7, 8, 9]) == 7 # [1, 2, 3, 4...
[ { "docstring": "Check if an integer n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the length of the longest strictly increasing subsequence with a prime length.", "function_declaration": ...
[ 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Check if an integer n 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": "Henry the Wi-Fi hacker has another challenge for you. Given a list of Wi-Fi networks represented by their signal strengths, he wants to determine the longest consecutive sequence of networks with strictly increasing signal strengths. However, this time he wants you to find the longest seque...
0.684902
Apps_4131
C
[ "is_prime", "longest_prime_length_increasing_subsequence" ]
2
[ [ "longest_prime_length_increasing_subsequence", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
61f88001bb7fcad6b34e7bc48254a42908c9c799
d6230614bed4b0f74174bc3ac0dc40cf9035c2cd
v1.0
complete
Apps
Apps_4122_C
def is_palindrome(n: int) -> bool: """ Check if a given number n is a palindrome. """ return str(n) == str(n)[::-1] def smallest_palindrome_multiple(x: int) -> int: """ Find the smallest positive integer that is a multiple of x and a palindrome. """ i = 1 while True: if is_p...
def is_palindrome(n): """ Check if a given number n is a palindrome. """ return str(n) == str(n)[::-1] def smallest_palindrome_multiple(x): """ Find the smallest positive integer that is a multiple of x and a palindrome. """ i = 1 while True: if is_palindrome(i) and i % x ==...
from solution import solve def test_sample(): T = 2 test_cases = [1, 5] assert solve(T, test_cases) == [1, 5] def test_single_digit_palindromes(): T = 5 test_cases = [1, 2, 3, 4, 5] assert solve(T, test_cases) == [1, 2, 3, 4, 5] def test_larger_palindromes(): T = 2 test_cases = [11, 2...
[ { "docstring": "Check if a given number n is a palindrome.", "function_declaration": "def is_palindrome(n):", "function_name": "is_palindrome", "parameter_list": "(n)" }, { "docstring": "Find the smallest positive integer that is a multiple of x and a palindrome.", "function_declaration"...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(n):\n \"\"\"\n Check if a given integer is a palindrome.\n \"\"\"\n num_str = str(n)\n return num_str == num_str[::-1]\n\ndef small...
trial_gpt4o_4
{ "original_instruction": "Ravi loves playing with numbers. He came across a game where he has to find the smallest positive integer that is a multiple of a given number 'X' and also forms a palindrome when written in decimal notation. Ravi needs your help to solve this problem efficiently.\n\n-----Input:-----\n- The...
0.709872
Apps_4122
C
[ "is_palindrome", "smallest_palindrome_multiple", "solve" ]
3
[ [ "smallest_palindrome_multiple", "is_palindrome" ], [ "solve", "smallest_palindrome_multiple" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d528fad3753ef2afd885984e891ad54ce5b74dc2
5baf371216429bf0d9bac5947a223d64985256d7
v1.0
complete
Apps
Apps_3738_C
from typing import List, Tuple def sort_invitations(n: int, invitations: List[Tuple[str, int]]) -> List[Tuple[str, int]]: """ Sorts invitations by priority level in descending order, and by name in alphabetical order for the same priority level. Parameters: - n: int, number of invitations - in...
def sort_invitations(n, invitations): """ Sorts invitations by priority level in descending order, and by name in alphabetical order for the same priority level. Parameters: - n: int, number of invitations - invitations: List of tuples [(name, priority), ...] Returns: - List of tuples ...
from solution import process_invitations def test_process_invitations_example(): input_data = "5\nJane 2\nDavid 3\nAlice 2\nBob 1\nCharlie 3" expected_output = "Charlie 3\nDavid 3\nAlice 2\nJane 2\nBob 1" assert process_invitations(input_data) == expected_output def test_process_invitations_same_priority(...
[ { "docstring": "Sorts invitations by priority level in descending order,\nand by name in alphabetical order for the same priority level.\n\nParameters:\n- n: int, number of invitations\n- invitations: List of tuples [(name, priority), ...]\n\nReturns:\n- List of tuples [(name, priority), ...] sorted accordingly...
[ 1, 1, 0, 1, 1, 0, 1, 1, 1, 0 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sort_invitations(n, invitations):\n \"\"\"\n Sort invitations by priority in descending order, and by name in alphabetical order for the same priority.\n ...
trial_gpt4o_7
{ "original_instruction": "Ali is working on a project to help with event management. He is tasked with creating a program to manage invitations to guests. Each invitation has a guest's name and a priority level. Ali needs to write a function that sorts the invitations first by priority level in descending order, and...
0.581416
Apps_3738
C
[ "sort_invitations", "process_invitations" ]
2
[ [ "process_invitations", "sort_invitations" ] ]
1
[]
false
[]
false
pytest
true
[]
true
03b850af1fcd801f56371527f20ea288a20bf97b
06c40fba3047d1baf0feb898bc8270d4db60db78
v1.0
complete
Apps
Apps_3983_C
def is_prime(num: int) -> bool: """ Helper function to determine if a number is prime. >>> is_prime(-1) False >>> is_prime(0) False >>> is_prime(1) False >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(5) True >>> is_prime(9) False >>> is_prime(37) Tr...
def is_prime(num): """ Helper function to determine if a number is prime. """ if num <= 1: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False return True d...
from solution import is_prime, filter_primes def test_is_prime(): assert not is_prime(-1) assert not is_prime(0) assert not is_prime(1) assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) assert is_prime(37) assert not is_prime(...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Return a new array containing only the prime numbers from the original array.", "function_declarati...
[ 0, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 =...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes an array of integers and returns a new array containing only the prime numbers from the original array. If no prime numbers are found, the function should return an empty array. \n\nThe function should filter the list in such a way that preserves the original ord...
0.741992
Apps_3983
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9da45540b48504fef16e368e0416ebb4ee38171
fb91e35cb2570dfe1fe11bdfd821a10d2619cbdd
v1.0
complete
Apps
Apps_3453_C
def can_accommodate_reservations(test_cases): """Determine if all reservations in the list can be accommodated without any time overlap for any of the tables. >>> can_accommodate_reservations([[(1, 3), (2, 5), (4, 6)], [(1, 2), (2, 3)]]) ['REJECTED', 'ACCEPTED'] """ # Implement your solution he...
def can_accommodate_reservations(test_cases): results = [] for reservations in test_cases: reservations.sort() # Sort by start time accepted = True for i in range(1, len(reservations)): if reservations[i][0] < reservations[i - 1][1]: accepted = False ...
from solution import restaurant_reservations def test_sample_input(): input_text = "2\n3\n1 3\n2 5\n4 6\n2\n1 2\n2 3\n" expected_output = "REJECTED\nACCEPTED\n" assert run_test_case(input_text) == expected_output def run_test_case(input_text): import sys from io import StringIO old_stdout = s...
[ { "docstring": null, "function_declaration": "def can_accommodate_reservations(test_cases):", "function_name": "can_accommodate_reservations", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_text):", "function_name": "parse_inpu...
[ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_accommodate_reservations(test_cases):\n results = []\n for reservations in test_cases:\n reservations.sort(key=lambda x: x[0])\n is_acce...
trial_gpt4o_9
{ "original_instruction": "You are designing a system to keep track of reservations at a restaurant. Each reservation can be for a different table, and no two reservations can overlap in time. Every table is identified by a unique number.\n\nYour task is to determine if all reservations in the list can be accommodate...
0.529526
Apps_3453
C
[ "can_accommodate_reservations", "parse_input", "restaurant_reservations" ]
3
[ [ "restaurant_reservations", "can_accommodate_reservations" ], [ "restaurant_reservations", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
c3ebab0cee97c6c1aad6a45c2430b520118958a9
89c05b601f717ef8a50a9a815a45e3d8c45a787d
v1.0
complete
Apps
Apps_4625_C
def custom_sort(lst: List[int]) -> List[int]: """ Given a list of integers, return the list sorted in non-decreasing order without using the built-in sort function. Implement a custom sorting algorithm to achieve this task, and ensure the algorithm's complexity is appropriate for the input size. >>...
def custom_sort(lst): """ Sorts a list of integers in non-decreasing order without using the built-in sort function. Uses the merge sort algorithm for sorting. """ if len(lst) <= 1: return lst mid = len(lst) // 2 left = custom_sort(lst[:mid]) right = custom_sort(lst[mid:]) ...
from solution import custom_sort def test_custom_sort_with_unique_elements(): assert custom_sort([4, 2, 7, 1, 9]) == [1, 2, 4, 7, 9] def test_custom_sort_with_duplicate_elements(): assert custom_sort([10, 5, 8, 3, 3, 2]) == [2, 3, 3, 5, 8, 10] def test_custom_sort_with_negative_elements(): assert custom_...
[ { "docstring": "Sorts a list of integers in non-decreasing order without using the built-in sort function.\nUses the merge sort algorithm for sorting.", "function_declaration": "def custom_sort(lst):", "function_name": "custom_sort", "parameter_list": "(lst)" }, { "docstring": "Merges two so...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def custom_sort(lst):\n \"\"\"\n Returns the list sorted in non-decreasing order using a custom sorting algorithm (bubble sort).\n \"\"\"\n n = len(lst)...
trial_gpt4o_9
{ "original_instruction": "# Task\nGiven a list of integers, return the list sorted in non-decreasing order without using the built-in sort function. Implement a custom sorting algorithm to achieve this task, and ensure the algorithm's complexity is appropriate for the input size.\n\n### Example\n\nFor `lst = [4, 2, ...
0.772396
Apps_4625
C
[ "custom_sort", "merge" ]
2
[ [ "custom_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e4e4461bcc667328d20ca840c9a783e57268d3e0
8b29c0b07edc9219147ff6c0ab15b26072571a42
v1.0
complete
Apps
Apps_4034_C
def max_submatrix_sum(matrix: List[List[int]]) -> int: """ Given a 2D matrix, finds the maximum sum of any contiguous submatrix. >>> max_submatrix_sum([ ... [1, 2, -1, -4, -20], ... [-8, -3, 4, 2, 1], ... [3, 8, 10, 1, 3], ... [-4, -1, 1, 7, -6] ... ]) == 29 >>> max_subma...
def max_submatrix_sum(matrix): """ Given a 2D matrix, finds the maximum sum of any contiguous submatrix. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') for left in range(m): tmp = [0] * n for right in range(left, m): for i in range(n): ...
from solution import max_submatrix_sum def test_example_case(): matrix = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_submatrix_sum(matrix) == 29 def test_single_element(): matrix = [[-50]] assert max_submatrix_sum(matr...
[ { "docstring": "Given a 2D matrix, finds the maximum sum of any contiguous submatrix.", "function_declaration": "def max_submatrix_sum(matrix):", "function_name": "max_submatrix_sum", "parameter_list": "(matrix)" }, { "docstring": "Helper function to apply Kadane's algorithm on 1D array to f...
[ 0, 1, 1, 0, 1, 1, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximum_submatrix_sum(matrix):\n \"\"\"\n Returns the maximum sum of the elements in any contiguous submatrix of the given matrix.\n \"\"\"\n def ka...
trial_gpt4o_6
{ "original_instruction": "You are given a matrix of dimensions n x m filled with non-negative integers. Your goal is to find the maximum sum of the elements in one contiguous submatrix. A submatrix is defined as a rectangular array of numbers obtained by selecting a contiguous block from the original matrix.\n\nWrit...
0.618391
Apps_4034
C
[ "max_submatrix_sum", "kadane" ]
2
[ [ "max_submatrix_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e4c529361a75c40646602ceab55a54a2e3fbc8d1
9c24fe11c2f0e48ce7a7a3d57c071d8a36b5e547
v1.0
complete
Apps
Apps_3849_C
from typing import List def can_split_into_k_primes(N: int, K: int, A: List[int]) -> str: """Determine if it's possible to split the array into exactly K non-empty continuous subarrays such that the sum of each subarray is a prime number. Args: N (int): Length of array A. K (int): Number of subarrays....
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False p = 3 while p * p <= n: if n % p == 0: return False p += 2 return True def can_split_into_k_primes(N, K, A): # Helper function to compute prefix su...
from solution import can_split_into_k_primes def test_example_1(): assert can_split_into_k_primes(5, 3, [3, 7, 1, 2, 11]) == "YES" def test_example_2(): assert can_split_into_k_primes(5, 2, [4, 6, 2, 5, 9]) == "NO" def test_single_element_prime(): assert can_split_into_k_primes(1, 1, [2]) == "YES" def t...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def can_split_into_k_primes(N, K, A):", "function_name": "can_split_into_k_primes", "parameter_list": "(N, K, A)"...
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num == 2 or num == 3:\n return T...
trial_gpt4o_3
{ "original_instruction": "You are given an integer array A of length N. Your task is to find if it is possible to split the array into exactly K non-empty continuous subarrays such that the sum of each subarray is a prime number.\n\nPrime number is a natural number greater than 1 that cannot be formed by multiplying...
0.678271
Apps_3849
C
[ "is_prime", "can_split_into_k_primes", "main" ]
3
[ [ "can_split_into_k_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8221182d14a37549c16f7654138691bb3e6c77cf
eee7b8826c0c7b98bd9089388225b1b3981a4f42
v1.0
complete
Apps
Apps_3779_C
def solve_treasure_grid(test_cases): """ Calculate the largest area of treasure cells that can be found within a rectangular sub-section of the grid for multiple test cases. Parameters: test_cases (list): A list where each element is a tuple containing the grid (list of strings), number of rows (in...
def max_histogram_area(histogram): """ Calculate the maximum rectangular area in the histogram (a list of non-negative integers). """ stack = [] max_area = 0 index = 0 while index < len(histogram): # Push current bar onto stack if it is higher than bar at stack top if no...
import pytest from solution import solve_treasure_grid def test_example(): test_cases = [([".#..", "#..#", "##.#", "#..#"], 4, 4), ([".##", "##.", "###"], 3, 3)] expected_results = [4, 1] assert solve_treasure_grid(test_cases) == expected_results def test_single_row(): test_cases = ...
[ { "docstring": "Calculate the maximum rectangular area in the histogram (a list of non-negative integers).", "function_declaration": "def max_histogram_area(histogram):", "function_name": "max_histogram_area", "parameter_list": "(histogram)" }, { "docstring": "Calculate the largest rectangul...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl", "solution_code": "def max_histogram_area(heights):\n stack = []\n max_area = 0\n index = 0\n\n while index < len(heights):\n if not stack ...
trial_gpt4o_7
{ "original_instruction": "Jenna is an avid gamer who loves grid-based puzzle games. Recently, she has encountered a thrilling new game called \"Treasure Grid\". In this game, Jenna plays on a 2D grid, and each cell in the grid can contain either an obstacle ('#') or a treasure ('.'). Jenna's goal is to determine the...
0.563454
Apps_3779
C
[ "max_histogram_area", "largest_treasure_area", "solve_treasure_grid" ]
3
[ [ "largest_treasure_area", "max_histogram_area" ], [ "solve_treasure_grid", "largest_treasure_area" ] ]
2
[]
false
[]
false
pytest
true
[]
true
6a188ac0796f92e275c07215ddbae6dd2574abe6
a4953364b65c82a70e84491b5b82e4c3220f6913
v1.0
complete
Apps
Apps_4511_C
def levenshtein_distance(a, b): """ Calculate the Levenshtein distance between two strings. >>> levenshtein_distance("kitten", "sitting") 3 >>> levenshtein_distance("flaw", "lawn") 2 >>> levenshtein_distance("", "abc") 3 >>> levenshtein_distance("abc", "") 3 >>> levenshtein_distance("abc", "...
def levenshtein_distance(a, b): """ Calculate the Levenshtein distance between two strings. """ if len(a) < len(b): return levenshtein_distance(b, a) if len(b) == 0: return len(a) previous_row = range(len(b) + 1) for i, c1 in enumerate(a): current_row = [i +...
from solution import spell_checker, levenshtein_distance def test_levenshtein_distance(): assert levenshtein_distance("kitten", "sitting") == 3 assert levenshtein_distance("flaw", "lawn") == 2 assert levenshtein_distance("", "abc") == 3 assert levenshtein_distance("abc", "") == 3 assert levenshtein...
[ { "docstring": "Calculate the Levenshtein distance between two strings.", "function_declaration": "def levenshtein_distance(a, b):", "function_name": "levenshtein_distance", "parameter_list": "(a, b)" }, { "docstring": "Corrects all misspelled words in a given text based on a provided dictio...
[ 1, 1, 0, 0, 1, 1, 1, 0, 0, 0 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def levenshtein_distance(word1, word2):\n \"\"\"\n Calculate Levenshtein distance between two words.\n \"\"\"\n dp = [[0] * (len(word2) + 1) for _ in ra...
trial_gpt4o_6
{ "original_instruction": "Your task is to implement a simplified spell checker. The spell checker should find and correct all misspelled words in a given text based on a provided dictionary of correctly spelled words.\n\nYou need to build a function `spell_checker` that takes two arguments: \n1. `text`: a string of ...
0.62285
Apps_4511
C
[ "levenshtein_distance", "spell_checker" ]
2
[ [ "spell_checker", "levenshtein_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
facca8adf545c2936d6099097e172a8baddeda8b
8ada5d0ed1924aca8350bbd84ef40ff22ad55483
v1.0
complete
Apps
Apps_5027_C
def isValidISBN(isbn: str) -> bool: """ Validates whether the given ISBN is valid according to ISBN-10 and ISBN-13 rules. >>> isValidISBN("0-306-40615-2") True >>> isValidISBN("978-3-16-148410-0") True >>> isValidISBN("123456789X") True >>> isValidISBN("123456789") False """
def isValidISBN(isbn): """ Validates whether the given ISBN is valid according to ISBN-10 and ISBN-13 rules """ isbn = isbn.replace('-', '') if len(isbn) == 10: return is_valid_isbn10(isbn) elif len(isbn) == 13: return is_valid_isbn13(isbn) return False def is_vali...
from solution import isValidISBN def test_valid_isbn10(): assert isValidISBN("0-306-40615-2") == True assert isValidISBN("123456789X") == True assert isValidISBN("0306406152") == True def test_invalid_isbn10(): assert isValidISBN("0306406153") == False assert isValidISBN("1234567890") == False de...
[ { "docstring": "Validates whether the given ISBN is valid according to ISBN-10 and ISBN-13 rules", "function_declaration": "def isValidISBN(isbn):", "function_name": "isValidISBN", "parameter_list": "(isbn)" }, { "docstring": null, "function_declaration": "def is_valid_isbn10(isbn):", ...
[ 1, 0, 0, 1, 1, 1, 0, 0, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def isValidISBN(isbn):\n \"\"\"\n Validate the given ISBN number.\n\n :param isbn: str, the ISBN number (could contain hyphens)\n :return: bool, True if...
trial_gpt4o_4
{ "original_instruction": "In a distant land, there is a new software being developed for a library management system. One of the key features of this system is the ability to categorize books quickly based on their ISBN (International Standard Book Number). The ISBN of a book is a unique identifier and can be either...
0.540355
Apps_5027
C
[ "isValidISBN", "is_valid_isbn10", "is_valid_isbn13" ]
3
[ [ "isValidISBN", "is_valid_isbn10" ], [ "isValidISBN", "is_valid_isbn13" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2f9bc6dd730a564622e33301d2b9679e14bfa846
23b2ae3804af86e4a1376f1b7c7470e8d815b876
v1.0
complete
Apps
Apps_4351_C
from typing import List def find_beautiful_words(words: List[str], k: int) -> List[str]: """ We have a list of words and an integer k. A word is considered "beautiful" if it can form a substring of itself that is a palindrome of at least length k. Write a function that returns the list of "beautiful" words...
from typing import List def is_palindrome(s: str) -> bool: return s == s[::-1] def find_beautiful_words(words: List[str], k: int) -> List[str]: beautiful_words = [] for word in words: found = False for i in range(len(word) - k + 1): for j in range(i + k, len(word) + 1): ...
from solution import find_beautiful_words def test_example(): words = ["racecar", "radar", "helix", "refer"] k = 3 assert find_beautiful_words(words, k) == ["racecar", "radar", "refer"] def test_single_letter_words(): words = ["a", "b", "c"] k = 1 assert find_beautiful_words(words, k) == ["a",...
[ { "docstring": null, "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def find_beautiful_words(words, k):", "function_name": "find_beautiful_words", "parameter_list": "(word...
[ 0, 0, 0, 0, 1, 1, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef find_beautiful_words(words: List[str], k: int) -> List[str]:\n def is_palindrome(s: str) -> bool:\n return s == s[::-1]\n\n...
trial_gpt4o_7
{ "original_instruction": "We have a list of words and an integer k. A word is considered \"beautiful\" if it can form a substring of itself that is a palindrome of at least length k.\nWrite a function that returns the list of \"beautiful\" words from the given list. \n\nA palindrome is a string that reads the same b...
0.753484
Apps_4351
C
[ "is_palindrome", "find_beautiful_words" ]
2
[ [ "find_beautiful_words", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8b54722d4a0f71d98268ae67f333f57f4b34201d
aa59669fb96626f9e4fd17776cb41234007b8743
v1.0
complete
Apps
Apps_4283_C
import math from typing import List, Tuple def is_prime(number: int) -> bool: """ Returns whether a number is a prime number. """ pass def find_element_to_remove_for_prime_product(arr: List[int]) -> int: """ Tries to find an element whose removal makes the product of remaining elements a prime number....
def is_prime(number): """ Returns whether a number is a prime number. """ if number <= 1: return False if number <= 3: return True if number % 2 == 0 or number % 3 == 0: return False i = 5 while i * i <= number: if number % i == 0 or number % (i + 2) == 0:...
import pytest from solution import is_prime, find_element_to_remove_for_prime_product, solve_prime_product_problem 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_find_element_t...
[ { "docstring": "Returns whether a number is a prime number.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Tries to find an element whose removal makes the product of remaining elements a prime number.", "fu...
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(number):\n \"\"\"\n Returns whether a number is a prime number.\n \"\"\"\n if number <= 1:\n return False\n if number <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "Zach is fascinated by number theory and is currently exploring the world of prime numbers. He has stumbled upon an interesting problem and could use your help.\n\nYou are given an integer array $a$ of length $n$. Zach wants to determine whether it is possible to remove exactly one element f...
0.684649
Apps_4283
C
[ "is_prime", "find_element_to_remove_for_prime_product", "solve_prime_product_problem" ]
3
[ [ "find_element_to_remove_for_prime_product", "is_prime" ], [ "solve_prime_product_problem", "find_element_to_remove_for_prime_product" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d0c81cea4ea277f7dc26421a91ec375aaba2e3be
c914783a2c4f459902de9a0927c3afdaa0c3fef5
v1.0
complete
Apps
Apps_4192_C
from typing import List, Tuple def preprocess_grid(grid: List[List[int]]) -> List[List[int]]: """ Preprocess the grid to find prefix sums. >>> preprocess_grid([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) [[0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45]] """ def query_sum(prefix_sum: List[List[int]],...
def preprocess_grid(grid): 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] + prefix_sum[i-1][j] + prefix_sum[i][j-1] - prefix_sum[i-1][j-1] return pre...
import pytest def test_preprocess_grid(): grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] expected = [ [0, 0, 0, 0], [0, 1, 3, 6], [0, 5, 12, 21], [0, 12, 27, 45] ] assert preprocess_grid(grid) == expected def test_query_sum(): prefix_sum = ...
[ { "docstring": null, "function_declaration": "def preprocess_grid(grid):", "function_name": "preprocess_grid", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def query_sum(prefix_sum, r1, c1, r2, c2):", "function_name": "query_sum", "parameter_list": ...
[ 0, 1, 0, 1, 1, 1, 1, 0, 0, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def preload_prefix_sum(grid):\n \"\"\"\n Calculate the prefix sum matrix for the given grid.\n \"\"\"\n N = len(grid)\n M = len(grid[0])\n prefix_...
trial_gpt4o_9
{ "original_instruction": "Villager Jenny has a garden with a collection of enchanted mushrooms arranged in a grid. The grid has `N` rows and `M` columns, and each cell of the grid contains a certain number of magical spores. Jenny wants to find out the total number of spores in specific subgrids from her garden.\n\n...
0.55622
Apps_4192
C
[ "preprocess_grid", "query_sum", "solve" ]
3
[ [ "solve", "preprocess_grid" ], [ "solve", "query_sum" ] ]
2
[]
false
[]
false
pytest
false
[]
true
40d59b2c4f8dd27d74e637f3722cde4a4ca835b0
02b73eb58299ecdfbbc1ae8e6e7145fab85154c1
v1.0
complete
Apps
Apps_4306_C
from typing import List, Union from itertools import permutations def is_prime(num: int) -> bool: """ Check if a number is a prime number. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(29) True """ pass def can_reorder_to_prime_pairs(arr: List[int]) -> Un...
from itertools import permutations def is_prime(num): """ Check if a number is a prime number. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) ...
from solution import is_prime, can_reorder_to_prime_pairs, process_test_cases def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(31) == True assert is_prime(1) == False def test_can_reorder_to_prime...
[ { "docstring": "Check if a number is a prime number.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Check if the array can be reordered such that the sum \nof every pair of adjacent elements is a prime number.", "...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import itertools\nimport math\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "You are given an array $a$ of length $n$ consisting of distinct integers. Write a program to determine whether it is possible to reorder the array in such a way that the sum of every pair of adjacent elements is a prime number. If it is possible, output the new array. If it is not possible,...
0.664543
Apps_4306
C
[ "is_prime", "can_reorder_to_prime_pairs", "process_test_cases" ]
3
[ [ "can_reorder_to_prime_pairs", "is_prime" ], [ "process_test_cases", "can_reorder_to_prime_pairs" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
5117f40d3f4bc573ef80ffef99e381e23c2e4626
2b7be6e62cedab7351d39dd803c5b88cd546b930
v1.0
complete
Apps
Apps_4650_C
def check_password_strength(password): """ Check if the given password meets the criteria for being strong. Criteria: 1. Length between 6 and 12 characters (inclusive) 2. Contains at least one uppercase letter 3. Contains at least one lowercase letter 4. Contains at least one digit 5. Contai...
import re def check_password_strength(password): """ Check if the given password meets the criteria for being strong. Criteria: 1. Length between 6 and 12 characters (inclusive) 2. Contains at least one uppercase letter 3. Contains at least one lowercase letter 4. Contains at least one...
from solution import check_password_strength, password_strength_checker def test_check_password_strength(): assert check_password_strength("Passw0rd!") == "Strong" assert check_password_strength("123456") == "Weak" assert check_password_strength("Ab1@") == "Weak" assert check_password_strength("Super$S...
[ { "docstring": "Check if the given password meets the criteria for being strong.\n\nCriteria:\n1. Length between 6 and 12 characters (inclusive)\n2. Contains at least one uppercase letter\n3. Contains at least one lowercase letter\n4. Contains at least one digit\n5. Contains at least one special character from ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import re\n\ndef is_strong_password(password: str) -> str:\n \"\"\"\n Checks if the given password is strong or weak based on predefined criteria.\n \"\"\"...
trial_gpt4o_8
{ "original_instruction": "=====Problem Statement=====\nA strong password satisfies the following criteria:\n\n1. It has at least 6 characters and at most 12 characters.\n2. It contains at least one uppercase letter.\n3. It contains at least one lowercase letter.\n4. It contains at least one digit.\n5. It contains at...
0.59301
Apps_4650
C
[ "check_password_strength", "password_strength_checker" ]
2
[ [ "password_strength_checker", "check_password_strength" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73497b762daf4242885aeb008876d72e084d4704
762ae9eba4d8f0de1f9772f5eb89818c9da87965
v1.0
complete
Apps
Apps_4794_C
from typing import List, Tuple def is_palindrome(s: str) -> bool: """ Check if a given string is a palindrome. >>> is_palindrome("madam") == True >>> is_palindrome("racecar") == True >>> is_palindrome("apple") == False """ def palindrome_pairs(words: List[str]) -> List[Tuple[int, int]]: ...
def is_palindrome(s): """ Check if a given string is a palindrome. """ return s == s[::-1] def palindrome_pairs(words): """ Identify all pairs of indices (i, j) such that the concatenation of words[i] and words[j] forms a palindrome. """ result = [] for i in range(len(words)): ...
from solution import is_palindrome, palindrome_pairs def test_is_palindrome(): assert is_palindrome("madam") == True assert is_palindrome("racecar") == True assert is_palindrome("apple") == False def test_palindrome_pairs_example1(): words = ["abcd", "dcba", "ll", "sssll"] assert palindrome_pairs(...
[ { "docstring": "Check if a given string is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Identify all pairs of indices (i, j) such that the concatenation of words[i] and words[j] forms a palindrom...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_palindrome_pairs(words):\n \"\"\"\n Given a list of words, return a list of tuples (i, j) such that the concatenation\n of words[i] and words[j] f...
trial_gpt4o_8
{ "original_instruction": "Design a function that takes a list of words and identifies all pairs of words whose concatenation forms a palindrome.\n\n-----Input-----\n\nThe input consists of a single integer N followed by a list of N strings. Each string consists of lowercase English letters only.\n\n-----Output-----\...
0.821821
Apps_4794
C
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
973482fccb19d5cfc5d4cd9e806c2b37c4836bdd
f000ffe9cbf83315884db08a51e8ad286fe4f9a2
v1.0
complete
Apps
Apps_4340_C
def sorted_matrix_elements(matrix): """ Returns all elements of the matrix in ascending order as a single sorted list. >>> sorted_matrix_elements([ ... [1, 5, 9], ... [10, 11, 13], ... [12, 13, 15] ... ]) [1, 5, 9, 10, 11, 12, 13, 13, 15] >>> sorted_matrix_elements([ ...
def sorted_matrix_elements(matrix): """ Returns all elements of the matrix in ascending order as a single sorted list. """ elements = [] for row in matrix: elements.extend(row) elements.sort() return elements # Utility functions to read input in the specified format def read_matrix(...
from solution import sorted_matrix_elements, read_matrix, matrix_to_sorted_list_string def test_sorted_matrix_elements(): matrix = [ [1, 5, 9], [10, 11, 13], [12, 13, 15] ] result = sorted_matrix_elements(matrix) expected = [1, 5, 9, 10, 11, 12, 13, 13, 15] assert result == ...
[ { "docstring": "Returns all elements of the matrix in ascending order as a single sorted list.", "function_declaration": "def sorted_matrix_elements(matrix):", "function_name": "sorted_matrix_elements", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def rea...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sorted_elementsOfMatrix(matrix):\n \"\"\"\n Given an n x n matrix filled with integers where each row is sorted in ascending order from left to right,\n ...
trial_gpt4o_8
{ "original_instruction": "Given an n x n matrix filled with integers where each row is sorted in ascending order from left to right, write a function to return all elements of the matrix in ascending order as a single sorted list.\n\n-----Input-----\n- The first line of the input contains an integer n referring to t...
0.611989
Apps_4340
C
[ "sorted_matrix_elements", "read_matrix", "matrix_to_sorted_list_string" ]
3
[ [ "matrix_to_sorted_list_string", "sorted_matrix_elements" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5af2d3fb57e70f7c2086e343551545112bc00a38
e9b1f9d434e692e5093e212d154c5b460a77c1f6
v1.0
complete
Apps
Apps_3187_C
from typing import List def largest_plus_sign(grid: List[List[int]]) -> int: """ Determine the order of the largest plus sign in a given grid. :param grid: List of List of integers representing the grid :return: Integer representing the order of the largest plus sign >>> largest_plus_sign([[1, 1,...
def largest_plus_sign(grid): """ Function to determine the order of the largest plus sign in a given grid :param grid: List of List of integers representing the grid :return: Integer representing the order of the largest plus sign """ n = len(grid) if n == 0: return 0 m = le...
def test_example_1(): n, m = 5, 5 input_grid = [ "1 1 1 1 1", "1 1 1 1 1", "1 1 1 1 1", "1 1 1 1 1", "1 1 1 1 1" ] assert read_input_and_solve(n, m, input_grid) == 2 def test_example_2(): n, m = 3, 3 input_grid = [ "1 0 1", "0 1 0", ...
[ { "docstring": "Function to determine the order of the largest plus sign in a given grid\n\n:param grid: List of List of integers representing the grid\n:return: Integer representing the order of the largest plus sign", "function_declaration": "def largest_plus_sign(grid):", "function_name": "largest_pl...
[ 0, 1, 0, 0, 0, 1, 0, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def largest_plus_sign(n, m, grid):\n if n == 0 or m == 0:\n return 0\n \n left = [[0] * m for _ in range(n)]\n right = [[0] * m for _ in range(n)...
trial_gpt4o_1
{ "original_instruction": "You are given a grid of size $n \\times m$ filled with integers. You need to find the largest plus sign that can be formed using cells with value 1. A plus sign consists of a center cell and four arms extending from it, with equal length in all four directions (up, down, left, right). The l...
0.597771
Apps_3187
C
[ "largest_plus_sign", "read_input_and_solve" ]
2
[ [ "read_input_and_solve", "largest_plus_sign" ] ]
1
[]
false
[]
false
pytest
false
[]
true
5e730c83a8a076e6ca672087071a377f3a047ea3
de05371da3e0124d1f9555e052dddf6938191b62
v1.0
complete
Apps
Apps_5060_C
def sum_of_prime_factors(n: int) -> int: """ Returns the sum of the prime factors of n. >>> sum_of_prime_factors(10) 7 >>> sum_of_prime_factors(15) 8 """ def special_number_pattern(N: int, K: int) -> int: """ Returns the final number in the sequence generated after K steps star...
def sum_of_prime_factors(n): """ Returns the sum of the prime factors of n. """ sum_factors = 0 # Dividing n by 2 until it's odd while n % 2 == 0: sum_factors += 2 n //= 2 # n must be odd at this point. So we start from 3 and only check for odd factors for i in r...
from solution import sum_of_prime_factors, special_number_pattern, process_test_cases def test_sum_of_prime_factors(): assert sum_of_prime_factors(10) == 7 assert sum_of_prime_factors(15) == 8 assert sum_of_prime_factors(17) == 17 assert sum_of_prime_factors(23) == 23 assert sum_of_prime_factors(46...
[ { "docstring": "Returns the sum of the prime factors of n.", "function_declaration": "def sum_of_prime_factors(n):", "function_name": "sum_of_prime_factors", "parameter_list": "(n)" }, { "docstring": "Returns the final number in the sequence generated after K steps starting from N.", "fu...
[ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prime_factors_sum(n):\n \"\"\"\n Return the sum of the prime factors of the given number n.\n \"\"\"\n i = 2\n factors_sum = 0\n while i * i <...
trial_gpt4o_5
{ "original_instruction": "Danny loves to play with numbers and has recently learned about prime factorization. He wants to create a special number pattern. Given two integers $N$ and $K$, he generates numbers based on the following rules:\n\n1. Start with the number $N$.\n2. In each step, add the sum of the prime fa...
0.644371
Apps_5060
C
[ "sum_of_prime_factors", "special_number_pattern", "process_test_cases" ]
3
[ [ "process_test_cases", "special_number_pattern" ], [ "special_number_pattern", "sum_of_prime_factors" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
57ded47a0b99cd6593df57c3baa49c1b831e9553
53e0213a23550aee1201330179e4e15a90cb153f
v1.0
complete
Apps
Apps_5119_C
def kth_perfect_number(k: int) -> int: """Generates the k-th perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself. Args: k (int): The ordinal position of the perfect number to find. Returns: int: The k-th perfect num...
def is_perfect_number(num): """ Checks if a given number is a perfect number. """ if num < 2: return False divisors_sum = 1 for i in range(2, int(num**0.5) + 1): if num % i == 0: divisors_sum += i if i != num // i: divisors_sum += num // i ...
from solution import kth_perfect_number def test_kth_perfect_number_1(): assert kth_perfect_number(1) == 6 def test_kth_perfect_number_2(): assert kth_perfect_number(2) == 28 def test_kth_perfect_number_3(): assert kth_perfect_number(3) == 496 def test_kth_perfect_number_4(): assert kth_perfect_numb...
[ { "docstring": "Checks if a given number is a perfect number.", "function_declaration": "def is_perfect_number(num):", "function_name": "is_perfect_number", "parameter_list": "(num)" }, { "docstring": "Returns the k-th perfect number.", "function_declaration": "def kth_perfect_number(k):...
[ 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kth_perfect_number(k):\n \"\"\"\n Returns the k-th perfect number.\n \"\"\"\n def is_perfect(n):\n if n < 2:\n return False\n ...
trial_gpt4o_9
{ "original_instruction": "Write a function `kth_perfect_number(k)` that generates the `k`-th \"perfect number\". A perfect number is defined as a positive integer that is equal to the sum of its proper divisors, excluding itself.\n\nFor example:\n- The proper divisors of `6` are `1, 2, 3`, and `1 + 2 + 3 = 6`, so `6...
0.599256
Apps_5119
C
[ "is_perfect_number", "kth_perfect_number" ]
2
[ [ "kth_perfect_number", "is_perfect_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e93d3f07c355138b3937725a184284785ed2b93f
7536f62a4392c20e82990681ffa0272fd66217ca
v1.0
complete
Apps
Apps_5270_C
from typing import List def filter_primes(numbers: List[int]) -> List[int]: """Returns a list of prime numbers from the given list of integers. >>> filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) [2, 3, 5, 7] >>> filter_primes([1, 4, 6, 8, 10]) [] >>> filter_primes([]) [] ...
from typing import List def is_prime(n: int) -> bool: """ Helper function to determine if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: retur...
from solution import filter_primes def test_filter_primes_with_primes(): assert filter_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filter_primes_no_primes(): assert filter_primes([1, 4, 6, 8, 10]) == [] def test_filter_primes_empty_list(): assert filter_primes([]) == [] def test_filter...
[ { "docstring": "Helper function to determine if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list of integers.", "function_declaration": "def filter_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(number: int) -> bool:\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if number <= 1:\n retur...
trial_gpt4o_9
{ "original_instruction": "Create a function that accepts a list of integers and returns a new list containing only the prime numbers from the original list. If the original list is empty or contains no prime numbers, the function should return an empty list.\n\nFunction signature: **filter_primes(numbers: List[int])...
0.670309
Apps_5270
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d412914c1e259f471b848c27640dc03031f3689
426728035e98f5ce6ad8b0f039c77f0954a67188
v1.0
complete
Apps
Apps_4951_C
def longest_active_period(test_cases): """ For each test case, return the length of the longest contiguous interval where there was at least one signup each day. >>> longest_active_period([(5, [1, 2, 0, 4, 5]), (6, [0, 0, 0, 0, 0, 0]), (8, [1, 1, 1, 0, 1, 1, 0, 1])]) [2, 0, 3] >>> longest_acti...
def longest_active_period(test_cases): results = [] for case in test_cases: n, days = case max_length, current_length = 0, 0 for signup in days: if signup > 0: current_length += 1 if current_length > max_length: max_length ...
import pytest from solution import solution, parse_input, longest_active_period def test_example_cases(): input_str = "3\n5\n1 2 0 4 5\n6\n0 0 0 0 0 0\n8\n1 1 1 0 1 1 0 1" expected_output = "2\n0\n3" assert solution(input_str) == expected_output def test_single_day_cases(): input_str = "2\n1\n1\n1\n0"...
[ { "docstring": null, "function_declaration": "def longest_active_period(test_cases):", "function_name": "longest_active_period", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input", "parame...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_active_growth_period(n, signups):\n max_length = 0\n current_length = 0\n \n for signup in signups:\n if signup > 0:\n cur...
trial_gpt4o_9
{ "original_instruction": "A social media application tracks the number of new users signing up each day. You are given the number of users who signed up on each of the past $n$ days. Occasionally, the app experiences an anomaly that causes no users to sign up for some days. The app developers want to analyze the tre...
0.638758
Apps_4951
C
[ "longest_active_period", "parse_input", "solution" ]
3
[ [ "solution", "longest_active_period" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
0a695c2270c2dc97c4587c4e8b86e8306e87023b
1dc8e90a5fad04fc770571454551b99876896358
v1.0
complete
Apps
Apps_5240_C
def sum_from_a_to_b(a: int, b: int) -> int: """ Returns the sum of integers from a to b (inclusive). >>> sum_from_a_to_b(1, 10) == 55 >>> sum_from_a_to_b(15, 20) == 105 >>> sum_from_a_to_b(100, 105) == 615 """ def coding_marathon_sums(groups: List[Tuple[int, List[Tuple[int, int]]]]) -> List...
def sum_from_a_to_b(a, b): """ Returns the sum of integers from a to b (inclusive). """ return (b * (b + 1)) // 2 - ((a - 1) * a) // 2 def coding_marathon_sums(groups): """ Computes the sum of integers from a to b for each participant in each group. :param groups: List of tuples, where...
from solution import coding_marathon_sums def test_single_group_multiple_participants(): assert coding_marathon_sums([ (3, [(1, 10), (15, 20), (100, 105)]) ]) == [55, 105, 615] def test_multiple_groups(): assert coding_marathon_sums([ (3, [(1, 10), (15, 20), (100, 105)]), (2, [(5, ...
[ { "docstring": "Returns the sum of integers from a to b (inclusive).", "function_declaration": "def sum_from_a_to_b(a, b):", "function_name": "sum_from_a_to_b", "parameter_list": "(a, b)" }, { "docstring": "Computes the sum of integers from a to b for each participant in each group.\n\n:para...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_sum(a, b):\n \"\"\"\n Compute the sum of integers from a to b (inclusive).\n \"\"\"\n return (b - a + 1) * (a + b) // 2\n\ndef marathon_resu...
trial_gpt4o_9
{ "original_instruction": "-----Problem Statement-----\nIn a coding marathon, participants are divided into several groups, each group with P participants. Each participant in a group is given a pair of integers (a, b) and is asked to perform the following operation: \n\nFor each participant i in a group, compute the...
0.564957
Apps_5240
C
[ "sum_from_a_to_b", "coding_marathon_sums" ]
2
[ [ "coding_marathon_sums", "sum_from_a_to_b" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dd5f2428ab4f08b2c898b1c0782be96dfb1d6f89
ee603cfcdcf3a433e8ca8a04e1bebd48e678ba25
v1.0
complete
Apps
Apps_5228_C
def extract_primes(numbers: List[int]) -> List[int]: """ Implement a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, but in reverse order of their appearance. >>> extract_primes([10, 41, 22, 53, 37, 89]) == [89, 37, 53, 41] >>> extract_...
def is_prime(n): """ Returns True if n is a prime number, otherwise False. """ if n <= 1: return False elif n == 2: return True elif 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 ex...
def test_extract_primes_example_1(): assert extract_primes([10, 41, 22, 53, 37, 89]) == [89, 37, 53, 41] def test_extract_primes_example_2(): assert extract_primes([31, 17, 12, 5, 6]) == [5, 17, 31] def test_extract_primes_example_3(): assert extract_primes([4, 6, 8, 10, 12]) == [] def test_extract_prime...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the original list in reverse order of their appearance.", "func...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def 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 <= 3:\n retu...
trial_gpt4o_6
{ "original_instruction": "Implement a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, but in reverse order of their appearance.\n\nThe order that the function receives its argument is:\n```python\nextract_primes(numbers)\n```\n\n## Examples\n\n`...
0.703273
Apps_5228
C
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
8559140dcabf166932ab1a736de5d5bd80b72019
27eaac28700f5f40eb8b54e9bfab4f7e585e686c
v1.0
complete
Apps
Apps_5574_C
def shortest_consecutive_perfect_square_subset(n: int, difficulties: List[int]) -> int: """ Find the length of the shortest subset of consecutive trails such that the product of their difficulty levels is a perfect square. >>> shortest_consecutive_perfect_square_subset(5, [2, 4, 6, 8, 10]) 1 >>> shortes...
def is_perfect_square(x): if x < 0: return False root = int(x**0.5) return root * root == x def shortest_consecutive_perfect_square_subset(n, difficulties): from math import gcd from collections import defaultdict def product_is_perfect_square(product): return is_perfect_square...
from solution import shortest_consecutive_perfect_square_subset def test_example_1(): assert shortest_consecutive_perfect_square_subset(5, [2, 4, 6, 8, 10]) == 1 def test_example_2(): assert shortest_consecutive_perfect_square_subset(3, [2, 3, 5]) == -1 def test_single_perfect_square(): assert shortest_c...
[ { "docstring": null, "function_declaration": "def is_perfect_square(x):", "function_name": "is_perfect_square", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def shortest_consecutive_perfect_square_subset(n, difficulties):", "function_name": "shortest_conse...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_perfect_square(x):\n \"\"\"\n Check if a number x is a perfect square.\n \"\"\"\n if x < 0:\n return False\n root = int(...
trial_gpt4o_2
{ "original_instruction": "Pat is organizing a hiking trip with a group of friends. There are $n$ hiking trails, numbered from $1$ to $n$, and each trail has a respective difficulty level $d_1, d_2, \\ldots, d_n$. Pat wants to select a consecutive subset of trails such that the product of their difficulty levels is a...
0.541066
Apps_5574
C
[ "is_perfect_square", "shortest_consecutive_perfect_square_subset" ]
2
[ [ "shortest_consecutive_perfect_square_subset", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8782735f14fc0d23030058f91c91105384f93c9c
d0f8eb7f3c7990f41b96241de84c24e592482315
v1.0
complete
Apps
Apps_5403_C
def max_submatrix_sum(matrix): """ Function to find the maximum sum of any non-empty submatrix in a given matrix. >>> matrix = [ ... [1, 2, -1, -4, -20], ... [-8, -3, 4, 2, 1], ... [3, 8, 10, 1, 3], ... [-4, -1, 1, 7, -6] ... ] >>> max_submatrix_sum(matrix) 29 ...
def max_submatrix_sum(matrix): """ Function to find the maximum sum of any non-empty submatrix in a given matrix. """ n = len(matrix) m = len(matrix[0]) max_sum = float('-inf') for left in range(m): temp = [0] * n for right in range(left, m): for i in range(n): ...
from solution import max_submatrix_sum def test_case_1(): matrix = [ [1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6] ] assert max_submatrix_sum(matrix) == 29 def test_case_2(): matrix = [ [-1, -2, -3], [-4, -5, -6], [...
[ { "docstring": "Function to find the maximum sum of any non-empty submatrix in a given matrix.", "function_declaration": "def max_submatrix_sum(matrix):", "function_name": "max_submatrix_sum", "parameter_list": "(matrix)" }, { "docstring": "Utility function to find the maximum sum subarray u...
[ 0, 1, 0, 0, 1, 1, 1, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_sum_submatrix(matrix):\n \"\"\"\n Returns the maximum sum of any non-empty submatrix within the given matrix.\n \"\"\"\n def kadane(arr):\n ...
trial_gpt4o_6
{ "original_instruction": "You are given a rectangular matrix of dimensions $n \\times m$ filled with integers. You need to find out the maximum sum of any non-empty submatrix in this given matrix.\n\nA submatrix is any contiguous rectangular part of the matrix.\n\n-----Input:-----\n- The first line of input contains...
0.624295
Apps_5403
C
[ "max_submatrix_sum", "kadane" ]
2
[ [ "max_submatrix_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
823732e1d09202cdf9d0eb66a918bb07cdfb59df
ba1c90758e767282bd35a268746d6478a5c2dfdf
v1.0
complete
Apps
Apps_4898_C
def palindrome_index_finder(s: str) -> int: """ Given a string s, this function returns the minimum index i such that when you remove the character at the index i in the string, the resulting string is a palindrome. If the string is already a palindrome, return -1. If no such index exists, return -1. ...
def is_palindrome(s: str) -> bool: """ Helper function to check if the given string s is a palindrome. """ return s == s[::-1] def palindrome_index_finder(s: str) -> int: """ Given a string s, this function returns the minimum index i such that when you remove the character at the index i ...
from solution import palindrome_index_finder def test_palindrome_index_finder_example_1(): assert palindrome_index_finder("abca") == 1 def test_palindrome_index_finder_example_2(): assert palindrome_index_finder("racecar") == -1 def test_palindrome_index_finder_example_3(): assert palindrome_index_finder...
[ { "docstring": "Helper function to check if the given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Given a string s, this function returns the minimum index i such that when you remov...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(s: str) -> bool:\n \"\"\"\n Helper function to check if the input string is a palindrome.\n \"\"\"\n return s == s[::-1]\n\ndef palind...
trial_gpt4o_4
{ "original_instruction": "### Palindrome Index Finder\n\nA palindrome is a string that reads the same backwards as forwards. Given a string `s`, you need to find the minimum index `i` such that when you remove the character at the index `i` in the string, the resulting string is a palindrome.\n\nIf the string is alr...
0.825664
Apps_4898
C
[ "is_palindrome", "palindrome_index_finder" ]
2
[ [ "palindrome_index_finder", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
222e34f3119b22e3fcb5b34c5cdcf4605ff289f8
96a22d94323e6fbb7b16e28cd870507d2273047a
v1.0
complete
Apps
Apps_4897_C
def is_armstrong_number(num): """ Check if a number is an Armstrong number. >>> is_armstrong_number(1) True >>> is_armstrong_number(153) True >>> is_armstrong_number(10) False """ pass def find_armstrong_numbers(N): """ Find all Armstrong numbers between 1 and N inclusive. >...
def is_armstrong_number(num): digits = list(map(int, str(num))) num_digits = len(digits) return num == sum(d ** num_digits for d in digits) def find_armstrong_numbers(N): return [i for i in range(1, N + 1) if is_armstrong_number(i)] def armstrong_numbers(test_cases): results = [] for N in test...
from solution import is_armstrong_number, find_armstrong_numbers, armstrong_numbers def test_is_armstrong_number(): assert is_armstrong_number(1) == True assert is_armstrong_number(153) == True assert is_armstrong_number(370) == True assert is_armstrong_number(371) == True assert is_armstrong_numbe...
[ { "docstring": null, "function_declaration": "def is_armstrong_number(num):", "function_name": "is_armstrong_number", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_armstrong_numbers(N):", "function_name": "find_armstrong_numbers", "parameter_...
[ 0, 1, 0, 0, 1, 0, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_armstrong(num):\n \"\"\"\n Checks if a number is an Armstrong number or not.\n \"\"\"\n digits = list(map(int, str(num)))\n num_digits = len(d...
trial_gpt4o_9
{ "original_instruction": "-----Problem Statement-----\nAn Armstrong number (also known as a narcissistic number, pluperfect number, or plus perfect number) of a given number of digits is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armst...
0.527766
Apps_4897
C
[ "is_armstrong_number", "find_armstrong_numbers", "armstrong_numbers" ]
3
[ [ "armstrong_numbers", "find_armstrong_numbers" ], [ "find_armstrong_numbers", "is_armstrong_number" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a385296c0dd78efd30b4b2430320dcb1263ea9c6
309f06f80a6e75f2d15599cdb4f726fe7833f01f
v1.0
complete
Apps
Apps_2041_C
def calculate_variance(readings, mean): """ Calculate variance given a list of readings and their mean. """ pass def anomaly_detection(T, N, temperature_readings): """ Calculate the number of hours with temperature anomaly. :param T: Threshold value for anomaly detection. :param N: Tot...
import math def calculate_variance(readings, mean): """ Calculate variance given a list of readings and their mean. """ N = len(readings) variance = sum((xi - mean) ** 2 for xi in readings) / N return variance def anomaly_detection(T, N, temperature_readings): """ Calculate the number ...
def test_anomaly_detection(): T = 4 N = 120 temperature_readings = [ 72, 71, 69, 70, 73, 74, 68, 72, 75, 70, 69, 71, 72, 73, 73, 72, 70, 69, 71, 70, 70, 72, 71, 68, 74, 69, 73, 72, 71, 72, 70, 69, 73, 75, 74, 71, 72, 73, 72, 71, 71, 70, 69, 75, 72, 71, 72, 74, 69, 70, 73, 75, 70, 7...
[ { "docstring": "Calculate variance given a list of readings and their mean.", "function_declaration": "def calculate_variance(readings, mean):", "function_name": "calculate_variance", "parameter_list": "(readings, mean)" }, { "docstring": "Calculate the number of hours with temperature anoma...
[ 1, 1, 0, 0, 0, 1, 0, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_anomalies(T, N, temperatures):\n \"\"\"\n Returns the number of hours that have an anomaly in their temperature readings\n based on the variance ...
trial_gpt4o_7
{ "original_instruction": "-----\nANOMALY DETECTION\n-----\n\nIn a research facility, scientists are continuously monitoring temperature readings collected every minute. For every one hour period, they need to check for anomalies. An anomaly in the temperature is detected if the variance of the temperature within an ...
0.5664
Apps_2041
C
[ "calculate_variance", "anomaly_detection" ]
2
[ [ "anomaly_detection", "calculate_variance" ] ]
1
[]
false
[]
false
pytest
false
[]
true
cfc1415111efb7de9dca02028469d7effbeb3f1a
a77c2ab2e9937bdd8469290c1e9469027bca20b7
v1.0
complete
Apps
Apps_5466_C
def sieve_of_eratosthenes(max_n): """ Generate a list of prime numbers up to max_n using the Sieve of Eratosthenes. >>> primes, is_prime = sieve_of_eratosthenes(10) >>> primes [2, 3, 5, 7] >>> is_prime[4] False >>> is_prime[5] True """ def goldbach_conjecture(N): """ Find two prime numb...
def sieve_of_eratosthenes(max_n): """ Generate a list of prime numbers up to max_n using the Sieve of Eratosthenes. """ is_prime = [True] * (max_n + 1) is_prime[0] = is_prime[1] = False # 0 and 1 are not prime numbers for start in range(2, int(max_n**0.5) + 1): if is_prime[start]: ...
def test_sieve_of_eratosthenes(): primes, is_prime = sieve_of_eratosthenes(10) assert primes == [2, 3, 5, 7] assert is_prime[4] == False assert is_prime[5] == True def test_goldbach_conjecture(): assert goldbach_conjecture(4) == (2, 2) assert goldbach_conjecture(10) == (3, 7) assert goldbac...
[ { "docstring": "Generate a list of prime numbers up to max_n using the Sieve of Eratosthenes.", "function_declaration": "def sieve_of_eratosthenes(max_n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(max_n)" }, { "docstring": "Find two prime numbers such that their sum equ...
[ 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sieve_of_eratosthenes(max_num):\n \"\"\"\n Returns a list of boolean values representing if the index is a prime number.\n \"\"\"\n is_prime = [True...
trial_gpt4o_2
{ "original_instruction": "David has recently learned about prime numbers and their interesting properties. He wants to find two prime numbers whose sum equals a given even number N, where N is greater than 2. This problem is known as the \"Goldbach Conjecture.\"\n\nGiven an even number N (greater than 2), find two p...
0.583259
Apps_5466
C
[ "sieve_of_eratosthenes", "goldbach_conjecture", "solve_goldbach" ]
3
[ [ "goldbach_conjecture", "sieve_of_eratosthenes" ], [ "solve_goldbach", "goldbach_conjecture" ] ]
2
[]
false
[]
false
pytest
false
[]
true
77e980cc9f7c9d67cd9866f07ddae4e8b525d245
7e07ac0ca8f20afa7b5e5b97899b012ef90ad947
v1.0
complete
Apps
Apps_5670_C
import math from typing import List, Tuple def euclidean_distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float: """ Computes the Euclidean distance between two points p1 and p2. """ def farthest_distance(points: List[Tuple[int, int]]) -> float: """ Computes the farthest Euclidean distance be...
import math def euclidean_distance(p1, p2): """ Computes the Euclidean distance between two points p1 and p2. """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def farthest_distance(points): """ Computes the farthest Euclidean distance between any two points in the set. """...
from solution import farthest_distance, euclidean_distance def test_euclidean_distance(): assert euclidean_distance((0, 0), (3, 4)) == 5.0 assert euclidean_distance((6, 8), (-3, -4)) == 15.0 assert euclidean_distance((1, 1), (1, 1)) == 0.0 def test_farthest_distance(): assert farthest_distance([(0, 0)...
[ { "docstring": "Computes the Euclidean distance between two points p1 and p2.", "function_declaration": "def euclidean_distance(p1, p2):", "function_name": "euclidean_distance", "parameter_list": "(p1, p2)" }, { "docstring": "Computes the farthest Euclidean distance between any two points in...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef farthest_distance(points):\n \"\"\"\n Calculates the farthest Euclidean distance between any two points in the set.\n \n :param point...
trial_gpt4o_1
{ "original_instruction": "A group of researchers is studying the migratory patterns of sea turtles. They have recorded the coordinates of several points visited by the turtles during their journey. For analysis purposes, they need to determine the farthest Euclidean distance between any two points in the set. You ar...
0.751846
Apps_5670
C
[ "euclidean_distance", "farthest_distance", "main" ]
3
[ [ "farthest_distance", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
eef8e31dd805529ec10ef28645333d2ff2829b16
f17e340babfb5209807f3859e51f8e14f0976f53
v1.0
complete
Apps
Apps_5785_C
import math from typing import List, Tuple def simplify_fraction(numerator: int, denominator: int) -> Tuple[int, int]: """Simplify a fraction to its simplest form. >>> simplify_fraction(4, 8) (1, 2) >>> simplify_fraction(50, 100) (1, 2) """ def reduce_fractions(fractions: List[Tuple[int, i...
import math def simplify_fraction(numerator, denominator): gcd = math.gcd(numerator, denominator) return (numerator // gcd, denominator // gcd) def reduce_fractions(fractions): simplified_fractions = [] for numerator, denominator in fractions: simplified_fractions.append(simplify_fraction(nume...
from solution import simplify_fraction, reduce_fractions def test_simplify_fraction(): assert simplify_fraction(4, 8) == (1, 2) assert simplify_fraction(50, 100) == (1, 2) assert simplify_fraction(7, 5) == (7, 5) assert simplify_fraction(15, 25) == (3, 5) assert simplify_fraction(22, 11) == (2, 1) ...
[ { "docstring": null, "function_declaration": "def simplify_fraction(numerator, denominator):", "function_name": "simplify_fraction", "parameter_list": "(numerator, denominator)" }, { "docstring": null, "function_declaration": "def reduce_fractions(fractions):", "function_name": "redu...
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef simplify_fraction(fractions):\n \"\"\"\n Simplifies a list of fractions.\n \n Parameters:\n fractions (list of tuples): A list of ...
trial_gpt4o_9
{ "original_instruction": "=====Function Descriptions=====\nmath.gcd\n\nThe `math.gcd` function returns the greatest common divisor of the two integers provided. The GCD of two integers is the largest integer that divides both of them without leaving a remainder.\n\nExample\nCode\n>>> import math\n>>> math.gcd(8, 12)...
0.705246
Apps_5785
C
[ "simplify_fraction", "reduce_fractions" ]
2
[ [ "reduce_fractions", "simplify_fraction" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4abfea8d5b1ea9ec9b3faf01ff024c85e02c301a
e6e5a5be3be224822e20cefe6169a2e5671fd27e
v1.0
complete
Apps
Apps_5098_C
def convert_to_minutes(zogday, zoghour, zogminute): """ Convert time in zogdays, zoghours, and zogminutes to total zogminutes. """ return zogday * 24 * 60 + zoghour * 60 + zogminute def check_events_overlap(events): """ Determine if any two events in a list overlap. Each event is repre...
def convert_to_minutes(zogday, zoghour, zogminute): """ Convert time in zogdays, zoghours, and zogminutes to total zogminutes. """ return zogday * 24 * 60 + zoghour * 60 + zogminute def check_events_overlap(events): """ Check if any two events overlap. """ event_times = [] for ...
from solution import check_events_overlap def test_no_overlap(): events = [ ((1, 5, 30), (0, 5, 0)), ((1, 10, 30), (0, 10, 0)), ((2, 20, 0), (0, 2, 0)) ] assert check_events_overlap(events) == "NO" def test_overlap_same_start_time(): events = [ ((1, 5, 30), (0, 5, 0)), ...
[ { "docstring": "Convert time in zogdays, zoghours, and zogminutes to total zogminutes.", "function_declaration": "def convert_to_minutes(zogday, zoghour, zogminute):", "function_name": "convert_to_minutes", "parameter_list": "(zogday, zoghour, zogminute)" }, { "docstring": "Check if any two ...
[ 0, 1, 0, 0, 1, 0, 1, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def convert_to_minutes(zz, hh, mm):\n \"\"\"\n Converts time in (zz, hh, mm) format to total minutes for easier comparison.\n \"\"\"\n return zz * 24 * ...
trial_gpt4o_9
{ "original_instruction": "In a distant planet called Zog, people measure time in \"zogdays\". A zogday is divided into \"zoghours\", and a zoghour into \"zogminutes\". \n\nYou are given a list of events, each represented by a starting time and duration. Each event looks like this: `start_time=(zz, hh, mm), duration=...
0.573589
Apps_5098
C
[ "convert_to_minutes", "check_events_overlap" ]
2
[ [ "check_events_overlap", "convert_to_minutes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a66046f553464c62a092107c9ee7ff3173f46e94
a44089fc04802dfe5027cd53d4233a20b21ff5c0
v1.0
complete
Apps
Apps_6102_C
def is_prime(n: int) -> bool: """ Checks if a number n is prime. >>> is_prime(2) True >>> is_prime(4) False """ pass def extract_primes(numbers: List[int]) -> List[int]: """ Takes a list of integers and returns a new list containing only the prime numbers from the original list...
def is_prime(n): """ Checks if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return T...
from solution import extract_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(13) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-3) == Fals...
[ { "docstring": "Checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Takes a list of integers and returns a new list containing only the prime numbers from the original list.", "function_decla...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return...
trial_gpt4o_8
{ "original_instruction": "Write a function that takes a list of integers and returns a new list containing only the prime numbers from the original list. The order of the elements must be maintained as in the original list.\n\nThe function should employ an efficient algorithm for checking primality to ensure it work...
0.781335
Apps_6102
C
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c163ed313025e3310d17b8445949255e24b81918
3f06bfa18d043574edead9df32e635a783946e10
v1.0
complete
Apps
Apps_5980_C
import math def is_prime(n: int) -> bool: """ Check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True def ...
import math 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(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True def sumOfPrimes(numbers): """ Returns the sum of the prim...
from solution import sumOfPrimes def test_sumOfPrimes_with_primes(): assert sumOfPrimes([1, 2, 3, 4, 5]) == 10 assert sumOfPrimes([7, 11, 13, 17]) == 48 assert sumOfPrimes([10, 2, 3, 7, 5]) == 17 def test_sumOfPrimes_no_primes(): assert sumOfPrimes([0, 1, 4, 6, 8]) == 0 assert sumOfPrimes([0, 1, 4...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the sum of the prime numbers in the list.", "function_declaration": "def sumOfPrimes(numbers):", "function_name": "sumOfPrimes", "param...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(n):\n \"\"\"\n Helper function to determine if a given number n is a prime number.\n \"\"\"\n if n <= 1:\n return Fal...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes an array of integers and returns the sum of the integers that are prime numbers. If the array contains no prime numbers, the function should return 0. \n\nA prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural n...
0.804199
Apps_5980
C
[ "is_prime", "sumOfPrimes" ]
2
[ [ "sumOfPrimes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c5c28d59d5c18cb2f25033790265fa81def6484
2440812aeec1771d763c993d12d80adead0a11e4
v1.0
complete
Apps
Apps_6247_C
from typing import List def median_of_concatenated_arrays(arr1: List[int], arr2: List[int]) -> float: """ Find the median of two sorted arrays that are concatenated together. >>> median_of_concatenated_arrays([1, 3], [2]) 2.0 >>> median_of_concatenated_arrays([1, 2], [3, 4]) 2.5 """
def median_of_concatenated_arrays(arr1, arr2): """ Returns the median of two concatenated sorted arrays. """ merged_array = merge_arrays(arr1, arr2) length = len(merged_array) if length % 2 == 1: return float(merged_array[length // 2]) else: mid1, mid2 = merged_array[len...
from solution import median_of_concatenated_arrays def test_median_of_concatenated_arrays_case1(): assert median_of_concatenated_arrays([1, 3], [2]) == 2.0 def test_median_of_concatenated_arrays_case2(): assert median_of_concatenated_arrays([1, 2], [3, 4]) == 2.5 def test_median_of_concatenated_arrays_case3(...
[ { "docstring": "Returns the median of two concatenated sorted arrays.", "function_declaration": "def median_of_concatenated_arrays(arr1, arr2):", "function_name": "median_of_concatenated_arrays", "parameter_list": "(arr1, arr2)" }, { "docstring": null, "function_declaration": "def merge_...
[ 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def median_of_concatenated_arrays(arr1, arr2):\n \"\"\"\n Returns the median of two sorted arrays concatenated together.\n \"\"\"\n # Combine both array...
trial_gpt4o_8
{ "original_instruction": "Write a function `median_of_concatenated_arrays(arr1, arr2)` that finds the median of two sorted arrays that are concatenated together. Both `arr1` and `arr2` are non-empty arrays of integers, sorted in non-decreasing order. The function should return the median value as a float.\n\n**Examp...
0.728437
Apps_6247
C
[ "median_of_concatenated_arrays", "merge_arrays" ]
2
[ [ "median_of_concatenated_arrays", "merge_arrays" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6ac9a7f2841e66baf780c794481424264f57a3d1
476e94adf4f55a351a87a1329ee52a5e24e6111d
v1.0
complete
Apps
Apps_6190_C
def is_prime(n: int) -> bool: """ Check if a number n is a prime number. """ pass def count_prime_partitions(s: str) -> int: """ Return the number of ways to partition the string s into non-empty substrings such that each substring represents a prime number. >>> count_prime_partiti...
def is_prime(n): """ Check if a number n is a prime number. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True def count_prime_partiti...
from solution import count_prime_partitions def test_example1(): assert count_prime_partitions("11373") == 6 def test_example2(): assert count_prime_partitions("3175") == 3 def test_single_digit_prime(): assert count_prime_partitions("7") == 1 def test_single_digit_non_prime(): assert count_prime_pa...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Return the number of ways to partition the string s into non-empty substrings\nsuch that each substring represents a pr...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import lru_cache\n\ndef is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "You are given a string containing only digits. Your task is to determine how many ways you can partition the string into non-empty substrings such that each substring represents a prime number. Each partitioning should use every character of the string exactly once.\n\nNote:\n- A prime numb...
0.691332
Apps_6190
C
[ "is_prime", "count_prime_partitions" ]
2
[ [ "count_prime_partitions", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f10e574c4ac7b27313a7fa1ac40436859704d5f0
3ad1c59426970511fa705f7e9c5ec2ca25ed8b77
v1.0
complete
Apps
Apps_5991_C
def restore_ip_addresses(s: str) -> List[str]: """ Given a string containing digits from 0 to 9, return all possible valid IP addresses that can be obtained by inserting dots into the string. A valid IP address consists of four integers (each ranging from 0 to 255) separated by periods. Each integer is...
def is_valid_segment(segment): """ Check if the given segment is a valid segment of an IP address. """ return 0 <= int(segment) <= 255 and str(int(segment)) == segment def restore_ip_addresses(s): """ Returns all possible valid IP addresses from the given string. """ def backtrack(start...
from solution import restore_ip_addresses def test_single_ip_address(): assert restore_ip_addresses("25525511135") == ["255.255.11.135", "255.255.111.35"] assert restore_ip_addresses("0000") == ["0.0.0.0"] def test_multiple_ip_addresses(): assert restore_ip_addresses("101023") == ["1.0.10.23", "1.0.102.3"...
[ { "docstring": "Check if the given segment is a valid segment of an IP address.", "function_declaration": "def is_valid_segment(segment):", "function_name": "is_valid_segment", "parameter_list": "(segment)" }, { "docstring": "Returns all possible valid IP addresses from the given string.", ...
[ 0, 1, 1, 1, 1, 0, 1, 0, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_part(s):\n \"\"\"\n Checks if a string s is a valid part of an IP address. A valid part should be within the range [0,255].\n It should not ha...
trial_gpt4o_9
{ "original_instruction": "Given a string containing digits from 0 to 9, write a function to return all possible valid IP addresses that can be obtained by inserting dots into the string. A valid IP address consists of four integers (each ranging from 0 to 255) separated by periods. Each integer is written without le...
0.610227
Apps_5991
C
[ "is_valid_segment", "restore_ip_addresses" ]
2
[ [ "restore_ip_addresses", "is_valid_segment" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b8d29e29a55acad6e38cd8faf78cd3f32b6f7ac0
5a561801b4c6dd95dd2c66f66ef6f6bfdb634f63
v1.0
complete
Apps
Apps_6159_C
def filter_primes(numbers: List[int]) -> List[int]: """ Write a Python function that takes a list of integers and returns a new list containing only the prime numbers from the original list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Implement the f...
def is_prime(n): """ Check if a number is a prime number. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_primes(numbers): """ Returns a list of prime numbers from the given list of integers. ...
from solution import filter_primes def test_filter_primes_all_prime(): """ Test when all numbers in the list are prime. """ assert filter_primes([2, 3, 5, 7, 11, 13, 17]) == [2, 3, 5, 7, 11, 13, 17] def test_filter_primes_mixed_numbers(): """ Test when the list contains both prime and non-prim...
[ { "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 prime numbers from the given list of integers.", "function_declaration": "def filter_primes(numbers...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0...
trial_gpt4o_9
{ "original_instruction": "Write a Python function that takes a list of integers and returns a new list containing only the prime numbers from the original list. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Implement the function using list comprehension.", ...
0.689044
Apps_6159
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6cdaee7d1c64d20e68c47980ed8ee4bfc2652548
1a462eba037e2e67e3d2e6771697ddcca627c241
v1.0
complete
Apps
Apps_6132_C
from typing import List def is_possible_to_form_palindrome(s: str) -> bool: """Determine if it's possible to rearrange the string into a palindrome. >>> is_possible_to_form_palindrome("aabb") True >>> is_possible_to_form_palindrome("ab") False >>> is_possible_to_form_palindrome("racecar") T...
def is_possible_to_form_palindrome(s): # Count the frequency of each character freq = {} for char in s: if char in freq: freq[char] += 1 else: freq[char] = 1 # Check the number of characters with odd frequency odd_count = 0 for count in freq.values():...
from solution import min_operations_to_form_palindrome, is_possible_to_form_palindrome, min_operations_for_test_cases def test_is_possible_to_form_palindrome(): assert is_possible_to_form_palindrome("aabb") assert not is_possible_to_form_palindrome("ab") assert is_possible_to_form_palindrome("racecar") ...
[ { "docstring": null, "function_declaration": "def is_possible_to_form_palindrome(s):", "function_name": "is_possible_to_form_palindrome", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def min_operations_to_form_palindrome(s):", "function_name": "min_operati...
[ 0, 1, 0, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl", "solution_code": "def min_operations_to_palindrome(S):\n from collections import Counter\n \n def can_form_palindrome(S):\n count = Counter(S...
trial_gpt4o_2
{ "original_instruction": "A palindrome is a string that reads the same forwards and backwards. Given a string \\(S\\), you are allowed to perform the following operation any number of times:\n- Choose a character from \\(S\\) and move it to the front of the string.\n\nYour task is to determine the minimum number of ...
0.768697
Apps_6132
C
[ "is_possible_to_form_palindrome", "min_operations_to_form_palindrome", "min_operations_for_test_cases" ]
3
[ [ "min_operations_for_test_cases", "min_operations_to_form_palindrome" ], [ "min_operations_to_form_palindrome", "is_possible_to_form_palindrome" ] ]
2
[ "min_operations_for_test_cases" ]
false
[]
false
pytest
true
[]
true
4b79d19d551540cb023d1317e1ac1311bff64969
ee9fe10c9243e7cbbd0c58a7d219cfb3e88a60ba
v1.0
complete
Apps
Apps_5541_C
from typing import List, Tuple def is_valid_fixture(n: int, m: int, matches: List[List[Tuple[int, int]]]) -> bool: """ Determines if the given fixture list is valid based on the specified constraints. n: int, number of teams m: int, number of days matches: list, list of matches for each day, forma...
def is_valid_fixture(n, m, matches): """ Determines if the given fixture list is valid based on the specified constraints. n: int, number of teams m: int, number of days matches: list, list of matches for each day, format: [(k1, [(a1, b1), (a2, b2), ...]), (k2, [(a3, b3), ...]), ...] R...
from solution import is_valid_fixture, check_fixtures def test_is_valid_fixture_valid_case(): n = 4 m = 2 matches = [ [(1, 2), (3, 4)], [(1, 3), (2, 4)] ] assert is_valid_fixture(n, m, matches) == True def test_is_valid_fixture_invalid_case_same_day(): n = 4 m = 2 match...
[ { "docstring": "Determines if the given fixture list is valid based on the specified constraints.\n\nn: int, number of teams\nm: int, number of days\nmatches: list, list of matches for each day, format: [(k1, [(a1, b1), (a2, b2), ...]), (k2, [(a3, b3), ...]), ...]\n\nReturns a boolean indicating if the fixture ...
[ 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_valid_fixture(n, m, matches):\n \"\"\"\n Determines if the given fixture list is valid based on the specified constraints.\n \n n: int, number of...
trial_gpt4o_0
{ "original_instruction": "Olivia is in charge of organizing a football tournament in her school. There are n teams participating in the tournament, and each team has a unique ID ranging from 1 to n. Olivia wants to create a fixture list where all the matches will be played over m days, with each day having one or mo...
0.606848
Apps_5541
C
[ "is_valid_fixture", "check_fixtures" ]
2
[ [ "check_fixtures", "is_valid_fixture" ] ]
1
[]
false
[]
false
pytest
true
[]
true
621ab52fda1b18fb4ef47c49df8718453caaa3ec
a94b661a84bd6570b84e1498c5418a08f306e190
v1.0
complete
Apps
Apps_6496_C
def read_input_and_calculate_total_sales(input_data: str) -> float: """ Reads input data, calculates the total sales amount for the day, and returns the result. Input data format: - First line contains an integer N representing the number of transactions. - The next N lines each contain a product n...
def calculate_total_sales(transactions): """ Calculates the total sales amount from a list of transactions. Each transaction is represented as a tuple of (product name, product price). """ total_sales = sum(price for name, price in transactions) return round(total_sales, 2) def read_input_and_c...
from solution import read_input_and_calculate_total_sales def test_single_transaction(): input_data = "1\nApple 1.20" assert read_input_and_calculate_total_sales(input_data) == 1.20 def test_multiple_transactions(): input_data = "4\nApple 1.20\nBanana 0.50\nOrange 0.75\nMango 2.00" assert read_input_a...
[ { "docstring": "Calculates the total sales amount from a list of transactions.\nEach transaction is represented as a tuple of (product name, product price).", "function_declaration": "def calculate_total_sales(transactions):", "function_name": "calculate_total_sales", "parameter_list": "(transaction...
[ 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def calculate_total_sales(transactions):\n \"\"\"\n Given a list of transactions where each transaction is represented by a tuple (product_name, price),\n ...
trial_gpt4o_9
{ "original_instruction": "Write a program to simulate a simplified version of a cash register system for a store. The system should handle multiple transactions and calculate the total sales for the day.\n\n-----Input-----\n- The first line contains a single integer `N`, which is the number of transactions.\n- The f...
0.600566
Apps_6496
C
[ "calculate_total_sales", "read_input_and_calculate_total_sales" ]
2
[ [ "read_input_and_calculate_total_sales", "calculate_total_sales" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a66689e9608d71095bce93458e32d97304942445
2aff43e8ec5cbc00af96de2bd490e9e7ca5a6ebe
v1.0
complete
Apps
Apps_6213_C
def organize_flower_deliveries(n: int, deliveries: List[Tuple[int, int]], m: int, query_times: List[int]) -> List[int]: """ Evelyn is managing a flower shop and needs your help to organize her flower deliveries. Each flower delivery is scheduled to be delivered within a certain time frame in the day, deno...
def count_deliveries_at_times(n, deliveries, m, query_times): delivery_count = [0] * 24 for t_start, t_end in deliveries: for time in range(t_start, t_end): delivery_count[time] += 1 result = [] for q in query_times: result.append(delivery_count[q]) return result def ...
from solution import organize_flower_deliveries def test_example(): n = 4 deliveries = [(9, 12), (10, 14), (13, 15), (19, 22)] m = 3 query_times = [11, 21, 5] expected_output = [2, 1, 0] assert organize_flower_deliveries(n, deliveries, m, query_times) == expected_output def test_single_deliver...
[ { "docstring": null, "function_declaration": "def count_deliveries_at_times(n, deliveries, m, query_times):", "function_name": "count_deliveries_at_times", "parameter_list": "(n, deliveries, m, query_times)" }, { "docstring": null, "function_declaration": "def organize_flower_deliveries(...
[ 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def deliveries_at_times(deliveries, queries):\n \"\"\"\n Determine the number of deliveries scheduled during the specific query times.\n\n :param deliverie...
trial_gpt4o_9
{ "original_instruction": "Evelyn is managing a flower shop and needs your help to organize her flower deliveries. Each flower delivery is scheduled to be delivered within a certain time frame in the day, denoted in 24-hour format. Given a list of delivery time frames and a list of specific times she needs to check, ...
0.625494
Apps_6213
C
[ "count_deliveries_at_times", "organize_flower_deliveries" ]
2
[ [ "organize_flower_deliveries", "count_deliveries_at_times" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94af389ae1a882054f02b0fc86b12b3c911985a0
b2a6374505e5c55083f0794fccde2c9bee250bdd
v1.0
complete
Apps
Apps_6830_C
def square_free_numbers(n: int) -> List[int]: """ Generate a sequence of the first n "square-free" numbers. A number is considered square-free if it is not divisible by any perfect square other than 1. If `n == 0`, return an empty list. >>> square_free_numbers(10) [1, 2, 3, 5, 6, 7, 10, 1...
def is_square_free(num): """ Determines if a number is square-free. """ if num == 1: return True for i in range(2, int(num**0.5) + 1): if (num % (i * i)) == 0: return False return True def square_free_numbers(n): """ Generates the first n square-free numbers....
from solution import square_free_numbers def test_square_free_numbers_first_10(): assert square_free_numbers(10) == [1, 2, 3, 5, 6, 7, 10, 11, 13, 14] def test_square_free_numbers_first_0(): assert square_free_numbers(0) == [] def test_square_free_numbers_first_1(): assert square_free_numbers(1) == [1] ...
[ { "docstring": "Determines if a number is square-free.", "function_declaration": "def is_square_free(num):", "function_name": "is_square_free", "parameter_list": "(num)" }, { "docstring": "Generates the first n square-free numbers.", "function_declaration": "def square_free_numbers(n):",...
[ 1, 1, 1, 1, 1, 1, 0, 0, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_square_free(num):\n \"\"\"\n Helper function to determine if a number is square-free.\n A number is square-free if it is not divisible by any perfec...
trial_gpt4o_9
{ "original_instruction": "Write a function that generates a sequence of \"square-free\" numbers. A number is considered square-free if it is not divisible by any perfect square other than 1. Your task is to generate the first `n` square-free numbers.\n\nFor example, the first 10 square-free numbers are: \n\n```\n[1,...
0.611634
Apps_6830
C
[ "is_square_free", "square_free_numbers" ]
2
[ [ "square_free_numbers", "is_square_free" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8aaa896898b421c3967182609d442d1a7b6c24c0
eae6602a8b383530d8d829f89801e45157d753ca
v1.0
complete
Apps
Apps_6141_C
def is_prime(n: int) -> bool: """ Determines if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(1) False >>> is_prime(0) False >>> is_prime(17) True >>> is_prime(18) False """ def split_and_sort_numbers(nums: List[int]) -> Tuple[List[i...
def is_prime(n): """ Determines if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def split_and_sort_numbers(nums...
from solution import split_and_sort_numbers, is_prime def test_split_and_sort_numbers_example(): nums = [8, 5, 1, 12, 3, 7, 15, 0, 4] result = split_and_sort_numbers(nums) assert result == ([3, 5, 7], [15, 12, 8, 4]) def test_split_and_sort_numbers_with_primes_only(): nums = [2, 3, 5, 7, 11, 13] r...
[ { "docstring": "Determines if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Splits a list of integers into prime and composite numbers.\nPrimes are sorted in ascending order, composites in descending o...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Checks if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n elif n <= 3:\n return True\n ...
trial_gpt4o_6
{ "original_instruction": "Create a function that takes an input list of integers and returns a tuple containing two lists: one with all the prime numbers from the original list, sorted in ascending order, and one with all the composite numbers from the original list, sorted in descending order. Zero and one should b...
0.785206
Apps_6141
C
[ "is_prime", "split_and_sort_numbers" ]
2
[ [ "split_and_sort_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c3f00b1263ae37f459c23d1d8f5a1ecd22a31f32
44413fc23f7946cea13568a277bc2c8422de9768
v1.0
complete
Apps
Apps_6406_C
def is_prime(n: int) -> bool: """ Check if a number is a prime number. >>> is_prime(2) True >>> is_prime(10) False """ def sum_of_primes(numbers: List[int]) -> int: """ Complete the function that takes a list of integers as input and returns the sum of the numbers that are prime. >>> sum_of...
def is_prime(n): if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def sum_of_primes(numbers): return sum(n for n in numbers if is_prime(n))
from solution import is_prime, sum_of_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(10) == False assert is_prime(13) == True assert is_prime(1) == False assert is_prime(-5) == Fals...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def sum_of_primes(numbers):", "function_name": "sum_of_primes", "parameter_list": "(numbers)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, else False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return...
trial_gpt4o_8
{ "original_instruction": "Complete the function that takes a list of integers as input and returns the sum of the numbers that are prime. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\n## Examples\n```\n[10, 11, 12, 13, 14, 15] ==> 24 (11 + 13)\n[2, 3, 4...
0.753048
Apps_6406
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
33244ccf1defd8a096c4918a0334bf170dd8a4f4
83a2311588eaa476cf32cca8b90f14d58a26f8cd
v1.0
complete
Apps
Apps_6349_C
def is_cyclic_permutation(s: str) -> bool: """ Determines if the given string s forms a cyclic permutation when its first character is moved to the end of the string. >>> is_cyclic_permutation("abc") False >>> is_cyclic_permutation("cab") False >>> is_cyclic_permutation("aaa") True >>> is_cy...
def is_cyclic_permutation(s): """ Determines if the given string s forms a cyclic permutation when its first character is moved to the end of the string. """ if len(s) <= 1: return True shifted_string = s[1:] + s[0] return shifted_string == s def check_cyclic_permutations(strings):...
from solution import is_cyclic_permutation, check_cyclic_permutations def test_is_cyclic_permutation(): assert is_cyclic_permutation("abc") == False assert is_cyclic_permutation("cab") == False assert is_cyclic_permutation("aaa") == True assert is_cyclic_permutation("a") == True assert is_cyclic_pe...
[ { "docstring": "Determines if the given string s forms a cyclic permutation when its first character\nis moved to the end of the string.", "function_declaration": "def is_cyclic_permutation(s):", "function_name": "is_cyclic_permutation", "parameter_list": "(s)" }, { "docstring": "Checks each...
[ 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_cyclic_permutation(s):\n \"\"\"\n Determine if the string s forms a cyclic permutation by moving the first character to the end.\n \"\"\"\n if s ...
trial_gpt4o_9
{ "original_instruction": "Alice has a collection of strings. She likes to play a game where she removes the first character from each string and appends it to the end of the string. If the resulting string matches the original string, it forms a \"cyclic permutation\". Given a set of strings, determine how many of t...
0.626748
Apps_6349
C
[ "is_cyclic_permutation", "check_cyclic_permutations" ]
2
[ [ "check_cyclic_permutations", "is_cyclic_permutation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
535489ecddd652818317065428867a53d73d3a57
b6b03faaffca2542cb8caa8489931faba3a0a19c
v1.0
complete
Apps
Apps_6000_C
def convert_to_minutes(time_str): """ Helper function to convert time 'HH:MM' to minutes since midnight. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def schedule_meeting(meetings, new_meeting): """ Determines if a new meeting can be scheduled without confl...
def convert_to_minutes(time_str): """ Helper function to convert time 'HH:MM' to minutes since midnight. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def schedule_meeting(meetings, new_meeting): """ Determines if a new meeting can be scheduled without confl...
from solution import schedule_meeting def test_non_overlapping_meeting(): meetings = [("09:00", "10:00"), ("11:00", "12:00"), ("13:00", "14:00")] new_meeting = ("10:00", "11:00") assert schedule_meeting(meetings, new_meeting) == True def test_overlapping_meeting(): meetings = [("09:00", "10:00"), ("11...
[ { "docstring": "Helper function to convert time 'HH:MM' to minutes since midnight.", "function_declaration": "def convert_to_minutes(time_str):", "function_name": "convert_to_minutes", "parameter_list": "(time_str)" }, { "docstring": "Determines if a new meeting can be scheduled without conf...
[ 1, 0, 1, 1, 0, 0, 0, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def schedule_meeting(meetings, new_meeting):\n \"\"\"\n Determines if a new meeting can fit into an existing schedule without overlapping.\n \n Paramete...
trial_gpt4o_9
{ "original_instruction": "# Tasks\n\nWrite a function `schedule_meeting(meetings, new_meeting)` that determines if a new meeting time can fit into an existing schedule without overlapping with other meetings.\n\nGiven:\n1. A list of tuples, `meetings`, where each tuple contains two strings representing the start and...
0.549558
Apps_6000
C
[ "convert_to_minutes", "schedule_meeting" ]
2
[ [ "schedule_meeting", "convert_to_minutes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d87e71088b02613e081c8b9ee8ac5a271a2c945d
8e3d2be291e51f251f066118724a468018377ee3
v1.0
complete
Apps
Apps_6633_C
from typing import List def extract_primes(numbers: List[int]) -> List[int]: """ Given a list of integers, identify and return a new list containing only the prime numbers from the original list. Prime numbers are numbers greater than 1 that have no divisors other than 1 and themselves. >>> extract_primes([2, ...
from typing import List def is_prime(n: int) -> bool: """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return Fa...
from solution import extract_primes def test_extract_primes_with_mixed_list(): assert extract_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_extract_primes_with_all_primes(): assert extract_primes([2, 3, 5, 7, 11, 13, 17, 19]) == [2, 3, 5, 7, 11, 13, 17, 19] def test_extract_primes_with_no_pri...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Function to extract prime numbers from a list of integers.", "function_declaration": "def extract_primes(nu...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 == 0:\n ret...
trial_gpt4o_9
{ "original_instruction": "Given a list of integers, identify and return a new list containing only the prime numbers from the original list. Prime numbers are numbers greater than 1 that have no divisors other than 1 and themselves. Implement the function `extract_primes(numbers: List[int]) -> List[int]` that takes ...
0.661468
Apps_6633
C
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6a2d2fd58fa25cb3a408ddb86a16df87af2f14fd
8fbf0db6017b227e9b8ac176991db44a0bd6a41a
v1.0
complete
Apps
Apps_6601_C
def next_term(term: str) -> str: """ Generates the next term in the look-and-say sequence given the current term. >>> next_term("1") == "11" >>> next_term("11") == "21" >>> next_term("21") == "1211" >>> next_term("1211") == "111221" """ pass def look_and_say(n: int) -> str: """ Returns ...
def next_term(term): """ Generates the next term in the look-and-say sequence given the current term. Args: term (str): the current term of the sequence. Returns: str: the next term of the sequence. """ result = [] i = 0 while i < len(term): count = 1 while i + ...
from solution import look_and_say, next_term def test_next_term(): assert next_term("1") == "11" assert next_term("11") == "21" assert next_term("21") == "1211" assert next_term("1211") == "111221" def test_look_and_say_single_term(): assert look_and_say(1) == "1" def test_look_and_say_two_terms(...
[ { "docstring": "Generates the next term in the look-and-say sequence given the current term.\n\nArgs:\nterm (str): the current term of the sequence.\n\nReturns:\nstr: the next term of the sequence.", "function_declaration": "def next_term(term):", "function_name": "next_term", "parameter_list": "(te...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def next_term(term):\n \"\"\"\n Generate the next term in the look-and-say sequence given the current term.\n \"\"\"\n result = []\n i = 0\n\n whi...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes an integer n and returns a string representation of the first n terms of the look-and-say sequence. The look-and-say sequence is a series of numbers where each number is derived from a description of the digits of the term before.\n\nThe first term is always \"1\...
0.575103
Apps_6601
C
[ "next_term", "look_and_say" ]
2
[ [ "look_and_say", "next_term" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e8d0b6ce3da075a80703eeaef468f05554c1bdc8
093e6933b247df6c8db1fc105d39327d17473d1f
v1.0
complete
Apps
Apps_6424_C
from typing import List def largest_concatenated_number(nums: List[int]) -> str: """ Given a list of non-negative integers, arranges them such that they form the largest possible number when concatenated. >>> largest_concatenated_number([10, 2]) == "210" >>> largest_concatenated_number([3, 30, 34...
from functools import cmp_to_key def compare(x, y): if x + y > y + x: return -1 elif x + y < y + x: return 1 else: return 0 def largest_concatenated_number(nums): """ Given a list of non-negative integers, arranges them such that they form the largest possible number when c...
from solution import largest_concatenated_number def test_largest_concatenated_number(): assert largest_concatenated_number([10, 2]) == "210" assert largest_concatenated_number([3, 30, 34, 5, 9]) == "9534330" assert largest_concatenated_number([1]) == "1" assert largest_concatenated_number([0, 0]) == "...
[ { "docstring": null, "function_declaration": "def compare(x, y):", "function_name": "compare", "parameter_list": "(x, y)" }, { "docstring": "Given a list of non-negative integers, arranges them such that they form the largest possible number when concatenated.", "function_declaration": "...
[ 1, 0, 1, 1, 1, 1, 1, 0, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from functools import cmp_to_key\n\ndef compare(a, b):\n \"\"\"\n Compare function for sorting the numbers.\n \"\"\"\n if a + b > b + a:\n return...
trial_gpt4o_9
{ "original_instruction": "Write a function that, for a given list of non-negative integers, arranges them such that they form the largest possible number when concatenated. The function should return this number as a string. You can assume that the input list will always contain at least one integer and all integers...
0.695628
Apps_6424
C
[ "compare", "largest_concatenated_number" ]
2
[ [ "largest_concatenated_number", "compare" ] ]
1
[]
false
[]
false
pytest
true
[]
true
993a600e9731e102aeafe63ecdb8d33674dde372
e116c3f78057af69c938880235e8a836f3d7575d
v1.0
complete
Apps
Apps_6099_C
from typing import List from collections import Counter def longest_anagram_sequence(words: List[str]) -> int: """ Write a function that accepts a list of strings and returns the length of the longest consecutive sequence of strings where each string is an anagram of the next in the list. >>> longest_...
from collections import Counter def are_anagrams(s1, s2): """ Helper function to determine if two strings are anagrams """ return Counter(s1) == Counter(s2) def longest_anagram_sequence(words): """ Returns the length of the longest consecutive sequence of anagram strings in the list """ ...
from solution import longest_anagram_sequence def test_longest_anagram_sequence(): assert longest_anagram_sequence(["listen", "silent", "enlist", "inlets", "google", "elgoog", "hello", "ohell"]) == 4 assert longest_anagram_sequence(["apple", "paple", "pale", "leap", "peal", "plea", "appeal"]) == 4 assert l...
[ { "docstring": "Helper function to determine if two strings are anagrams", "function_declaration": "def are_anagrams(s1, s2):", "function_name": "are_anagrams", "parameter_list": "(s1, s2)" }, { "docstring": "Returns the length of the longest consecutive sequence of anagram strings in the li...
[ 0, 0, 1, 0, 0, 1, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_anagram_sequence(words):\n def sorted_word(word):\n return ''.join(sorted(word))\n \n sorted_words = [sorted_word(word) for word in word...
trial_gpt4o_7
{ "original_instruction": "Write a function that accepts a list of strings and returns the length of the longest consecutive sequence of strings where each string is an anagram of the next in the list.\n\n### Example\n\n```python\nlongest_anagram_sequence([\"listen\", \"silent\", \"enlist\", \"inlets\", \"google\", \...
0.633744
Apps_6099
C
[ "are_anagrams", "longest_anagram_sequence" ]
2
[ [ "longest_anagram_sequence", "are_anagrams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1b050d117af5faddebce62d7088a4fa8bdfdb27f
6b3c018055210d7e6bbaeafcba02ecd48a7af918
v1.0
complete
Apps
Apps_6472_C
def toggle_lamps(lamps: str) -> str: """ Toggles the lamps in a given house. Turns '0' to '1' and '1' to '0'. >>> toggle_lamps("010") "101" >>> toggle_lamps("111") "000" """ def are_all_lamps_on(houses: List[str], l: int, r: int) -> str: """ Checks if all lamps are on in the given rang...
def toggle_lamps(lamps): """ Toggles the lamps in a given house. Turns '0' to '1' and '1' to '0'. """ return ''.join('1' if lamp == '0' else '0' for lamp in lamps) def are_all_lamps_on(houses, l, r): """ Checks if all lamps are on in the given range of houses. """ for i in range(l -...
from solution import toggle_lamps, are_all_lamps_on, process_operations def test_toggle_lamps(): assert toggle_lamps("010") == "101" assert toggle_lamps("111") == "000" assert toggle_lamps("000") == "111" def test_are_all_lamps_on(): house_states = ["010", "111", "000"] assert are_all_lamps_on(hou...
[ { "docstring": "Toggles the lamps in a given house.\nTurns '0' to '1' and '1' to '0'.", "function_declaration": "def toggle_lamps(lamps):", "function_name": "toggle_lamps", "parameter_list": "(lamps)" }, { "docstring": "Checks if all lamps are on in the given range of houses.", "function...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def toggle_lamps(lamps, l, r):\n \"\"\"\n Toggles all lamps from house l to house r (inclusive).\n \"\"\"\n for i in range(l-1, r):\n lamps[i] = ...
trial_gpt4o_3
{ "original_instruction": "In a city, there are n houses aligned along a straight road, and each house has some number of lamps installed. Each lamp in the house can either be on or off. You are given the initial state of the lamps in each house, where '1' denotes a lamp being on and '0' denotes a lamp being off.\n\n...
0.507273
Apps_6472
C
[ "toggle_lamps", "are_all_lamps_on", "process_operations" ]
3
[ [ "process_operations", "are_all_lamps_on" ], [ "process_operations", "toggle_lamps" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c43d38776167ab2a038ca0990281715d06b423db
7ab604e1509eeb8b4879d342adb75ddace5609c2
v1.0
complete
Apps
Apps_6429_C
def castle_painting(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int]]]]) -> List[str]: """ Determine if it is possible to paint the castle such that no two connected rooms have the same color. >>> T = 2 >>> test_cases = [ ... (3, 3, [(1, 2), (2, 3), (3, 1)]), ... (4, 5, [(1, 2), (...
def is_painting_possible(adj, N): color = [-1] * N def can_paint(room, c): color[room] = c for neighbor in adj[room]: if color[neighbor] == c: return False if color[neighbor] == -1 and not can_paint(neighbor, (c + 1) % 3): return False ...
import pytest from solution import castle_painting def test_example_cases(): T = 2 test_cases = [ (3, 3, [(1, 2), (2, 3), (3, 1)]), (4, 5, [(1, 2), (2, 3), (3, 4), (4, 1), (1, 3)]) ] expected_output = [ "Possible\n1 2 3", "Not Possible" ] assert castle_painting(T...
[ { "docstring": null, "function_declaration": "def is_painting_possible(adj, N):", "function_name": "is_painting_possible", "parameter_list": "(adj, N)" }, { "docstring": null, "function_declaration": "def castle_painting(T, test_cases):", "function_name": "castle_painting", "para...
[ 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_color_valid(room, color, graph, colors):\n for neighbor in graph[room]:\n if colors[neighbor] == color:\n return False\n return True\...
trial_gpt4o_2
{ "original_instruction": "A castle contains several rooms which must be painted. The castle layout is represented as a graph, where each node represents a room, and each edge represents a direct passage between two rooms. Each room must be painted one of three colors: red, blue, or green. No two rooms directly conne...
0.605183
Apps_6429
C
[ "is_painting_possible", "castle_painting" ]
2
[ [ "castle_painting", "is_painting_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c1e04d0c75c17bf555a8987c4c00d6520c9a9a96
a74274537a561586d81d0e44a389f1074db90c3c
v1.0
complete
Apps
Apps_6817_C
from typing import List, Union def replace_primes(lst: List[int]) -> List[Union[int, str]]: """ Takes a list of integers and returns a list of the same integers, but with all prime numbers replaced by the string "prime". >>> replace_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) ['prime', 'prime', 4, 'pri...
def is_prime(n): """ Checks if a number is prime. """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def replace_primes(lst): """ Returns a list with all prime numbers replaced by the string "prime". ...
from solution import replace_primes def test_replace_primes_all_primes(): assert replace_primes([2, 3, 5, 7, 11]) == ['prime', 'prime', 'prime', 'prime', 'prime'] def test_replace_primes_mixed_numbers(): assert replace_primes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == ['prime', 'prime', 4, 'prime', 6, 'prime', 8, 9, 10...
[ { "docstring": "Checks if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list with all prime numbers replaced by the string \"prime\".\nIf the input list is empty, it returns an empty list.", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes a list of integers and returns a list of the same integers, but with all prime numbers replaced by the string \"prime\". \n\nTo briefly explain, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. If the functi...
0.634081
Apps_6817
C
[ "is_prime", "replace_primes" ]
2
[ [ "replace_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d15e7b66e759e96368a316b640606fb06eee7798
c7ad92cb06cc55fa9a8feb842b8864424e1c9b41
v1.0
complete
Apps
Apps_7225_C
import math from functools import reduce def min_cupcakes(departments: List[int]) -> int: """ Returns the minimum number of cupcakes needed such that each department gets exactly one cupcake per employee and no cupcakes are left over. >>> min_cupcakes([5]) == 5 >>> min_cupcakes([5, 7, 3]) == 1...
import math from functools import reduce def lcm(a, b): return abs(a*b) // math.gcd(a, b) def min_cupcakes(departments): """ Returns the minimum number of cupcakes needed such that each department gets exactly one cupcake per employee and no cupcakes are left over. """ total_employees = reduce...
from solution import min_cupcakes def test_single_department(): assert min_cupcakes([5]) == 5 def test_multiple_departments(): assert min_cupcakes([5, 7, 3]) == 105 def test_all_same_size_departments(): assert min_cupcakes([4, 4, 4]) == 4 def test_two_departments(): assert min_cupcakes([6, 8]) == 24...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the minimum number of cupcakes needed such that each department\ngets exactly one cupcake per employee and no cupcakes are left over.", "function_d...
[ 0, 1, 1, 1, 1, 0, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef min_cupcakes(departments):\n \"\"\"\n...
trial_gpt4o_9
{ "original_instruction": "A company treats its employees with cupcakes on special occasions. The management wants to determine the minimum number of cupcakes they need to order such that each employee gets at least one cupcake, and no cupcakes are left over.\n\nCreate a function, `min_cupcakes`, that takes a list of...
0.615065
Apps_7225
C
[ "lcm", "min_cupcakes" ]
2
[ [ "min_cupcakes", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1a626343ebd611530580fbf038a9dcd29755a3c0
aa992d21f1c77fa0661a2788e5612620e17d47ee
v1.0
complete
Apps
Apps_6971_C
from typing import List, Tuple def easiest_path(t: int, test_cases: List[Tuple[int, int, List[List[int]]]]) -> List[int]: """ Determine the difficulty of the easiest path from the top-left corner to the bottom-right corner of the grid. Parameters: t (int): The number of test cases. test_cases (Lis...
from collections import deque def valid_path(G, mid, n, m): directions = [(0, 1), (1, 0)] queue = deque([(0, 0)]) visited = [[False] * m for _ in range(n)] visited[0][0] = True while queue: x, y = queue.popleft() if x == n - 1 and y == m - 1: return True for...
def test_easiest_path(): test_cases = [ (2, [ (3, 3, [ [1, 2, 2], [3, 8, 2], [5, 3, 5] ]), (2, 2, [ [1, 1], [1, 1] ]) ]), (1, [ (2, 2, [ ...
[ { "docstring": null, "function_declaration": "def valid_path(G, mid, n, m):", "function_name": "valid_path", "parameter_list": "(G, mid, n, m)" }, { "docstring": null, "function_declaration": "def min_difficulty(G, n, m):", "function_name": "min_difficulty", "parameter_list": "(G...
[ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from heapq import heappush, heappop\n\ndef easiest_path_difficulty(t, test_cases):\n def calculate_min_difficulty(n, m, grid):\n directions = [(0, 1), (1,...
trial_gpt4o_5
{ "original_instruction": "Peter has recently started working as a courier. He has to deliver packages in a city that is laid out as a perfect grid of size $n \\times m$. Peter starts at the top-left corner of the grid (0, 0) and must deliver a package to the bottom-right corner of the grid (n-1, m-1).\n\nThe grid is...
0.628481
Apps_6971
C
[ "valid_path", "min_difficulty", "easiest_path" ]
3
[ [ "easiest_path", "min_difficulty" ], [ "min_difficulty", "valid_path" ] ]
2
[]
false
[]
false
pytest
false
[]
true
6f15ffc4b7b10c7619ae6a46de6004536a6a3cf5
ad583c2618be2d79076053b45a3596e3d1aa2e18
v1.0
complete
Apps
Apps_7121_C
from typing import List def first_n_primes(n: int) -> List[int]: """ Complete the function that takes a positive integer `n` and returns a list of the first `n` prime numbers. Examples: >>> first_n_primes(1) == [2] >>> first_n_primes(3) == [2, 3, 5] >>> first_n_primes(5) == [2, 3, 5, 7, 1...
def is_prime(num): if num <= 1: return False if num == 2: return True if num % 2 == 0: return False max_divisor = int(num**0.5) + 1 for i in range(3, max_divisor, 2): if num % i == 0: return False return True def first_n_primes(n): primes = [] ...
from solution import first_n_primes def test_first_prime(): assert first_n_primes(1) == [2] def test_first_three_primes(): assert first_n_primes(3) == [2, 3, 5] def test_first_five_primes(): assert first_n_primes(5) == [2, 3, 5, 7, 11] def test_first_ten_primes(): assert first_n_primes(10) == [2, 3,...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def first_n_primes(n):", "function_name": "first_n_primes", "parameter_list": "(n)" } ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num == 2:\n return True\n if num % 2 == 0:\n return False\n max_divisor = int...
trial_gpt4o_0
{ "original_instruction": "Complete the function that takes a positive integer `n` and returns a list of the first `n` prime numbers.\n\n## Examples\n\n```python\nn = 1 ==> [2] # first prime number is 2\nn = 3 ==> [2, 3, 5] # first 3 prime numbers are 2, 3, 5\nn = 5 ==> [2, 3, 5, 7, 11] #...
0.752147
Apps_7121
C
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8776399bbb40427e225c76922fe3b75b3089a571
9c1972b367aea01daf388f89bb5c261ad7e6e96b
v1.0
complete
Apps
Apps_6259_C
class TreeNode: def __init__(self, value): self.value = value self.children = [] def build_tree(values, edges): """Build the tree from given node values and edges.""" nodes = [TreeNode(value) for value in values] adjacency_list = [[] for _ in range(len(values))] for u, v in edg...
class TreeNode: def __init__(self, value): self.value = value self.children = [] def build_tree(values, edges): nodes = [TreeNode(value) for value in values] adjacency_list = [[] for _ in range(len(values))] for u, v in edges: adjacency_list[u-1].append(v-1) adjacen...
from solution import process_queries def test_example_case(): N = 5 Q = 5 values = [1, 2, 3, 4, 5] edges = [(1, 2), (1, 3), (2, 4), (2, 5)] queries = ["2 1", "2 2", "1 2 10", "2 1", "2 2"] expected_output = [15, 11, 23, 19] assert process_queries(N, Q, values, edges, queries) == expected_ou...
[]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\nclass Tree:\n def __init__(self, N, values):\n self.N = N\n self.values = values\n self.tree =...
trial_gpt4o_7
{ "original_instruction": "Alex is working with a tree data structure and needs to perform certain operations on it. The tree has $N$ nodes, numbered from $1$ to $N$, where each node has an integer value assigned to it.\n\nA \"subtree\" of a node $u$ is defined as a node $u$ and all its descendants in the tree.\n\nYo...
0.592264
Apps_6259
C
[ "build_tree", "update_value", "subtree_sum", "process_queries" ]
4
[ [ "process_queries", "build_tree" ], [ "process_queries", "subtree_sum" ], [ "process_queries", "update_value" ] ]
3
[ "process_queries" ]
false
[ "TreeNode" ]
true
pytest
true
[]
true
3f94fec21e3e2e76e7f7c38ad0f657cf85b815ab
445581832f1bd99b6757559e82a6335b3d75faf7
v1.0
complete
Apps
Apps_6994_C
from typing import List def get_minutes_since_midnight(time_str: str) -> int: """Convert a time in HH:MM format to minutes since midnight.""" hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def events_overlap(timestamps: List[str], duration: int) -> bool: """Determines if an...
def get_minutes_since_midnight(time_str): """ Convert a time in HH:MM format to minutes since midnight. """ hours, minutes = map(int, time_str.split(':')) return hours * 60 + minutes def events_overlap(timestamps, duration): """ Determines if any two events overlap given their starting time...
from solution import events_overlap def test_no_overlap(): timestamps = ["09:00", "10:30", "12:00"] duration = 60 assert events_overlap(timestamps, duration) == False def test_overlap(): timestamps = ["09:00", "09:30", "10:00"] duration = 45 assert events_overlap(timestamps, duration) == True ...
[ { "docstring": "Convert a time in HH:MM format to minutes since midnight.", "function_declaration": "def get_minutes_since_midnight(time_str):", "function_name": "get_minutes_since_midnight", "parameter_list": "(time_str)" }, { "docstring": "Determines if any two events overlap given their s...
[ 0, 1, 1, 0, 0, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def events_overlap(timestamps, duration):\n \"\"\"\n Determines if any events in a list of timestamps overlap given a duration.\n \n Args:\n timestam...
trial_gpt4o_9
{ "original_instruction": "You are given a list of event timestamps and a duration in minutes, and your task is to determine if any two events overlap. \n\nAn event's duration starts at its given timestamp and lasts for the specified duration.\n\n## Input\n\n- A list of timestamps in `HH:MM` 24-hour format, indicatin...
0.582418
Apps_6994
C
[ "get_minutes_since_midnight", "events_overlap" ]
2
[ [ "events_overlap", "get_minutes_since_midnight" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bf0235c9b6a867985e3affe82a043d7446eae13b
f6417ab6f0d3665dd28964e8faf1a50b22deb0cf
v1.0
complete
Apps
Apps_7742_C
def is_palindrome(word: str) -> bool: """ Check if the given word is a palindrome. """ return word == word[::-1] def min_removals_to_non_palindrome(word: str) -> int: """ Determines if the word is a palindrome, and if it is, counts the minimum number of character removals required to make it a non...
def is_palindrome(word): """ Check if the given word is a palindrome. """ return word == word[::-1] def min_removals_to_non_palindrome(word): """ Determines if the word is a palindrome, and if it is, counts the minimum number of character removals required to make it a non-palindrome. ...
from solution import min_removals_to_non_palindrome def test_min_removals_to_non_palindrome_palindromes(): assert min_removals_to_non_palindrome("racecar") == 1 assert min_removals_to_non_palindrome("abba") == 1 assert min_removals_to_non_palindrome("level") == 1 assert min_removals_to_non_palindrome("...
[ { "docstring": "Check if the given word is a palindrome.", "function_declaration": "def is_palindrome(word):", "function_name": "is_palindrome", "parameter_list": "(word)" }, { "docstring": "Determines if the word is a palindrome, and if it is, counts the minimum\nnumber of character removal...
[ 0, 1, 1, 0, 0, 0, 0, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_removals_to_non_palindrome(word):\n \"\"\"\n Determines if a given word is a palindrome, and if it is,\n counts the minimum number of character rem...
trial_gpt4o_9
{ "original_instruction": "Write a program that determines if a given word is a palindrome, and then, if it is, count the minimum number of character removals required to make it a non-palindrome.\n\nA palindrome is a word that reads the same backward as forward (e.g., \"level\", \"racecar\"). \n\nIf the word is not ...
0.813129
Apps_7742
C
[ "is_palindrome", "min_removals_to_non_palindrome" ]
2
[ [ "min_removals_to_non_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2863b990c63911b5ed49d8266b1b90e428a5318c
20619f34deb7aa88b3faf2c545385d42844ed602
v1.0
complete
Apps
Apps_7056_C
def max_cookies(N: int, M: int, available_ingredients: List[int], cookies_info: List[List[int]]) -> int: """ Determine the maximum number of different types of cookies that can be baked. Args: N (int): The number of available ingredients. M (int): The number of different types of cookies. available...
def max_cookies(N, M, available_ingredients, cookies_info): count = 0 for cookie in cookies_info: can_bake = True for i in range(0, len(cookie), 2): ingredient_index = cookie[i] - 1 # Convert to 0-based index required_quantity = cookie[i + 1] if...
from solution import max_cookies, solve_baking_problem def test_example_case(): input_data = "4 3\n10 5 6 8\n2 1 3 2 2\n3 1 2 3 1 4 2\n2 2 4 4 1\n" result = solve_baking_problem(input_data) assert result == 2 def test_only_one_cookie_can_be_baked(): input_data = "3 2\n5 4 3\n2 1 2 2 3\n2 1 6 2 2\n" ...
[ { "docstring": null, "function_declaration": "def max_cookies(N, M, available_ingredients, cookies_info):", "function_name": "max_cookies", "parameter_list": "(N, M, available_ingredients, cookies_info)" }, { "docstring": null, "function_declaration": "def solve_baking_problem(input_str)...
[ 0, 1, 0, 0, 0, 0, 1, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_types_of_cookies(N, M, available_quantities, cookie_recipes):\n max_cookies_baked = 0\n\n for recipe in cookie_recipes:\n can_bake = True\n ...
trial_gpt4o_9
{ "original_instruction": "Anna is planning to bake a variety of cookies for a local bake sale. She has a list of ingredients required for each type of cookie, and she needs to figure out how many different types of cookies she can bake given the quantities of ingredients available in her pantry.\n\n**Input**\n\nYou ...
0.686837
Apps_7056
C
[ "max_cookies", "solve_baking_problem" ]
2
[ [ "solve_baking_problem", "max_cookies" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5640c118fe06fb36704f5591e189270a5d51e13c
fedd76c1824cea8b22b6fb3419849bdf4073697c
v1.0
complete
Apps
Apps_6565_C
def look_and_say(n: int) -> str: """ Generate the n-th term in the look-and-say sequence. >>> look_and_say(1) '1' >>> look_and_say(2) '11' >>> look_and_say(3) '21' >>> look_and_say(4) '1211' >>> look_and_say(5) '111221' """
def look_and_say(n): """ Generate the n-th term in the look-and-say sequence. """ if n <= 0: return "" result = "1" for _ in range(1, n): result = _get_next_sequence(result) return result def _get_next_sequence(sequence): """ Generates the next sequence in the l...
from solution import look_and_say def test_look_and_say_first_term(): assert look_and_say(1) == "1" def test_look_and_say_second_term(): assert look_and_say(2) == "11" def test_look_and_say_third_term(): assert look_and_say(3) == "21" def test_look_and_say_fourth_term(): assert look_and_say(4) == "1...
[ { "docstring": "Generate the n-th term in the look-and-say sequence.", "function_declaration": "def look_and_say(n):", "function_name": "look_and_say", "parameter_list": "(n)" }, { "docstring": "Generates the next sequence in the look-and-say sequence.", "function_declaration": "def _get...
[ 1, 1, 1, 0, 1, 0, 1, 1, 1, 1 ]
8
easy
0.8
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def look_and_say(n):\n \"\"\"\n Generate the nth term in the look-and-say sequence.\n \"\"\"\n if n == 1:\n return '1'\n \n def next_term(t...
trial_gpt4o_9
{ "original_instruction": "Write a function to generate the 'look-and-say' sequence. Given an integer `n`, generate the `n`th term in the sequence.\n\n**The look-and-say sequence:**\n- 1\n- 11\n- 21\n- 1211\n- 111221\n- ...\n\nEach term is generated by describing the previous term in terms of consecutive digits.\n\n*...
0.624891
Apps_6565
C
[ "look_and_say", "_get_next_sequence" ]
2
[ [ "look_and_say", "_get_next_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ce07fb6c0c8320d51ddfc9f6125de3afde21ea82
eadf2862e4f65f62f6f91425020ad943208aa031
v1.0
complete
Apps
Apps_6504_C
def shift_string(input_string: str) -> str: """ Shifts each character in the input string to the right by one position in the ASCII table, with wrapping for alphabetic characters. Non-alphabetic characters remain unchanged. >>> shift_string("abc") 'bcd' >>> shift_string("xyz") 'yza' ...
def shift_char(c): """ Shifts a character to the right by one position in the ASCII table, wrapping around as necessary for alphabetic characters. """ if 'a' <= c <= 'z': return chr(((ord(c) - ord('a') + 1) % 26) + ord('a')) elif 'A' <= c <= 'Z': return chr(((ord(c) - ord('A') + ...
from solution import shift_string def test_shift_string_simple(): assert shift_string("abc") == "bcd" def test_shift_string_wrap_around_lowercase(): assert shift_string("xyz") == "yza" def test_shift_string_wrap_around_uppercase(): assert shift_string("XYZ") == "YZA" def test_shift_string_mixed_case_and...
[ { "docstring": "Shifts a character to the right by one position in the ASCII table,\nwrapping around as necessary for alphabetic characters.", "function_declaration": "def shift_char(c):", "function_name": "shift_char", "parameter_list": "(c)" }, { "docstring": "Shifts each character in the ...
[ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def shift_string(s):\n \"\"\"\n Shifts each alphabetical character in the string s to the next one in the ASCII table.\n Wraps around 'z' to 'a' and 'Z' to...
trial_gpt4o_9
{ "original_instruction": "Write a function that takes a string as input and returns a new string such that each character from the original string is shifted to the right by one position in the ASCII table. If the shift causes the character to go past 'z', it should wrap around to 'a'. Similarly, if the character go...
0.758093
Apps_6504
C
[ "shift_char", "shift_string" ]
2
[ [ "shift_string", "shift_char" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8a56420b451b12bf2574dde65c43528d85085833
255fa4b2fdc8cfb5f4962eb1a97ce1e68df0e008
v1.0
complete
Apps
Apps_7737_C
def is_prime(n: int) -> bool: """ Returns True if the number n is prime, else False. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(5) True >>> is_prime(9) False >>> is_prime(11) True >>> is_prime(-1) False >>> is_prime(0) ...
def is_prime(n): """ Returns True if the number n is prime, else False. """ if n <= 1: return False if n == 2: return True # 2 is the only even prime number if n % 2 == 0: return False # Exclude other even numbers for i in range(3, int(n**0.5) + 1, 2): if n ...
from solution import is_prime, filter_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(9) == False assert is_prime(11) == True assert is_prime(-1) == False assert is_prime(0) == False...
[ { "docstring": "Returns True if the number n is prime, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list nums.", "function_declaration": "def filter_primes(...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determine if a number is prime.\n \n Args:\n n (int): The number to check.\n \n Returns:\n bool: True if the num...
trial_gpt4o_9
{ "original_instruction": "Implement a function that takes a list of integers and returns a new list containing only the prime numbers from the original list, in the same order as they appeared.\n\n### Steps:\n\n* Create a helper function `is_prime` that determines if a number is prime.\n* Iterate through each intege...
0.788393
Apps_7737
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
98b799461b9e4037b4d5e8170c4f45b3dce93144
37e0adeff4b5af28d4134214f9db3f263fd7e1e2
v1.0
complete
Apps
Apps_6867_C
import math from typing import List, Tuple def distance(p1: Tuple[int, int], p2: Tuple[int, int]) -> float: """ Calculate the Euclidean distance between two points. >>> distance((0, 0), (3, 4)) 5.0 """ return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def perimeter(vertices: List[Tuple...
import math def distance(p1, p2): return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) def perimeter(vertices): """ Calculate the perimeter of a polygon given its vertices. vertices: List of tuples, where each tuple represents (x, y) coordinates of a vertex. Returns: Perimeter o...
from solution import perimeter def test_perimeter_square(): vertices = [(0, 0), (0, 1), (1, 1), (1, 0)] assert perimeter(vertices) == 4.00 def test_perimeter_rectangle(): vertices = [(0, 0), (0, 2), (3, 2), (3, 0)] assert perimeter(vertices) == 10.00 def test_perimeter_triangle(): vertices = [(0,...
[ { "docstring": null, "function_declaration": "def distance(p1, p2):", "function_name": "distance", "parameter_list": "(p1, p2)" }, { "docstring": "Calculate the perimeter of a polygon given its vertices.\n\nvertices: List of tuples, where each tuple represents (x, y) coordinates of a vertex....
[ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import sqrt\n\ndef perimeter(vertices):\n \"\"\"\n Returns the perimeter of a polygon given its vertices.\n Vertices should be a list of tuples, ...
trial_gpt4o_3
{ "original_instruction": "Write a function `perimeter` that calculates the perimeter of a polygon given its vertices.\n\nThe function should accept a list of tuples, where each tuple represents the (x, y) coordinates of a vertex, and return the perimeter of the polygon. The vertices are connected in the order they a...
0.588118
Apps_6867
C
[ "distance", "perimeter" ]
2
[ [ "perimeter", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
86f582a8c32e3cb5ff7be3cdcd86dae1fc1d7443
9fb9619f48494e8b784e76767221ade2b2c15a5d
v1.0
complete
Apps
Apps_7104_C
def highest_depth_of_centroid_tree(n: int, edges: List[Tuple[int, int]]) -> int: """ Given a tree with `N` nodes and `N-1` edges, find the highest depth of the centroid tree created from the input tree. Depth of the centroid tree is defined as the maximum number of nodes from the root to any leaf in the centroi...
import sys sys.setrecursionlimit(200000) def get_subtree_sizes(tree, node, parent, subtree_sizes): subtree_sizes[node] = 1 for neighbor in tree[node]: if neighbor != parent: get_subtree_sizes(tree, neighbor, node, subtree_sizes) subtree_sizes[node] += subtree_sizes[neighbor] de...
from solution import highest_depth_of_centroid_tree def test_highest_depth_small_tree(): n = 5 edges = [(1, 2), (1, 3), (3, 4), (3, 5)] assert highest_depth_of_centroid_tree(n, edges) == 2 def test_highest_depth_large_tree(): n = 10 edges = [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), (4, ...
[ { "docstring": null, "function_declaration": "def get_subtree_sizes(tree, node, parent, subtree_sizes):", "function_name": "get_subtree_sizes", "parameter_list": "(tree, node, parent, subtree_sizes)" }, { "docstring": null, "function_declaration": "def find_centroid(tree, node, parent, s...
[ 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import sys\nfrom collections import defaultdict, deque\n\nsys.setrecursionlimit(200000)\n\ndef find_subtree_sizes(tree, node, parent, sizes):\n sizes[node] = 1\n...
trial_gpt4o_7
{ "original_instruction": "A tree is a connected acyclic graph. In a tree, we define the concept of a centroid. A centroid tree of a given tree is constructed as follows:\n\n1. Find the centroid of the current tree. If the tree has an even number of nodes, we can choose any one of the centroids.\n2. Remove the centro...
0.504929
Apps_7104
C
[ "get_subtree_sizes", "find_centroid", "decompose", "highest_depth_of_centroid_tree" ]
4
[ [ "decompose", "find_centroid" ], [ "highest_depth_of_centroid_tree", "decompose" ], [ "highest_depth_of_centroid_tree", "get_subtree_sizes" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b5a0ac8159d67ca79ad46ae178d89f82c3b6d6db
9604a43c8bbaa89f24865f1394a35fad9fd792d5
v1.0
complete
Apps
Apps_8001_C
def find_magical_node(queries): """ Given the description of a tree, identify with the magical node for each query. The magical node is the centroid of the tree. If there are multiple centroids, choose the one with the smallest identifier. Args: queries: A list of tuples where each tuple con...
from collections import deque def find_centroids(tree_adj_list, N): if N == 1: return [0] # Find all leaves leaves = deque() degrees = [0] * N for i in range(N): degrees[i] = len(tree_adj_list[i]) if degrees[i] == 1: leaves.append(i) remaining_nodes = N...
def test_example(): input_data = "2\n6\n1 2\n2 3\n3 4\n4 5\n2 6\n4\n1 2\n1 3\n1 4\n" assert process_input(input_data) == [3, 1] def test_single_node(): input_data = "1\n1\n" assert process_input(input_data) == [1] def test_star_shaped_tree(): input_data = "1\n5\n1 2\n1 3\n1 4\n1 5\n" assert pr...
[ { "docstring": null, "function_declaration": "def find_centroids(tree_adj_list, N):", "function_name": "find_centroids", "parameter_list": "(tree_adj_list, N)" }, { "docstring": null, "function_declaration": "def find_magical_node(queries):", "function_name": "find_magical_node", ...
[ 1, 0, 0, 0, 0, 0, 1, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef find_tree_center(n, edges):\n if n == 1:\n return 1\n \n adjacency_list = [[] for _ in range(n + 1)]\n for u...
trial_gpt4o_8
{ "original_instruction": "In a distant universe, there exists a unique type of forest where each tree is a magical structure composed of nodes and edges. Each tree contains exactly one magical node. A tree is defined as an acyclic connected graph with N nodes and N-1 edges. The magical node has a special property of...
0.56822
Apps_8001
C
[ "find_centroids", "find_magical_node", "process_input" ]
3
[ [ "find_magical_node", "find_centroids" ], [ "process_input", "find_magical_node" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
95d84dd81cb316f33c52b31021cf2c374270e8b2
80afcc072b5fb5004ac98f7caff80fdb865ed2d2
v1.0
complete
Apps
Apps_7387_C
class FileSystem: def __init__(self): self.folders = {'/': {'size': 0, 'subfolders': {}}} def create_folder(self, parent_path, folder_name): path = parent_path + '/' + folder_name if parent_path != '/' else '/' + folder_name if parent_path in self.folders: self.folde...
class FileSystem: def __init__(self): self.folders = {'/': {'size': 0, 'subfolders': {}}} def create_folder(self, parent_path, folder_name): path = parent_path + '/' + folder_name if parent_path != '/' else '/' + folder_name if parent_path in self.folders: self.folde...
from solution import file_system_monitor def test_sample(): operations = [ "CREATE / folder1", "CREATE / folder2", "CREATE /folder1 folder3", "MOVE /folder1 /folder1/folder3 100", "MOVE / /folder1 200", "QUERY /", "QUERY /folder1" ] expected = [300, 3...
[]
[ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class FileSystem:\n def __init__(self):\n self.folders = {'/': {}}\n self.files = {'/': 0}\n\n def create_folder(self, parent_path, folder_name)...
trial_gpt4o_1
{ "original_instruction": "A company is implementing a feature for monitoring file system usage for its users. The feature allows users to create and delete folders, move files between folders, and query the total size of files within a specific folder. You are responsible for designing an algorithm to manage and res...
0.650631
Apps_7387
C
[ "process_operations", "file_system_monitor" ]
2
[ [ "file_system_monitor", "process_operations" ] ]
1
[]
false
[ "FileSystem" ]
true
pytest
true
[]
true
ac8751fd10acf6dc4846257ed3ed5d9b81a64b98
92789222832bee09ad5b61122e9d54d15f4ae976
v1.0
complete
Apps
Apps_7081_C
from typing import List def can_form_palindrome(s: str) -> str: """ Determines if the string can be rearranged to form a palindrome. >>> can_form_palindrome("civic") "YES" >>> can_form_palindrome("ivicc") "YES" >>> can_form_palindrome("hello") "NO" >>> can_form_palindrome("racecar") "YES" """ ...
def can_form_palindrome(s): """ Determines if the string can be rearranged to form a palindrome. """ from collections import Counter # Count the frequency of each character char_counts = Counter(s) # To form a palindrome, at most one character can have an odd count odd_count = ...
def test_can_form_palindrome(): # direct tests on the helper function assert can_form_palindrome("civic") == "YES" assert can_form_palindrome("ivicc") == "YES" assert can_form_palindrome("hello") == "NO" assert can_form_palindrome("racecar") == "YES" assert can_form_palindrome("a") == "YES" ...
[ { "docstring": "Determines if the string can be rearranged to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "For each string in the provided list, prints 'YES' if it can be rearran...
[ 1, 0, 1, 1, 1, 1, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome(s):\n \"\"\"\n Helper function to determine if a string can be rearranged to form a palindrome.\n \"\"\"\n from collections impo...
trial_gpt4o_9
{ "original_instruction": "Oliver is fascinated by palindromes. A palindrome is a word, number, phrase, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). Now, he has a list of strings and wants to check each one to see if it can be rearranged ...
0.746077
Apps_7081
C
[ "can_form_palindrome", "check_palindrome_possibilities" ]
2
[ [ "check_palindrome_possibilities", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
false
[]
true
99c603422c039667ce6c24b032075694284e5589
f7c8d2a2942687b952839e3835e346fdd4bd1ec4
v1.0
complete
Apps
Apps_7689_C
def sort_prime_and_nonprime(arr: List[int]) -> List[int]: """ Sorts an array such that all prime numbers appear at the beginning in ascending order, followed by non-prime numbers in ascending order. Args: arr (List[int]): List of integers to be sorted. Returns: List[int]: Sorted list with...
def is_prime(num): if num < 2: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num ** 0.5) + 1, 2): if num % i == 0: return False return True def sort_prime_and_nonprime(arr): primes = [x for x in arr if is_pr...
from solution import sort_prime_and_nonprime def test_example_case_1(): assert sort_prime_and_nonprime([3, 8, 4, 7, 6, 2]) == [2, 3, 7, 4, 6, 8] def test_example_case_2(): assert sort_prime_and_nonprime([10, 1, 11, 17, 20]) == [11, 17, 1, 10, 20] def test_all_primes(): assert sort_prime_and_nonprime([2, ...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def sort_prime_and_nonprime(arr):", "function_name": "sort_prime_and_nonprime", "parameter_list": "(arr)" }...
[ 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef is_prime(num):\n \"\"\"\n Utility function to check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <...
trial_gpt4o_7
{ "original_instruction": "Given an array of integers, your task is to sort the array such that all prime numbers appear at the beginning in ascending order, followed by non-prime numbers in ascending order. \n\nA number is considered prime if it has no positive divisors other than 1 and itself. For the sake of this ...
0.624524
Apps_7689
C
[ "is_prime", "sort_prime_and_nonprime" ]
2
[ [ "sort_prime_and_nonprime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3442a41f9c982251629a968ef3c538acce675063
949f22ad3781a4b1acb526cb0a7446e03c1a7236
v1.0
complete
Apps
Apps_8723_C
from typing import List from math import gcd from functools import reduce def smallest_common_multiple(arr: List[int]) -> int: """Returns the smallest common multiple (SCM) of the integers in the array. >>> smallest_common_multiple([1, 2, 3, 4, 5]) 60 >>> smallest_common_multiple([1, 2, 3]) 6 >>> small...
from math import gcd from functools import reduce def lcm(a, b): return abs(a * b) // gcd(a, b) def smallest_common_multiple(arr): """ Returns the smallest common multiple (SCM) of the integers in the array. """ if not arr: return None # Remove zeros from the array since LCM with zero...
from solution import smallest_common_multiple def test_scm_positive_numbers(): assert smallest_common_multiple([1, 2, 3, 4, 5]) == 60 assert smallest_common_multiple([1, 2, 3]) == 6 assert smallest_common_multiple([5, 10]) == 10 def test_scm_negative_numbers(): assert smallest_common_multiple([-2, 3, ...
[ { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": "Returns the smallest common multiple (SCM) of the integers in the array.", "function_declaration": "def smallest_common_multiple(arr):", "function_name...
[ 1, 1, 0, 0, 1, 1, 1, 1, 0, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom functools import reduce\n\ndef gcd(a, b):\n \"\"\"\n Helper function to calculate the greatest common divisor of a and b.\n \"\"\"\n w...
trial_gpt4o_9
{ "original_instruction": "Implement a function called `smallest_common_multiple` that takes an array of integers as an argument and returns the smallest common multiple (SCM) of these integers. The smallest common multiple is the smallest number that is evenly divisible by all numbers in the array.\n\nEnsure to hand...
0.660933
Apps_8723
C
[ "lcm", "smallest_common_multiple" ]
2
[ [ "smallest_common_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f8a52858cd3b26764ca9b522ff4db470ee0050c
b148ff78275e547d4568a06984703511aff95255
v1.0
complete
Apps
Apps_7144_C
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 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...
from solution import minimum_transportation_cost def test_single_case_all_connected(): T = 1 test_cases = [ (4, 5, [ (0, 1, 10), (0, 2, 15), (1, 2, 5), (1, 3, 20), (2, 3, 25) ]) ] assert minimum_transportation_cost(T, test_case...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 1, 0, 0, 1, 0, 0, 0, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UnionFind:\n def __init__(self, n):\n self.parent = list(range(n))\n self.rank = [0] * n\n\n def find(self, u):\n if self.parent[u]...
trial_gpt4o_4
{ "original_instruction": "In a certain kingdom, there are N cities numbered from 1 to N. Each city is connected by a series of roads, which are bidirectional. These roads are considered as weighted edges in a graph. The King of the kingdom wants to set up a highly efficient transportation system by selecting some of...
0.675177
Apps_7144
C
[ "find", "union", "kruskal_mst", "minimum_transportation_cost" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "minimum_transportation_cost", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
b98169622aea729e451402fa8a563708d62f9514
a3929ae9e6bf6d44c7e0eb7c5f8427a507e87ace
v1.0
complete
Apps
Apps_8512_C
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 is_twin_prime_in_range(L, R, x): """ ...
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 is_twin_prime_in_range(L, R, x): prim...
def test_is_twin_prime_in_range(): assert is_twin_prime_in_range(1, 20, 17) == "Yes" assert is_twin_prime_in_range(10, 30, 23) == "No" assert is_twin_prime_in_range(3, 30, 29) == "Yes" assert is_twin_prime_in_range(3, 30, 25) == "No" assert is_twin_prime_in_range(1, 10, 5) == "Yes" assert is_twi...
[ { "docstring": null, "function_declaration": "def sieve_of_eratosthenes(n):", "function_name": "sieve_of_eratosthenes", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def is_twin_prime_in_range(L, R, x):", "function_name": "is_twin_prime_in_range", "para...
[ 0, 1, 1, 0, 0, 0, 0, 0, 1 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n, sieve):\n \"\"\"\n Check if `n` is a prime number using a precomputed sieve list.\n \"\"\"\n return sieve[n]\n\ndef sieve_of_eratosthene...
trial_gpt4o_9
{ "original_instruction": "Sally is fascinated by prime numbers. She recently learned about twin primes, which are pairs of prime numbers that differ by exactly two (e.g., (3, 5), (11, 13)). She wonders if a given number x can be a part of any twin prime pair.\n\nShe needs your help to find out if the number x is a p...
0.628593
Apps_8512
C
[ "sieve_of_eratosthenes", "is_twin_prime_in_range", "twin_prime_check" ]
3
[ [ "is_twin_prime_in_range", "sieve_of_eratosthenes" ], [ "twin_prime_check", "is_twin_prime_in_range" ] ]
2
[]
false
[]
false
pytest
false
[]
true
c236ce2f81aa69fabb5bc662a741d02297362c60
788433541c2bbad567fee0781f63b3a57890e0c2
v1.0
complete
Apps
Apps_8746_C
def filterPrimes(numbers: List[int]) -> List[int]: """ Returns a list of prime numbers from the input list of integers. >>> filterPrimes([2, 3, 4, 5, 6, 7, 8, 9, 10]) [2, 3, 5, 7] >>> filterPrimes([15, 23, 37, 42, 51, 63, 71]) [23, 37, 71] >>> filterPrimes([0, 1, 2, 3, 4, 5]) [2, 3, 5]...
def is_prime(number): """ Helper function to check if a number is prime. """ if number <= 1: return False if number == 2: return True if number % 2 == 0: return False for i in range(3, int(number ** 0.5) + 1, 2): if number % i == 0: return False ...
from solution import filterPrimes def test_filterPrimes_with_mixed_numbers(): assert filterPrimes([2, 3, 4, 5, 6, 7, 8, 9, 10]) == [2, 3, 5, 7] def test_filterPrimes_with_all_non_primes(): assert filterPrimes([1, 4, 6, 8, 10, 12, 14]) == [] def test_filterPrimes_with_all_primes(): assert filterPrimes([2,...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(number):", "function_name": "is_prime", "parameter_list": "(number)" }, { "docstring": "Returns a list of prime numbers from the input list of integers.", "function_declaration": "def f...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n r...
trial_gpt4o_9
{ "original_instruction": "## Description\n\nWrite a function that accepts a list of integers and returns a new list containing only the integers that are prime numbers.\n\nA prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. In other words, a prime number is only di...
0.685393
Apps_8746
C
[ "is_prime", "filterPrimes" ]
2
[ [ "filterPrimes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5290e2e6781d0a7a478067f0d4d0597b6f8f0a28
62507e74da64afc22e1d80a0984be60444f55a28
v1.0
complete
Apps
Apps_8507_C
def is_anagram(str1, str2): """ Check if two strings are anagrams of each other. Parameters: str1 (str): The first string. str2 (str): The second string. Returns: bool: True if the strings are anagrams, False otherwise. Examples: >>> is_anagram("listen", "silent") ...
def is_anagram(str1, str2): """ Check if two strings are anagrams of each other. Parameters: str1 (str): The first string. str2 (str): The second string. Returns: bool: True if the strings are anagrams, False otherwise. """ return sorted(str1) == sorted(str2) def find_anag...
from solution import is_anagram, find_anagrams def test_is_anagram_positive(): assert is_anagram("listen", "silent") == True assert is_anagram("listen", "enlist") == True def test_is_anagram_negative(): assert is_anagram("hello", "world") == False assert is_anagram("python", "java") == False def test...
[ { "docstring": "Check if two strings are anagrams of each other.\n\nParameters:\nstr1 (str): The first string.\nstr2 (str): The second string.\n\nReturns:\nbool: True if the strings are anagrams, False otherwise.", "function_declaration": "def is_anagram(str1, str2):", "function_name": "is_anagram", ...
[ 1, 1, 1, 0, 1, 0, 0, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_anagram(str1, str2):\n \"\"\"\n Checks if two strings are anagrams of each other.\n \n Parameters:\n str1 (str): The first string.\n str2 (...
trial_gpt4o_9
{ "original_instruction": "**Step 1:** Create a function called `is_anagram()` that takes two strings as input and checks whether they are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.\n\nF...
0.595654
Apps_8507
C
[ "is_anagram", "find_anagrams" ]
2
[ [ "find_anagrams", "is_anagram" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a70152ccfcca6cf7b238ae440b35bda9f47cf43a
d5bf2ac29f2c91c4f539aa0ea0b1985230b19b5b
v1.0
complete
Apps
Apps_8740_C
def can_form_palindrome(s: str) -> bool: """ Determines whether it is possible to rearrange the characters of the string s to form a palindrome. >>> can_form_palindrome("aabbcc") True >>> can_form_palindrome("abc") False >>> can_form_palindrome("aab") True """ def analyze_strings(t: int, st...
def can_form_palindrome(s): """ Determines whether it is possible to rearrange the characters of the string s to form a palindrome. """ from collections import Counter # Count the occurrences of each character char_count = Counter(s) # A string can be rearranged to form a palindrome if a...
from solution import can_form_palindrome, analyze_strings def test_can_form_palindrome(): assert can_form_palindrome("aabbcc") == True assert can_form_palindrome("abc") == False assert can_form_palindrome("aab") == True assert can_form_palindrome("racecar") == True assert can_form_palindrome("aabbc...
[ { "docstring": "Determines whether it is possible to rearrange the characters\nof the string s to form a palindrome.", "function_declaration": "def can_form_palindrome(s):", "function_name": "can_form_palindrome", "parameter_list": "(s)" }, { "docstring": "Analyzes multiple strings to determ...
[ 0, 1, 1, 0, 0, 1, 1, 1, 1, 1 ]
7
easy
0.7
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def can_form_palindrome(s):\n \"\"\"\n Determines if the string s can be rearranged to form a palindrome.\n \"\"\"\n from collections import Counter\n ...
trial_gpt4o_9
{ "original_instruction": "Imagine you are helping a research team in a university obsessed with palindromes. They have recently discovered some ancient scripts that contain strings and are interested in analyzing if rearranging these strings can create palindromes. As their programmer, your task is to determine whet...
0.79077
Apps_8740
C
[ "can_form_palindrome", "analyze_strings" ]
2
[ [ "analyze_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a9beea62ea23655e9d7571405e7bd93d230e69f
09000edb5728add2e3606f8e4e58a16d006021ed
v1.0
complete
Apps
Apps_7247_C
def solve_problem(N, M, edge_list): """ Given an undirected graph with N nodes and M edges, where each edge has a non-negative weight, find the minimum possible sum of weights of the edges in the graph after removing as many edges as possible while ensuring that the remaining graph is connected. ----...
class UnionFind: def __init__(self, n): self.parent = list(range(n)) self.rank = [1] * n def find(self, u): if self.parent[u] != u: self.parent[u] = self.find(self.parent[u]) return self.parent[u] def union(self, u, v): root_u = self.find(u) ...
def test_simple_case(): N = 5 M = 6 edges = [ (1, 2, 3), (1, 3, 4), (1, 4, 2), (2, 3, 1), (2, 5, 5), (3, 5, 7) ] assert solve_problem(N, M, edges) == 11 def test_all_edges_same_weight(): N = 4 M = 5 edges = [(1, 2, 1), (1, 3, 1), (2, 3, 1)...
[]
[ 1, 1, 0, 1, 1, 1, 0, 1 ]
6
easy
0.75
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find(parent, i):\n if parent[i] != i:\n parent[i] = find(parent, parent[i])\n return parent[i]\n\ndef union(parent, rank, x, y):\n ...
trial_gpt4o_1
{ "original_instruction": "You are given an undirected graph with $N$ nodes and $M$ edges. Each edge has a non-negative weight. Your task is to remove as many edges as possible while ensuring that the sum of weights of the remaining edges in each connected component is minimized. \n\nThe remaining graph must still be...
0.816948
Apps_7247
C
[ "minimum_spanning_tree_sum", "solve_problem" ]
2
[ [ "solve_problem", "minimum_spanning_tree_sum" ] ]
1
[]
false
[ "UnionFind" ]
true
pytest
false
[]
true
e7aef5f53048e9413181210743a174d766f6f238
18136d4e927106c7bfa54005a37b67d97215909b
v1.0
complete
Apps
Apps_8976_C
def maximalRectangle(matrix: List[List[int]]) -> int: """ Find the largest rectangle containing only 1's and returns its area. >>> maximalRectangle([ ... [1, 0, 1, 0, 0], ... [1, 0, 1, 1, 1], ... [1, 1, 1, 1, 1], ... [1, 0, 0, 1, 0] ... ]) == 6 >>> maximalRectangle([ ...
def maximalRectangle(matrix): """ Find the largest rectangle containing only 1's and returns its area. """ if not matrix or not matrix[0]: return 0 max_area = 0 heights = [0] * len(matrix[0]) for row in matrix: for i in range(len(row)): heights[i] = heights[i] +...
import pytest from solution import maximalRectangle def test_maximalRectangle_example1(): matrix = [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] assert maximalRectangle(matrix) == 6 def test_maximalRectangle_example2(): matrix = [ [0, 1], [1...
[ { "docstring": "Find the largest rectangle containing only 1's and returns its area.", "function_declaration": "def maximalRectangle(matrix):", "function_name": "maximalRectangle", "parameter_list": "(matrix)" }, { "docstring": "Helper function to find the largest rectangle in histogram.", ...
[ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def maximalRectangle(matrix):\n \"\"\"\n Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's \n and return its...
trial_gpt4o_2
{ "original_instruction": "You are given a 2D binary matrix filled with 0's and 1's. Find the largest rectangle containing only 1's and return its area.\n\nExample 1:\n\nInput:\n[\n [1, 0, 1, 0, 0],\n [1, 0, 1, 1, 1],\n [1, 1, 1, 1, 1],\n [1, 0, 0, 1, 0]\n]\nOutput: 6\n\nExplanation: The largest rectangle contain...
0.729955
Apps_8976
C
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5d48fe4d512aef447dddfe3b2edfd76f32f7ab13
a783aa21cb0c439b8d257277d101bb03185ec140
v1.0
complete
Apps
Apps_8408_C
def solution(input_str: str) -> list: """ Determines the maximum number of non-overlapping sessions the artist can schedule for each test case. The input is provided as a single string with test cases and session intervals. The function returns a list of integers, each representing the maximum number of n...
def max_non_overlapping_sessions(test_cases): results = [] for sessions in test_cases: sessions.sort(key=lambda x: x[1]) last_end = 0 count = 0 for start, end in sessions: if start > last_end: last_end = end count += 1 ...
from solution import solution def test_basic_case(): input_str = "2\n3\n1 2\n2 3\n3 4\n4\n1 3\n2 5\n4 6\n7 8\n" expected_output = [2, 3] assert solution(input_str) == expected_output def test_single_case(): input_str = "1\n2\n1 4\n2 3\n" expected_output = [1] assert solution(input_str) == expe...
[ { "docstring": null, "function_declaration": "def max_non_overlapping_sessions(test_cases):", "function_name": "max_non_overlapping_sessions", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def parse_input(input_str):", "function_name": "parse_input...
[ 1, 1, 0, 0, 0, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_non_overlapping_sessions(test_cases):\n results = []\n \n for sessions in test_cases:\n sessions.sort(key=lambda x: x[1])\n last_end_...
trial_gpt4o_9
{ "original_instruction": "Write a program to help an artist organize his painting sessions. The artist can schedule one painting session per day. However, he can only start a new session if it doesn't overlap with an ongoing one from the previous days. Given a sorted list of painting sessions with their start and en...
0.615405
Apps_8408
C
[ "max_non_overlapping_sessions", "parse_input", "solution" ]
3
[ [ "solution", "max_non_overlapping_sessions" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
0dd2839db5625c40edc795464c10493381ede7fa
f4b17ddf0ad86a8901e2a62ceb35c481401df729
v1.0
complete
Apps
Apps_8716_C
from typing import List def sum_of_primes(n: int) -> int: """ Returns the sum of the first n prime numbers. >>> sum_of_primes(5) # 2 + 3 + 5 + 7 + 11 = 28 28 >>> sum_of_primes(10) # First 10 primes sum to 129 129 """ def test_sum_of_primes_example1(): assert sum_of_primes(5) == 28 #...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def sum_of_primes(n: int) -> i...
from solution import sum_of_primes def test_sum_of_primes_example1(): assert sum_of_primes(5) == 28 # 2 + 3 + 5 + 7 + 11 = 28 def test_sum_of_primes_example2(): assert sum_of_primes(10) == 129 # First 10 primes sum to 129 def test_sum_of_primes_single_prime(): assert sum_of_primes(1) == 2 # Only the f...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the sum of the first n prime numbers.", "function_declaration": "def sum_of_primes(n):", "function_name": "sum_of_primes", "paramet...
[ 1, 0, 1, 0, 1, 1, 0, 0, 0, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i...
trial_gpt4o_0
{ "original_instruction": "Write a function that takes an integer `n` and returns the sum of the first `n` prime numbers. For example, if `n` is 5, the function should return the sum of the first five prime numbers: 2 + 3 + 5 + 7 + 11 = 28.\n\n**Function Signature:** `def sum_of_primes(n: int) -> int:`\n\n**Example:*...
0.681032
Apps_8716
C
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f6ddd332be04b8c3863e1901a84bdd61a5d12337
ec312cb59557377271053e522ba33faaef282d64
v1.0
complete
Apps
Apps_8645_C
from typing import List def generate_primes(n: int, S: int) -> List[int]: """Generate a list of the first n prime numbers in ascending order such that their sum does not exceed S. >>> generate_primes(5, 28) [2, 3, 5, 7, 11] >>> generate_primes(5, 15) [] """ def test_generate_primes_s...
from typing import List def is_prime(x: int) -> bool: if x <= 1: return False if x == 2: return True if x % 2 == 0: return False for i in range(3, int(x**0.5) + 1, 2): if x % i == 0: return False return True def generate_primes(n: int, S: int) -> List[in...
from solution import generate_primes def test_generate_primes_simple_case(): assert generate_primes(5, 28) == [2, 3, 5, 7, 11] def test_generate_primes_not_possible(): assert generate_primes(5, 15) == [] def test_generate_primes_large_value(): result = generate_primes(10, 1000) assert result == [2, 3...
[ { "docstring": null, "function_declaration": "def is_prime(x):", "function_name": "is_prime", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def generate_primes(n, S):", "function_name": "generate_primes", "parameter_list": "(n, S)" } ]
[ 0, 1, 0, 1, 0, 0, 0, 1, 1, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(x: int) -> bool:\n if x <= 1:\n return False\n if x == 2:\n return True\n if x % 2 == 0:\n ret...
trial_gpt4o_1
{ "original_instruction": "Phoebe loves prime numbers and she wants to generate them in a unique way. She has a function `is_prime(x)` that returns `True` if `x` is a prime number and `False` otherwise. She wants you to help her by writing a function `generate_primes(n)` that generates a list of the first `n` prime n...
0.710039
Apps_8645
C
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5982fba802090048a02551d94734b3266b6a6cfb
6a4a23ed300af3993c28f44618d66128b6857b3b
v1.0
complete
Apps
Apps_8342_C
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def merge_two_lists(l1, l2): """ Merges two sorted linked lists and returns it as a new sorted list. """ pass def list_to_linked_list(lst): """ Converts a list to a linked list. """ ...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def merge_two_lists(l1, l2): """ Merges two sorted linked lists and returns it as a new sorted list. """ dummy = ListNode() current = dummy while l1 and l2: if l1.val < l2.val:...
from solution import merge_two_lists_list def test_merge_two_lists_example_1(): assert merge_two_lists_list([1, 2, 4], [1, 3, 4]) == [1, 1, 2, 3, 4, 4] def test_merge_two_lists_example_2(): assert merge_two_lists_list([2, 6, 8], [1, 3, 4]) == [1, 2, 3, 4, 6, 8] def test_merge_two_lists_example_3(): asser...
[]
[ 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 ]
9
easy
0.9
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef merge_two_lists(l1, l2):\n dummy = ListNode()...
trial_gpt4o_9
{ "original_instruction": "Write a function to merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.\n\n## Examples\n```python\n# List 1: 1 -> 2 -> 4\n# List 2: 1 -> 3 -> 4\n# Merged List: 1 -> 1 -> 2 -> 3 -> 4 -> 4\nmerge_...
0.502171
Apps_8342
C
[ "merge_two_lists", "list_to_linked_list", "linked_list_to_list", "merge_two_lists_list" ]
4
[ [ "merge_two_lists_list", "linked_list_to_list" ], [ "merge_two_lists_list", "list_to_linked_list" ], [ "merge_two_lists_list", "merge_two_lists" ] ]
3
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
b5284dc312d6e2dd56acca0cd51b0144bd755320
05bc579109d0419a6e39af17161fc1f896337520
v1.0
complete
Apps
Apps_8994_C
def filter_primes(lst: List[int]) -> List[int]: """ Returns a new list containing only the elements that are prime numbers. >>> filter_primes([3, 4, 7, 10, 11]) [3, 7, 11] >>> filter_primes([1, 4, 6, 8, 9, 10, 12, 14]) [] >>> filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]) ...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def filter_primes(lst): """ Returns a new list containing only the elements of lst that...
from solution import filter_primes def test_filter_primes_all_primes(): assert filter_primes([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] def test_filter_primes_no_primes(): assert filter_primes([1, 4, 6, 8, 9, 10, 12, 14]) == [] def test_filter_primes_mixed()...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a new list containing only the elements of lst that are prime numbers.", "function_declaration": "d...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n i...
trial_gpt4o_4
{ "original_instruction": "Complete the function that takes a list of integers and returns a new list containing only the elements that are prime numbers.\n\n## Example\n\n```python\n[3, 4, 7, 10, 11] # should return [3, 7, 11]\n```", "prompt_id": "00008994", "row_id": 8994, "seed_ids": "[4728]" }
0.641468
Apps_8994
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
96d763ab6bd9cb274b02fd54a8c5634b88d09fc7
5f68ec4f1e33f604565f80e8b14628286b91fb63
v1.0
complete
Apps
Apps_8466_C
class TreeNode: def __init__(self, value): self.value = value self.children = [] def max_subtree_sum(node): """ Calculate the maximum sum obtainable from any subtree of the binary tree. >>> tree = TreeNode(1) >>> tree.children = [TreeNode(2), TreeNode(3)] >>> tree.children[0...
class TreeNode: def __init__(self, value): self.value = value self.children = [] def max_subtree_sum(node): if not node: return 0, float('-inf') current_sum = node.value max_sum = node.value for child in node.children: child_sum, child_max_sum = max_subtree...
def test_max_subtree_sum(): input_data = "1\n5\n1 2 3 -2 4\n1 2\n1 3\n2 4\n2 5\n" output = main(input_data) assert output == "8" def test_single_node(): input_data = "1\n1\n5\n" output = main(input_data) assert output == "5" def test_negative_values(): input_data = "1\n3\n-1 -2 -3\n1 2\n1 ...
[]
[ 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared1_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value=0, children=None):\n if children is None:\n children = []\n self.val...
trial_gpt4o_9
{ "original_instruction": "You are given a binary tree with N nodes. Each node has a value associated with it. Your task is to determine the maximum sum that can be obtained from any subtree of the given binary tree.\n\nA subtree of a binary tree is a tree consisting of a node in the tree and all of its descendants i...
0.635024
Apps_8466
C
[ "max_subtree_sum", "build_tree", "solve", "main" ]
4
[ [ "solve", "build_tree" ], [ "solve", "max_subtree_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
1c271f7e6af3428662e39c560dae26f7caebbefe
8d8bd95e8acca5f4b30aadfd0a27fc4ed58cd83c
v1.0
complete
Apps
Apps_6768_C
def minimum_cost_to_connect_cities(T: int, test_cases: List[Tuple[int, int, List[Tuple[int, int, int]]]]) -> List[int]: """ Determine the minimum cost required to connect all the cities. Parameters: T (int): Number of test cases. test_cases (List[Tuple[int, int, List[Tuple[int, int, int]]]]): ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
from solution import minimum_cost_to_connect_cities def test_example_cases(): T = 2 test_cases = [ (4, 5, [(1, 2, 3), (1, 3, 4), (4, 2, 5), (3, 4, 6), (1, 4, 10)]), (3, 2, [(1, 2, 4), (2, 3, 6)]), ] expected = [12, 10] assert minimum_cost_to_connect_cities(T, test_cases) == expected...
[ { "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, 0, 0, 0, 1, 1, 1, 1 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def kruskal(n, edges):\n \"\"\"\n Helper function to run Kruskal's algorithm to find the Minimum Spanning Tree (MST) cost.\n \"\"\"\n # Helper function ...
trial_gpt4o_9
{ "original_instruction": "In the kingdom of Algorithms, King Alcom wants to build a network of roads to connect several cities to ensure ease of travel across the kingdom. Each road has a travel cost associated with it. The king wants to minimize the total cost of the roads used while still ensuring that all cities ...
0.702809
Apps_6768
C
[ "find", "union", "kruskal", "minimum_cost_to_connect_cities" ]
4
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "minimum_cost_to_connect_cities", "kruskal" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
true
[]
true
d3a8b36e974f7a340f2c8985fadb3c567dd9975f
223de2f0314052d4583245ce99c45f52be3e2898
v1.0
complete
Apps
Apps_9096_C
def is_palindrome(subarray): """ Helper function to check if a subarray is a palindrome. """ return subarray == subarray[::-1] def beauty_of_array(arr): """ Function to find the beauty of the given array. The beauty is defined as the length of the longest contiguous subarray that forms a pa...
def is_palindrome(subarray): """ Helper function to check if a subarray is a palindrome. """ return subarray == subarray[::-1] def beauty_of_array(arr): """ Function to find the beauty of the given array. The beauty is defined as the length of the longest contiguous subarray that forms a pa...
from solution import beauty_of_array, process_test_cases def test_is_palindrome(): # local helper for tests from solution import is_palindrome assert is_palindrome([1, 2, 2, 1]) == True assert is_palindrome([1, 2, 3, 2, 1]) == True assert is_palindrome([1, 2, 3]) == False assert is_palindrome([...
[ { "docstring": "Helper function to check if a subarray is a palindrome.", "function_declaration": "def is_palindrome(subarray):", "function_name": "is_palindrome", "parameter_list": "(subarray)" }, { "docstring": "Function to find the beauty of the given array.\nThe beauty is defined as the ...
[ 0, 1, 1, 0, 0, 1, 0, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindrome_subarray(arr):\n \"\"\"\n Returns the length of the longest contiguous subarray that forms a palindrome.\n \"\"\"\n n = len(arr)\...
trial_gpt4o_5
{ "original_instruction": "You are given an array of $n$ integers. We define the beauty of an array as the length of the longest contiguous subarray that forms a palindrome. A contiguous subarray is a sequence of consecutive elements within the array. \n\nYour task is to find the beauty of the given array.\n\nA subar...
0.690901
Apps_9096
C
[ "is_palindrome", "beauty_of_array", "process_test_cases" ]
3
[ [ "beauty_of_array", "is_palindrome" ], [ "process_test_cases", "beauty_of_array" ] ]
2
[ "process_test_cases" ]
false
[]
false
pytest
true
[]
true
e3c8cce08e312b4ac625b08c33e8c13417f344a2
a487a359dd78947e4a6ea5ced34112931680cc67
v1.0
complete
Apps
Apps_7536_C
def is_prime(n: int) -> bool: """ Checks if a number is a prime number. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(5) True >>> is_prime(15) False >>> is_prime(17) True >>> is_prime(1) False >>> is_prime(0) False >>> is_prime(1000000) False ...
def is_prime(n): """ Checks 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 r...
from solution import is_prime, sum_of_unique_primes def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(15) == False assert is_prime(17) == True assert is_prime(1) == False assert is_prime(0) =...
[ { "docstring": "Checks if a number is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "For each test case, returns the sum of all unique prime numbers in the array.", "function_declaration": "def sum_of_...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Returns True if n is a prime number, otherwise False.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n r...
trial_gpt4o_9
{ "original_instruction": "During pandemic time, Chef is spending a lot of time with his son, and they both enjoy playing with numbers. One day, Chef decided to engage his son with a fun task involving prime numbers.\nChef gives his son an integer array of size $N$ and asks him to find all unique prime numbers in the...
0.728346
Apps_7536
C
[ "is_prime", "sum_of_unique_primes" ]
2
[ [ "sum_of_unique_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1984624a5ff914631050f5ec493d226012f1666
0c890c198c2097d05e2bda38ed80a75bc7708e0f
v1.0
complete
Apps
Apps_9447_C
def reconstruct_bst(in_order): """Reconstruct the original Binary Search Tree (BST) from its in-order traversal and return the pre-order traversal of the reconstructed tree. Args: in_order: List[int] - A list of integers representing the in-order traversal of a BST. Returns: List[int] - A ...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def sorted_array_to_bst(arr): if not arr: return None # Find the middle index mid = len(arr) // 2 # Make the middle element the root root = TreeNode(arr[mid]) # Recu...
from solution import reconstruct_bst def test_reconstruct_bst_example(): in_order = [2, 3, 5, 6, 7, 8, 10] expected_pre_order = [6, 3, 2, 5, 8, 7, 10] assert reconstruct_bst(in_order) == expected_pre_order def test_reconstruct_bst_single_element(): in_order = [7] expected_pre_order = [7] asser...
[]
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n\ndef reconstruct_bst(in_order):\n...
trial_gpt4o_8
{ "original_instruction": "You are given an array representing the in-order traversal of a Binary Search Tree (BST). Your task is to reconstruct the original BST and then output the pre-order traversal of the reconstructed tree.\n\nFor example:\n```\nin_order = [2, 3, 5, 6, 7, 8, 10]\n```\nYour function `reconstruct_...
0.466901
Apps_9447
C
[ "sorted_array_to_bst", "pre_order_traversal", "reconstruct_bst" ]
3
[ [ "reconstruct_bst", "pre_order_traversal" ], [ "reconstruct_bst", "sorted_array_to_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
6fbc3af8ef7d8c039e354b8407fd96983476322a
99a1c3e5b4dc4960f5980dbb17cc3b9db220e68b
v1.0
complete
Apps
Apps_9424_C
def can_distribute(weights, F, max_load): # Helper function to check if we can distribute the weights pass def minimize_maximum_load(T, test_cases): """ Function to minimize the maximum load any friend has to carry >>> minimize_maximum_load(2, [(3, 5, [1, 2, 3, 4, 5]), (2, 5, [1, 2, 3, 4, 5])]) [6,...
def can_distribute(weights, F, max_load): current_load = 0 friends_used = 1 for weight in weights: if current_load + weight > max_load: friends_used += 1 current_load = weight if friends_used > F: return False else: current_loa...
from solution import minimize_maximum_load, process_input def test_minimize_maximum_load(): input_data = """2 3 5 1 2 3 4 5 2 5 1 2 3 4 5""" T, test_cases = process_input(input_data) results = minimize_maximum_load(T, test_cases) assert results == [6, 9] def test_single_friend(): input_data = """1...
[ { "docstring": null, "function_declaration": "def can_distribute(weights, F, max_load):", "function_name": "can_distribute", "parameter_list": "(weights, F, max_load)" }, { "docstring": null, "function_declaration": "def minimize_maximum_load(T, test_cases):", "function_name": "minim...
[ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 ]
6
medium
0.6
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def min_max_load(T, test_cases):\n def canDistribute(weights, friends, max_load):\n current_load = 0\n used_friends = 1\n\n for weight in we...
trial_gpt4o_5
{ "original_instruction": "A group of friends is planning a hiking trip and they need to distribute their supplies evenly among themselves. They have a list of supplies of different weights, and they want to minimize the maximum load any one friend has to carry. \n\n-----Input:-----\n- First line will contain $T$, th...
0.62528
Apps_9424
C
[ "can_distribute", "minimize_maximum_load", "process_input" ]
3
[ [ "minimize_maximum_load", "can_distribute" ] ]
1
[ "process_input" ]
false
[]
false
pytest
true
[]
true
8b7f9f62d13cff395e54d81f341828d05c8fa6c1
badca1278f9ba059355df1a6be00539f8cb9f0f0
v1.0
complete
Apps
Apps_9196_C
from typing import List def is_prime(num: int) -> bool: """ Returns True if the number is prime, otherwise False. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False """ pass def filter_primes(numbers: List[int]) -> List[int]: """ Returns a list containing o...
def is_prime(num): """ Returns True if the number is prime, otherwise False. """ if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True def filter_primes(numbers): """ Returns a list containing only the pri...
from solution import filter_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(1) == False assert is_prime(0) == False assert is_prime(-1) == False def test_filter_primes(): ...
[ { "docstring": "Returns True if the number is prime, otherwise False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list containing only the prime numbers from the original list.", "function_declaration...
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
10
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Determine if the given integer n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n ret...
trial_gpt4o_9
{ "original_instruction": "Given a list of integers, the code provided is supposed to return a new list containing only the prime numbers from the original list.\n\nHowever, the code is not producing the correct output.\n\n# Task\n\nFix the bug so that the function correctly returns a list of prime numbers.\n\n# Note...
0.726001
Apps_9196
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
669c7a3acb23e0c939eb9e8780a324098456aaed
2d371b9c215902c97c5b7313c5f4007f7c3fa917