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
instruct
Apps
Apps_4283_I
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. You are given an integer array $a$ of length $n$. Zach wants to determine whether it is possible to remove exactly one element from the array such that the rem...
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": "", "prompt_id": "00004283", "row_id": 4283, "seed_ids": "[28]" }
0.685095
Apps_4283
I
[ "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
e2d00a565a8206c9519aedcc73ac8a25649289fe
c914783a2c4f459902de9a0927c3afdaa0c3fef5
v1.0
instruct
Apps
Apps_4286_I
Write a function that takes an array of integers and returns a new array consisting of all the positive integers in the original array, each replaced by the largest prime factor of that integer. If the integer is negative or zero, the output array should have the integer unchanged at its corresponding index. ## Exampl...
import math def largest_prime_factor(n): if n <= 1: return None while n % 2 == 0: max_prime = 2 n //= 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: max_prime = i n //= i if n > 2: max_prime = n return ...
from solution import replace_with_largest_prime_factor def test_replace_with_largest_prime_factor(): assert replace_with_largest_prime_factor([10, -7, 15, 0, 33]) == [5, -7, 5, 0, 11] assert replace_with_largest_prime_factor([20, 25, 77, 8, 100]) == [5, 5, 11, 2, 5] assert replace_with_largest_prime_factor...
[ { "docstring": null, "function_declaration": "def largest_prime_factor(n):", "function_name": "largest_prime_factor", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def replace_with_largest_prime_factor(arr):", "function_name": "replace_with_largest_prime_fa...
[ 1, 1, 1, 0, 0, 1, 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": "import math\n\ndef largest_prime_factor(n):\n \"\"\"\n Helper function to find the largest prime factor of a given positive integer n.\n \"\"\"\n larges...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00004286", "row_id": 4286, "seed_ids": "[4199]" }
0.640533
Apps_4286
I
[ "largest_prime_factor", "replace_with_largest_prime_factor" ]
2
[ [ "replace_with_largest_prime_factor", "largest_prime_factor" ] ]
1
[]
false
[]
false
pytest
true
[]
true
476363b1358db9ba7ca9fedcd78f14e924004e06
9e2d517d18799527f859d77b8919014dd2590b6b
v1.0
instruct
Apps
Apps_4306_I
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, output -1. -----Input----- ...
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": "", "prompt_id": "00004306", "row_id": 4306, "seed_ids": "[82]" }
0.722099
Apps_4306
I
[ "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
32033936cc1017b7964d0532be6b5f916231d0d0
2b7be6e62cedab7351d39dd803c5b88cd546b930
v1.0
instruct
Apps
Apps_4340_I
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. -----Input----- - The first line of the input contains an integer n referring to the number of rows and columns of...
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": "", "prompt_id": "00004340", "row_id": 4340, "seed_ids": "[946]" }
0.624912
Apps_4340
I
[ "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
770795ead2944bd2b4e2f4eece7fd4283a04ed5c
e9b1f9d434e692e5093e212d154c5b460a77c1f6
v1.0
instruct
Apps
Apps_4351_I
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 the given list. A palindrome is a string that reads the same backward as forward. Function Signat...
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": "", "prompt_id": "00004351", "row_id": 4351, "seed_ids": "[1870]" }
0.734817
Apps_4351
I
[ "is_palindrome", "find_beautiful_words" ]
2
[ [ "find_beautiful_words", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9069c08b6a42198172e085c52623070dead03656
aa59669fb96626f9e4fd17776cb41234007b8743
v1.0
instruct
Apps
Apps_4452_I
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. For example: ``` next_palindrome(123) -> 131 next_palindrome(489) -> 494 next_palindrome(99) -> 101 ``` Your...
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": "", "prompt_id": "00004452", "row_id": 4452, "seed_ids": "[4360]" }
0.836341
Apps_4452
I
[ "is_palindrome", "next_palindrome" ]
2
[ [ "next_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6e160e315800ad4a190bdcbd73e77cb78b0715d6
e9ce84392c47f841e5e58629fcc0e19bfdd95df0
v1.0
instruct
Apps
Apps_4511_I
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. You need to build a function `spell_checker` that takes two arguments: 1. `text`: a string of words separated by spaces. 2. `d...
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": "", "prompt_id": "00004511", "row_id": 4511, "seed_ids": "[4891]" }
0.596296
Apps_4511
I
[ "levenshtein_distance", "spell_checker" ]
2
[ [ "spell_checker", "levenshtein_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
938a415254620007d3613392b4125c9536cdd773
8ada5d0ed1924aca8350bbd84ef40ff22ad55483
v1.0
instruct
Apps
Apps_4625_I
# Task 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. ### Example For `lst = [4, 2, 7, 1, 9]`, the result should be `[...
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": "", "prompt_id": "00004625", "row_id": 4625, "seed_ids": "[4397]" }
0.695535
Apps_4625
I
[ "custom_sort", "merge" ]
2
[ [ "custom_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
541e710029ad96af68b92eb8efce99434b252205
8b29c0b07edc9219147ff6c0ab15b26072571a42
v1.0
instruct
Apps
Apps_4650_I
=====Problem Statement===== A strong password satisfies the following criteria: 1. It has at least 6 characters and at most 12 characters. 2. It contains at least one uppercase letter. 3. It contains at least one lowercase letter. 4. It contains at least one digit. 5. It contains at least one special character from th...
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": "", "prompt_id": "00004650", "row_id": 4650, "seed_ids": "[2564]" }
0.589027
Apps_4650
I
[ "check_password_strength", "password_strength_checker" ]
2
[ [ "password_strength_checker", "check_password_strength" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c6de5e623cca5890dd7caadb12ef44ab5a3a400b
762ae9eba4d8f0de1f9772f5eb89818c9da87965
v1.0
instruct
Apps
Apps_4794_I
Design a function that takes a list of words and identifies all pairs of words whose concatenation forms a palindrome. -----Input----- The input consists of a single integer N followed by a list of N strings. Each string consists of lowercase English letters only. -----Output----- The output should list all pairs o...
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": "", "prompt_id": "00004794", "row_id": 4794, "seed_ids": "[873]" }
0.790844
Apps_4794
I
[ "is_palindrome", "palindrome_pairs" ]
2
[ [ "palindrome_pairs", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1c1c9e81771b585e6cec5c4ac35bfd78bafac46e
f000ffe9cbf83315884db08a51e8ad286fe4f9a2
v1.0
instruct
Apps
Apps_4897_I
-----Problem Statement----- An 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 Armstrong number because 153 = 1^3 ...
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": "", "prompt_id": "00004897", "row_id": 4897, "seed_ids": "[955]" }
0.538996
Apps_4897
I
[ "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
0227e1bbb2978c09c700c13a6f1226bf4ef70b69
309f06f80a6e75f2d15599cdb4f726fe7833f01f
v1.0
instruct
Apps
Apps_4898_I
### Palindrome Index Finder A 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. If the string is already a palindrome, return `-1`. I...
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": "", "prompt_id": "00004898", "row_id": 4898, "seed_ids": "[1778]" }
0.766546
Apps_4898
I
[ "is_palindrome", "palindrome_index_finder" ]
2
[ [ "palindrome_index_finder", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
790adf15cfec89833a48fd2d1f8bf142a73faaf8
96a22d94323e6fbb7b16e28cd870507d2273047a
v1.0
instruct
Apps
Apps_4951_I
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 trend in the active growth perio...
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": "", "prompt_id": "00004951", "row_id": 4951, "seed_ids": "[802]" }
0.666871
Apps_4951
I
[ "longest_active_period", "parse_input", "solution" ]
3
[ [ "solution", "longest_active_period" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
a1a70588a167ef542f6ec7f6e9cb67ec91b840a4
1dc8e90a5fad04fc770571454551b99876896358
v1.0
instruct
Apps
Apps_5027_I
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 10 or 13 characters long. Y...
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": "", "prompt_id": "00005027", "row_id": 5027, "seed_ids": "[3553]" }
0.63225
Apps_5027
I
[ "isValidISBN", "is_valid_isbn10", "is_valid_isbn13" ]
3
[ [ "isValidISBN", "is_valid_isbn10" ], [ "isValidISBN", "is_valid_isbn13" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fab278c1fa97be90cfa2aaf9ecf09b3ddc887780
23b2ae3804af86e4a1376f1b7c7470e8d815b876
v1.0
instruct
Apps
Apps_5060_I
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: 1. Start with the number $N$. 2. In each step, add the sum of the prime factors of the current number to i...
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": "", "prompt_id": "00005060", "row_id": 5060, "seed_ids": "[1515]" }
0.60685
Apps_5060
I
[ "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
a82331ffcf44c8e8cb6fe53ac7788622bc2abd78
53e0213a23550aee1201330179e4e15a90cb153f
v1.0
instruct
Apps
Apps_5098_I
In a distant planet called Zog, people measure time in "zogdays". A zogday is divided into "zoghours", and a zoghour into "zogminutes". You 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=(dz, dh, dm)` where `zz`, `hh`, and `...
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": "", "prompt_id": "00005098", "row_id": 5098, "seed_ids": "[4383]" }
0.58027
Apps_5098
I
[ "convert_to_minutes", "check_events_overlap" ]
2
[ [ "check_events_overlap", "convert_to_minutes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
50cfcc271ebb51a0b6ee6a6360810a86623b0e8a
a44089fc04802dfe5027cd53d4233a20b21ff5c0
v1.0
instruct
Apps
Apps_5119_I
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. For example: - The proper divisors of `6` are `1, 2, 3`, and `1 + 2 + 3 = 6`, so `6` is a perfect number. - The prope...
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": "", "prompt_id": "00005119", "row_id": 5119, "seed_ids": "[2756]" }
0.615249
Apps_5119
I
[ "is_perfect_number", "kth_perfect_number" ]
2
[ [ "kth_perfect_number", "is_perfect_number" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd6802a4fdf209efd2be011720a2c7bff34671ef
7536f62a4392c20e82990681ffa0272fd66217ca
v1.0
instruct
Apps
Apps_5228_I
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. The order that the function receives its argument is: ```python extract_primes(numbers) ``` ## Examples ```python extract_primes([10, 41, 22, 5...
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": "", "prompt_id": "00005228", "row_id": 5228, "seed_ids": "[3260]" }
0.706139
Apps_5228
I
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
false
[]
true
03d7ad8e8abc7c99d87a90a08c55fd991dc85ad4
27eaac28700f5f40eb8b54e9bfab4f7e585e686c
v1.0
instruct
Apps
Apps_5240_I
-----Problem Statement----- In 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: For each participant i in a group, compute the sum of integers from a to b (in...
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": "", "prompt_id": "00005240", "row_id": 5240, "seed_ids": "[1210]" }
0.642125
Apps_5240
I
[ "sum_from_a_to_b", "coding_marathon_sums" ]
2
[ [ "coding_marathon_sums", "sum_from_a_to_b" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c6ccfa8213988a67d39aa173fb5e675902176522
ee603cfcdcf3a433e8ca8a04e1bebd48e678ba25
v1.0
instruct
Apps
Apps_5270_I
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. Function signature: **filter_primes(numbers: List[int]) -> List[int]** Prime number i...
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": "", "prompt_id": "00005270", "row_id": 5270, "seed_ids": "[4017]" }
0.649553
Apps_5270
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
884c45a9d8c11972068711834fd21e090cdc6ace
426728035e98f5ce6ad8b0f039c77f0954a67188
v1.0
instruct
Apps
Apps_5306_I
A robotic arm is tasked with sorting items on a conveyor belt by color. The conveyor belt is represented as a list of integers, where each integer corresponds to a specific color. The robotic arm has limited reach and can only swap elements that are next to each other. Your task is to design a function that sorts the c...
def count_inversions(arr): """ Helper function to count the number of inversions in the array using a modified merge sort. An inversion is when two elements are out of order. """ if len(arr) < 2: return arr, 0 mid = len(arr) // 2 left, left_inv = count_inversions(arr[:mid]) right...
from solution import minimum_adjacent_swaps_to_sort_belts def test_single_case(): T = 1 test_cases = [(3, [3, 1, 2])] assert minimum_adjacent_swaps_to_sort_belts(T, test_cases) == [2] def test_multiple_cases(): T = 2 test_cases = [(3, [3, 1, 2]), (4, [4, 3, 2, 1])] assert minimum_adjacent_swap...
[ { "docstring": "Helper function to count the number of inversions in the array using a modified merge sort.\nAn inversion is when two elements are out of order.", "function_declaration": "def count_inversions(arr):", "function_name": "count_inversions", "parameter_list": "(arr)" }, { "docstr...
[ 0, 0, 0, 1, 0, 1, 0, 1, 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 minimum_swaps_to_sort(T, test_cases):\n \"\"\"\n Returns the minimum number of adjacent swaps required to sort the conveyor belts for all test cases.\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00005306", "row_id": 5306, "seed_ids": "[568]" }
0.665944
Apps_5306
I
[ "count_inversions", "merge_and_count", "minimum_adjacent_swaps_to_sort_belts" ]
3
[ [ "count_inversions", "merge_and_count" ], [ "minimum_adjacent_swaps_to_sort_belts", "count_inversions" ] ]
2
[]
false
[]
false
pytest
true
[]
true
024117be105179da064994ffee02cf9a93e9afb1
9463db415c3a4934114aeff8bba6c5d65351a958
v1.0
instruct
Apps
Apps_5403_I
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. A submatrix is any contiguous rectangular part of the matrix. -----Input:----- - The first line of input contains two integers, $n$ and $m$, represe...
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": "", "prompt_id": "00005403", "row_id": 5403, "seed_ids": "[570]" }
0.625579
Apps_5403
I
[ "max_submatrix_sum", "kadane" ]
2
[ [ "max_submatrix_sum", "kadane" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69774901f6d46c6d1cfd95daa9258d3bd8c28f06
ba1c90758e767282bd35a268746d6478a5c2dfdf
v1.0
instruct
Apps
Apps_5404_I
The Prime Number Game Three friends, Alice, Bob, and Charlie, are playing a game with prime numbers. The game is played in rounds, where each round consists of choosing a prime number from an initial set and removing all its multiples from the set. The game continues until no prime numbers are left in the set. Each pl...
def prime_game_winner(test_cases): results = [] for case in test_cases: n, numbers = case primes = [num for num in numbers if is_prime(num)] # Sort primes in descending order to simulate optimal play primes_sorted = sorted(primes, reverse=True) if not ...
from solution import prime_game_winner, is_prime # Tests for 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 # Tests for prime_game_winner def test_prime_game_winner(): assert prime_game_winner([(5, [2, 3, 4...
[ { "docstring": null, "function_declaration": "def prime_game_winner(test_cases):", "function_name": "prime_game_winner", "parameter_list": "(test_cases)" }, { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" ...
[ 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": "def sieve(n):\n \"\"\" Returns a list of primes up to n \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while p * p <= n:\n if is_prime[p]:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00005404", "row_id": 5404, "seed_ids": "[1525]" }
0.699331
Apps_5404
I
[ "prime_game_winner", "is_prime" ]
2
[ [ "prime_game_winner", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
894dc0232276e076279e78971ad5e17153be01ff
f829b696500a20b0d6b5bbb59eb3a60deb774a58
v1.0
instruct
Apps
Apps_5466_I
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." Given an even number N (greater than 2), find two prime numbers p1 and p2 such that ...
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": "", "prompt_id": "00005466", "row_id": 5466, "seed_ids": "[1031]" }
0.697693
Apps_5466
I
[ "sieve_of_eratosthenes", "goldbach_conjecture", "solve_goldbach" ]
3
[ [ "goldbach_conjecture", "sieve_of_eratosthenes" ], [ "solve_goldbach", "goldbach_conjecture" ] ]
2
[]
false
[]
false
pytest
false
[]
true
2d36fe0c042e7a62ec6d4d0806baa5b3694a0154
7e07ac0ca8f20afa7b5e5b97899b012ef90ad947
v1.0
instruct
Apps
Apps_5541_I
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 more matches on different field...
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": "", "prompt_id": "00005541", "row_id": 5541, "seed_ids": "[1493]" }
0.714469
Apps_5541
I
[ "is_valid_fixture", "check_fixtures" ]
2
[ [ "check_fixtures", "is_valid_fixture" ] ]
1
[]
false
[]
false
pytest
true
[]
true
df5ee7d528a465cf652bd5d1da1ddfa8b61813b9
a94b661a84bd6570b84e1498c5418a08f306e190
v1.0
instruct
Apps
Apps_5574_I
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 perfect square. Since Pat w...
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": "", "prompt_id": "00005574", "row_id": 5574, "seed_ids": "[2152]" }
0.66149
Apps_5574
I
[ "is_perfect_square", "shortest_consecutive_perfect_square_subset" ]
2
[ [ "shortest_consecutive_perfect_square_subset", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e5e7a3043321810a489cbe2095c54fab342d4d0
d0f8eb7f3c7990f41b96241de84c24e592482315
v1.0
instruct
Apps
Apps_5670_I
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 are tasked with writing a progr...
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": "", "prompt_id": "00005670", "row_id": 5670, "seed_ids": "[1141]" }
0.691233
Apps_5670
I
[ "euclidean_distance", "farthest_distance", "main" ]
3
[ [ "farthest_distance", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c3cabd0d74491513c7b1f1611ba11c07fb8762c1
f17e340babfb5209807f3859e51f8e14f0976f53
v1.0
instruct
Apps
Apps_5785_I
=====Function Descriptions===== math.gcd The `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. Example Code >>> import math >>> math.gcd(8, 12) 4 >>> math.gcd(54, 24) 6 =====Probl...
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": "", "prompt_id": "00005785", "row_id": 5785, "seed_ids": "[2632]" }
0.672109
Apps_5785
I
[ "simplify_fraction", "reduce_fractions" ]
2
[ [ "reduce_fractions", "simplify_fraction" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7846a905d50843d9a7be4b8e1fe4ab44edc75d30
e6e5a5be3be224822e20cefe6169a2e5671fd27e
v1.0
instruct
Apps
Apps_5980_I
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. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. For the purposes of thi...
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": "", "prompt_id": "00005980", "row_id": 5980, "seed_ids": "[4529]" }
0.698859
Apps_5980
I
[ "is_prime", "sumOfPrimes" ]
2
[ [ "sumOfPrimes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c2ed9cd93521512c70d087844b4cc4a055216a3a
2440812aeec1771d763c993d12d80adead0a11e4
v1.0
instruct
Apps
Apps_5991_I
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 leading zeros, except for the n...
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": "", "prompt_id": "00005991", "row_id": 5991, "seed_ids": "[3312]" }
0.631593
Apps_5991
I
[ "is_valid_segment", "restore_ip_addresses" ]
2
[ [ "restore_ip_addresses", "is_valid_segment" ] ]
1
[]
false
[]
false
pytest
true
[]
true
668f0333e98ae3265892f60fec9ffc765ccf70ae
5a561801b4c6dd95dd2c66f66ef6f6bfdb634f63
v1.0
instruct
Apps
Apps_6000_I
# Tasks Write 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. Given: 1. A list of tuples, `meetings`, where each tuple contains two strings representing the start and end time of a meeting in 24-hour ...
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": "", "prompt_id": "00006000", "row_id": 6000, "seed_ids": "[3786]" }
0.636564
Apps_6000
I
[ "convert_to_minutes", "schedule_meeting" ]
2
[ [ "schedule_meeting", "convert_to_minutes" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d4f16b29bdc97c18805c93ce7f0d0641cfa2339
8e3d2be291e51f251f066118724a468018377ee3
v1.0
instruct
Apps
Apps_6099_I
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. ### Example ```python longest_anagram_sequence(["listen", "silent", "enlist", "inlets", "google", "elgoog", "hello", "ohell"]) # Should return ...
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": "", "prompt_id": "00006099", "row_id": 6099, "seed_ids": "[4300]" }
0.626099
Apps_6099
I
[ "are_anagrams", "longest_anagram_sequence" ]
2
[ [ "longest_anagram_sequence", "are_anagrams" ] ]
1
[]
false
[]
false
pytest
true
[]
true
77308caa42910a00e0fe7c4a9397f4d454f2d8de
6b3c018055210d7e6bbaeafcba02ecd48a7af918
v1.0
instruct
Apps
Apps_6132_I
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: - Choose a character from \(S\) and move it to the front of the string. Your task is to determine the minimum number of operations required to rearrange the...
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": "", "prompt_id": "00006132", "row_id": 6132, "seed_ids": "[879]" }
0.834951
Apps_6132
I
[ "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
f4a41c19a6011e723057a94a50382ac9a7099f14
ee9fe10c9243e7cbbd0c58a7d219cfb3e88a60ba
v1.0
instruct
Apps
Apps_6141_I
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 be excluded from both lists. ...
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": "", "prompt_id": "00006141", "row_id": 6141, "seed_ids": "[4536]" }
0.630539
Apps_6141
I
[ "is_prime", "split_and_sort_numbers" ]
2
[ [ "split_and_sort_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
70801aca9d92bd375704b8287e6f76035dd138b2
44413fc23f7946cea13568a277bc2c8422de9768
v1.0
instruct
Apps
Apps_6159_I
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.
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": "", "prompt_id": "00006159", "row_id": 6159, "seed_ids": "[3622]" }
0.68548
Apps_6159
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e63fee8a1c6992d2dcf77513fe488fe4deab1d3
1a462eba037e2e67e3d2e6771697ddcca627c241
v1.0
instruct
Apps
Apps_6162_I
You are given an undirected graph with N nodes and M edges. Each edge has a weight associated with it. You need to find the weight of the minimum spanning tree (MST) of the graph. If the graph is not connected, print -1 instead. -----Input----- - The first line of the input contains a single integer T denoting the nu...
def find(parent, i): if parent[i] == i: return i return find(parent, parent[i]) def union(parent, rank, x, y): root_x = find(parent, x) root_y = find(parent, y) if rank[root_x] < rank[root_y]: parent[root_x] = root_y elif rank[root_x] > rank[root_y]: parent[root_y] ...
def test_solve_mst_problems(): test_cases = [ (4, 5, [(0, 1, 10), (0, 2, 6), (1, 2, 5), (2, 3, 2), (1, 3, 15)]), (3, 3, [(0, 1, 5), (1, 2, 10), (2, 0, 7)]) ] expected_outputs = [13, 12] assert solve_mst_problems(test_cases) == expected_outputs def test_disconnected_graph(): te...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 0, 1, 1, 1, 0, 0, 0, 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": "from heapq import heappop, heappush\n\ndef find(parent, i):\n if parent[i] == i:\n return i\n return find(parent, parent[i])\n\ndef union(parent, rank,...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006162", "row_id": 6162, "seed_ids": "[843]" }
0.816853
Apps_6162
I
[ "find", "union", "kruskal_mst", "solve_mst_problems" ]
4
[ [ "kruskal_mst", "find" ], [ "kruskal_mst", "union" ], [ "solve_mst_problems", "kruskal_mst" ], [ "union", "find" ] ]
4
[]
false
[]
false
pytest
false
[]
true
4e5e647beebbe878f72d6a1a51eee2fcf66b2d2b
9505ca607509b34999b4a0b6e7572a033b2e914c
v1.0
instruct
Apps
Apps_6190_I
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. Note: - A prime number is a natural number greater t...
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": "", "prompt_id": "00006190", "row_id": 6190, "seed_ids": "[2421]" }
0.615976
Apps_6190
I
[ "is_prime", "count_prime_partitions" ]
2
[ [ "count_prime_partitions", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
11db75b0bd77a4956369c7bbf0975b83d5be59bc
3ad1c59426970511fa705f7e9c5ec2ca25ed8b77
v1.0
instruct
Apps
Apps_6213_I
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, help her determine which deli...
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": "", "prompt_id": "00006213", "row_id": 6213, "seed_ids": "[36]" }
0.696622
Apps_6213
I
[ "count_deliveries_at_times", "organize_flower_deliveries" ]
2
[ [ "organize_flower_deliveries", "count_deliveries_at_times" ] ]
1
[]
false
[]
false
pytest
true
[]
true
831b21335814fabd465a3aa51d3dcf763a352571
b2a6374505e5c55083f0794fccde2c9bee250bdd
v1.0
instruct
Apps
Apps_6259_I
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. A "subtree" of a node $u$ is defined as a node $u$ and all its descendants in the tree. You need to process $Q$ queries of th...
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": "", "prompt_id": "00006259", "row_id": 6259, "seed_ids": "[1558]" }
0.671172
Apps_6259
I
[ "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
31c5019198b59050cfbdcc67a3b648d902995a88
445581832f1bd99b6757559e82a6335b3d75faf7
v1.0
instruct
Apps
Apps_6349_I
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 them form a cyclic permutation. ...
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": "", "prompt_id": "00006349", "row_id": 6349, "seed_ids": "[940]" }
0.599169
Apps_6349
I
[ "is_cyclic_permutation", "check_cyclic_permutations" ]
2
[ [ "check_cyclic_permutations", "is_cyclic_permutation" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5248a7ddcf49f343960295c185a16ab5af4a048b
b6b03faaffca2542cb8caa8489931faba3a0a19c
v1.0
instruct
Apps
Apps_6382_I
A city is represented by a grid of size $N \times M$ where each cell can either be empty (represented by $0$) or contain a building (represented by $1$). The mayor of the city plans to build a new park that can cover an entire rectangular sub-grid within the city grid. The park cannot contain any buildings within its b...
def maximalRectangle(grid): if not grid: return 0 n, m = len(grid), len(grid[0]) height = [0] * m max_area = 0 for i in range(n): for j in range(m): height[j] = height[j] + 1 if grid[i][j] == 0 else 0 max_area = max(max_area, largestRectangleArea(he...
import pytest from solution import findLargestParkArea def test_findLargestParkArea(): t = 1 test_cases = [ (4, 5, [ [1, 0, 0, 0, 1], [0, 0, 1, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 1] ]) ] assert findLargestParkArea(t, test_cases) == [6] ...
[ { "docstring": null, "function_declaration": "def maximalRectangle(grid):", "function_name": "maximalRectangle", "parameter_list": "(grid)" }, { "docstring": null, "function_declaration": "def largestRectangleArea(heights):", "function_name": "largestRectangleArea", "parameter_li...
[ 1, 0, 0, 0, 1, 0, 1, 0, 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 maximalRectangle(grid):\n if not grid:\n return 0\n \n n, m = len(grid), len(grid[0])\n height = [0] * m\n max_area = 0\n\n for i in ra...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00006382", "row_id": 6382, "seed_ids": "[563]" }
0.634725
Apps_6382
I
[ "maximalRectangle", "largestRectangleArea", "findLargestParkArea" ]
3
[ [ "findLargestParkArea", "maximalRectangle" ], [ "maximalRectangle", "largestRectangleArea" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d6b57b3bfd9e7b997a7811307a2cf79d9de4f9bc
99e0a41b916af156bc3dec2e6e3c30378fd3a4a2
v1.0
instruct
Apps
Apps_6406_I
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. ## Examples ``` [10, 11, 12, 13, 14, 15] ==> 24 (11 + 13) [2, 3, 4, 5, 6, 7, 8, 9] ==> 17 (2 + 3 +...
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": "", "prompt_id": "00006406", "row_id": 6406, "seed_ids": "[3924]" }
0.708273
Apps_6406
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8824d14b18426fb50fdbe0fc0939d706941a66df
83a2311588eaa476cf32cca8b90f14d58a26f8cd
v1.0
instruct
Apps
Apps_6429_I
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 connected by a passage should be p...
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": "", "prompt_id": "00006429", "row_id": 6429, "seed_ids": "[902]" }
0.687224
Apps_6429
I
[ "is_painting_possible", "castle_painting" ]
2
[ [ "castle_painting", "is_painting_possible" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4e9660e7ed680f2f761ef9e005886edee128b905
a74274537a561586d81d0e44a389f1074db90c3c
v1.0
instruct
Apps
Apps_6472_I
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. You are required to perform a s...
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": "", "prompt_id": "00006472", "row_id": 6472, "seed_ids": "[2083]" }
0.640965
Apps_6472
I
[ "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
23b875913b72777fa0119e6e90eafff518369195
7ab604e1509eeb8b4879d342adb75ddace5609c2
v1.0
instruct
Apps
Apps_6491_I
Leo is interested in data structures and recently learned about binary search trees (BST). He wants to add a series of numbers to an initially empty binary search tree and calculate the depth of the resulting tree. The depth of a binary search tree is defined as the number of edges in the longest path from the root to ...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(node, key): """ Inserts a new node with the given key into the BST. """ if node is None: return TreeNode(key) if key < node.val: node.left = insert(...
from solution import bst_depth def test_bst_depth_simple(): assert bst_depth(6, [3, 1, 4, 2, 5, 6]) == 3 def test_bst_depth_single_element(): assert bst_depth(1, [5]) == 0 def test_bst_depth_sorted_increasing(): assert bst_depth(5, [1, 2, 3, 4, 5]) == 4 def test_bst_depth_sorted_decreasing(): assert...
[]
[ 0, 1, 0, 1, 1, 0, 0, 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": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\nclass BinarySearchTree:\n def __ini...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00006491", "row_id": 6491, "seed_ids": "[2033]" }
0.519392
Apps_6491
I
[ "insert", "max_depth", "bst_depth" ]
3
[ [ "bst_depth", "insert" ], [ "bst_depth", "max_depth" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
4af97a7527f16888c67a4ffbd288395a255fd2a7
c59a66b0846b6ade9501722ea10db1af4c2b794b
v1.0
instruct
Apps
Apps_6496_I
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. -----Input----- - The first line contains a single integer `N`, which is the number of transactions. - The following `N` lines each contain a...
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": "", "prompt_id": "00006496", "row_id": 6496, "seed_ids": "[1036]" }
0.639988
Apps_6496
I
[ "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
c7e2b2ef9f4b68a50599eadaeaffe741d872a23f
2aff43e8ec5cbc00af96de2bd490e9e7ca5a6ebe
v1.0
instruct
Apps
Apps_6504_I
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 goes past 'Z', it should wrap a...
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": "", "prompt_id": "00006504", "row_id": 6504, "seed_ids": "[3014]" }
0.709935
Apps_6504
I
[ "shift_char", "shift_string" ]
2
[ [ "shift_string", "shift_char" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3350fa92cbbe630c39be358601d2076216ff1e62
255fa4b2fdc8cfb5f4962eb1a97ce1e68df0e008
v1.0
instruct
Apps
Apps_6601_I
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. The first term is always "1". The second term is obtained by...
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": "", "prompt_id": "00006601", "row_id": 6601, "seed_ids": "[3378]" }
0.602935
Apps_6601
I
[ "next_term", "look_and_say" ]
2
[ [ "look_and_say", "next_term" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22818e147a4fbe69b8e4787558cb14b469dcaf92
093e6933b247df6c8db1fc105d39327d17473d1f
v1.0
instruct
Apps
Apps_6633_I
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 a list of integers as input a...
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": "", "prompt_id": "00006633", "row_id": 6633, "seed_ids": "[4220]" }
0.631404
Apps_6633
I
[ "is_prime", "extract_primes" ]
2
[ [ "extract_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f860b69b638aecdd84ffafaccbde35103893dd2c
8fbf0db6017b227e9b8ac176991db44a0bd6a41a
v1.0
instruct
Apps
Apps_6717_I
Implement a function that takes a list of integers and returns a list containing only the elements that are prime numbers. If the input list is empty or no prime numbers are found, return an empty list. **Steps**: 1. Create a helper function `is_prime` which checks if a number is a prime. 2. Iterate through the input ...
def is_prime(n): """ Check if a number is a prime number. :param n: Integer, the number to check. :return: Boolean, True if the number is prime, otherwise False. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5...
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": "Check if a number is a prime number.\n:param n: Integer, the number to check.\n:return: Boolean, True if the number is prime, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Filter the prim...
[ 0, 1, 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 Checks if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2 ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006717", "row_id": 6717, "seed_ids": "[4168]" }
0.746899
Apps_6717
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
26fe6c82f6f4cc2173252545715d959fcdffd3ba
96607787e86cd43f5087c4ae3a7f6aa8f3aa9805
v1.0
instruct
Apps
Apps_6768_I
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 are connected. You are taske...
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": "", "prompt_id": "00006768", "row_id": 6768, "seed_ids": "[543]" }
0.771251
Apps_6768
I
[ "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
f2caff0f714ead764f855f8615527d8e6e0f38ec
223de2f0314052d4583245ce99c45f52be3e2898
v1.0
instruct
Apps
Apps_6771_I
You are given a list of rectangles on a Cartesian plane. Each rectangle is defined by its bottom-left corner and top-right corner. Your task is to determine if these rectangles overlap and return a list of rectangles from the input that overlap with at least one other rectangle. -----Input----- The first line contain...
def is_overlapping(rect1, rect2): """ Checks if two rectangles overlap. Each rectangle is defined by (x1, y1, x2, y2) Return True if they overlap, False otherwise. """ x1, y1, x2, y2 = rect1 a1, b1, a2, b2 = rect2 if x1 < a2 and a1 < x2 and y1 < b2 and b1 < y2: return True ...
from solution import is_overlapping, find_overlapping_rectangles, solve_overlapping_rectangles def test_is_overlapping(): assert is_overlapping((1, 1, 4, 4), (2, 2, 6, 6)) == True assert is_overlapping((1, 1, 4, 4), (4, 4, 6, 6)) == False assert is_overlapping((1, 1, 4, 4), (0, 0, 2, 2)) == True assert...
[ { "docstring": "Checks if two rectangles overlap.\nEach rectangle is defined by (x1, y1, x2, y2)\nReturn True if they overlap, False otherwise.", "function_declaration": "def is_overlapping(rect1, rect2):", "function_name": "is_overlapping", "parameter_list": "(rect1, rect2)" }, { "docstring...
[ 0, 1, 1, 0, 1, 0, 1, 1, 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 rectangles_overlap(rectangles):\n def is_overlapping(r1, r2):\n return not (r1[2] <= r2[0] or r2[2] <= r1[0] or r1[3] <= r2[1] or r2[3] <= r1[1])\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00006771", "row_id": 6771, "seed_ids": "[2108]" }
0.7463
Apps_6771
I
[ "is_overlapping", "find_overlapping_rectangles", "format_output", "solve_overlapping_rectangles" ]
4
[ [ "find_overlapping_rectangles", "is_overlapping" ], [ "solve_overlapping_rectangles", "find_overlapping_rectangles" ], [ "solve_overlapping_rectangles", "format_output" ] ]
3
[ "format_output" ]
false
[]
false
pytest
true
[]
true
ed7f3f2850e2e0f1f568c67b495799454e1f5dad
721a0a34f00da79cfec408c9d55c546d60a7ebbc
v1.0
instruct
Apps
Apps_6817_I
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". To briefly explain, a prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. If the function receives an empty list, it sho...
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": "", "prompt_id": "00006817", "row_id": 6817, "seed_ids": "[2761]" }
0.640419
Apps_6817
I
[ "is_prime", "replace_primes" ]
2
[ [ "replace_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d7127ac6156cffa3fcee542b37a66efe085bcc11
c7ad92cb06cc55fa9a8feb842b8864424e1c9b41
v1.0
instruct
Apps
Apps_6830_I
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. For example, the first 10 square-free numbers are: ``` [1, 2, 3, 5, 6, 7, 10, 11, 13, 14] ``` ...
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": "", "prompt_id": "00006830", "row_id": 6830, "seed_ids": "[4502]" }
0.6492
Apps_6830
I
[ "is_square_free", "square_free_numbers" ]
2
[ [ "square_free_numbers", "is_square_free" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bcf263147d0cc16aa0ddbc3bc35484c5ddb4b801
eae6602a8b383530d8d829f89801e45157d753ca
v1.0
instruct
Apps
Apps_6867_I
Write a function `perimeter` that calculates the perimeter of a polygon given its vertices. The 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 appear in the list, and the last...
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": "", "prompt_id": "00006867", "row_id": 6867, "seed_ids": "[3705]" }
0.68014
Apps_6867
I
[ "distance", "perimeter" ]
2
[ [ "perimeter", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b79ffa1fabd4474b86cae16c1ca8b7734aacd4d1
9fb9619f48494e8b784e76767221ade2b2c15a5d
v1.0
instruct
Apps
Apps_6953_I
Complete the function that checks if a given integer `n` is a Carmichael number. A Carmichael number is a composite number `n` that satisfies Fermat's little theorem for every integer `a` that is coprime to `n`, that is: ``` pow(a, n-1, n) == 1 ``` for all integers `a` with `1 < a < n` and `gcd(a, n) == 0`. A numbe...
import math def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def gcd(a, b): while b: ...
from solution import is_carmichael def test_is_carmichael_true_cases(): assert is_carmichael(561) == True assert is_carmichael(1105) == True assert is_carmichael(1729) == True assert is_carmichael(2465) == True assert is_carmichael(2821) == True def test_is_carmichael_false_cases(): assert is_...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function...
[ 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 math import gcd\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 retur...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00006953", "row_id": 6953, "seed_ids": "[3147]" }
0.577657
Apps_6953
I
[ "is_prime", "gcd", "is_carmichael" ]
3
[ [ "is_carmichael", "gcd" ], [ "is_carmichael", "is_prime" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8c94b5dc72c304fc7aceedf40d7d1197c1ede415
5e947fafd7f827dab764265e7526befd9e109c93
v1.0
instruct
Apps
Apps_6971_I
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). The grid is represented by a matrix $G$ of ...
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": "", "prompt_id": "00006971", "row_id": 6971, "seed_ids": "[39]" }
0.700159
Apps_6971
I
[ "valid_path", "min_difficulty", "easiest_path" ]
3
[ [ "easiest_path", "min_difficulty" ], [ "min_difficulty", "valid_path" ] ]
2
[]
false
[]
false
pytest
false
[]
true
380dafc0adaf0fa3f152b3cacf7838916a0a1dfa
ad583c2618be2d79076053b45a3596e3d1aa2e18
v1.0
instruct
Apps
Apps_6994_I
You are given a list of event timestamps and a duration in minutes, and your task is to determine if any two events overlap. An event's duration starts at its given timestamp and lasts for the specified duration. ## Input - A list of timestamps in `HH:MM` 24-hour format, indicating the start times of events. - An i...
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": "", "prompt_id": "00006994", "row_id": 6994, "seed_ids": "[4862]" }
0.61984
Apps_6994
I
[ "get_minutes_since_midnight", "events_overlap" ]
2
[ [ "events_overlap", "get_minutes_since_midnight" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2159a0191174c8a8750d56452406d9f6f5612e9f
f6417ab6f0d3665dd28964e8faf1a50b22deb0cf
v1.0
instruct
Apps
Apps_7035_I
You are given a binary tree. Find the maximum path sum in the tree. The path can start and end at any node in the tree and must follow through parent-child connections. A path is defined as a sequence of nodes where each pair of consecutive nodes in the sequence has a parent-child relationship. The path must contain a...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(nodes, index): if index == -1: return None val, left_index, right_index = nodes[index] node = TreeNode(val) node.left = build_tree(node...
from solution import solve def test_single_node(): trees = [[(1, -1, -1)]] assert solve(trees) == [1] def test_simple_tree(): trees = [[(1, 1, 2), (2, -1, -1), (3, -1, -1)]] assert solve(trees) == [6] def test_negative_values(): trees = [[(1, 1, 2), (2, -1, -1), (-3, -1, -1)]] assert solve(tr...
[]
[ 1, 1, 0, 0, 0, 0, 0, 1, 0 ]
3
medium
0.333
{ "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 build_tr...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00007035", "row_id": 7035, "seed_ids": "[1428]" }
0.676759
Apps_7035
I
[ "build_tree", "max_path_sum", "solve" ]
3
[ [ "solve", "build_tree" ], [ "solve", "max_path_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
35a48def01e1d5391880c1f59932df4fbda22d3b
a6e7f41390eb7012181d62ef8ff39414c146f963
v1.0
instruct
Apps
Apps_7056_I
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. **Input** You will be provided with the number ...
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": "", "prompt_id": "00007056", "row_id": 7056, "seed_ids": "[2780]" }
0.75351
Apps_7056
I
[ "max_cookies", "solve_baking_problem" ]
2
[ [ "solve_baking_problem", "max_cookies" ] ]
1
[]
false
[]
false
pytest
true
[]
true
428fd9a289cc94dbd56544d6a3f5548767becd4d
fedd76c1824cea8b22b6fb3419849bdf4073697c
v1.0
instruct
Apps
Apps_7081_I
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 to form a palindrome. He is c...
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": "", "prompt_id": "00007081", "row_id": 7081, "seed_ids": "[1079]" }
0.847499
Apps_7081
I
[ "can_form_palindrome", "check_palindrome_possibilities" ]
2
[ [ "check_palindrome_possibilities", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
false
[]
true
022af14379449fbd4831b069a0770abfb926efd6
f7c8d2a2942687b952839e3835e346fdd4bd1ec4
v1.0
instruct
Apps
Apps_7104_I
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: 1. Find the centroid of the current tree. If the tree has an even number of nodes, we can choose any one of the centroids. 2. Remove the centroid and its connecting edges from...
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": "", "prompt_id": "00007104", "row_id": 7104, "seed_ids": "[1500]" }
0.628603
Apps_7104
I
[ "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
e64359fabc9ee8f1b25aa785b78166706cf52dea
9604a43c8bbaa89f24865f1394a35fad9fd792d5
v1.0
instruct
Apps
Apps_7121_I
Complete the function that takes a positive integer `n` and returns a list of the first `n` prime numbers. ## Examples ```python n = 1 ==> [2] # first prime number is 2 n = 3 ==> [2, 3, 5] # first 3 prime numbers are 2, 3, 5 n = 5 ==> [2, 3, 5, 7, 11] # first 5 prime numbers are 2, 3, 5, ...
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": "", "prompt_id": "00007121", "row_id": 7121, "seed_ids": "[4617]" }
0.774343
Apps_7121
I
[ "is_prime", "first_n_primes" ]
2
[ [ "first_n_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c8f53e0e451759ec83b229aad6cfbe91ded95f1a
9c1972b367aea01daf388f89bb5c261ad7e6e96b
v1.0
instruct
Apps
Apps_7144_I
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 these roads so that any city...
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": "", "prompt_id": "00007144", "row_id": 7144, "seed_ids": "[1260]" }
0.758596
Apps_7144
I
[ "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
2a076f97b42fc7245ec6805414343a36556aea86
a3929ae9e6bf6d44c7e0eb7c5f8427a507e87ace
v1.0
instruct
Apps
Apps_7225_I
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. Create a function, `min_cupcakes`, that takes a list of integers as input. Each intege...
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": "", "prompt_id": "00007225", "row_id": 7225, "seed_ids": "[4870]" }
0.639664
Apps_7225
I
[ "lcm", "min_cupcakes" ]
2
[ [ "min_cupcakes", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6efb83d06d22d3b80572544449a4c68c45f7fb8f
aa992d21f1c77fa0661a2788e5612620e17d47ee
v1.0
instruct
Apps
Apps_7247_I
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. The remaining graph must still be connected. -----Input----- - ...
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": "", "prompt_id": "00007247", "row_id": 7247, "seed_ids": "[1362]" }
0.823902
Apps_7247
I
[ "minimum_spanning_tree_sum", "solve_problem" ]
2
[ [ "solve_problem", "minimum_spanning_tree_sum" ] ]
1
[]
false
[ "UnionFind" ]
true
pytest
false
[]
true
18e0aabf75467e8b281f77cae7d509f8b40f82a8
18136d4e927106c7bfa54005a37b67d97215909b
v1.0
instruct
Apps
Apps_7317_I
In the kingdom of Dinotopia, there are several dinosaur nests. Each nest can contain a number of eggs, and each egg has a specific hatch time. The king of Dinotopia wants to know the total number of eggs that will hatch within a given period. The period is defined by its start and end times, and an egg is considered t...
def count_hatching_eggs(hatch_times, periods): """ Returns a list of counts representing the number of eggs that hatch within the given periods. :param hatch_times: List of integers representing hatch times of eggs :param periods: List of tuples representing the periods (start time, end time) :...
def test_basic_examples(): assert count_hatching_eggs([1, 3, 5, 7, 9], [(1, 5), (4, 8), (10, 15)]) == [3, 2, 0] assert count_hatching_eggs([2, 2, 2, 2], [(1, 3), (2, 2)]) == [4, 4] assert count_hatching_eggs([1, 2, 3, 4, 5, 6], [(3, 6), (5, 10), (1, 1)]) == [4, 2, 1] def test_edge_cases(): assert count...
[ { "docstring": "Returns a list of counts representing the number of eggs that hatch within the given periods.\n\n:param hatch_times: List of integers representing hatch times of eggs\n:param periods: List of tuples representing the periods (start time, end time)\n:return: List of integers representing the count...
[ 1, 0, 0, 1, 1, 1, 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 count_eggs_in_periods(N, hatch_times, Q, periods):\n hatch_times.sort() # Sort the hatch times for efficient counting later\n \n results = []\n \n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00007317", "row_id": 7317, "seed_ids": "[2165]" }
0.624475
Apps_7317
I
[ "count_hatching_eggs", "binary_search_left", "binary_search_right" ]
3
[ [ "count_hatching_eggs", "binary_search_left" ], [ "count_hatching_eggs", "binary_search_right" ] ]
2
[]
false
[]
false
pytest
false
[]
true
3e4f13d7923669c6939935eeb3a45f16907cd7ac
f44d951b81889b242a3118f18faaf0e07e1c2a3c
v1.0
instruct
Apps
Apps_7361_I
Write a function that takes a list of integers as input and returns the list with all prime numbers replaced by their squares. If no prime numbers are found in the list, the function should return the original list. ### Example: ```python input: [4, 7, 10, 11] output: [4, 49, 10, 121] input: [1, 4, 6, 8] output: [1,...
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 <= 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...
from solution import square_primes def test_square_primes_with_primes(): assert square_primes([4, 7, 10, 11]) == [4, 49, 10, 121] def test_square_primes_with_no_primes(): assert square_primes([1, 4, 6, 8]) == [1, 4, 6, 8] def test_square_primes_all_primes(): assert square_primes([2, 3, 5, 7, 11]) == [4, ...
[ { "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 list with prime numbers replaced by their squares.", "function_declaration": "def square_primes(n...
[ 0, 1, 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": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n return...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007361", "row_id": 7361, "seed_ids": "[4013]" }
0.615636
Apps_7361
I
[ "is_prime", "square_primes" ]
2
[ [ "square_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f28b9d0b82662589ee283648ef9c820c6f943c01
e8ea80c36035a684aa5b48589e262c8a67580f7a
v1.0
instruct
Apps
Apps_7387_I
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 respond to these operations effi...
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": "", "prompt_id": "00007387", "row_id": 7387, "seed_ids": "[1071]" }
0.660679
Apps_7387
I
[ "process_operations", "file_system_monitor" ]
2
[ [ "file_system_monitor", "process_operations" ] ]
1
[]
false
[ "FileSystem" ]
true
pytest
true
[]
true
e7621b5dda5b0a079077acb1a164b71053d67830
92789222832bee09ad5b61122e9d54d15f4ae976
v1.0
instruct
Apps
Apps_7536_I
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. Chef gives his son an integer array of size $N$ and asks him to find all unique prime numbers in the array. Once the unique prime ...
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": "", "prompt_id": "00007536", "row_id": 7536, "seed_ids": "[1529]" }
0.656535
Apps_7536
I
[ "is_prime", "sum_of_unique_primes" ]
2
[ [ "sum_of_unique_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
207167ebba5a0bc6429e6c5f65493fe2fa76e0a2
0c890c198c2097d05e2bda38ed80a75bc7708e0f
v1.0
instruct
Apps
Apps_7558_I
Write a function that takes a list of integers and returns a new list containing only the prime numbers from the input list. ~~~if:python You may use a helper function to determine if a number is prime. Assume the input list can be empty or contain up to 1000 integers. ~~~ ~~~if:bf For BF, the input will be an array...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True def filter_primes...
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(1) == False assert is_prime(0) == False assert is_prime(-1) == False assert is_prime(17) == True...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns a list of prime numbers from the given list of integers.", "function_declaration": "def filter_prim...
[ 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 determine if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n retu...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007558", "row_id": 7558, "seed_ids": "[4255]" }
0.699522
Apps_7558
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c5a7fff8e216d533e186aa82a0866288c3cd36c5
9a3d3870b14a9aa3dff082ef39fba5ceab61e387
v1.0
instruct
Apps
Apps_7573_I
# Domain Extractor from Email Address ## Overview Email addresses often contain domains that can be useful for various purposes such as categorization or validation. A domain in an email address is the part after the '@' symbol up to the last dot '.'. ## Task Define two functions, `extractDomain` and `extractDomain...
def extractDomain(email): """ Returns the domain part of the email address. Parameters: email (str): The email address from which to extract the domain. Returns: str: The domain part of the email. """ return email.split('@')[1] def extractDomainsFromList(emails): """ R...
from solution import extractDomain, extractDomainsFromList def test_extractDomain_single_email(): assert extractDomain("user@example.com") == "example.com" assert extractDomain("admin@domain.org") == "domain.org" assert extractDomain("someone@gmail.com") == "gmail.com" assert extractDomain("contact@sub...
[ { "docstring": "Returns the domain part of the email address.\n\nParameters:\nemail (str): The email address from which to extract the domain.\n\nReturns:\nstr: The domain part of the email.", "function_declaration": "def extractDomain(email):", "function_name": "extractDomain", "parameter_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 extractDomain(email):\n \"\"\"\n Extracts the domain from a single email address.\n :param email: A string representing an email address.\n :return:...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007573", "row_id": 7573, "seed_ids": "[4130]" }
0.642234
Apps_7573
I
[ "extractDomain", "extractDomainsFromList" ]
2
[ [ "extractDomainsFromList", "extractDomain" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0e72097e5c02cf70cdc453c08a56f1b9d596f730
5fde01f65b7e90bfa671abcfcc51bd92d37988a9
v1.0
instruct
Apps
Apps_7681_I
-----Problem Statement----- John is interested in sequences. Specifically, he is curious about sequences of integers where all elements of the sequence must be distinct and each integer in the sequence must lie within a given range. He wants to know how many such sequences of a given length can be formed. You are give...
MOD = 1_000_000_007 def factorial(n): if n == 0 or n == 1: return 1 result = 1 for i in range(2, n+1): result = (result * i) % MOD return result def count_sequences(L, A, B): n = B - A + 1 # number of elements in the range [A, B] if L > n: return 0 # Calculate...
import pytest from solution import count_sequences, read_input, solve def test_count_sequences(): assert count_sequences(3, 1, 5) == 60 assert count_sequences(4, 10, 15) == 360 assert count_sequences(5, 20, 25) == 720 assert count_sequences(2, 5, 6) == 2 assert count_sequences(3, 5, 5) == 0 # edge...
[ { "docstring": null, "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def count_sequences(L, A, B):", "function_name": "count_sequences", "parameter_list": "(L, A, B)" }, { ...
[ 1, 1, 1, 1, 0, 1, 0, 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 count_sequences(Q, cases):\n MOD = 1_000_000_007\n\n def factorial(n):\n if n == 0:\n return 1\n result = 1\n for i in ran...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00007681", "row_id": 7681, "seed_ids": "[1387]" }
0.810243
Apps_7681
I
[ "factorial", "count_sequences", "solve", "read_input" ]
4
[ [ "count_sequences", "factorial" ], [ "solve", "count_sequences" ] ]
2
[ "read_input" ]
false
[]
false
pytest
true
[]
true
eec12118d9d4956b711ec34d511cb507714cf96a
c30b1384cc3f03fdacbdef3a144522a51dc546e9
v1.0
instruct
Apps
Apps_7689_I
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. A number is considered prime if it has no positive divisors other than 1 and itself. For the sake of this problem, the number 1 is not co...
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": "", "prompt_id": "00007689", "row_id": 7689, "seed_ids": "[1438]" }
0.716483
Apps_7689
I
[ "is_prime", "sort_prime_and_nonprime" ]
2
[ [ "sort_prime_and_nonprime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8dceb8ef215fce46fc4e3466f420fb20fb715e39
949f22ad3781a4b1acb526cb0a7446e03c1a7236
v1.0
instruct
Apps
Apps_7737_I
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. ### Steps: * Create a helper function `is_prime` that determines if a number is prime. * Iterate through each integer in the input list. * Use the hel...
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": "", "prompt_id": "00007737", "row_id": 7737, "seed_ids": "[4168]" }
0.676741
Apps_7737
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dd2ef78ec22b49423a031717190246ba664a6765
37e0adeff4b5af28d4134214f9db3f263fd7e1e2
v1.0
instruct
Apps
Apps_7742_I
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. A palindrome is a word that reads the same backward as forward (e.g., "level", "racecar"). If the word is not a palindrome, the program should retu...
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": "", "prompt_id": "00007742", "row_id": 7742, "seed_ids": "[4711]" }
0.785158
Apps_7742
I
[ "is_palindrome", "min_removals_to_non_palindrome" ]
2
[ [ "min_removals_to_non_palindrome", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
57c27916d12999748cb21efc9881943cfa288e0a
20619f34deb7aa88b3faf2c545385d42844ed602
v1.0
instruct
Apps
Apps_7770_I
Given an array of integers, determine if each integer in the array is composed of only prime digits (2, 3, 5, 7). Return "YES" if all digits are prime, otherwise return "NO". -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Ea...
def is_prime_digit(char): """ Returns True if the provided character represents a prime digit (2, 3, 5, 7), otherwise False. """ return char in {'2', '3', '5', '7'} def all_prime_digits(num_str): """ Determines if all digits in the given string represent prime digits. """ for char in nu...
from solution import check_prime_digits def test_check_prime_digits_all_prime(): test_cases = ["235", "357", "222"] expected = ["YES", "YES", "YES"] assert check_prime_digits(test_cases) == expected def test_check_prime_digits_with_non_prime(): test_cases = ["124", "678", "123456789"] expected = [...
[ { "docstring": "Returns True if the provided character represents a prime digit (2, 3, 5, 7), otherwise False.", "function_declaration": "def is_prime_digit(char):", "function_name": "is_prime_digit", "parameter_list": "(char)" }, { "docstring": "Determines if all digits in the given string ...
[ 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_digit(digit):\n \"\"\"\n Checks if a digit is a prime digit (2, 3, 5, 7).\n \"\"\"\n prime_digits = {'2', '3', '5', '7'}\n return digit ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00007770", "row_id": 7770, "seed_ids": "[529]" }
0.663799
Apps_7770
I
[ "is_prime_digit", "all_prime_digits", "check_prime_digits" ]
3
[ [ "all_prime_digits", "is_prime_digit" ], [ "check_prime_digits", "all_prime_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f34025427bd4fc66460dcb1ef590a13729a5143a
2763a5d8a3cac6945f8e68dbf078573ee337bb3c
v1.0
instruct
Apps
Apps_7862_I
Given an input string that contains lowercase alphabetic characters and one or more special placeholders denoted by `?`, generate all possible strings by replacing each placeholder with a lowercase alphabetic character such that the resulting strings represent valid English words. You are provided with a helper funct...
from typing import List import string def isValidWord(word: str) -> bool: """ Placeholder for the actual implementation of the validation function. """ # The actual implementation will check if the word is a valid English word. # This mock implementation always returns True for simplicity. # In...
from solution import possibleValidWords, isValidWord def test_isValidWord(): assert isValidWord("apple") assert isValidWord("bag") assert isValidWord("bog") assert isValidWord("bug") assert not isValidWord("abcd") def test_possibleValidWords_with_single_placeholder(): assert possibleValidWords...
[ { "docstring": "Placeholder for the actual implementation of the validation function.", "function_declaration": "def isValidWord(word):", "function_name": "isValidWord", "parameter_list": "(word)" }, { "docstring": null, "function_declaration": "def generate_possible_words(input_string, ...
[ 0, 0, 0, 1, 1, 1, 1, 0, 0, 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\n# Assuming we have helper function `isValidWord` implemented.\ndef isValidWord(word: str) -> bool:\n \"\"\"\n Placeholder function....
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00007862", "row_id": 7862, "seed_ids": "[3904]" }
0.670442
Apps_7862
I
[ "isValidWord", "generate_possible_words", "possibleValidWords" ]
3
[ [ "generate_possible_words", "isValidWord" ], [ "possibleValidWords", "generate_possible_words" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5b5aab3e5b7e02f73d6564564ec1925fb7e9c137
a033201de964c1f8a04a3025c35930a930d498b1
v1.0
instruct
Apps
Apps_7941_I
You are given an array of integers and a target sum. Your task is to determine the number of unique pairs of elements in the array whose sum equals the target sum. Two pairs are considered unique if they consist of different numbers, even if they sum to the same value. Each element in the array can only be used once in...
def count_unique_pairs(arr, target_sum): """ Returns the number of unique pairs whose sum equals the target sum, modulo 10^9 + 7. """ MOD = 10**9 + 7 seen = set() pairs = set() for num in arr: complement = target_sum - num if complement in seen: # Add the sorted ...
from solution import count_unique_pairs def test_example_case(): assert count_unique_pairs([1, 5, 3, 3, 2], 6) == 2 def test_no_pairs(): assert count_unique_pairs([1, 2, 3], 10) == 0 def test_all_elements_same(): assert count_unique_pairs([2, 2, 2, 2], 4) == 1 def test_multiple_same_pairs(): assert ...
[ { "docstring": "Returns the number of unique pairs whose sum equals the target sum, modulo 10^9 + 7.", "function_declaration": "def count_unique_pairs(arr, target_sum):", "function_name": "count_unique_pairs", "parameter_list": "(arr, target_sum)" }, { "docstring": null, "function_declar...
[ 0, 0, 0, 0, 0, 1, 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 count_unique_pairs_with_target_sum(arr, target):\n MOD = 10**9 + 7\n arr.sort()\n n = len(arr)\n count = 0\n left, right = 0, n - 1\n\n while ...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00007941", "row_id": 7941, "seed_ids": "[627]" }
0.698358
Apps_7941
I
[ "count_unique_pairs", "number_of_unique_pairs" ]
2
[ [ "number_of_unique_pairs", "count_unique_pairs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7974796cf495158620a02e23a7d4ccb6a684daaa
3b08c5b92e36b5b08eabeb7573b031b6164bfcdb
v1.0
instruct
Apps
Apps_8001_I
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 being at the center of the t...
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": "", "prompt_id": "00008001", "row_id": 8001, "seed_ids": "[1451]" }
0.640735
Apps_8001
I
[ "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
9f6124e5560157761779a19ffa88709314d2e6e6
80afcc072b5fb5004ac98f7caff80fdb865ed2d2
v1.0
instruct
Apps
Apps_8066_I
You are given an array of integers. Your task is to sort the array such that the even numbers appear before the odd numbers and both are sorted in ascending order within their respective segments. You must accomplish this without using any built-in sort functions. ___ ## Examples: ``` input: [9, 4, 2, 7, 3, 10, 1...
def custom_sort_array(arr): """ Returns the array sorted such that even numbers appear before odd numbers, and both segments are individually sorted in ascending order. """ evens = [x for x in arr if x % 2 == 0] odds = [x for x in arr if x % 2 != 0] evens = custom_sort(evens) odds = cus...
from solution import custom_sort_array def test_custom_sort_array_even_odd(): assert custom_sort_array([9, 4, 2, 7, 3, 10, 1, 6]) == [2, 4, 6, 10, 1, 3, 7, 9] def test_custom_sort_array_mixed(): assert custom_sort_array([5, 3, 2, 8, 1, 12]) == [2, 8, 12, 1, 3, 5] def test_custom_sort_array_all_even(): as...
[ { "docstring": "Returns the array sorted such that even numbers appear before odd numbers,\nand both segments are individually sorted in ascending order.", "function_declaration": "def custom_sort_array(arr):", "function_name": "custom_sort_array", "parameter_list": "(arr)" }, { "docstring":...
[ 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_sorted_array(arr):\n \"\"\"\n Sorts the array such that even numbers appear before the odd numbers,\n and both are sorted in ascending order wit...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008066", "row_id": 8066, "seed_ids": "[2953]" }
0.69739
Apps_8066
I
[ "custom_sort_array", "custom_sort" ]
2
[ [ "custom_sort_array", "custom_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
67c6829c10a4929f795524da07f0a3bac4aab062
48be24d5cdb7fdb212f8f814f05580551d980cc1
v1.0
instruct
Apps
Apps_8121_I
Yoda, the Jedi Master, is training a group of young Padawans to enhance their skills in using the Force. One of the crucial exercises is to understand and work with patterns and sequences in the Force. Yoda presents a challenge to his Padawans: given a sequence of integers, determine the length of the longest subsequen...
def longest_palindromic_subsequence(seq): N = len(seq) dp = [[0] * N for _ in range(N)] for i in range(N): dp[i][i] = 1 for cl in range(2, N + 1): for i in range(N - cl + 1): j = i + cl - 1 if seq[i] == seq[j] and cl == 2: dp[i][j] = 2 ...
import pytest from solution import solve_palindromic_subsequence, parse_input def test_example(): input_str = "2\n7\n1 2 3 4 3 2 1\n5\n5 3 4 3 5\n" test_cases = parse_input(input_str) results = solve_palindromic_subsequence(test_cases) assert results == [7, 5] def test_single_element(): input_str ...
[ { "docstring": null, "function_declaration": "def longest_palindromic_subsequence(seq):", "function_name": "longest_palindromic_subsequence", "parameter_list": "(seq)" }, { "docstring": null, "function_declaration": "def solve_palindromic_subsequence(test_cases):", "function_name": "...
[ 0, 0, 0, 0, 0, 1, 1, 0 ]
2
hard
0.25
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "def longest_palindromic_subsequence_length(sequence):\n \"\"\"\n Returns the length of the longest palindromic subsequence in the given sequence.\n \"\"\"\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008121", "row_id": 8121, "seed_ids": "[1591]" }
0.648182
Apps_8121
I
[ "longest_palindromic_subsequence", "solve_palindromic_subsequence", "parse_input" ]
3
[ [ "solve_palindromic_subsequence", "longest_palindromic_subsequence" ] ]
1
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
cd1c00773c4d2e90e0fba5827efdddd3dd5c3bf6
088bb74a2eea59000dc355169d0f581750c2a9c6
v1.0
instruct
Apps
Apps_8126_I
A major technology company has a network of data centers. The data centers are represented by nodes in a graph, and there are directed links connecting some pairs of data centers, represented by edges in the graph. The company wants to optimize the data routing within the network during specific time frames. Given a d...
from collections import defaultdict, deque def find_all_paths(N, graph, start, end): visited = set() queue = deque([(start, [])]) paths_count = 0 while queue: node, path = queue.popleft() if node in visited: continue visited.add(node) path = path + [node...
def test_example_case(): input_data = """2 4 5 1 2 1 3 3 2 2 4 3 4 2 1 4 3 4 3 3 1 2 2 3 3 1 1 1 3""" expected_output = [3, 2, 1] results = process_input(input_data) assert results == expected_output, f"Expected {expected_output}, but got {results}" def test_single_path(): input_data = """1 3 2 1 2...
[ { "docstring": null, "function_declaration": "def find_all_paths(N, graph, start, end):", "function_name": "find_all_paths", "parameter_list": "(N, graph, start, end)" }, { "docstring": null, "function_declaration": "def count_paths(T, test_cases):", "function_name": "count_paths", ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict, deque\n\ndef find_all_paths(graph, start, end):\n \"\"\"\n Uses DFS to find all distinct paths without revisiting nodes.\...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00008126", "row_id": 8126, "seed_ids": "[669]" }
0.728682
Apps_8126
I
[ "find_all_paths", "count_paths", "process_input" ]
3
[ [ "count_paths", "find_all_paths" ], [ "process_input", "count_paths" ] ]
2
[ "process_input" ]
false
[]
false
pytest
false
[]
true
45d25387f6851b6ccf2f7312f50fd954d533a773
3e314d48a86b2f7696f451648f1e8f9306efcdd5
v1.0
instruct
Apps
Apps_8309_I
You are given an integer array `nums` and an integer `k`. You need to perform a series of operations on `nums` to satisfy the following conditions: 1. Sum the digits of each number in `nums`. 2. Append the resulting sums to a new array. 3. Perform step 1 for `k` iterations. Your task is to return the array resulting ...
def sum_of_digits(num): """ Returns the sum of the digits of the given number. """ s = 0 while num > 0: s += num % 10 num //= 10 return s def transform(nums): """ Transforms the given list of integers by summing the digits of each integer. """ return [sum_of_digi...
from solution import sum_of_digits, transform, k_iterations def test_sum_of_digits(): assert sum_of_digits(13) == 4 assert sum_of_digits(25) == 7 assert sum_of_digits(83) == 11 assert sum_of_digits(111) == 3 assert sum_of_digits(222) == 6 def test_transform(): assert transform([13, 25, 83]) ==...
[ { "docstring": "Returns the sum of the digits of the given number.", "function_declaration": "def sum_of_digits(num):", "function_name": "sum_of_digits", "parameter_list": "(num)" }, { "docstring": "Transforms the given list of integers by summing the digits of each integer.", "function_...
[ 0, 0, 1, 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 sum_of_digits(num):\n \"\"\"\n Helper function to sum the digits of a number until a single digit is achieved.\n \"\"\"\n while num > 9:\n nu...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00008309", "row_id": 8309, "seed_ids": "[1960]" }
0.756875
Apps_8309
I
[ "sum_of_digits", "transform", "k_iterations" ]
3
[ [ "k_iterations", "transform" ], [ "transform", "sum_of_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d032140af9d3d1328858d3490588e924d2d56a5c
21c5e03469b212ac38f55d94501a103c413b5af9
v1.0
instruct
Apps
Apps_8342_I
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. ## Examples ```python # List 1: 1 -> 2 -> 4 # List 2: 1 -> 3 -> 4 # Merged List: 1 -> 1 -> 2 -> 3 -> 4 -> 4 merge_two_lists([1, 2, 4], [1, 3, 4]) == [...
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": "", "prompt_id": "00008342", "row_id": 8342, "seed_ids": "[2752]" }
0.482256
Apps_8342
I
[ "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
d138995f606fd68263d9599559b18010356047e2
05bc579109d0419a6e39af17161fc1f896337520
v1.0
instruct
Apps
Apps_8408_I
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 end days, determine the maximum...
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": "", "prompt_id": "00008408", "row_id": 8408, "seed_ids": "[1490]" }
0.710131
Apps_8408
I
[ "max_non_overlapping_sessions", "parse_input", "solution" ]
3
[ [ "solution", "max_non_overlapping_sessions" ], [ "solution", "parse_input" ] ]
2
[ "parse_input" ]
false
[]
false
pytest
true
[]
true
105906d0a2bd65f442dd35ca0ac45468e598f157
f4b17ddf0ad86a8901e2a62ceb35c481401df729
v1.0
instruct
Apps
Apps_8417_I
You are designing an ecosystem for a new simulation game where players need to create the most balanced environment to maximize the growth of plants and the well-being of animals. The ecosystem is represented by a series of nodes and edges in a graph, where nodes represent different areas (each area can be a plant or a...
def max_benefit(T, test_cases): def find_max_non_interacting_nodes_benefit(n, m, benefits, edges): from itertools import combinations max_benefit_sum = 0 # Convert edge list to adjacency list adj = {i: set() for i in range(1, n+1)} for u, v in edges: ...
def test_max_benefit(): input_data = '''2 5 4 1 2 3 4 5 1 2 2 3 4 5 3 4 3 2 10 20 30 1 2 2 3 ''' expected_output = '''9 40 ''' assert solve(input_data) == expected_output.strip() def test_max_benefit_single_node(): input_data = '''1 1 0 10 ''' expected_output = '''10 ''' assert solve(input_...
[ { "docstring": null, "function_declaration": "def max_benefit(T, test_cases):", "function_name": "max_benefit", "parameter_list": "(T, test_cases)" }, { "docstring": null, "function_declaration": "def process_input(input_data):", "function_name": "process_input", "parameter_list"...
[ 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": "from itertools import combinations\n\ndef max_benefit_value(n, m, benefits, edges):\n adjacency_list = {i: set() for i in range(1, n+1)}\n for u, v in edges:\...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00008417", "row_id": 8417, "seed_ids": "[521]" }
0.608641
Apps_8417
I
[ "max_benefit", "process_input", "generate_output", "solve" ]
4
[ [ "solve", "generate_output" ], [ "solve", "max_benefit" ], [ "solve", "process_input" ] ]
3
[ "process_input", "generate_output" ]
false
[]
false
pytest
false
[]
true
0ced1d7e8d1f906e61b5147604cfba64e96d27cb
3d8a237d21dd04943461f3314682757c7d4d6ad5
v1.0
instruct
Apps
Apps_8466_I
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. A subtree of a binary tree is a tree consisting of a node in the tree and all of its descendants in the tree. -----Input----- Th...
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": "", "prompt_id": "00008466", "row_id": 8466, "seed_ids": "[917]" }
0.708044
Apps_8466
I
[ "max_subtree_sum", "build_tree", "solve", "main" ]
4
[ [ "solve", "build_tree" ], [ "solve", "max_subtree_sum" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
c50c861218393c1b7acfdcadcee09e34f2730659
8d8bd95e8acca5f4b30aadfd0a27fc4ed58cd83c
v1.0
instruct
Apps
Apps_8507_I
**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. For example, `is_anagram("listen...
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": "", "prompt_id": "00008507", "row_id": 8507, "seed_ids": "[2716]" }
0.585807
Apps_8507
I
[ "is_anagram", "find_anagrams" ]
2
[ [ "find_anagrams", "is_anagram" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bdf494625e266ea526c52d00651be4dc67d0a7d8
d5bf2ac29f2c91c4f539aa0ea0b1985230b19b5b
v1.0
instruct
Apps
Apps_8512_I
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. She needs your help to find out if the number x is a part of any twin prime pair with...
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": "", "prompt_id": "00008512", "row_id": 8512, "seed_ids": "[757]" }
0.643378
Apps_8512
I
[ "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
a3f6de3634481fe1b2a1476556abc7e3d1fe1f94
788433541c2bbad567fee0781f63b3a57890e0c2
v1.0
instruct
Apps
Apps_8607_I
Your task is to develop a function to perform k-means clustering on a dataset. You will receive a dataset and the number of clusters, k. Your function should return the cluster centroids and the cluster labels for each data point. You should implement the k-means algorithm from scratch, ensuring that the chosen init...
import random def euclidean_distance(point1, point2): return sum((x - y) ** 2 for x, y in zip(point1, point2)) ** 0.5 def get_initial_centroids(data, k): random_indices = random.sample(range(len(data)), k) return [data[idx] for idx in random_indices] def assign_clusters(data, centroids): clusters = [...
from solution import k_means_clustering def test_k_means_clustering_2_clusters(): data = [(1, 2), (1, 4), (1, 0), (4, 2), (4, 4), (4, 0)] k = 2 centroids, labels = k_means_clustering(data, k) assert len(centroids) == k assert len(labels) == len(data) assert all(label in range(k) for label ...
[ { "docstring": null, "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": null, "function_declaration": "def get_initial_centroids(data, k):", "function_name": "get_initial_cen...
[ 1, 0, 0, 0, 0, 0, 1, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport math\n\ndef euclidean_distance(point1, point2):\n return math.sqrt(sum((x - y) ** 2 for x, y in zip(point1, point2)))\n\ndef find_closest_c...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008607", "row_id": 8607, "seed_ids": "[4891]" }
0.801867
Apps_8607
I
[ "euclidean_distance", "get_initial_centroids", "assign_clusters", "update_centroids", "k_means_clustering" ]
5
[ [ "assign_clusters", "euclidean_distance" ], [ "k_means_clustering", "assign_clusters" ], [ "k_means_clustering", "get_initial_centroids" ], [ "k_means_clustering", "update_centroids" ] ]
4
[]
false
[]
false
pytest
true
[]
true
7dc3b184e1f34651b7aec169c0201ad5578827dd
d842cb63be2f4dcfd6eb49f54c710b849dcd7275
v1.0
instruct
Apps
Apps_8645_I
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 numbers in ascending order. H...
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": "", "prompt_id": "00008645", "row_id": 8645, "seed_ids": "[1400]" }
0.706273
Apps_8645
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1d2a0b52a20d619b1ae435bb0a7b86d996554f22
6a4a23ed300af3993c28f44618d66128b6857b3b
v1.0
instruct
Apps
Apps_8716_I
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. **Function Signature:** `def sum_of_primes(n: int) -> int:` **Example:** ```python sum_of_primes(5) -> 2...
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": "", "prompt_id": "00008716", "row_id": 8716, "seed_ids": "[2873]" }
0.717216
Apps_8716
I
[ "is_prime", "sum_of_primes" ]
2
[ [ "sum_of_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ab1eca74e67057276d5de442d70fe71696aa8b01
ec312cb59557377271053e522ba33faaef282d64
v1.0
instruct
Apps
Apps_8723_I
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. Ensure to handle edge cases where the array m...
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": "", "prompt_id": "00008723", "row_id": 8723, "seed_ids": "[4829]" }
0.634828
Apps_8723
I
[ "lcm", "smallest_common_multiple" ]
2
[ [ "smallest_common_multiple", "lcm" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2d3884c4459ddbf69a16b4120cf3b5f8dc93e166
b148ff78275e547d4568a06984703511aff95255
v1.0
instruct
Apps
Apps_8740_I
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 whether it's possible to reorder ...
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": "", "prompt_id": "00008740", "row_id": 8740, "seed_ids": "[2310]" }
0.820541
Apps_8740
I
[ "can_form_palindrome", "analyze_strings" ]
2
[ [ "analyze_strings", "can_form_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
389c85aaa69c7ac5465b14686e4c9c633a58d41d
09000edb5728add2e3606f8e4e58a16d006021ed
v1.0
instruct
Apps
Apps_8746_I
## Description Write a function that accepts a list of integers and returns a new list containing only the integers that are prime numbers. A 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 divisible by 1 and itself. ## Exam...
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": "", "prompt_id": "00008746", "row_id": 8746, "seed_ids": "[4670]" }
0.708355
Apps_8746
I
[ "is_prime", "filterPrimes" ]
2
[ [ "filterPrimes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2b0a622fac45005741c0ecf8812d15a6d645b99b
62507e74da64afc22e1d80a0984be60444f55a28
v1.0
instruct
Apps
Apps_8889_I
A company has designed a new system where each employee can send a packet to any other employee via direct channels. However, these channels are not always the most efficient routes as they can be unreliable. For better communication, they have built a network of indirect intermediary nodes, each of which acts as a rel...
import heapq def dijkstra(graph, start, end, N): """ Applies Dijkstra's algorithm to find the shortest path from start to end in a graph. """ min_heap = [(0, start)] distances = {node: float('infinity') for node in range(1, N+1)} distances[start] = 0 while min_heap: current_distanc...
def test_dijkstra(): graph = { 1: [(2, 1)], 2: [(3, 2)], 3: [(4, 3)], 4: [] } assert dijkstra(graph, 1, 4, 4) == 6 assert dijkstra(graph, 2, 4, 4) == 5 assert dijkstra(graph, 3, 1, 4) == "NOT POSSIBLE" def test_solve(): test_cases = [ {'N': 4, 'M': 4, 'ed...
[ { "docstring": "Applies Dijkstra's algorithm to find the shortest path from start to end in a graph.", "function_declaration": "def dijkstra(graph, start, end, N):", "function_name": "dijkstra", "parameter_list": "(graph, start, end, N)" }, { "docstring": null, "function_declaration": "d...
[ 0, 0, 1, 0, 0, 0, 0, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_apps-i2i_20000_1739004406_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef shortest_path_times(T, test_cases):\n def dijkstra(graph, N, start, end):\n distances = {node: float('infinity') for node in range(1, ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008889", "row_id": 8889, "seed_ids": "[1123]" }
0.69136
Apps_8889
I
[ "dijkstra", "solve", "read_input", "main" ]
4
[ [ "solve", "dijkstra" ] ]
1
[ "read_input" ]
false
[]
false
pytest
false
[]
true
230ecc79ad5adba142770e0e908d9c933b464a89
362e3142a70325fecad048aedfcffcb58eef1a2f
v1.0
instruct
Apps
Apps_8949_I
Design a function that takes a list of integers and returns a list of those integers which are perfect squares. A perfect square is a number that can be expressed as the product of an integer with itself. For example, `1, 4, 9, 16, 25` are perfect squares `(1*1, 2*2, 3*3, 4*4, 5*5)`. Your function should iterate thr...
import math def is_perfect_square(n): """ Helper function to check if a number is a perfect square. """ if n < 0: return False root = int(math.sqrt(n)) return n == root * root def get_perfect_squares(lst): """ Returns a list of perfect squares from the given list of integers. ...
from solution import get_perfect_squares def test_no_perfect_squares(): assert get_perfect_squares([2, 3, 5, 6, 7]) == [] def test_mixed_numbers(): assert get_perfect_squares([1, 2, 3, 4, 5]) == [1, 4] def test_all_perfect_squares(): assert get_perfect_squares([1, 4, 9, 16, 25]) == [1, 4, 9, 16, 25] def...
[ { "docstring": "Helper function to check if a number is a perfect square.", "function_declaration": "def is_perfect_square(n):", "function_name": "is_perfect_square", "parameter_list": "(n)" }, { "docstring": "Returns a list of perfect squares from the given list of integers.", "function...
[ 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": "import math\n\ndef find_perfect_squares(nums):\n \"\"\"\n Returns a list of perfect squares from the given list of integers.\n \"\"\"\n perfect_squares ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008949", "row_id": 8949, "seed_ids": "[4053]" }
0.654212
Apps_8949
I
[ "is_perfect_square", "get_perfect_squares" ]
2
[ [ "get_perfect_squares", "is_perfect_square" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4319e11a56845a04a92d2f2fff2589d79c97dd5e
0ada2d4fcb0015db9480ef9cc7888447bb93222b
v1.0
instruct
Apps
Apps_8958_I
**Problem:** Permutation Index Calculation You are given an array of length N which contains a permutation of the numbers from 1 to N. Your task is to determine the rank (1-based index) of this permutation when all permutations of the array are arranged in lexicographical order. A permutation is a way of arranging a...
def factorial(n): """ Returns the factorial of n. """ if n == 0 or n == 1: return 1 result = 1 for i in range(2, n + 1): result *= i return result def permutation_index(perm): """ Returns the rank of the permutation 'perm' when all permutations of the array are a...
from solution import process_input def test_permutation_index_single_case(): T = 1 test_cases = [[4, 3, 1, 2, 4]] assert process_input(T, test_cases) == [13] def test_permutation_index_multiple_cases(): T = 3 test_cases = [ [4, 3, 1, 2, 4], [3, 1, 2, 3], [5, 5, 4, 3, 2, 1] ...
[ { "docstring": "Returns the factorial of n.", "function_declaration": "def factorial(n):", "function_name": "factorial", "parameter_list": "(n)" }, { "docstring": "Returns the rank of the permutation 'perm' when all permutations\nof the array are arranged in lexicographical order.\nThe resul...
[ 0, 0, 0, 0, 1, 0, 0, 1, 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 permutation_index(N, permutation):\n \"\"\"\n Calculates the rank of the permutation in lexicographical order.\n \"\"\"\n MOD = 10**9 + 7\n facto...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00008958", "row_id": 8958, "seed_ids": "[897]" }
0.721493
Apps_8958
I
[ "factorial", "permutation_index", "process_input" ]
3
[ [ "permutation_index", "factorial" ], [ "process_input", "permutation_index" ] ]
2
[ "process_input" ]
false
[]
false
pytest
true
[]
true
7e7235cca87b722c210554f9c6537b4e27921a22
3dfcd8d8a20f08029c29a56b8257648c374cc86d
v1.0
instruct
Apps
Apps_8976_I
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. Example 1: Input: [ [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0] ] Output: 6 Explanation: The largest rectangle containing only 1's has an area of 6. Example 2:...
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": "", "prompt_id": "00008976", "row_id": 8976, "seed_ids": "[1896]" }
0.767239
Apps_8976
I
[ "maximalRectangle", "largestRectangleArea" ]
2
[ [ "maximalRectangle", "largestRectangleArea" ] ]
1
[]
false
[]
false
pytest
true
[]
true
50a81e7a150b60652c9f26b1cc5cb1a6ee8f4970
a783aa21cb0c439b8d257277d101bb03185ec140