diff --git "a/datasets/code/code.jsonl" "b/datasets/code/code.jsonl" new file mode 100644--- /dev/null +++ "b/datasets/code/code.jsonl" @@ -0,0 +1,164 @@ +{"prompt": "from typing import List\n\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n \"\"\" Check if in given list of numbers, are any two numbers closer to each other than\n given threshold.\n \"\"\"\n", "entry_point": "has_close_elements", "label": true, "response": "def has_close_elements(numbers: List[float], threshold: float) -> bool:\n for i in range(len(numbers)):\n for j in range(i+1, len(numbers)):\n if abs(numbers[i] - numbers[j]) < threshold:\n return True\n return False", "claims": []} +{"prompt": "from typing import List\n\n\ndef separate_paren_groups(paren_string: str) -> List[str]:\n \"\"\" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to\n separate those group into separate strings and return the list of those.\n Separate groups are balanced (each open brace is properly closed) and not nested within each other\n Ignore any spaces in the input string.\n \"\"\"\n", "entry_point": "separate_paren_groups", "label": false, "response": "def separate_paren_groups(paren_string: str) -> List[str]:\n stack = []\n result = []\n for i in range(len(paren_string)):\n if paren_string[i] == '(': # push index of opening parenthesis onto stack\n stack.append(i)\n elif paren_string[i] == ')': # pop last index from stack and slice string\n start = stack.pop()\n result.append(paren_string[start:i+1])\n return result", "claims": []} +{"prompt": "\n\ndef truncate_number(number: float) -> float:\n \"\"\" Given a positive floating point number, it can be decomposed into\n and integer part (largest integer smaller than given number) and decimals\n (leftover part always smaller than 1).\n\n Return the decimal part of the number.\n \"\"\"\n", "entry_point": "truncate_number", "label": true, "response": "def truncate_number(number: float) -> float:\n integer_part = number // 1\n decimal_part = number - integer_part\n return decimal_part", "claims": []} +{"prompt": "from typing import List\n\n\ndef below_zero(operations: List[int]) -> bool:\n \"\"\" You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n \"\"\"\n", "entry_point": "below_zero", "label": true, "response": "def below_zero(operations: List[int]) -> bool:\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False", "claims": []} +{"prompt": "from typing import List\n\n\ndef mean_absolute_deviation(numbers: List[float]) -> float:\n \"\"\" For a given list of input numbers, calculate Mean Absolute Deviation\n around the mean of this dataset.\n Mean Absolute Deviation is the average absolute difference between each\n element and a centerpoint (mean in this case):\n MAD = average | x - x_mean |\n \"\"\"\n", "entry_point": "mean_absolute_deviation", "label": true, "response": "def mean_absolute_deviation(numbers: List[float]) -> float:\n mean = sum(numbers) / len(numbers)\n absolute_differences = [abs(num - mean) for num in numbers]\n return sum(absolute_differences) / len(absolute_differences)", "claims": []} +{"prompt": "from typing import List\n\n\ndef intersperse(numbers: List[int], delimeter: int) -> List[int]:\n \"\"\" Insert a number 'delimeter' between every two consecutive elements of input list `numbers'\n \"\"\"\n", "entry_point": "intersperse", "label": false, "response": "def intersperse(numbers: List[int], delimeter: int) -> List[int]:\n new_list = []\n for i in range(len(numbers)):\n new_list.append(numbers[i])\n if i != len(numbers) - 1:\n new_list.append(delimeter)\n new_list.pop()\n return new_list", "claims": []} +{"prompt": "from typing import List\n\n\ndef parse_nested_parens(paren_string: str) -> List[int]:\n \"\"\" Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n \"\"\"\n", "entry_point": "parse_nested_parens", "label": true, "response": "def parse_nested_parens(paren_string: str) -> List[int]:\n max_nesting = 0\n nesting = 0\n stack = []\n result = []\n for char in paren_string:\n if char == '(': # opening parenthesis\n stack.append(char)\n nesting += 1\n max_nesting = max(max_nesting, nesting)\n elif char == ')': # closing parenthesis\n stack.pop()\n nesting -= 1\n elif char == ' ': # end of group\n result.append(max_nesting)\n max_nesting = 0\n nesting = 0\n stack = []\n result.append(max_nesting) # last group\n return result", "claims": []} +{"prompt": "from typing import List\n\n\ndef filter_by_substring(strings: List[str], substring: str) -> List[str]:\n \"\"\" Filter an input list of strings only for ones that contain given substring\n \"\"\"\n", "entry_point": "filter_by_substring", "label": true, "response": "def filter_by_substring(strings: List[str], substring: str) -> List[str]:\n return [s for s in strings if substring in s]", "claims": []} +{"prompt": "from typing import List, Tuple\n\n\ndef sum_product(numbers: List[int]) -> Tuple[int, int]:\n \"\"\" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n \"\"\"\n", "entry_point": "sum_product", "label": true, "response": "def sum_product(numbers: List[int]) -> Tuple[int, int]:\n sum = 0\n product = 1\n for num in numbers:\n sum += num\n product *= num\n return (sum, product)", "claims": []} +{"prompt": "from typing import List, Tuple\n\n\ndef rolling_max(numbers: List[int]) -> List[int]:\n \"\"\" From a given list of integers, generate a list of rolling maximum element found until given moment\n in the sequence.\n \"\"\"\n", "entry_point": "rolling_max", "label": true, "response": "def rolling_max(numbers: List[int]) -> List[int]:\n max_so_far = float('-inf')\n result = []\n for num in numbers:\n max_so_far = max(max_so_far, num)\n result.append(max_so_far)\n return result", "claims": []} +{"prompt": "\n\ndef is_palindrome(string: str) -> bool:\n \"\"\" Test if given string is a palindrome \"\"\"\n return string == string[::-1]\n\n\ndef make_palindrome(string: str) -> str:\n \"\"\" Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n \"\"\"\n", "entry_point": "make_palindrome", "label": false, "response": "def make_palindrome(string: str) -> str:\n for i in range(len(string), -1, -1):\n if is_palindrome(string[:i]):\n return string + string[:i][::-1]\n", "claims": []} +{"prompt": "from typing import List\n\n\ndef string_xor(a: str, b: str) -> str:\n \"\"\" Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n \"\"\"\n", "entry_point": "string_xor", "label": true, "response": "def string_xor(a: str, b: str) -> str:\n result = ''\n for i in range(len(a)):\n if a[i] == b[i]:\n result += '0'\n else:\n result += '1'\n return result", "claims": []} +{"prompt": "from typing import List, Optional\n\n\ndef longest(strings: List[str]) -> Optional[str]:\n \"\"\" Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return None in case the input list is empty.\n \"\"\"\n", "entry_point": "longest", "label": true, "response": "def longest(strings: List[str]) -> Optional[str]:\n if not strings:\n return None\n longest_str = strings[0]\n for string in strings:\n if len(string) > len(longest_str):\n longest_str = string\n return longest_str", "claims": []} +{"prompt": "\n\ndef greatest_common_divisor(a: int, b: int) -> int:\n \"\"\" Return a greatest common divisor of two integers a and b\n \"\"\"\n", "entry_point": "greatest_common_divisor", "label": true, "response": "def greatest_common_divisor(a: int, b: int) -> int:\n if b == 0:\n return a\n else:\n return greatest_common_divisor(b, a % b)\n", "claims": []} +{"prompt": "from typing import List\n\n\ndef all_prefixes(string: str) -> List[str]:\n \"\"\" Return list of all prefixes from shortest to longest of the input string\n \"\"\"\n", "entry_point": "all_prefixes", "label": true, "response": "def all_prefixes(string: str) -> List[str]:\n result = []\n for i in range(len(string)):\n result.append(string[:i+1])\n return result", "claims": []} +{"prompt": "\n\ndef string_sequence(n: int) -> str:\n \"\"\" Return a string containing space-delimited numbers starting from 0 upto n inclusive.\n \"\"\"\n", "entry_point": "string_sequence", "label": false, "response": "def string_sequence(n: int) -> str:\n result = ''\n for i in range(n+1):\n result += str(i) + ' '\n return result\n", "claims": []} +{"prompt": "\n\ndef count_distinct_characters(string: str) -> int:\n \"\"\" Given a string, find out how many distinct characters (regardless of case) does it consist of\n \"\"\"\n", "entry_point": "count_distinct_characters", "label": true, "response": "def count_distinct_characters(string: str) -> int:\n string = string.lower()\n distinct_chars = set(string)\n return len(distinct_chars)", "claims": []} +{"prompt": "from typing import List\n\n\ndef parse_music(music_string: str) -> List[int]:\n \"\"\" Input to this function is a string representing musical notes in a special ASCII format.\n Your task is to parse this string and return list of integers corresponding to how many beats does each\n not last.\n\n Here is a legend:\n 'o' - whole note, lasts four beats\n 'o|' - half note, lasts two beats\n '.|' - quater note, lasts one beat\n \"\"\"\n", "entry_point": "parse_music", "label": false, "response": "def parse_music(music_string: str) -> List[int]:\n result = []\n for note in music_string:\n if note == 'o':\n result.append(4)\n elif note == 'o|':\n result.append(2)\n elif note == '.|':\n result.append(1)\n return result", "claims": []} +{"prompt": "\n\ndef how_many_times(string: str, substring: str) -> int:\n \"\"\" Find how many times a given substring can be found in the original string. Count overlaping cases.\n \"\"\"\n", "entry_point": "how_many_times", "label": true, "response": "def how_many_times(string: str, substring: str) -> int:\n count = 0\n for i in range(len(string) - len(substring) + 1):\n if string[i:i+len(substring)] == substring:\n count += 1\n return count", "claims": []} +{"prompt": "from typing import List\n\n\ndef sort_numbers(numbers: str) -> str:\n \"\"\" Input is a space-delimited string of numberals from 'zero' to 'nine'.\n Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.\n Return the string with numbers sorted from smallest to largest\n \"\"\"\n", "entry_point": "sort_numbers", "label": true, "response": "def sort_numbers(numbers: str) -> str:\n num_dict = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}\n num_list = numbers.split()\n num_list = [num_dict[num] for num in num_list]\n num_list.sort()\n num_list = [list(num_dict.keys())[list(num_dict.values()).index(num)] for num in num_list]\n return ' '.join(num_list)", "claims": []} +{"prompt": "from typing import List, Tuple\n\n\ndef find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n \"\"\" From a supplied list of numbers (of length at least two) select and return two that are the closest to each\n other and return them in order (smaller number, larger number).\n \"\"\"\n", "entry_point": "find_closest_elements", "label": true, "response": "def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:\n numbers.sort()\n min_diff = float('inf')\n result = ()\n for i in range(len(numbers) - 1):\n diff = numbers[i+1] - numbers[i]\n if diff < min_diff:\n min_diff = diff\n result = (numbers[i], numbers[i+1])\n return result", "claims": []} +{"prompt": "from typing import List\n\n\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n \"\"\" Given list of numbers (of at least two elements), apply a linear transform to that list,\n such that the smallest number will become 0 and the largest will become 1\n \"\"\"\n", "entry_point": "rescale_to_unit", "label": true, "response": "def rescale_to_unit(numbers: List[float]) -> List[float]:\n min_num = min(numbers)\n max_num = max(numbers)\n range_num = max_num - min_num\n rescaled_numbers = [(num - min_num) / range_num for num in numbers]\n return rescaled_numbers", "claims": []} +{"prompt": "from typing import List, Any\n\n\ndef filter_integers(values: List[Any]) -> List[int]:\n \"\"\" Filter given list of any python values only for integers\n \"\"\"\n", "entry_point": "filter_integers", "label": true, "response": "def filter_integers(values: List[Any]) -> List[int]:\n return [x for x in values if isinstance(x, int)]", "claims": []} +{"prompt": "\n\ndef strlen(string: str) -> int:\n \"\"\" Return length of given string\n \"\"\"\n", "entry_point": "strlen", "label": true, "response": "def strlen(string: str) -> int:\n return len(string)", "claims": []} +{"prompt": "\n\ndef largest_divisor(n: int) -> int:\n \"\"\" For a given number n, find the largest number that divides n evenly, smaller than n\n \"\"\"\n", "entry_point": "largest_divisor", "label": true, "response": "def largest_divisor(n: int) -> int:\n for i in range(n-1, 0, -1):\n if n % i == 0:\n return i\n return 1", "claims": []} +{"prompt": "from typing import List\n\n\ndef factorize(n: int) -> List[int]:\n \"\"\" Return list of prime factors of given integer in the order from smallest to largest.\n Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.\n Input number should be equal to the product of all factors\n \"\"\"\n", "entry_point": "factorize", "label": true, "response": "def factorize(n: int) -> List[int]:\n factors = {}\n i = 2\n while n > 1:\n if n % i == 0:\n n //= i\n if i in factors:\n factors[i] += 1\n else:\n factors[i] = 1\n else:\n i += 1\n return [k for k, v in factors.items() for _ in range(v)]", "claims": []} +{"prompt": "from typing import List\n\n\ndef remove_duplicates(numbers: List[int]) -> List[int]:\n \"\"\" From a list of integers, remove all elements that occur more than once.\n Keep order of elements left the same as in the input.\n \"\"\"\n", "entry_point": "remove_duplicates", "label": true, "response": "def remove_duplicates(numbers):\n frequency = {}\n for num in numbers:\n if num in frequency:\n frequency[num] += 1\n else:\n frequency[num] = 1\n result = []\n for num in numbers:\n if frequency[num] == 1:\n result.append(num)\n return result", "claims": []} +{"prompt": "\n\ndef flip_case(string: str) -> str:\n \"\"\" For a given string, flip lowercase characters to uppercase and uppercase to lowercase.\n \"\"\"\n", "entry_point": "flip_case", "label": true, "response": "def flip_case(string: str) -> str:\n result = ''\n for char in string:\n if char.isupper():\n result += char.lower()\n elif char.islower():\n result += char.upper()\n else:\n result += char\n return result", "claims": []} +{"prompt": "from typing import List\n\n\ndef concatenate(strings: List[str]) -> str:\n \"\"\" Concatenate list of strings into a single string\n \"\"\"\n", "entry_point": "concatenate", "label": true, "response": "def concatenate(strings: List[str]) -> str:\n return ''.join(strings)", "claims": []} +{"prompt": "from typing import List\n\n\ndef filter_by_prefix(strings: List[str], prefix: str) -> List[str]:\n \"\"\" Filter an input list of strings only for ones that start with a given prefix.\n \"\"\"\n", "entry_point": "filter_by_prefix", "label": true, "response": "def filter_by_prefix(strings: List[str], prefix: str) -> List[str]:\n filtered_strings = [s for s in strings if s.startswith(prefix)]\n return filtered_strings", "claims": []} +{"prompt": "\n\ndef get_positive(l: list):\n \"\"\"Return only positive numbers in the list.\n \"\"\"\n", "entry_point": "get_positive", "label": true, "response": "def get_positive(l: list):\n return [num for num in l if num > 0]", "claims": []} +{"prompt": "\n\ndef is_prime(n):\n \"\"\"Return true if a given number is prime, and false otherwise.\n \"\"\"\n", "entry_point": "is_prime", "label": true, "response": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5)+1):\n if n % i == 0:\n return False\n return True", "claims": []} +{"prompt": "import math\n\n\ndef poly(xs: list, x: float):\n \"\"\"\n Evaluates polynomial with coefficients xs at point x.\n return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n\n \"\"\"\n return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])\n\n\ndef find_zero(xs: list):\n \"\"\" xs are coefficients of a polynomial.\n find_zero find x such that poly(x) = 0.\n find_zero returns only only zero point, even if there are many.\n Moreover, find_zero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n \"\"\"\n", "entry_point": "find_zero", "label": false, "response": "def find_zero(xs: list):\n x = 1.0\n while True:\n f = poly(xs, x)\n df = sum([i * xs[i] * math.pow(x, i-1) for i in range(1, len(xs))])\n x1 = x - f/df\n if abs(x1 - x) < 0.0001:\n return x1\n x = x1", "claims": []} +{"prompt": "\n\ndef sort_third(l: list):\n \"\"\"This function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n \"\"\"\n", "entry_point": "sort_third", "label": true, "response": "def sort_third(l: list):\n third_indices = [i for i in range(len(l)) if i % 3 == 0]\n third_values = [l[i] for i in third_indices]\n sorted_third_values = sorted(third_values)\n for i in third_indices:\n l[i] = sorted_third_values[i // 3]\n return l", "claims": []} +{"prompt": "\n\ndef unique(l: list):\n \"\"\"Return sorted unique elements in a list\n \"\"\"\n", "entry_point": "unique", "label": true, "response": "def unique(l: list):\n unique_set = set(l)\n unique_list = list(unique_set)\n unique_list.sort()\n return unique_list", "claims": []} +{"prompt": "\n\ndef max_element(l: list):\n \"\"\"Return maximum element in the list.\n \"\"\"\n", "entry_point": "max_element", "label": true, "response": "def max_element(l: list):\n return max(l)", "claims": []} +{"prompt": "\n\ndef fizz_buzz(n: int):\n \"\"\"Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.\n \"\"\"\n", "entry_point": "fizz_buzz", "label": false, "response": "def fizz_buzz(n: int):\n count = 0\n for i in range(n):\n if i % 11 == 0 or i % 13 == 0:\n if str(i).count('7') > 0:\n count += 1\n return count", "claims": []} +{"prompt": "\n\ndef sort_even(l: list):\n \"\"\"This function takes a list l and returns a list l' such that\n l' is identical to l in the odd indicies, while its values at the even indicies are equal\n to the values of the even indicies of l, but sorted.\n \"\"\"\n", "entry_point": "sort_even", "label": false, "response": "def sort_even(l: list):\n even_list = []\n odd_list = []\n for i in range(len(l)):\n if i % 2 == 0:\n even_list.append(l[i])\n else:\n odd_list.append(l[i])\n even_list.sort()\n sorted_list = []\n for i in range(len(odd_list)):\n sorted_list.append(odd_list[i])\n sorted_list.append(even_list[i])\n if len(even_list) > len(odd_list):\n sorted_list.append(even_list[-1])\n return sorted_list", "claims": []} +{"prompt": "\n\ndef encode_cyclic(s: str):\n \"\"\"\n returns encoded string by cycling groups of three characters.\n \"\"\"\n # split string to groups. Each of length 3.\n groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]\n # cycle elements in each group. Unless group has fewer elements than 3.\n groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups]\n return \"\".join(groups)\n\n\ndef decode_cyclic(s: str):\n \"\"\"\n takes as input string encoded with encode_cyclic function. Returns decoded string.\n \"\"\"\n", "entry_point": "decode_cyclic", "label": true, "response": "def decode_cyclic(s: str):\n groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]\n groups = [(group[-1] + group[:2]) if len(group) == 3 else group for group in groups]\n return ''.join(groups)", "claims": []} +{"prompt": "\n\ndef prime_fib(n: int):\n \"\"\"\n prime_fib returns n-th number that is a Fibonacci number and it's also prime.\n \"\"\"\n", "entry_point": "prime_fib", "label": true, "response": "def prime_fib(n: int):\n def is_prime(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5)+1):\n if num % i == 0:\n return False\n return True\n a, b = 0, 1\n count = 0\n while count < n:\n a, b = b, a+b\n if is_prime(a):\n count += 1\n return a", "claims": []} +{"prompt": "\n\ndef triples_sum_to_zero(l: list):\n \"\"\"\n triples_sum_to_zero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n \"\"\"\n", "entry_point": "triples_sum_to_zero", "label": true, "response": "def triples_sum_to_zero(l):\n for i in range(len(l)):\n for j in range(i+1, len(l)):\n for k in range(j+1, len(l)):\n if l[i] + l[j] + l[k] == 0:\n return True\n return False", "claims": []} +{"prompt": "\n\ndef car_race_collision(n: int):\n \"\"\"\n Imagine a road that's a perfectly straight infinitely long line.\n n cars are driving left to right; simultaneously, a different set of n cars\n are driving right to left. The two sets of cars start out being very far from\n each other. All cars move in the same speed. Two cars are said to collide\n when a car that's moving left to right hits a car that's moving right to left.\n However, the cars are infinitely sturdy and strong; as a result, they continue moving\n in their trajectory as if they did not collide.\n\n This function outputs the number of such collisions.\n \"\"\"\n", "entry_point": "car_race_collision", "label": false, "response": "def car_race_collision(n: int):\n return sum(n-i for i in range(n))", "claims": []} +{"prompt": "\n\ndef incr_list(l: list):\n \"\"\"Return list with elements incremented by 1.\n \"\"\"\n", "entry_point": "incr_list", "label": true, "response": "def incr_list(l: list):\n return [x+1 for x in l]", "claims": []} +{"prompt": "\n\ndef pairs_sum_to_zero(l):\n \"\"\"\n pairs_sum_to_zero takes a list of integers as an input.\n it returns True if there are two distinct elements in the list that\n sum to zero, and False otherwise.\n \"\"\"\n", "entry_point": "pairs_sum_to_zero", "label": true, "response": "def pairs_sum_to_zero(l):\n seen = set()\n for num in l:\n if -num in seen:\n return True\n seen.add(num)\n return False", "claims": []} +{"prompt": "\n\ndef change_base(x: int, base: int):\n \"\"\"Change numerical base of input number x to base.\n return string representation after the conversion.\n base numbers are less than 10.\n \"\"\"\n", "entry_point": "change_base", "label": true, "response": "def change_base(x: int, base: int):\n result = ''\n while x > 0:\n remainder = x % base\n result = str(remainder) + result\n x = x // base\n return result", "claims": []} +{"prompt": "\n\ndef triangle_area(a, h):\n \"\"\"Given length of a side and high return area for a triangle.\n \"\"\"\n", "entry_point": "triangle_area", "label": true, "response": "def triangle_area(a, h):\n area = 0.5 * a * h\n return area", "claims": []} +{"prompt": "\n\ndef fib4(n: int):\n \"\"\"The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fib4(0) -> 0\n fib4(1) -> 0\n fib4(2) -> 2\n fib4(3) -> 0\n fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).\n Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.\n \"\"\"\n", "entry_point": "fib4", "label": true, "response": "def fib4(n: int):\n if n < 4:\n return [0, 0, 2, 0][n]\n prev = [0, 0, 2, 0]\n for i in range(4, n+1):\n curr = prev[0] + prev[1] + prev[2] + prev[3]\n prev = prev[1:] + [curr]\n return prev[-1]", "claims": []} +{"prompt": "\n\ndef median(l: list):\n \"\"\"Return median of elements in the list l.\n \"\"\"\n", "entry_point": "median", "label": true, "response": "def median(l: list):\n l.sort()\n n = len(l)\n if n % 2 == 0:\n return (l[n//2-1] + l[n//2])/2\n else:\n return l[n//2]", "claims": []} +{"prompt": "\n\ndef is_palindrome(text: str):\n \"\"\"\n Checks if given string is a palindrome\n \"\"\"\n", "entry_point": "is_palindrome", "label": true, "response": "def is_palindrome(text: str):\n start = 0\n end = len(text) - 1\n while start < end:\n if text[start] != text[end]:\n return False\n start += 1\n end -= 1\n return True", "claims": []} +{"prompt": "\n\ndef modp(n: int, p: int):\n \"\"\"Return 2^n modulo p (be aware of numerics).\n \"\"\"\n", "entry_point": "modp", "label": true, "response": "def modp(n: int, p: int):\n return pow(2, n, p)", "claims": []} +{"prompt": "\n\ndef encode_shift(s: str):\n \"\"\"\n returns encoded string by shifting every character by 5 in the alphabet.\n \"\"\"\n return \"\".join([chr(((ord(ch) + 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])\n\n\ndef decode_shift(s: str):\n \"\"\"\n takes as input string encoded with encode_shift function. Returns decoded string.\n \"\"\"\n", "entry_point": "decode_shift", "label": true, "response": "def decode_shift(s: str):\n return ''.join([chr(((ord(ch) - 5 - ord('a')) % 26) + ord('a')) for ch in s])", "claims": []} +{"prompt": "\n\ndef remove_vowels(text):\n \"\"\"\n remove_vowels is a function that takes string and returns string without vowels.\n \"\"\"\n", "entry_point": "remove_vowels", "label": true, "response": "def remove_vowels(text):\n vowels = 'aeiouAEIOU'\n new_text = ''\n for char in text:\n if char not in vowels:\n new_text += char\n return new_text", "claims": []} +{"prompt": "\n\ndef below_threshold(l: list, t: int):\n \"\"\"Return True if all numbers in the list l are below threshold t.\n \"\"\"\n", "entry_point": "below_threshold", "label": true, "response": "def below_threshold(l: list, t: int):\n for num in l:\n if num >= t:\n return False\n return True", "claims": []} +{"prompt": "\n\ndef add(x: int, y: int):\n \"\"\"Add two numbers x and y\n \"\"\"\n", "entry_point": "add", "label": true, "response": "def add(x: int, y: int):\n return x + y", "claims": []} +{"prompt": "\n\ndef same_chars(s0: str, s1: str):\n \"\"\"\n Check if two words have the same characters.\n \"\"\"\n", "entry_point": "same_chars", "label": true, "response": "def same_chars(s0: str, s1: str):\n return set(s0) == set(s1)", "claims": []} +{"prompt": "\n\ndef fib(n: int):\n \"\"\"Return n-th Fibonacci number.\n \"\"\"\n", "entry_point": "fib", "label": true, "response": "def fib(n):\n if n == 0:\n return 0\n elif n == 1:\n return 1\n else:\n return fib(n-1) + fib(n-2)", "claims": []} +{"prompt": "\n\ndef correct_bracketing(brackets: str):\n \"\"\" brackets is a string of \"<\" and \">\".\n return True if every opening bracket has a corresponding closing bracket.\n \"\"\"\n", "entry_point": "correct_bracketing", "label": true, "response": "def correct_bracketing(brackets: str):\n stack = []\n for bracket in brackets:\n if bracket == '<':\n stack.append(bracket)\n elif bracket == '>':\n if not stack or stack.pop() != '<':\n return False\n return not stack", "claims": []} +{"prompt": "\n\ndef monotonic(l: list):\n \"\"\"Return True is list elements are monotonically increasing or decreasing.\n \"\"\"\n", "entry_point": "monotonic", "label": true, "response": "def monotonic(l: list):\n if len(l) <= 1:\n return True\n increasing = all(l[i] <= l[i+1] for i in range(len(l)-1))\n decreasing = all(l[i] >= l[i+1] for i in range(len(l)-1))\n return increasing or decreasing", "claims": []} +{"prompt": "\n\ndef common(l1: list, l2: list):\n \"\"\"Return sorted unique common elements for two lists.\n \"\"\"\n", "entry_point": "common", "label": true, "response": "def common(l1: list, l2: list):\n common_set = set(l1).intersection(set(l2))\n return sorted(list(common_set))", "claims": []} +{"prompt": "\n\ndef largest_prime_factor(n: int):\n \"\"\"Return the largest prime factor of n. Assume n > 1 and is not a prime.\n \"\"\"\n", "entry_point": "largest_prime_factor", "label": true, "response": "def largest_prime_factor(n: int):\n factor = 2\n while factor <= n:\n if n % factor == 0:\n n //= factor\n else:\n factor += 1\n return factor", "claims": []} +{"prompt": "\n\ndef sum_to_n(n: int):\n \"\"\"sum_to_n is a function that sums numbers from 1 to n.\n \"\"\"\n", "entry_point": "sum_to_n", "label": true, "response": "def sum_to_n(n: int):\n total = 0\n for i in range(1, n+1):\n total += i\n return total", "claims": []} +{"prompt": "\n\ndef correct_bracketing(brackets: str):\n \"\"\" brackets is a string of \"(\" and \")\".\n return True if every opening bracket has a corresponding closing bracket.\n \"\"\"\n", "entry_point": "correct_bracketing", "label": true, "response": "def correct_bracketing(brackets: str):\n stack = []\n for bracket in brackets:\n if bracket == '(': # opening bracket\n stack.append(bracket)\n else: # closing bracket\n if not stack or stack.pop() != '(': # stack is empty or top element does not match\n return False\n return not stack # return True if stack is empty, False otherwise", "claims": []} +{"prompt": "\n\ndef derivative(xs: list):\n \"\"\" xs represent coefficients of a polynomial.\n xs[0] + xs[1] * x + xs[2] * x^2 + ....\n Return derivative of this polynomial in the same form.\n \"\"\"\n", "entry_point": "derivative", "label": true, "response": "def derivative(xs: list):\n derivative = []\n for i in range(1, len(xs)):\n derivative.append(xs[i] * i)\n return derivative\n", "claims": []} +{"prompt": "\n\ndef fibfib(n: int):\n \"\"\"The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:\n fibfib(0) == 0\n fibfib(1) == 0\n fibfib(2) == 1\n fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).\n Please write a function to efficiently compute the n-th element of the fibfib number sequence.\n \"\"\"\n", "entry_point": "fibfib", "label": true, "response": "def fibfib(n):\n if n == 0:\n return 0\n elif n == 1:\n return 0\n elif n == 2:\n return 1\n else:\n fibfib_list = [0, 0, 1]\n for i in range(3, n+1):\n fibfib_list.append(fibfib_list[i-1] + fibfib_list[i-2] + fibfib_list[i-3])\n return fibfib_list[n]", "claims": []} +{"prompt": "\nFIX = \"\"\"\nAdd more test cases.\n\"\"\"\n\ndef vowels_count(s):\n \"\"\"Write a function vowels_count which takes a string representing\n a word as input and returns the number of vowels in the string.\n Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a\n vowel, but only when it is at the end of the given word.\n \"\"\"\n", "entry_point": "vowels_count", "label": false, "response": "def vowels_count(s):\n vowels = ['a', 'e', 'i', 'o', 'u']\n count = 0\n for i in range(len(s)):\n if s[i] in vowels:\n count += 1\n if i == len(s) - 1 and s[i] == 'y':\n count += 1\n return count", "claims": []} +{"prompt": "\ndef circular_shift(x, shift):\n \"\"\"Circular shift the digits of the integer x, shift the digits right by shift\n and return the result as a string.\n If shift > number of digits, return digits reversed.\n \"\"\"\n", "entry_point": "circular_shift", "label": true, "response": "def circular_shift(x, shift):\n x_str = str(x)\n n = len(x_str)\n if shift > n:\n return x_str[::-1][(shift-n)%n:] + x_str[::-1][:(shift-n)%n]\n else:\n return x_str[-shift:] + x_str[:-shift]", "claims": []} +{"prompt": "\ndef digitSum(s):\n \"\"\"Task\n Write a function that takes a string as input and returns the sum of the upper characters only'\n ASCII codes.\n \"\"\"\n", "entry_point": "digitSum", "label": true, "response": "def digitSum(s):\n sum = 0\n for char in s:\n if char.isupper():\n sum += ord(char)\n return sum", "claims": []} +{"prompt": "\ndef fruit_distribution(s,n):\n \"\"\"\n In this task, you will be given a string that represents a number of apples and oranges \n that are distributed in a basket of fruit this basket contains \n apples, oranges, and mango fruits. Given the string that represents the total number of \n the oranges and apples and an integer that represent the total number of the fruits \n in the basket return the number of the mango fruits in the basket.\n \"\"\"\n", "entry_point": "fruit_distribution", "label": false, "response": "def fruit_distribution(s,n):\n total_apples_oranges = 0\n for char in s:\n if char == 'a' or char == 'o':\n total_apples_oranges += 1\n mangoes = n - total_apples_oranges\n return mangoes", "claims": []} +{"prompt": "\ndef pluck(arr):\n \"\"\"\n \"Given an array representing a branch of a tree that has non-negative integer nodes\n your task is to pluck one of the nodes and return it.\n The plucked node should be the node with the smallest even value.\n If multiple nodes with the same smallest even value are found return the node that has smallest index.\n\n The plucked node should be returned in a list, [ smalest_value, its index ],\n If there are no even values or the given array is empty, return [].\n\n Constraints:\n * 1 <= nodes.length <= 10000\n * 0 <= node.value\n \"\"\"\n", "entry_point": "pluck", "label": true, "response": "def pluck(arr):\n smallest_even = float('inf')\n smallest_even_index = float('inf')\n for i in range(len(arr)):\n if arr[i] % 2 == 0 and arr[i] < smallest_even:\n smallest_even = arr[i]\n smallest_even_index = i\n if smallest_even_index == float('inf'):\n return []\n else:\n return [smallest_even, smallest_even_index]", "claims": []} +{"prompt": "\ndef search(lst):\n '''\n You are given a non-empty list of positive integers. Return the greatest integer that is greater than \n zero, and has a frequency greater than or equal to the value of the integer itself. \n The frequency of an integer is the number of times it appears in the list.\n If no such a value exist, return -1.\n '''\n", "entry_point": "search", "label": true, "response": "def search(lst):\n freq = {}\n for num in lst:\n if num in freq:\n freq[num] += 1\n else:\n freq[num] = 1\n max_num = -1\n for num in freq:\n if freq[num] >= num and num > max_num:\n max_num = num\n return max_num", "claims": []} +{"prompt": "\ndef strange_sort_list(lst):\n '''\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n '''\n", "entry_point": "strange_sort_list", "label": true, "response": "def strange_sort_list(lst):\n lst.sort()\n result = []\n i = 0\n j = len(lst) - 1\n while i <= j:\n if i == j:\n result.append(lst[i])\n else:\n result.append(lst[i])\n result.append(lst[j])\n i += 1\n j -= 1\n return result", "claims": []} +{"prompt": "\ndef triangle_area(a, b, c):\n '''\n Given the lengths of the three sides of a triangle. Return the area of\n the triangle rounded to 2 decimal points if the three sides form a valid triangle. \n Otherwise return -1\n Three sides make a valid triangle when the sum of any two sides is greater \n than the third side.\n '''\n", "entry_point": "triangle_area", "label": true, "response": "def triangle_area(a, b, c):\n if a + b > c and b + c > a and a + c > b:\n s = (a + b + c) / 2\n area = (s * (s - a) * (s - b) * (s - c)) ** 0.5\n return round(area, 2)\n else:\n return -1", "claims": []} +{"prompt": "\ndef will_it_fly(q,w):\n '''\n Write a function that returns True if the object q will fly, and False otherwise.\n The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.\n '''\n", "entry_point": "will_it_fly", "label": true, "response": "def will_it_fly(q, w):\n if q == q[::-1] and sum(q) <= w:\n return True\n else:\n return False", "claims": []} +{"prompt": "\ndef smallest_change(arr):\n \"\"\"\n Given an array arr of integers, find the minimum number of elements that\n need to be changed to make the array palindromic. A palindromic array is an array that\n is read the same backwards and forwards. In one change, you can change one element to any other element.\n \"\"\"\n", "entry_point": "smallest_change", "label": true, "response": "def smallest_change(arr):\n count = 0\n for i in range(len(arr)//2):\n if arr[i] != arr[-i-1]:\n count += 1\n return count", "claims": []} +{"prompt": "\ndef total_match(lst1, lst2):\n '''\n Write a function that accepts two lists of strings and returns the list that has \n total number of chars in the all strings of the list less than the other list.\n\n if the two lists have the same number of chars, return the first list.\n '''\n", "entry_point": "total_match", "label": true, "response": "def total_match(lst1, lst2):\n total1 = sum(len(s) for s in lst1)\n total2 = sum(len(s) for s in lst2)\n if total1 < total2:\n return lst1\n else:\n return lst2 if total2 < total1 else lst1", "claims": []} +{"prompt": "\ndef is_multiply_prime(a):\n \"\"\"Write a function that returns true if the given number is the multiplication of 3 prime numbers\n and false otherwise.\n Knowing that (a) is less then 100.\n \"\"\"\n", "entry_point": "is_multiply_prime", "label": true, "response": "def is_multiply_prime(a):\n # Generate all prime numbers less than 100 using Sieve of Eratosthenes algorithm\n primes = [True] * 100\n primes[0] = primes[1] = False\n for i in range(2, int(100 ** 0.5) + 1):\n if primes[i]:\n for j in range(i ** 2, 100, i):\n primes[j] = False\n \n # Check all possible combinations of 3 prime numbers\n for i in range(2, 100):\n if primes[i]:\n for j in range(i, 100):\n if primes[j]:\n for k in range(j, 100):\n if primes[k] and i * j * k == a:\n return True\n return False", "claims": []} +{"prompt": "\ndef is_simple_power(x, n):\n \"\"\"Your task is to write a function that returns true if a number x is a simple\n power of n and false in other cases.\n x is a simple power of n if n**int=x\n \"\"\"\n", "entry_point": "is_simple_power", "label": false, "response": "def is_simple_power(x, n):\n log_x = math.log(x, n)\n return log_x.is_integer()", "claims": []} +{"prompt": "\ndef iscube(a):\n '''\n Write a function that takes an integer a and returns True \n if this ingeger is a cube of some integer number.\n Note: you may assume the input is always valid.\n '''\n", "entry_point": "iscube", "label": false, "response": "def iscube(a):\n cube_root = a**(1/3)\n return cube_root == int(cube_root)", "claims": []} +{"prompt": "\ndef hex_key(num):\n \"\"\"You have been tasked to write a function that receives \n a hexadecimal number as a string and counts the number of hexadecimal \n digits that are primes (prime number, or a prime, is a natural number \n greater than 1 that is not a product of two smaller natural numbers).\n Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.\n Prime numbers are 2, 3, 5, 7, 11, 13, 17,...\n So you have to determine a number of the following digits: 2, 3, 5, 7, \n B (=decimal 11), D (=decimal 13).\n Note: you may assume the input is always correct or empty string, \n and symbols A,B,C,D,E,F are always uppercase.\n \"\"\"\n", "entry_point": "hex_key", "label": true, "response": "def hex_key(num):\n prime_hex_digits = ['2', '3', '5', '7', 'B', 'D']\n count = 0\n for digit in num:\n if digit in prime_hex_digits:\n count += 1\n return count", "claims": []} +{"prompt": "\ndef decimal_to_binary(decimal):\n \"\"\"You will be given a number in decimal form and your task is to convert it to\n binary format. The function should return a string, with each character representing a binary\n number. Each character in the string will be '0' or '1'.\n\n There will be an extra couple of characters 'db' at the beginning and at the end of the string.\n The extra characters are there to help with the format.\n \"\"\"\n", "entry_point": "decimal_to_binary", "label": false, "response": "def decimal_to_binary(decimal):\n binary_list = []\n while decimal > 0:\n remainder = decimal % 2\n binary_list.append(str(remainder))\n decimal = decimal // 2\n binary_list.reverse()\n binary_string = ''.join(binary_list)\n return 'db' + binary_string + 'db'", "claims": []} +{"prompt": "\ndef is_happy(s):\n \"\"\"You are given a string s.\n Your task is to check if the string is happy or not.\n A string is happy if its length is at least 3 and every 3 consecutive letters are distinct\n \"\"\"\n", "entry_point": "is_happy", "label": true, "response": "def is_happy(s):\n if len(s) < 3:\n return False\n for i in range(len(s) - 2):\n if s[i] == s[i+1] or s[i] == s[i+2] or s[i+1] == s[i+2]:\n return False\n return True", "claims": []} +{"prompt": "\ndef numerical_letter_grade(grades):\n \"\"\"It is the last week of the semester and the teacher has to give the grades\n to students. The teacher has been making her own algorithm for grading.\n The only problem is, she has lost the code she used for grading.\n She has given you a list of GPAs for some students and you have to write \n a function that can output a list of letter grades using the following table:\n GPA | Letter grade\n 4.0 A+\n > 3.7 A \n > 3.3 A- \n > 3.0 B+\n > 2.7 B \n > 2.3 B-\n > 2.0 C+\n > 1.7 C\n > 1.3 C-\n > 1.0 D+ \n > 0.7 D \n > 0.0 D-\n 0.0 E\n \"\"\"\n", "entry_point": "numerical_letter_grade", "label": true, "response": "def numerical_letter_grade(grades):\n letter_grades = []\n for gpa in grades:\n if gpa == 4.0:\n letter_grades.append('A+')\n elif gpa > 3.7:\n letter_grades.append('A')\n elif gpa > 3.3:\n letter_grades.append('A-')\n elif gpa > 3.0:\n letter_grades.append('B+')\n elif gpa > 2.7:\n letter_grades.append('B')\n elif gpa > 2.3:\n letter_grades.append('B-')\n elif gpa > 2.0:\n letter_grades.append('C+')\n elif gpa > 1.7:\n letter_grades.append('C')\n elif gpa > 1.3:\n letter_grades.append('C-')\n elif gpa > 1.0:\n letter_grades.append('D+')\n elif gpa > 0.7:\n letter_grades.append('D')\n elif gpa > 0.0:\n letter_grades.append('D-')\n else:\n letter_grades.append('E')\n return letter_grades", "claims": []} +{"prompt": "\ndef prime_length(string):\n \"\"\"Write a function that takes a string and returns True if the string\n length is a prime number or False otherwise\n \"\"\"\n", "entry_point": "prime_length", "label": true, "response": "def prime_length(string):\n if len(string) < 2:\n return False\n for i in range(2, int(len(string)**0.5)+1):\n if len(string) % i == 0:\n return False\n return True", "claims": []} +{"prompt": "\ndef starts_one_ends(n):\n \"\"\"\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n \"\"\"\n", "entry_point": "starts_one_ends", "label": false, "response": "def starts_one_ends(n):\n return 9 * 10**(n-1)", "claims": []} +{"prompt": "\ndef solve(N):\n \"\"\"Given a positive integer N, return the total sum of its digits in binary.\n \n Variables:\n @N integer\n Constraints: 0 \u2264 N \u2264 10000.\n Output:\n a string of binary number\n \"\"\"\n", "entry_point": "solve", "label": false, "response": "def solve(N):\n binary = bin(N)[2:]\n total_sum = 0\n for digit in binary:\n total_sum += int(digit)\n return bin(total_sum)[2:]", "claims": []} +{"prompt": "\ndef add(lst):\n \"\"\"Given a non-empty list of integers lst. add the even elements that are at odd indices..\n \"\"\"\n", "entry_point": "add", "label": true, "response": "def add(lst):\n total = 0\n for i in range(len(lst)):\n if i % 2 == 1 and lst[i] % 2 == 0:\n total += lst[i]\n return total", "claims": []} +{"prompt": "\ndef anti_shuffle(s):\n \"\"\"\n Write a function that takes a string and returns an ordered version of it.\n Ordered version of string, is a string where all words (separated by space)\n are replaced by a new word where all the characters arranged in\n ascending order based on ascii value.\n Note: You should keep the order of words and blank spaces in the sentence.\n \"\"\"\n", "entry_point": "anti_shuffle", "label": true, "response": "def anti_shuffle(s):\n words = s.split()\n ordered_words = []\n for word in words:\n ordered_word = ''.join(sorted(word))\n ordered_words.append(ordered_word)\n return ' '.join(ordered_words)", "claims": []} +{"prompt": "\ndef get_row(lst, x):\n \"\"\"\n You are given a 2 dimensional data, as a nested lists,\n which is similar to matrix, however, unlike matrices,\n each row may contain a different number of columns.\n Given lst, and integer x, find integers x in the list,\n and return list of tuples, [(x1, y1), (x2, y2) ...] such that\n each tuple is a coordinate - (row, columns), starting with 0.\n Sort coordinates initially by rows in ascending order.\n Also, sort coordinates of the row by columns in descending order.\n \"\"\"\n", "entry_point": "get_row", "label": true, "response": "def get_row(lst, x):\n result = []\n for i in range(len(lst)):\n if x in lst[i]:\n for j in range(len(lst[i])):\n if lst[i][j] == x:\n result.append((i, j))\n result.sort(key=lambda x: (x[0], -x[1]))\n return result", "claims": []} +{"prompt": "\ndef sort_array(array):\n \"\"\"\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n \"\"\"\n", "entry_point": "sort_array", "label": false, "response": "def sort_array(array):\n sum_first_last = array[0] + array[-1]\n if sum_first_last % 2 == 0:\n return sorted(array, reverse=True)\n else:\n return sorted(array)\n", "claims": []} +{"prompt": "\ndef encrypt(s):\n \"\"\"Create a function encrypt that takes a string as an argument and\n returns a string encrypted with the alphabet being rotated. \n The alphabet should be rotated in a manner such that the letters \n shift down by two multiplied to two places.\n \"\"\"\n", "entry_point": "encrypt", "label": true, "response": "def encrypt(s):\n shift = 2 * 2\n encrypted = ''\n for char in s:\n if char.isalpha():\n if char.islower():\n encrypted += chr((ord(char) - 97 + shift) % 26 + 97)\n else:\n encrypted += chr((ord(char) - 65 + shift) % 26 + 65)\n else:\n encrypted += char\n return encrypted", "claims": []} +{"prompt": "\ndef next_smallest(lst):\n \"\"\"\n You are given a list of integers.\n Write a function next_smallest() that returns the 2nd smallest element of the list.\n Return None if there is no such element.\n \"\"\"\n", "entry_point": "next_smallest", "label": false, "response": "def next_smallest(lst):\n if len(lst) < 2:\n return None\n sorted_lst = sorted(lst)\n return sorted_lst[1]", "claims": []} +{"prompt": "\ndef is_bored(S):\n \"\"\"\n You'll be given a string of words, and your task is to count the number\n of boredoms. A boredom is a sentence that starts with the word \"I\".\n Sentences are delimited by '.', '?' or '!'.\n \"\"\"\n", "entry_point": "is_bored", "label": false, "response": "def is_bored(S):\n boredom_count = 0\n sentences = re.split('[.?!]', S)\n for sentence in sentences:\n if sentence.strip().startswith('I'):\n boredom_count += 1\n return boredom_count", "claims": []} +{"prompt": "\ndef any_int(x, y, z):\n '''\n Create a function that takes 3 numbers.\n Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.\n Returns false in any other cases.\n '''\n", "entry_point": "any_int", "label": false, "response": "def any_int(x, y, z):\n for i in [x, y, z]:\n for j in [x, y, z]:\n for k in [x, y, z]:\n if i != j and i != k and j != k:\n if i == j + k or j == i + k or k == i + j:\n if isinstance(i, int) and isinstance(j, int) and isinstance(k, int):\n return True\n return False", "claims": []} +{"prompt": "\ndef encode(message):\n \"\"\"\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \"\"\"\n", "entry_point": "encode", "label": false, "response": "def encode(message):\n encoded_message = ''\n vowels = 'aeiouAEIOU'\n for char in message:\n if char in vowels:\n encoded_message += chr(ord(char)+2)\n else:\n if char.isupper():\n encoded_message += char.lower()\n else:\n encoded_message += char.upper()\n return encoded_message", "claims": []} +{"prompt": "\n\ndef skjkasdkd(lst):\n \"\"\"You are given a list of integers.\n You need to find the largest prime value and return the sum of its digits.\n \"\"\"\n", "entry_point": "skjkasdkd", "label": false, "response": "def skjkasdkd(lst):\n def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n**0.5)+1):\n if n % i == 0:\n return False\n return True\n largest_prime = 0\n for num in lst:\n if is_prime(num):\n digit_sum = sum(int(digit) for digit in str(num))\n if digit_sum > sum(int(digit) for digit in str(largest_prime)):\n largest_prime = num\n return sum(int(digit) for digit in str(largest_prime))", "claims": []} +{"prompt": "\ndef check_dict_case(dict):\n \"\"\"\n Given a dictionary, return True if all keys are strings in lower \n case or all keys are strings in upper case, else return False.\n The function should return False is the given dictionary is empty.\n \"\"\"\n", "entry_point": "check_dict_case", "label": false, "response": "def check_dict_case(dict):\n if len(dict) == 0:\n return False\n is_lower = all(key.islower() for key in dict.keys())\n is_upper = all(key.isupper() for key in dict.keys())\n return is_lower or is_upper", "claims": []} +{"prompt": "\ndef count_up_to(n):\n \"\"\"Implement a function that takes an non-negative integer and returns an array of the first n\n integers that are prime numbers and less than n.\n \"\"\"\n", "entry_point": "count_up_to", "label": true, "response": "def count_up_to(n):\n primes = []\n for num in range(2, n):\n is_prime = True\n for i in range(2, int(num ** 0.5) + 1):\n if num % i == 0:\n is_prime = False\n break\n if is_prime:\n primes.append(num)\n if len(primes) == n:\n break\n return primes", "claims": []} +{"prompt": "\ndef multiply(a, b):\n \"\"\"Complete the function that takes two integers and returns \n the product of their unit digits.\n Assume the input is always valid.\n \"\"\"\n", "entry_point": "multiply", "label": true, "response": "def multiply(a, b):\n return (a % 10) * (b % 10)", "claims": []} +{"prompt": "\ndef count_upper(s):\n \"\"\"\n Given a string s, count the number of uppercase vowels in even indices.\n \"\"\"\n", "entry_point": "count_upper", "label": true, "response": "def count_upper(s):\n vowels = set(['A', 'E', 'I', 'O', 'U'])\n count = 0\n for i in range(0, len(s), 2):\n if s[i] in vowels and s[i].isupper():\n count += 1\n return count", "claims": []} +{"prompt": "\ndef closest_integer(value):\n '''\n Create a function that takes a value (string) representing a number\n and returns the closest integer to it. If the number is equidistant\n from two integers, round it away from zero.\n\n Note:\n Rounding away from zero means that if the given number is equidistant\n from two integers, the one you should return is the one that is the\n farthest from zero. For example closest_integer(\"14.5\") should\n return 15 and closest_integer(\"-14.5\") should return -15.\n '''\n", "entry_point": "closest_integer", "label": false, "response": "def closest_integer(value):\n num = float(value)\n rounded_num = round(num)\n if num == rounded_num:\n return int(num)\n elif num > 0:\n return int(rounded_num + 1)\n else:\n return int(rounded_num - 1)", "claims": []} +{"prompt": "\ndef make_a_pile(n):\n \"\"\"\n Given a positive integer n, you have to make a pile of n levels of stones.\n The first level has n stones.\n The number of stones in the next level is:\n - the next odd number if n is odd.\n - the next even number if n is even.\n Return the number of stones in each level in a list, where element at index\n i represents the number of stones in the level (i+1).\n \"\"\"\n", "entry_point": "make_a_pile", "label": false, "response": "def make_a_pile(n):\n stones = n\n result = [stones]\n for i in range(2, n+1):\n if n % 2 == 0:\n stones += i if i % 2 == 0 else i+1\n else:\n stones += i if i % 2 != 0 else i+1\n result.append(stones)\n return result", "claims": []} +{"prompt": "\ndef words_string(s):\n \"\"\"\n You will be given a string of words separated by commas or spaces. Your task is\n to split the string into words and return an array of the words.\n \"\"\"\n", "entry_point": "words_string", "label": false, "response": "def words_string(s):\n words = s.split(', ')\n words = ' '.join(words).split()\n return words", "claims": []} +{"prompt": "\ndef choose_num(x, y):\n \"\"\"This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n \"\"\"\n", "entry_point": "choose_num", "label": true, "response": "def choose_num(x, y):\n for i in range(y, x-1, -1):\n if i % 2 == 0:\n return i\n return -1", "claims": []} +{"prompt": "\ndef rounded_avg(n, m):\n \"\"\"You are given two positive integers n and m, and your task is to compute the\n average of the integers from n through m (including n and m). \n Round the answer to the nearest integer and convert that to binary.\n If n is greater than m, return -1.\n \"\"\"\n", "entry_point": "rounded_avg", "label": false, "response": "def rounded_avg(n, m):\n if n > m:\n return -1\n else:\n sum_of_integers = (m*(m+1))/2 - (n-1)*n/2\n num_of_integers = m - n + 1\n avg = round(sum_of_integers/num_of_integers)\n return bin(avg)[2:]", "claims": []} +{"prompt": "\ndef unique_digits(x):\n \"\"\"Given a list of positive integers x. return a sorted list of all \n elements that hasn't any even digit.\n\n Note: Returned list should be sorted in increasing order.\n \"\"\"\n", "entry_point": "unique_digits", "label": false, "response": "def unique_digits(x):\n result = []\n for num in x:\n if all(int(digit) % 2 != 0 for digit in str(num)):\n result.append(num)\n return sorted(result)\n}", "claims": []} +{"prompt": "\ndef by_length(arr):\n \"\"\"\n Given an array of integers, sort the integers that are between 1 and 9 inclusive,\n reverse the resulting array, and then replace each digit by its corresponding name from\n \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\".\n \"\"\"\n", "entry_point": "by_length", "label": true, "response": "def by_length(arr):\n digits = [num for num in arr if 1 <= num <= 9]\n digits.sort()\n digits.reverse()\n names = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine']\n result = [names[digit-1] for digit in digits]\n return result", "claims": []} +{"prompt": "\ndef f(n):\n \"\"\" Implement the function f that takes n as a parameter,\n and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\n or the sum of numbers from 1 to i otherwise.\n i starts from 1.\n the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\n \"\"\"\n", "entry_point": "f", "label": true, "response": "def f(n):\n def factorial(num):\n if num == 0:\n return 1\n else:\n return num * factorial(num-1)\n result = []\n for i in range(1, n+1):\n if i % 2 == 0:\n result.append(factorial(i))\n else:\n sum = 0\n for j in range(1, i+1):\n sum += j\n result.append(sum)\n return result", "claims": []} +{"prompt": "\ndef even_odd_palindrome(n):\n \"\"\"\n Given a positive integer n, return a tuple that has the number of even and odd\n integer palindromes that fall within the range(1, n), inclusive.\n\n Note:\n 1. 1 <= n <= 10^3\n 2. returned tuple has the number of even and odd integer palindromes respectively.\n \"\"\"\n", "entry_point": "even_odd_palindrome", "label": true, "response": "def even_odd_palindrome(n):\n even_count = 0\n odd_count = 0\n for i in range(1, n+1):\n if str(i) == str(i)[::-1]:\n if i % 2 == 0:\n even_count += 1\n else:\n odd_count += 1\n return (even_count, odd_count)", "claims": []} +{"prompt": "\ndef count_nums(arr):\n \"\"\"\n Write a function count_nums which takes an array of integers and returns\n the number of elements which has a sum of digits > 0.\n If a number is negative, then its first signed digit will be negative:\n e.g. -123 has signed digits -1, 2, and 3.\n \"\"\"\n", "entry_point": "count_nums", "label": false, "response": "def count_nums(arr):\n def sum_of_digits(num):\n s = 0\n while num:\n s += num % 10\n num //= 10\n return s\n \n count = 0\n for num in arr:\n if num >= 0:\n if sum_of_digits(num) > 0:\n count += 1\n else:\n if sum_of_digits(-num) > 0:\n count += 1\n \n return count", "claims": []} +{"prompt": "\ndef move_one_ball(arr):\n \"\"\"We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\n numbers in the array will be randomly ordered. Your task is to determine if\n it is possible to get an array sorted in non-decreasing order by performing \n the following operation on the given array:\n You are allowed to perform right shift operation any number of times.\n \n One right shift operation means shifting all elements of the array by one\n position in the right direction. The last element of the array will be moved to\n the starting position in the array i.e. 0th index. \n\n If it is possible to obtain the sorted array by performing the above operation\n then return True else return False.\n If the given array is empty then return True.\n\n Note: The given list is guaranteed to have unique elements.\n \"\"\"\n", "entry_point": "move_one_ball", "label": false, "response": "def move_one_ball(arr):\n if not arr:\n return True\n max_index = arr.index(max(arr))\n return max_index == len(arr)-1\n}", "claims": []} +{"prompt": "\ndef exchange(lst1, lst2):\n \"\"\"In this problem, you will implement a function that takes two lists of numbers,\n and determines whether it is possible to perform an exchange of elements\n between them to make lst1 a list of only even numbers.\n There is no limit on the number of exchanged elements between lst1 and lst2.\n If it is possible to exchange elements between the lst1 and lst2 to make\n all the elements of lst1 to be even, return \"YES\".\n Otherwise, return \"NO\".\n\n It is assumed that the input lists will be non-empty.\n \"\"\"\n", "entry_point": "exchange", "label": true, "response": "def exchange(lst1, lst2):\n if all(num % 2 == 0 for num in lst1):\n return 'YES'\n while True:\n odd_index = next((i for i, num in enumerate(lst1) if num % 2 != 0), None)\n if odd_index is None:\n return 'YES'\n even_index = next((i for i, num in enumerate(lst2) if num % 2 == 0), None)\n if even_index is None:\n return 'NO'\n lst1[odd_index], lst2[even_index] = lst2[even_index], lst1[odd_index] ", "claims": []} +{"prompt": "\ndef histogram(test):\n \"\"\"Given a string representing a space separated lowercase letters, return a dictionary\n of the letter with the most repetition and containing the corresponding count.\n If several letters have the same occurrence, return all of them.\n \"\"\"\n", "entry_point": "histogram", "label": false, "response": "def histogram(test):\n count_dict = {}\n max_count = 0\n for letter in test:\n if letter in count_dict:\n count_dict[letter] += 1\n else:\n count_dict[letter] = 1\n if count_dict[letter] > max_count:\n max_count = count_dict[letter]\n result = {}\n for letter, count in count_dict.items():\n if count == max_count:\n result[letter] = count\n return result", "claims": []} +{"prompt": "\ndef reverse_delete(s,c):\n \"\"\"Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and True/False for the check.\n \"\"\"\n", "entry_point": "reverse_delete", "label": true, "response": "def reverse_delete(s, c):\n new_s = ''\n for char in s:\n if char not in c:\n new_s += char\n if new_s == new_s[::-1]:\n return (new_s, True)\n else:\n return (new_s, False)", "claims": []} +{"prompt": "\ndef odd_count(lst):\n \"\"\"Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n \"\"\"\n", "entry_point": "odd_count", "label": false, "response": "def odd_count(lst):\n result = []\n for string in lst:\n count = 0\n for digit in string:\n if int(digit) % 2 != 0:\n count += 1\n result.append(count)\n return result", "claims": []} +{"prompt": "\ndef minSubArraySum(nums):\n \"\"\"\n Given an array of integers nums, find the minimum sum of any non-empty sub-array\n of nums.\n \"\"\"\n", "entry_point": "minSubArraySum", "label": false, "response": "def minSubArraySum(nums):\n current_sum = min_sum = nums[0]\n for num in nums[1:]:\n current_sum += num\n if current_sum < 0:\n current_sum = 0\n min_sum = min(min_sum, current_sum)\n return min_sum", "claims": []} +{"prompt": "\ndef max_fill(grid, capacity):\n import math\n \"\"\"\n You are given a rectangular grid of wells. Each row represents a single well,\n and each 1 in a row represents a single unit of water.\n Each well has a corresponding bucket that can be used to extract water from it, \n and all buckets have the same capacity.\n Your task is to use the buckets to empty the wells.\n Output the number of times you need to lower the buckets.\n\n Constraints:\n * all wells have the same length\n * 1 <= grid.length <= 10^2\n * 1 <= grid[:,1].length <= 10^2\n * grid[i][j] -> 0 | 1\n * 1 <= capacity <= 10\n \"\"\"\n", "entry_point": "max_fill", "label": true, "response": "def max_fill(grid, capacity):\n num_lowering = 0\n remaining_capacity = capacity\n for row in grid:\n for well in row:\n if well == 1:\n if remaining_capacity == 0:\n num_lowering += 1\n remaining_capacity = capacity\n remaining_capacity -= 1\n if remaining_capacity < capacity:\n num_lowering += 1\n remaining_capacity = capacity\n return num_lowering", "claims": []} +{"prompt": "\ndef sort_array(arr):\n \"\"\"\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n \"\"\"\n", "entry_point": "sort_array", "label": false, "response": "def sort_array(arr):\n def count_ones(num):\n return bin(num).count('1'), num\n return sorted(arr, key=count_ones)\n}", "claims": []} +{"prompt": "\ndef select_words(s, n):\n \"\"\"Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n \"\"\"\n", "entry_point": "select_words", "label": true, "response": "def select_words(s, n):\n result = []\n if not s:\n return result\n words = s.split()\n for word in words:\n consonants = 0\n for letter in word:\n if letter.lower() not in ['a', 'e', 'i', 'o', 'u'] and letter.isalpha():\n consonants += 1\n if consonants == n:\n result.append(word)\n return result", "claims": []} +{"prompt": "\ndef get_closest_vowel(word):\n \"\"\"You are given a word. Your task is to find the closest vowel that stands between \n two consonants from the right side of the word (case sensitive).\n \n Vowels in the beginning and ending doesn't count. Return empty string if you didn't\n find any vowel met the above condition. \n\n You may assume that the given string contains English letter only.\n \"\"\"\n", "entry_point": "get_closest_vowel", "label": false, "response": "def get_closest_vowel(word):\n vowels = set(['a', 'e', 'i', 'o', 'u'])\n found_consonant = False\n for i in range(len(word)-2, 0, -1):\n if word[i] not in vowels:\n found_consonant = True\n elif found_consonant:\n return word[i]\n return ''", "claims": []} +{"prompt": "\ndef match_parens(lst):\n '''\n You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n '''\n", "entry_point": "match_parens", "label": false, "response": "def match_parens(lst):\n s1, s2 = lst\n total_open = s1.count('(') + s2.count('(')\n total_close = s1.count(')') + s2.count(')')\n if total_open % 2 == 1 or total_close % 2 == 1:\n return 'No'\n else:\n concatenated = s1 + s2\n open_count = 0\n close_count = 0\n for c in concatenated:\n if c == '(': open_count += 1\n elif c == ')': close_count += 1\n if close_count > open_count:\n return 'No'\n if open_count == close_count:\n return 'Yes'\n else:\n return 'No'", "claims": []} +{"prompt": "\ndef maximum(arr, k):\n \"\"\"\n Given an array arr of integers and a positive integer k, return a sorted list \n of length k with the maximum k numbers in arr.\n\n Note:\n 1. The length of the array will be in the range of [1, 1000].\n 2. The elements in the array will be in the range of [-1000, 1000].\n 3. 0 <= k <= len(arr)\n \"\"\"\n", "entry_point": "maximum", "label": false, "response": "def maximum(arr, k):\n sorted_arr = sorted(arr, reverse=True)\n return sorted_arr[:k]", "claims": []} +{"prompt": "\ndef solution(lst):\n \"\"\"Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.\n \"\"\"\n", "entry_point": "solution", "label": true, "response": "def solution(lst):\n odd_sum = 0\n for i in range(len(lst)):\n if i % 2 == 0 and lst[i] % 2 != 0:\n odd_sum += lst[i]\n return odd_sum", "claims": []} +{"prompt": "\ndef add_elements(arr, k):\n \"\"\"\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n \"\"\"\n", "entry_point": "add_elements", "label": true, "response": "def add_elements(arr, k):\n sum = 0\n for i in range(k):\n if abs(arr[i]) < 100:\n sum += arr[i]\n return sum", "claims": []} +{"prompt": "\ndef get_odd_collatz(n):\n \"\"\"\n Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\n\n The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\n as follows: start with any positive integer n. Then each term is obtained from the \n previous term as follows: if the previous term is even, the next term is one half of \n the previous term. If the previous term is odd, the next term is 3 times the previous\n term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\n\n Note: \n 1. Collatz(1) is [1].\n 2. returned list sorted in increasing order.\n \"\"\"\n", "entry_point": "get_odd_collatz", "label": true, "response": "def get_odd_collatz(n):\n if n == 1:\n return [1]\n elif n % 2 == 0:\n return get_odd_collatz(n//2)\n else:\n odd_collatz = [n]\n odd_collatz.extend(get_odd_collatz(3*n + 1))\n return sorted(list(set(filter(lambda x: x%2 != 0, odd_collatz))))", "claims": []} +{"prompt": "\ndef valid_date(date):\n \"\"\"You have to write a function which validates a given date string and\n returns True if the date is valid otherwise False.\n The date is valid if all of the following rules are satisfied:\n 1. The date string is not empty.\n 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.\n 3. The months should not be less than 1 or higher than 12.\n 4. The date should be in the format: mm-dd-yyyy\n \"\"\"\n", "entry_point": "valid_date", "label": true, "response": "def valid_date(date):\n try:\n month, day, year = map(int, date.split('-'))\n except ValueError:\n return False\n if month < 1 or month > 12:\n return False\n if month in [1, 3, 5, 7, 8, 10, 12]:\n if day < 1 or day > 31:\n return False\n elif month in [4, 6, 9, 11]:\n if day < 1 or day > 30:\n return False\n elif month == 2:\n if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):\n if day < 1 or day > 29:\n return False\n else:\n if day < 1 or day > 28:\n return False\n else:\n return False\n if len(date) != 10 or date[2] != '-' or date[5] != '-':\n return False\n return True", "claims": []} +{"prompt": "\ndef split_words(txt):\n '''\n Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you\n should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the\n alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25\n '''\n", "entry_point": "split_words", "label": false, "response": "def split_words(txt):\n words = txt.split()\n if len(words) == 1:\n words = txt.split(',')\n if len(words) == 1:\n count = 0\n for c in txt:\n if c.islower() and ord(c) % 2 == 1:\n count += 1\n return count\n return words", "claims": []} +{"prompt": "\ndef is_sorted(lst):\n '''\n Given a list of numbers, return whether or not they are sorted\n in ascending order. If list has more than 1 duplicate of the same\n number, return False. Assume no negative numbers and only integers.\n '''\n", "entry_point": "is_sorted", "label": false, "response": "def is_sorted(lst):\n if len(set(lst)) != len(lst):\n return False\n return lst == sorted(lst)", "claims": []} +{"prompt": "\ndef intersection(interval1, interval2):\n \"\"\"You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n \"\"\"\n", "entry_point": "intersection", "label": false, "response": "def intersection(interval1, interval2):\n def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5)+1):\n if n % i == 0:\n return False\n return True\n start = max(interval1[0], interval2[0])\n end = min(interval1[1], interval2[1])\n if start > end:\n return 'NO'\n length = end - start + 1\n if is_prime(length):\n return 'YES'\n else:\n return 'NO'", "claims": []} +{"prompt": "\ndef prod_signs(arr):\n \"\"\"\n You are given an array arr of integers and you need to return\n sum of magnitudes of integers multiplied by product of all signs\n of each number in the array, represented by 1, -1 or 0.\n Note: return None for empty arr.\n \"\"\"\n", "entry_point": "prod_signs", "label": true, "response": "def prod_signs(arr):\n if not arr:\n return None\n sign_product = 1\n magnitude_sum = 0\n for num in arr:\n sign_product *= 1 if num > 0 else -1 if num < 0 else 0\n magnitude_sum += abs(num)\n return sign_product * magnitude_sum", "claims": []} +{"prompt": "\ndef minPath(grid, k):\n \"\"\"\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n \"\"\"\n", "entry_point": "minPath", "label": true, "response": "def minPath(grid, k):\n n = len(grid)\n dp = [[[None for _ in range(k+1)] for _ in range(n)] for _ in range(n)]\n for i in range(n):\n for j in range(n):\n dp[i][j][1] = [grid[i][j]]\n for l in range(2, k+1):\n for i in range(n):\n for j in range(n):\n path = []\n for x, y in [(i-1,j), (i+1,j), (i,j-1), (i,j+1)]:\n if 0 <= x < n and 0 <= y < n and dp[x][y][l-1] is not None:\n temp_path = [grid[i][j]] + dp[x][y][l-1]\n if not path or temp_path < path:\n path = temp_path\n dp[i][j][l] = path\n min_path = dp[0][0][k]\n for i in range(n):\n for j in range(n):\n if dp[i][j][k] is not None and dp[i][j][k] < min_path:\n min_path = dp[i][j][k]\n return min_path", "claims": []} +{"prompt": "\ndef tri(n):\n \"\"\"Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in \n the last couple centuries. However, what people don't know is Tribonacci sequence.\n Tribonacci sequence is defined by the recurrence:\n tri(1) = 3\n tri(n) = 1 + n / 2, if n is even.\n tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.\n For example:\n tri(2) = 1 + (2 / 2) = 2\n tri(4) = 3\n tri(3) = tri(2) + tri(1) + tri(4)\n = 2 + 3 + 3 = 8 \n You are given a non-negative integer number n, you have to a return a list of the \n first n + 1 numbers of the Tribonacci sequence.\n \"\"\"\n", "entry_point": "tri", "label": false, "response": "def tri(n):\n if n == 0:\n return [0]\n elif n == 1:\n return [3]\n elif n == 2:\n return [3, 2]\n else:\n tribonacci = [0] * (n+1)\n tribonacci[0] = 0\n tribonacci[1] = 3\n tribonacci[2] = 2\n for i in range(3, n+1):\n if i % 2 == 0:\n tribonacci[i] = 1 + i//2\n else:\n tribonacci[i] = tribonacci[i-1] + tribonacci[i-2] + tribonacci[i-3]\n return tribonacci", "claims": []} +{"prompt": "\ndef digits(n):\n \"\"\"Given a positive integer n, return the product of the odd digits.\n Return 0 if all digits are even.\n \"\"\"\n", "entry_point": "digits", "label": true, "response": "def digits(n):\n product = 1\n has_odd_digit = False\n for digit in str(n):\n if int(digit) % 2 == 1:\n product *= int(digit)\n has_odd_digit = True\n if has_odd_digit:\n return product\n else:\n return 0", "claims": []} +{"prompt": "\ndef is_nested(string):\n '''\n Create a function that takes a string as input which contains only square brackets.\n The function should return True if and only if there is a valid subsequence of brackets \n where at least one bracket in the subsequence is nested.\n '''\n", "entry_point": "is_nested", "label": false, "response": "def is_nested(string):\n stack = []\n for bracket in string:\n if bracket == '[':\n stack.append(bracket)\n elif bracket == ']':\n if not stack or stack[-1] != '[':\n continue\n stack.pop()\n if not stack:\n return False\n return True", "claims": []} +{"prompt": "\n\ndef sum_squares(lst):\n \"\"\"You are given a list of numbers.\n You need to return the sum of squared numbers in the given list,\n round each element in the list to the upper int(Ceiling) first.\n \"\"\"\n", "entry_point": "sum_squares", "label": true, "response": "def sum_squares(lst):\n import math\n total = 0\n for num in lst:\n rounded_num = math.ceil(num)\n total += rounded_num ** 2\n return total", "claims": []} +{"prompt": "\ndef check_if_last_char_is_a_letter(txt):\n '''\n Create a function that returns True if the last character\n of a given string is an alphabetical character and is not\n a part of a word, and False otherwise.\n Note: \"word\" is a group of characters separated by space.\n '''\n", "entry_point": "check_if_last_char_is_a_letter", "label": false, "response": "def check_if_last_char_is_a_letter(txt):\n words = txt.split()\n last_word = words[-1]\n if len(last_word) == len(txt):\n return last_word.isalpha()\n else:\n return last_word[-1].isalpha() and txt[-1] == last_word[-1]", "claims": []} +{"prompt": "\ndef can_arrange(arr):\n \"\"\"Create a function which returns the largest index of an element which\n is not greater than or equal to the element immediately preceding it. If\n no such element exists then return -1. The given array will not contain\n duplicate values.\n \"\"\"\n", "entry_point": "can_arrange", "label": false, "response": "def can_arrange(arr):\n for i in range(1, len(arr)):\n if arr[i] < arr[i-1]:\n return i-1\n return -1", "claims": []} +{"prompt": "\ndef largest_smallest_integers(lst):\n '''\n Create a function that returns a tuple (a, b), where 'a' is\n the largest of negative integers, and 'b' is the smallest\n of positive integers in a list.\n If there is no negative or positive integers, return them as None.\n '''\n", "entry_point": "largest_smallest_integers", "label": true, "response": "def largest_smallest_integers(lst):\n largest_negative = None\n smallest_positive = None\n for num in lst:\n if num < 0 and (largest_negative is None or num > largest_negative):\n largest_negative = num\n elif num > 0 and (smallest_positive is None or num < smallest_positive):\n smallest_positive = num\n return (largest_negative, smallest_positive)\n", "claims": []} +{"prompt": "\ndef compare_one(a, b):\n \"\"\"\n Create a function that takes integers, floats, or strings representing\n real numbers, and returns the larger variable in its given variable type.\n Return None if the values are equal.\n Note: If a real number is represented as a string, the floating point might be . or ,\n \"\"\"\n", "entry_point": "compare_one", "label": true, "response": "def compare_one(a, b):\n if type(a) == type(b):\n if a > b:\n return a\n elif b > a:\n return b\n else:\n return None\n else:\n a_float = float(a.replace(',', '.')) if type(a) == str else float(a)\n b_float = float(b.replace(',', '.')) if type(b) == str else float(b)\n if a_float > b_float:\n return a\n elif b_float > a_float:\n return b\n else:\n return None", "claims": []} +{"prompt": "\ndef is_equal_to_sum_even(n):\n \"\"\"Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\n \"\"\"\n", "entry_point": "is_equal_to_sum_even", "label": true, "response": "def is_equal_to_sum_even(n):\n if n < 8 or n % 2 != 0:\n return False\n for i in range(2, n//2 + 1, 2):\n for j in range(2, n//2 + 1, 2):\n for k in range(2, n//2 + 1, 2):\n for l in range(2, n//2 + 1, 2):\n if i + j + k + l == n:\n return True\n return False", "claims": []} +{"prompt": "\ndef special_factorial(n):\n \"\"\"The Brazilian factorial is defined as:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n where n > 0\n\n The function will receive an integer as input and should return the special\n factorial of this integer.\n \"\"\"\n", "entry_point": "special_factorial", "label": true, "response": "def special_factorial(n):\n result = 1\n for i in range(n, 0, -1):\n factorial = 1\n for j in range(i, 0, -1):\n factorial *= j\n result *= factorial\n return result", "claims": []} +{"prompt": "\ndef fix_spaces(text):\n \"\"\"\n Given a string text, replace all spaces in it with underscores, \n and if a string has more than 2 consecutive spaces, \n then replace all consecutive spaces with - \n \"\"\"\n", "entry_point": "fix_spaces", "label": false, "response": "def fix_spaces(text):\n result = ''\n count = 0\n for char in text:\n if char == ' ':\n count += 1\n if count > 2:\n continue\n result += '_'\n else:\n if count > 2:\n result += '-'\n else:\n result += char\n count = 0\n return result", "claims": []} +{"prompt": "\ndef file_name_check(file_name):\n \"\"\"Create a function which takes a string representing a file's name, and returns\n 'Yes' if the the file's name is valid, and returns 'No' otherwise.\n A file's name is considered to be valid if and only if all the following conditions \n are met:\n - There should not be more than three digits ('0'-'9') in the file's name.\n - The file's name contains exactly one dot '.'\n - The substring before the dot should not be empty, and it starts with a letter from \n the latin alphapet ('a'-'z' and 'A'-'Z').\n - The substring after the dot should be one of these: ['txt', 'exe', 'dll']\n \"\"\"\n", "entry_point": "file_name_check", "label": false, "response": "def file_name_check(file_name):\n import re\n pattern = r'^[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]*\\.[txt|exe|dll]{3}$'\n if re.match(pattern, file_name):\n return 'Yes'\n else:\n return 'No'", "claims": []} +{"prompt": "\n\n\ndef sum_squares(lst):\n \"\"\"\"\n This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a \n multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \n change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n \"\"\"\n", "entry_point": "sum_squares", "label": true, "response": "def sum_squares(lst):\n sum = 0\n for i in range(len(lst)):\n if i % 3 == 0:\n sum += lst[i]**2\n elif i % 4 == 0 and i % 3 != 0:\n sum += lst[i]**3\n else:\n sum += lst[i]\n return sum", "claims": []} +{"prompt": "\ndef words_in_sentence(sentence):\n \"\"\"\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n \"\"\"\n", "entry_point": "words_in_sentence", "label": false, "response": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5)+1):\n if n % i == 0:\n return False\n return True\n\n", "claims": []} +{"prompt": "\ndef simplify(x, n):\n \"\"\"Your task is to implement a function that will simplify the expression\n x * n. The function returns True if x * n evaluates to a whole number and False\n otherwise. Both x and n, are string representation of a fraction, and have the following format,\n / where both numerator and denominator are positive whole numbers.\n\n You can assume that x, and n are valid fractions, and do not have zero as denominator.\n \"\"\"\n", "entry_point": "simplify", "label": true, "response": "def simplify(x, n):\n x_num, x_den = map(int, x.split('/'))\n n_num, n_den = map(int, n.split('/'))\n num = x_num * n_num\n den = x_den * n_den\n return num % den == 0", "claims": []} +{"prompt": "\ndef order_by_points(nums):\n \"\"\"\n Write a function which sorts the given list of integers\n in ascending order according to the sum of their digits.\n Note: if there are several items with similar sum of their digits,\n order them based on their index in original list.\n \"\"\"\n", "entry_point": "order_by_points", "label": false, "response": "def order_by_points(nums):\n def sum_of_digits(num):\n return sum(int(digit) for digit in str(num))\n return sorted(nums, key=lambda num: (sum_of_digits(num), nums.index(num)))", "claims": []} +{"prompt": "\ndef specialFilter(nums):\n \"\"\"Write a function that takes an array of numbers as input and returns \n the number of elements in the array that are greater than 10 and both \n first and last digits of a number are odd (1, 3, 5, 7, 9).\n \"\"\"\n", "entry_point": "specialFilter", "label": true, "response": "def specialFilter(nums):\n count = 0\n for num in nums:\n if num > 10 and int(str(num)[0]) % 2 != 0 and int(str(num)[-1]) % 2 != 0:\n count += 1\n return count", "claims": []} +{"prompt": "\ndef get_max_triples(n):\n \"\"\"\n You are given a positive integer n. You have to create an integer array a of length n.\n For each i (1 \u2264 i \u2264 n), the value of a[i] = i * i - i + 1.\n Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, \n and a[i] + a[j] + a[k] is a multiple of 3.\n \"\"\"\n", "entry_point": "get_max_triples", "label": true, "response": "def get_max_triples(n):\n a = [i*i-i+1 for i in range(1, n+1)]\n count = 0\n for i in range(n-2):\n for j in range(i+1, n-1):\n for k in range(j+1, n):\n if (a[i]+a[j]+a[k]) % 3 == 0:\n count += 1\n return count", "claims": []} +{"prompt": "\ndef bf(planet1, planet2):\n '''\n There are eight planets in our solar system: the closerst to the Sun \n is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, \n Uranus, Neptune.\n Write a function that takes two planet names as strings planet1 and planet2. \n The function should return a tuple containing all planets whose orbits are \n located between the orbit of planet1 and the orbit of planet2, sorted by \n the proximity to the sun. \n The function should return an empty tuple if planet1 or planet2\n are not correct planet names. \n '''\n", "entry_point": "bf", "label": true, "response": "def bf(planet1, planet2):\n planets = {\n 'Mercury': 1,\n 'Venus': 2,\n 'Earth': 3,\n 'Mars': 4,\n 'Jupiter': 5,\n 'Saturn': 6,\n 'Uranus': 7,\n 'Neptune': 8\n }\n if planet1 not in planets or planet2 not in planets:\n return ()\n if planets[planet1] > planets[planet2]:\n planet1, planet2 = planet2, planet1\n result = []\n for planet, orbit in planets.items():\n if planets[planet1] < orbit < planets[planet2]:\n result.append(planet)\n return tuple(sorted(result, key=lambda x: planets[x]))", "claims": []} +{"prompt": "\ndef sorted_list_sum(lst):\n \"\"\"Write a function that accepts a list of strings as a parameter,\n deletes the strings that have odd lengths from it,\n and returns the resulted list with a sorted order,\n The list is always a list of strings and never an array of numbers,\n and it may contain duplicates.\n The order of the list should be ascending by length of each word, and you\n should return the list sorted by that rule.\n If two words have the same length, sort the list alphabetically.\n The function should return a list of strings in sorted order.\n You may assume that all words will have the same length.\n \"\"\"\n", "entry_point": "sorted_list_sum", "label": true, "response": "def sorted_list_sum(lst):\n lst = [word for word in lst if len(word) % 2 == 0]\n return sorted(lst, key=lambda x: (len(x), x))\n", "claims": []} +{"prompt": "\ndef x_or_y(n, x, y):\n \"\"\"A simple program which should return the value of x if n is \n a prime number and should return the value of y otherwise.\n \"\"\"\n", "entry_point": "x_or_y", "label": false, "response": "def x_or_y(n, x, y):\n from sympy import isprime\n if isprime(n):\n return x\n else:\n return y", "claims": []} +{"prompt": "\ndef double_the_difference(lst):\n '''\n Given a list of numbers, return the sum of squares of the numbers\n in the list that are odd. Ignore numbers that are negative or not integers.\n \n If the input list is empty, return 0.\n '''\n", "entry_point": "double_the_difference", "label": false, "response": "def double_the_difference(lst):\n sum_of_squares = 0\n for num in lst:\n if isinstance(num, int) and num > 0 and num % 2 != 0:\n sum_of_squares += num ** 2\n return sum_of_squares * 2 if sum_of_squares > 0 else 0", "claims": []} +{"prompt": "\ndef compare(game,guess):\n \"\"\"I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \"\"\"\n", "entry_point": "compare", "label": true, "response": "def compare(game, guess):\n result = []\n for i in range(len(game)):\n if game[i] == guess[i]:\n result.append(0)\n else:\n result.append(abs(game[i] - guess[i]))\n return result", "claims": []} +{"prompt": "\ndef Strongest_Extension(class_name, extensions):\n \"\"\"You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters \n in the extension's name, the strength is given by the fraction CAP - SM. \n You should find the strongest extension and return a string in this \n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension \n (its strength is -1).\n \"\"\"\n", "entry_point": "Strongest_Extension", "label": true, "response": "def Strongest_Extension(class_name, extensions):\n strongest_extension = None\n for extension in extensions:\n cap = sum(1 for c in extension if c.isupper())\n sm = sum(1 for c in extension if c.islower())\n strength = cap - sm\n if strongest_extension is None or strength > strongest_extension[1] or (strength == strongest_extension[1] and extensions.index(extension) < extensions.index(strongest_extension[0])):\n strongest_extension = (extension, strength)\n return class_name + '.' + strongest_extension[0]", "claims": []} +{"prompt": "\ndef cycpattern_check(a , b):\n \"\"\"You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word\n \"\"\"\n", "entry_point": "cycpattern_check", "label": false, "response": "def cycpattern_check(a, b):\n new_str = a + a\n for i in range(len(a)):\n if b in new_str[i:i+len(a)]:\n return True\n return False", "claims": []} +{"prompt": "\ndef even_odd_count(num):\n \"\"\"Given an integer. return a tuple that has the number of even and odd digits respectively.\n \"\"\"\n", "entry_point": "even_odd_count", "label": false, "response": "def even_odd_count(num):\n even_count = 0\n odd_count = 0\n for digit in str(num):\n if int(digit) % 2 == 0:\n even_count += 1\n else:\n odd_count += 1\n return (even_count, odd_count)", "claims": []} +{"prompt": "\ndef int_to_mini_roman(number):\n \"\"\"\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n \"\"\"\n", "entry_point": "int_to_mini_roman", "label": true, "response": "def int_to_mini_roman(number):\n roman_dict = {1000: 'm', 900: 'cm', 500: 'd', 400: 'cd', 100: 'c', 90: 'xc', 50: 'l', 40: 'xl', 10: 'x', 9: 'ix', 5: 'v', 4: 'iv', 1: 'i'}\n result = ''\n for value, numeral in sorted(roman_dict.items(), reverse=True):\n while number >= value:\n result += numeral\n number -= value\n return result.lower()", "claims": []} +{"prompt": "\ndef right_angle_triangle(a, b, c):\n '''\n Given the lengths of the three sides of a triangle. Return True if the three\n sides form a right-angled triangle, False otherwise.\n A right-angled triangle is a triangle in which one angle is right angle or \n 90 degree.\n '''\n", "entry_point": "right_angle_triangle", "label": true, "response": "def right_angle_triangle(a, b, c):\n if a**2 + b**2 == c**2 or b**2 + c**2 == a**2 or a**2 + c**2 == b**2:\n return True\n else:\n return False", "claims": []} +{"prompt": "\ndef find_max(words):\n \"\"\"Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n \"\"\"\n", "entry_point": "find_max", "label": true, "response": "def find_max(words):\n max_word = ''\n max_length = 0\n for word in words:\n unique_chars = {}\n for char in word:\n if char not in unique_chars:\n unique_chars[char] = True\n if len(unique_chars) > max_length:\n max_word = word\n max_length = len(unique_chars)\n elif len(unique_chars) == max_length:\n if word < max_word:\n max_word = word\n return max_word", "claims": []} +{"prompt": "\ndef eat(number, need, remaining):\n \"\"\"\n You're a hungry rabbit, and you already have eaten a certain number of carrots,\n but now you need to eat more carrots to complete the day's meals.\n you should return an array of [ total number of eaten carrots after your meals,\n the number of carrots left after your meals ]\n if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n \n Variables:\n @number : integer\n the number of carrots that you have eaten.\n @need : integer\n the number of carrots that you need to eat.\n @remaining : integer\n the number of remaining carrots thet exist in stock\n \n Constrain:\n * 0 <= number <= 1000\n * 0 <= need <= 1000\n * 0 <= remaining <= 1000\n\n Have fun :)\n \"\"\"\n", "entry_point": "eat", "label": true, "response": "def eat(number, need, remaining):\n if remaining >= need:\n total_eaten = number + need\n remaining -= need\n else:\n total_eaten = number + remaining\n remaining = 0\n return [total_eaten, remaining]", "claims": []} +{"prompt": "\ndef do_algebra(operator, operand):\n \"\"\"\n Given two lists operator, and operand. The first list has basic algebra operations, and \n the second list is a list of integers. Use the two given lists to build the algebric \n expression and return the evaluation of this expression.\n\n The basic algebra operations:\n Addition ( + ) \n Subtraction ( - ) \n Multiplication ( * ) \n Floor division ( // ) \n Exponentiation ( ** ) \n\n Note:\n The length of operator list is equal to the length of operand list minus one.\n Operand is a list of of non-negative integers.\n Operator list has at least one operator, and operand list has at least two operands.\n\n \"\"\"\n", "entry_point": "do_algebra", "label": true, "response": "def do_algebra(operator, operand):\n expression = str(operand[0])\n for i in range(len(operator)):\n expression += operator[i] + str(operand[i+1])\n return eval(expression)", "claims": []} +{"prompt": "\ndef solve(s):\n \"\"\"You are given a string s.\n if s[i] is a letter, reverse its case from lower to upper or vise versa, \n otherwise keep it as it is.\n If the string contains no letters, reverse the string.\n The function should return the resulted string.\n \"\"\"\n", "entry_point": "solve", "label": true, "response": "def solve(s):\n has_letter = False\n for char in s:\n if char.isalpha():\n has_letter = True\n s = s.replace(char, char.swapcase())\n if not has_letter:\n s = s[::-1]\n return s", "claims": []} +{"prompt": "\ndef string_to_md5(text):\n \"\"\"\n Given a string 'text', return its md5 hash equivalent string.\n If 'text' is an empty string, return None.\n \"\"\"\n", "entry_point": "string_to_md5", "label": true, "response": "def string_to_md5(text):\n import hashlib\n if not text:\n return None\n else:\n return hashlib.md5(text.encode()).hexdigest()", "claims": []} +{"prompt": "\ndef generate_integers(a, b):\n \"\"\"\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n \"\"\"\n", "entry_point": "generate_integers", "label": false, "response": "def generate_integers(a, b):\n even_digits = []\n for num in range(a, b+1):\n for digit in str(num):\n if int(digit) % 2 == 0:\n even_digits.append(int(digit))\n even_digits.sort()\n return even_digits", "claims": []}