task_id stringlengths 16 18 | prompt stringlengths 138 1.57k | entry_point stringlengths 3 62 | entry_point_auxiliary stringlengths 1 30 | test stringlengths 607 3.55k |
|---|---|---|---|---|
HumanExtension/0 | from typing import List
def has_close_elements_in_array(array: List[List[float]], threshold: float) -> bool:
"""Check if in given array, are any two numbers closer to each other than given threshold.
>>> has_close_elements_in_array([[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]], 0.5)
True
>>> has_close_elements_i... | has_close_elements_in_array | has_close_elements | from typing import List
def has_close_elements(numbers: List[float], threshold: float) -> bool:
"""Check if in given list of numbers, are any two numbers closer to each other than
given threshold.
>>> has_close_elements([1.0, 2.0, 3.0], 0.5)
False
>>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2... |
HumanExtension/1 | from typing import Any, List
def nested_separate_paren_groups(paren_string: str) -> Any:
"""Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Different from separate_paren_groups, yo... | nested_separate_paren_groups | separate_paren_groups | from typing import Any, List
def separate_paren_groups(paren_string: str) -> List[str]:
"""Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Separate groups are balanced (each open b... |
HumanExtension/2 | def is_number_rounded_up(number: float) -> bool:
"""Given a positive floating point number, return True if the number is
rounded up, False otherwise.
>>> is_number_rounded_up(3.5)
True
>>> is_number_rounded_up(3.4)
False""" | is_number_rounded_up | truncate_number | def truncate_number(number: float) -> float:
"""Given a positive floating point number, it can be decomposed into
and integer part (largest integer smaller than given number) and decimals
(leftover part always smaller than 1).
Return the decimal part of the number.
>>> truncate_number(3.5)
0.5
... |
HumanExtension/3 | from typing import List
def below_zero_with_initial_value(operations: List[int], initial: int) -> bool:
"""You're given a list of deposit and withdrawal operations on a bank account that starts with
non-negative initial balance. Your task is to detect if at any point the balance of account fallls
below ze... | below_zero_with_initial_value | below_zero | from typing import List
def below_zero(operations: List[int]) -> bool:
"""You're given a list of deposit and withdrawal operations on a bank account that starts with
zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
at that point function should return True... |
HumanExtension/4 | from typing import List
def find_outlier(numbers: List[float]) -> List[float]:
"""For a given list of input numbers, find the outlier.
Outliers are defined as data whose distance from the mean is greater than
the mean absolute deviation.
The order of the outliers in the output list should be the same ... | find_outlier | mean_absolute_deviation | from typing import List
def mean_absolute_deviation(numbers: List[float]) -> float:
"""For a given list of input numbers, calculate Mean Absolute Deviation
around the mean of this dataset.
Mean Absolute Deviation is the average absolute difference between each
element and a centerpoint (mean in this c... |
HumanExtension/5 | from typing import List
def intersperse_with_start_end(numbers: List[int], delimeter: int) -> List[int]:
"""Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
and also add 'delimeter' at the beginning and end of the list.
>>> intersperse_with_start_end([], 4)
[4... | intersperse_with_start_end | intersperse | from typing import List
def intersperse(numbers: List[int], delimeter: int) -> List[int]:
"""Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
>>> intersperse([], 4)
[]
>>> intersperse([1, 2, 3], 4)
[1, 4, 2, 4, 3]
"""
if not numbers:
return... |
HumanExtension/6 | from typing import List
def remove_nested_parens(paren_string: str) -> str:
"""Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
Filter out the group whose deepest level of nesting of parentheses is greater than 2.
E.g. (()()) has maximum two levels... | remove_nested_parens | parse_nested_parens | from typing import List
def parse_nested_parens(paren_string: str) -> List[int]:
"""Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
For each of the group, output the deepest level of nesting of parentheses.
E.g. (()()) has maximum two levels of ne... |
HumanExtension/7 | from typing import List
def filter_by_substrings(strings: List[str], substrings: List[str]) -> List[str]:
"""Filter an input list of strings only for ones that contain all of given substrings
>>> filter_by_substrings([], ['a', 'b'])
[]
>>> filter_by_substrings(['abc', 'bacd', 'cde', 'array'], ['a', 'b... | filter_by_substrings | filter_by_substring | from typing import List
def filter_by_substring(strings: List[str], substring: str) -> List[str]:
"""Filter an input list of strings only for ones that contain given substring
>>> filter_by_substring([], 'a')
[]
>>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')
['abc', 'bacd', 'array']... |
HumanExtension/8 | from typing import List, Tuple
def product_sum(numbers: List[int]) -> Tuple[int, int]:
"""For a given list of integers, return a tuple consisting of a product and a sum of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
>>> product_sum([])
(1, 0)
... | product_sum | sum_product | from typing import List, Tuple
def sum_product(numbers: List[int]) -> Tuple[int, int]:
"""For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
>>> sum_product([])
(0, 1)
... |
HumanExtension/9 | from typing import List
def rolling_max_with_initial_value(numbers: List[int], initial: int) -> List[int]:
"""From a given list of integers, generate a list of rolling maximum element found until given moment
in the sequence. Additionally, the maximum value starts with `initial`.
>>> rolling_max_with_init... | rolling_max_with_initial_value | rolling_max | from typing import List
def rolling_max(numbers: List[int]) -> List[int]:
"""From a given list of integers, generate a list of rolling maximum element found until given moment
in the sequence.
>>> rolling_max([1, 2, 3, 2, 3, 4, 2])
[1, 2, 3, 3, 3, 4, 4]
"""
running_max = None
result = []
... |
HumanExtension/10 | def find_shortest_palindrome_prefix(string: str) -> str:
"""Find the shortest prefix that generates the same shortest palindrome that
begins with the supplied string.
>>> find_shortest_palindrome_prefix('')
''
>>> find_shortest_palindrome_prefix('cat')
'cat'
>>> find_shortest_palindrome_pref... | find_shortest_palindrome_prefix | make_palindrome | def make_palindrome(string: str) -> str:
"""Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- Find the longest postfix of supplied string that is a palindrome.
- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix... |
HumanExtension/11 | def string_xor_three(a: str, b: str, c: str) -> str:
"""Input are three strings a, b, and c consisting only of 1s and 0s.
Perform binary XOR on these inputs and return result also as a string.
>>> string_xor('010', '110', '001')
'101'""" | string_xor_three | string_xor | def string_xor(a: str, b: str) -> str:
"""Input are two strings a and b consisting only of 1s and 0s.
Perform binary XOR on these inputs and return result also as a string.
>>> string_xor('010', '110')
'100'
"""
def xor(i, j):
if i == j:
return '0'
else:
... |
HumanExtension/12 | from typing import List, Optional
def second_longest(strings: List[str]) -> Optional[str]:
"""Out of list of strings, return the second longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list doesn't have the second longest elements.
>>> second_... | second_longest | longest | from typing import List, Optional
def longest(strings: List[str]) -> Optional[str]:
"""Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
>>> longest([])
>>> longest(['a', 'b', 'c'])
'a'... |
HumanExtension/13 | from typing import Tuple
def reduce_fraction(nominator: int, denominator: int) -> Tuple[int, int]:
"""Given nominator and denominator, reduce them to the simplest form.
Reducing fractions means simplifying a fraction, wherein we divide the numerator and denominator by a common divisor until the common factor ... | reduce_fraction | greatest_common_divisor | from typing import Tuple
def greatest_common_divisor(a: int, b: int) -> int:
"""Return a greatest common divisor of two integers a and b
>>> greatest_common_divisor(3, 5)
1
>>> greatest_common_divisor(25, 15)
5
"""
while b:
(a, b) = (b, a % b)
return a
def reduce_fraction(nom... |
HumanExtension/14 | from typing import List
def all_suffixes_prefixes(string: str) -> List[str]:
"""Return list of suffixes which are also a prefix from shortest to
longest of the input string
>>> all_suffixes('abc')
['abc']""" | all_suffixes_prefixes | all_prefixes | from typing import List
def all_prefixes(string: str) -> List[str]:
"""Return list of all prefixes from shortest to longest of the input string
>>> all_prefixes('abc')
['a', 'ab', 'abc']
"""
result = []
for i in range(len(string)):
result.append(string[:i + 1])
return result
def ... |
HumanExtension/15 | def digit_sum(n: int) -> str:
"""Return the sum of all digits from 0 upto n inclusive.
>>> digit_sum(0)
0
>>> digit_sum(5)
15""" | digit_sum | string_sequence | def string_sequence(n: int) -> str:
"""Return a string containing space-delimited numbers starting from 0 upto n inclusive.
>>> string_sequence(0)
'0'
>>> string_sequence(5)
'0 1 2 3 4 5'
"""
return ' '.join([str(x) for x in range(n + 1)])
def digit_sum(n: int) -> str:
"""Return the su... |
HumanExtension/16 | from typing import List
def count_words_with_distinct_characters(strings: List[str]) -> int:
"""Given a list of strings, count the number of words made up of all different letters (regardless of case)
>>> count_words_with_distinct_characters(['xyz', 'Jerry'])
1
>>> count_words_with_distinct_characters... | count_words_with_distinct_characters | count_distinct_characters | from typing import List
def count_distinct_characters(string: str) -> int:
"""Given a string, find out how many distinct characters (regardless of case) does it consist of
>>> count_distinct_characters('xyzXYZ')
3
>>> count_distinct_characters('Jerry')
4
"""
return len(set(string.lower()))... |
HumanExtension/17 | from typing import List
def count_beats(music_string: str) -> int:
"""Input to this function is a string representing musical notes in a special ASCII format.
Your task is to parse this string and return the total number of beats in the song.
Here is a legend:
'o' - whole note, lasts four beats
... | count_beats | parse_music | from typing import List
def parse_music(music_string: str) -> List[int]:
"""Input to this function is a string representing musical notes in a special ASCII format.
Your task is to parse this string and return list of integers corresponding to how many beats does each
not last.
Here is a legend:
... |
HumanExtension/18 | def match_cancer_pattern(dna: str, cancer_pattern: str) -> int:
"""Find how many times a given cancer pattern can be found in the given DNA. Count overlaping cases.
>>> match_cancer_pattern('ATGCGATACGCTTGA', 'CG')
3
>>> match_cancer_pattern('ATGCGATACGCTTGA', 'CGC')
1""" | match_cancer_pattern | how_many_times | def how_many_times(string: str, substring: str) -> int:
"""Find how many times a given substring can be found in the original string. Count overlaping cases.
>>> how_many_times('', 'a')
0
>>> how_many_times('aaa', 'a')
3
>>> how_many_times('aaaa', 'aa')
3
"""
times = 0
for i in r... |
HumanExtension/19 | def sort_numbers_descending(numbers: str) -> str:
"""Input is a space-delimited string of numberals from 'zero' to 'nine'.
Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
Return the string with numbers sorted from largest to smallest
>>> sort_numbers_... | sort_numbers_descending | sort_numbers | def sort_numbers(numbers: str) -> str:
"""Input is a space-delimited string of numberals from 'zero' to 'nine'.
Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
Return the string with numbers sorted from smallest to largest
>>> sort_numbers('three one ... |
HumanExtension/20 | from typing import List, Tuple
def find_closest_distance(numbers: List[float]) -> float:
"""From a supplied list of numbers (of length at least two) select and return the distance between two that are
the closest to each other.
>>> find_closest_distance([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])
0.2
>>> find... | find_closest_distance | find_closest_elements | from typing import List, Tuple
def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:
"""From a supplied list of numbers (of length at least two) select and return two that are the closest to each
other and return them in order (smaller number, larger number).
>>> find_closest_elements([1... |
HumanExtension/21 | from typing import List
def rescale_to_percentile(numbers: List[float]) -> List[float]:
"""Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 100
>>> rescale_to_percentile([1.0, 2.0, 3.0, 4.0, 5.0... | rescale_to_percentile | rescale_to_unit | from typing import List
def rescale_to_unit(numbers: List[float]) -> List[float]:
"""Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1
>>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])
[0.0, 0... |
HumanExtension/22 | from typing import Any, List
def get_second_integer(values: List[Any]) -> List[int]:
"""Return the second integer element in the list
If there is no second integer element, return None
>>> get_second_observed_integer(['a', 3.14, 5])
None
>>> get_second_observed_integer([1, 2, 3, 'abc', {}, []])
... | get_second_integer | filter_integers | from typing import Any, List
def filter_integers(values: List[Any]) -> List[int]:
"""Filter given list of any python values only for integers
>>> filter_integers(['a', 3.14, 5])
[5]
>>> filter_integers([1, 2, 3, 'abc', { }, []])
[1, 2, 3]
"""
return [x for x in values if isinstance(x, int... |
HumanExtension/23 | def is_string_length_odd(string: str) -> str:
"""Return 'odd' if length of given string is odd, otherwise 'even'
>>> is_string_length_odd('')
'even'
>>> is_string_length_odd('abc')
'odd'""" | is_string_length_odd | strlen | def strlen(string: str) -> int:
"""Return length of given string
>>> strlen('')
0
>>> strlen('abc')
3
"""
return len(string)
def is_string_length_odd(string: str) -> str:
"""Return 'odd' if length of given string is odd, otherwise 'even'
>>> is_string_length_odd('')
'even'
... |
HumanExtension/24 | def get_smallest_chunk_num(n: int) -> bool:
"""Given n, find the smallest k such that a number n can be made from k chunks of the same size.
Chunk size must be smaller than n.
>>> get_smallest_chunk_num(15)
3""" | get_smallest_chunk_num | largest_divisor | def largest_divisor(n: int) -> int:
"""For a given number n, find the largest number that divides n evenly, smaller than n
>>> largest_divisor(15)
5
"""
for i in reversed(range(n)):
if n % i == 0:
return i
def get_smallest_chunk_num(n: int) -> bool:
"""Given n, find the sma... |
HumanExtension/25 | from typing import List
def count_unique_prime_factors(n: int) -> int:
"""Return the number of unique prime factors of given integer
>>> count_unique_prime_factors(8)
1
>>> count_unique_prime_factors(25)
1
>>> count_unique_prime_factors(70)
3""" | count_unique_prime_factors | factorize | from typing import List
def factorize(n: int) -> List[int]:
"""Return list of prime factors of given integer in the order from smallest to largest.
Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.
Input number should be equal to the product... |
HumanExtension/26 | from typing import List
def count_duplicates(numbers: List[int]) -> int:
"""From a list of integers, count how many elements occur more than once.
>>> count_duplicates([1, 2, 3, 2, 4])
2
>>> count_duplicates([2, 2, 3, 2, 3])
5""" | count_duplicates | remove_duplicates | from typing import List
def remove_duplicates(numbers: List[int]) -> List[int]:
"""From a list of integers, remove all elements that occur more than once.
Keep order of elements left the same as in the input.
>>> remove_duplicates([1, 2, 3, 2, 4])
[1, 3, 4]
"""
import collections
c = colle... |
HumanExtension/27 | def get_more_uppercase_word(string: str) -> str:
"""Return string if string has more or equal number of uppercase characters than
the number of lowercase characters. Otherwise, return string whose characters
are flipped by their case.
>>> flip_alternative_words('Hello')
'hELLO'
>>> flip_alternat... | get_more_uppercase_word | flip_case | def flip_case(string: str) -> str:
"""For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
>>> flip_case('Hello')
'hELLO'
"""
return string.swapcase()
def get_more_uppercase_word(string: str) -> str:
"""Return string if string has more or equal number of upper... |
HumanExtension/28 | from typing import List
def create_multiline_string(strings: List[str]) -> str:
"""Create a multiline string from a list of strings. Note that last line should also end with a newline. If string is empty, return empty string.
>>> create_multiline_string([])
''
>>> create_multiline_string([... | create_multiline_string | concatenate | from typing import List
def concatenate(strings: List[str]) -> str:
"""Concatenate list of strings into a single string
>>> concatenate([])
''
>>> concatenate(['a', 'b', 'c'])
'abc'
"""
return ''.join(strings)
def create_multiline_string(strings: List[str]) -> str:
"""Create a multil... |
HumanExtension/29 | from typing import List
def create_autocomplete_options(input: str, options: List[str]) -> List[str]:
"""Create autocomplete options for a given input string from a list of options.
Options should be sorted alphabetically.
>>> create_autocomplete_options('a', [])
[]
>>> create_autocomplete_options... | create_autocomplete_options | filter_by_prefix | from typing import List
def filter_by_prefix(strings: List[str], prefix: str) -> List[str]:
"""Filter an input list of strings only for ones that start with a given prefix.
>>> filter_by_prefix([], 'a')
[]
>>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a')
['abc', 'array']
"""
retur... |
HumanExtension/30 | from typing import List
def sum_positive(l: list) -> int:
"""Return the sum of all positive numbers in the list.
>>> sum_positive([-1, 2, -4, 5, 6])
13
>>> sum_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
146""" | sum_positive | get_positive | from typing import List
def get_positive(l: List[int]) -> List[int]:
"""Return only positive numbers in the list.
>>> get_positive([-1, 2, -4, 5, 6])
[2, 5, 6]
>>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
[5, 3, 2, 3, 9, 123, 1]
"""
return [e for e in l if e > 0]
def sum_pos... |
HumanExtension/31 | def get_prime_times_prime(n: int) -> bool:
"""Returns a sorted list of numbers less than n that are
the product of two distinct primes.
>>> get_number(6)
[]
>>> get_number(20)
[6, 10, 14, 15]""" | get_prime_times_prime | is_prime | def is_prime(n: int) -> bool:
"""Return true if a given number is prime, and false otherwise.
>>> is_prime(6)
False
>>> is_prime(101)
True
>>> is_prime(11)
True
>>> is_prime(13441)
True
>>> is_prime(61)
True
>>> is_prime(4)
False
>>> is_prime(1)
False
"""
... |
HumanExtension/32 | from typing import List
def sort_first_column(l: List[List[int]]):
"""This function takes an array of n by 3.
It returns an array of N x 3 such that the elements in the first column are sorted.
>>> sort_last_column([[1, 2, 3], [9, 6, 4], [5, 3, 2]])
[[1, 2, 3], [5, 6, 4], [9, 3, 2]]
>>> sort_last_... | sort_first_column | sort_third | from typing import List
def sort_third(l: List[int]) -> List[int]:
"""This function takes a list l and returns a list l' such that
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
to the values of the corresponding... |
HumanExtension/33 | from typing import List
def max_element_nested_list(l: list):
"""Return maximum element in a nested list.
l could be nested by any depth.
>>> max_element_nested_list([1, 2, 3])
3
>>> max_element_nested_list([[5, 3], [[-5], [2, -3, 3], [[9, 0], [123]], 1], -10])
123""" | max_element_nested_list | max_element | from typing import List
def max_element(l: List[int]) -> int:
"""Return maximum element in the list.
>>> max_element([1, 2, 3])
3
>>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
123
"""
m = l[0]
for e in l:
if e > m:
m = e
return m
def max_element_nes... |
HumanExtension/34 | def lucky_number(k: int) -> int:
"""Return the smallest non-negative number n that the digit 7 appears at
least k times in integers less than n which are divisible by 11 or 13.
>>> lucky_number(3)
79
>>> lucky_number(0)
0""" | lucky_number | fizz_buzz | def fizz_buzz(n: int) -> int:
"""Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
>>> fizz_buzz(50)
0
>>> fizz_buzz(78)
2
>>> fizz_buzz(79)
3
"""
ns = []
for i in range(n):
if i % 11 == 0 or i % 13 == 0:
n... |
HumanExtension/35 | def paired_sort(l: list[int]) -> list[int]:
"""This function takes a list l and returns a list l' such that
l' is sorted to l in the odd indicies, also its values at the
even indicies are equal to the values of the even indicies of l,
but sorted.
>>> sort_even([1, 2, 3])
[1, 2, 3]
>>> sort_e... | paired_sort | sort_even | def sort_even(l: list[int]) -> list[int]:
"""This function takes a list l and returns a list l' such that
l' is identical to l in the odd indicies, while its values at the
even indicies are equal to the values of the even indicies of l,
but sorted.
>>> sort_even([1, 2, 3])
[1, 2, 3]
>>> sort... |
HumanExtension/36 | def prime_fib_diff(n: int):
"""Return the difference between the n-th number that is a Fibonacci number and
it's also prime and the (n+1)-th number that is a Fibonacci number and it's also prime.
>>> prime_fib_dif(1)
1
>>> prime_fib_dif(2)
2
>>> prime_fib_dif(3)
8
>>> prime_fib_dif(4... | prime_fib_diff | prime_fib | def prime_fib(n: int) -> int:
"""
prime_fib returns n-th number that is a Fibonacci number and it's also prime.
>>> prime_fib(1)
2
>>> prime_fib(2)
3
>>> prime_fib(3)
5
>>> prime_fib(4)
13
>>> prime_fib(5)
89
"""
import math
def is_prime(p):
if p < 2:... |
HumanExtension/37 | def get_shortest_prefix_triples_sum_to_zero(l: list) -> list:
"""get_shortest_prefix_triples_sum_to_zero takes a list of integers as an input.
it returns the shortest prefix of the list such that there are three distinct elements in the prefix that
sum to zero, and an empty list if no such prefix exists.
... | get_shortest_prefix_triples_sum_to_zero | triples_sum_to_zero | def triples_sum_to_zero(l: list[int]) -> bool:
"""
triples_sum_to_zero takes a list of integers as an input.
it returns True if there are three distinct elements in the list that
sum to zero, and False otherwise.
>>> triples_sum_to_zero([1, 3, 5, 0])
False
>>> triples_sum_to_zero([1, 3, -2,... |
HumanExtension/38 | def ball_collision(n: int):
"""Imagine a road that's a perfectly straight infinitely long line.
n balls are rolling left to right; simultaneously, a different set of n balls
are rolling right to left. The two sets of balls start out being very far from
each other. All balls move in the same speed. Two... | ball_collision | car_race_collision | def car_race_collision(n: int) -> int:
"""
Imagine a road that's a perfectly straight infinitely long line.
n cars are driving left to right; simultaneously, a different set of n cars
are driving right to left. The two sets of cars start out being very far from
each other. All cars move in the s... |
HumanExtension/39 | def incr_sublist(l: list, start: int, end: int):
"""Return list that the element in the sublist from
`start` (inclusive) to `end` (exclusive) incremented by 1.
>>> incr_until_10([1, 2, 3], 0, 2)
[2, 3, 3]
>>> incr_until_10([5, 3, 5, 2, 3, 3, 9, 0, 123], 3, 7)
[5, 3, 5, 3, 4, 4, 10, 0, 123]""" | incr_sublist | incr_list | def incr_list(l: list[int]) -> list[int]:
"""Return list with elements incremented by 1.
>>> incr_list([1, 2, 3])
[2, 3, 4]
>>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])
[6, 4, 6, 3, 4, 4, 10, 1, 124]
"""
return [e + 1 for e in l]
def incr_sublist(l: list, start: int, end: int):
"""Retu... |
HumanExtension/40 | from typing import List
def triple_sum_to_zero_with_zero(l):
"""triple_sum_to_zero_with_zero takes a list of integers as an input.
it returns True if there are three distinct elements in the list that
sum to zero and one of elements must be zero, and False otherwise.
>>> triple_sum_to_zero_with_zero([... | triple_sum_to_zero_with_zero | pairs_sum_to_zero | from typing import List
def pairs_sum_to_zero(l: List[int]) -> bool:
"""
pairs_sum_to_zero takes a list of integers as an input.
it returns True if there are two distinct elements in the list that
sum to zero, and False otherwise.
>>> pairs_sum_to_zero([1, 3, 5, 0])
False
>>> pairs_sum_to_... |
HumanExtension/41 | def change_base_extension(n: str, base_from: int, base_to: int) -> str:
"""Change numerical base of input number n represented as string from base_from to base_to.
return string representation after the conversion.
base numbers are less than 10.
>>> change_base_extension('22', 3, 2)
'1000'
>>> c... | change_base_extension | change_base | def change_base(x: int, base: int) -> str:
"""Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
>>> change_base(8, 3)
'22'
>>> change_base(8, 2)
'1000'
>>> change_base(7, 2)
'111'
"""
ret = ''
... |
HumanExtension/42 | import math
def equilaternal_triangle_area(a):
"""Given length of a side return area for an equilaternal triangle.
>>> round(equilaternal_triangle_area(5), 2)
10.83""" | equilaternal_triangle_area | triangle_area | import math
def triangle_area(a: int, h: int) -> float:
"""Given length of a side and high return area for a triangle.
>>> triangle_area(5, 3)
7.5
"""
return a * h / 2.0
def equilaternal_triangle_area(a):
"""Given length of a side return area for an equilaternal triangle.
>>> round(equil... |
HumanExtension/43 | def fib2_to_4(n: int):
"""Return the n-th value of sequence defined by the following recurrence relation.
fib2_to_4(0) -> 0
fib2_to_4(1) -> 1
fib2_to_4(n) -> fib4(n) if n is even
fib2_to_4(n) -> fib2_to_4(n-1) + fib2_to_4(n-2) if n is odd
>>> fib2_to_4(5)
8
>>> fib2_to_4(0)
0
>>>... | fib2_to_4 | fib4 | def fib4(n: int) -> int:
"""The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fib4(0) -> 0
fib4(1) -> 0
fib4(2) -> 2
fib4(3) -> 0
fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
Please write a function to efficiently compute the n-... |
HumanExtension/44 | from typing import List
def is_skewed(l: list):
"""Return "positive" if the list l is positive skewed, "negative" if the list l is negative skewed.
Otherwise, return "neutral".
A distribution with negative skew can have its mean greater than the median.
A distribution with positive skew can have its m... | is_skewed | median | from typing import List
def median(l: List[int]) -> float:
"""Return median of elements in the list l.
>>> median([3, 1, 2, 4, 5])
3
>>> median([-10, 4, 6, 1000, 10, 20])
15.0
"""
l = sorted(l)
if len(l) % 2 == 1:
return l[len(l) // 2]
else:
return (l[len(l) // 2 - ... |
HumanExtension/45 | def is_even_palidrome(s: str) -> bool:
"""Checks if the chacters located in the even indices in the
given string is a palindrome.
>>> is_palindrome('')
True
>>> is_palindrome('aba')
True
>>> is_palindrome('acaaa')
True
>>> is_palindrome('zbcd')
False""" | is_even_palidrome | is_palindrome | def is_palindrome(text: str) -> bool:
"""
Checks if given string is a palindrome
>>> is_palindrome('')
True
>>> is_palindrome('aba')
True
>>> is_palindrome('aaaaa')
True
>>> is_palindrome('zbcd')
False
"""
for i in range(len(text)):
if text[i] != text[len(text) - ... |
HumanExtension/46 | def modp4(n: int, p: int) -> int:
"""Return 4^n modulo p (be aware of numerics).
>>> modp4(3, 5)
4
>>> modp4(1101, 101)""" | modp4 | modp | def modp(n: int, p: int) -> int:
"""Return 2^n modulo p (be aware of numerics).
>>> modp(3, 5)
3
>>> modp(1101, 101)
2
>>> modp(0, 101)
1
>>> modp(3, 11)
8
>>> modp(100, 101)
1
"""
ret = 1
for i in range(n):
ret = 2 * ret % p
return ret
def modp4(n: ... |
HumanExtension/47 | def equal(text1: str, text2: str) -> bool:
"""check if the non-vowel characters in text1 and the non-vowel characters in texts is equal or not.
>>> count_vowels('apple', 'pple')
True
>>> count_vowels("pear", "par")
True
>>> count_vowels("test", "text")
False""" | equal | remove_vowels | def remove_vowels(text: str) -> str:
"""
remove_vowels is a function that takes string and returns string without vowels.
>>> remove_vowels('')
''
>>> remove_vowels('abcdef')
'bcdf'
>>> remove_vowels('aaaaa')
''
>>> remove_vowels('aaBAA')
'B'
>>> remove_vowels('zbcd')
'zb... |
HumanExtension/48 | from typing import List
def detect_high_blood_sugar(blood_sugar_graph: list) -> bool:
"""Return True if the symptom of high blood sugar is detected in the blood sugar graph.
High blood sugar rate means that the blood sugar level is above 100.
High blood sugar is detected even if only one high blood sugar ... | detect_high_blood_sugar | below_threshold | from typing import List
def below_threshold(l: List[int], t: int) -> bool:
"""Return True if all numbers in the list l are below threshold t.
>>> below_threshold([1, 2, 4, 10], 100)
True
>>> below_threshold([1, 20, 4, 10], 5)
False
"""
for e in l:
if e >= t:
return Fals... |
HumanExtension/49 | def sum_fib(n: int):
"""Return sum of first n Fibonacci numbers.
You can use this property: sum_{i=1}^{n} F_i = F_{n+2} - 1
>>> sum_fib(8)
54
>>> sum_fib(1)
1
>>> sum_fib(6)
20""" | sum_fib | fib | def fib(n: int) -> int:
"""Return n-th Fibonacci number.
>>> fib(10)
55
>>> fib(1)
1
>>> fib(8)
21
"""
if n == 0:
return 0
if n == 1:
return 1
return fib(n - 1) + fib(n - 2)
def sum_fib(n: int):
"""Return sum of first n Fibonacci numbers.
You can use... |
HumanExtension/50 | def extended_correct_bracketing(brackets: str) -> bool:
"""brackets is a string of "<", "(", ">" and ")".
There is opening bracket "<" and "(" and closing bracket ">", ")".
return True if every opening bracket has a corresponding closing bracket.
Note that it is ok not to match the shape between opening... | extended_correct_bracketing | correct_bracketing | def correct_bracketing(brackets: str) -> bool:
"""brackets is a string of "<" and ">".
return True if every opening bracket has a corresponding closing bracket.
>>> correct_bracketing('<')
False
>>> correct_bracketing('<>')
True
>>> correct_bracketing('<<><>>')
True
>>> correct_brac... |
HumanExtension/51 | def monotonic_2d(arr: list[list[int]]) -> bool:
"""Check if all rows and columns in the given array is monotonimally
increasing or decreasing.
Assume that the given array is rectangular.
>>> monotonic_2d([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
True
>>> monotonic_2d([[3, 5, 8], [2, 6, 9], [4, 7, 10]])... | monotonic_2d | monotonic | def monotonic(l: list[int]) -> bool:
"""Return True is list elements are monotonically increasing or decreasing.
>>> monotonic([1, 2, 4, 20])
True
>>> monotonic([1, 20, 4, 10])
False
>>> monotonic([4, 1, 0, -10])
True
"""
if l == sorted(l) or l == sorted(l, reverse=True):
ret... |
HumanExtension/52 | def get_exponent_of_largest_prime_factor(n: int):
"""Return the exponent of largest prime factor after factorizing n. Assume n > 1 and is not a prime.
>>> get_exponent_of_largest_prime_factor(13195) # 13195 = 5 * 7 * 13 * 29
1
>>> get_exponent_of_largest_prime_factor(2048) # 2048 = 2^11
11""" | get_exponent_of_largest_prime_factor | largest_prime_factor | def largest_prime_factor(n: int) -> int:
"""Return the largest prime factor of n. Assume n > 1 and is not a prime.
>>> largest_prime_factor(13195)
29
>>> largest_prime_factor(2048)
2
"""
def is_prime(k):
if k < 2:
return False
for i in range(2, k - 1):
... |
HumanExtension/53 | def second_derivative(xs: list[int]) -> list[int]:
"""xs represent coefficients of a polynomial.
xs[0] + xs[1] * x + xs[2] * x^2 + ....
Return second derivative of this polynomial in the same form.
>>> derivative([3, 1, 2, 4, 5])
[4, 24, 60]
>>> derivative([1, 2, 3])
[6]""" | second_derivative | derivative | def derivative(xs: list[int]) -> list[int]:
"""xs represent coefficients of a polynomial.
xs[0] + xs[1] * x + xs[2] * x^2 + ....
Return derivative of this polynomial in the same form.
>>> derivative([3, 1, 2, 4, 5])
[1, 4, 12, 20]
>>> derivative([1, 2, 3])
[2, 6]
"""
return [i * x f... |
HumanExtension/54 | def is_vowel_enough(s: str) -> bool:
"""Check if the given string contains at least 30% of vowels.
>>> is_vowel_enough("abcde")
True
>>> is_vowel_enough("abc")
False""" | is_vowel_enough | vowels_count | def vowels_count(s: str) -> int:
"""Write a function vowels_count which takes a string representing
a word as input and returns the number of vowels in the string.
Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
vowel, but only when it is at the end of the given word.
Example:
... |
HumanExtension/55 | def is_circular_same(x: int, y: int) -> bool:
"""Return True if x and y are circularly same, False otherwise.
Circulary same means that any of circular shift of x is equal
to any of circular shift of y.
>>> is_circular_same(12, 21)
True
>>> is_circular_same(354, 453)
False""" | is_circular_same | circular_shift | def circular_shift(x: int, shift: int) -> str:
"""Circular shift the digits of the integer x, shift the digits right by shift
and return the result as a string.
If shift > number of digits, return digits reversed.
>>> circular_shift(12, 1)
'21'
>>> circular_shift(12, 2)
'12'
"""
s = ... |
HumanExtension/56 | from typing import List
def sort_by_sum_upper_character_ascii(s: List[str]) -> List[str]:
"""Sort string based on the custom key defined as the sum of the upper
characters only' ASCII codes. The order of string should be preserved in
case of a tie.
Examples:
sort_by_digitsum(["", "abAB", ... | sort_by_sum_upper_character_ascii | digitSum | from typing import List
def digitSum(s: str) -> int:
"""Task
Write a function that takes a string as input and returns the sum of the upper characters only'
ASCII codes.
Examples:
>>> digitSum('')
0
>>> digitSum('abAB')
131
>>> digitSum('abcCd')
67
>>> digitSum('helloE')
... |
HumanExtension/57 | def happy_fruit_distribution(s: str, n: int) -> int:
"""In this task, you will be given a string that represents a number of apples and oranges
that are distributed in a basket of fruit this basket contains
apples, oranges, and mango fruits. Given the string that represents the total number of
the orang... | happy_fruit_distribution | fruit_distribution | def fruit_distribution(s: str, n: int) -> int:
"""
In this task, you will be given a string that represents a number of apples and oranges
that are distributed in a basket of fruit this basket contains
apples, oranges, and mango fruits. Given the string that represents the total number of
the orange... |
HumanExtension/58 | from typing import List
def pluck_and_select_larger_branch(arr: List[int]) -> List[int]:
"""Given a branch represented as a list of non-negative integers,
plucking (and then cutting) a node will result in the branch
being split into two (or fewer) seperate branches.
Among the divided branches,
... | pluck_and_select_larger_branch | pluck | from typing import List
def pluck(arr: List[int]) -> List[int]:
"""
"Given an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the... |
HumanExtension/59 | from typing import List
def remove_integers_with_higher_frequency(lst: List[int]) -> List[int]:
"""Return a list obtained from the given non-empty list of positive integers
by removing all integers whose frequency is greater than or equal to the integer itself.
Ensure that the order of elements betwe... | remove_integers_with_higher_frequency | search | from typing import List
def search(lst: List[int]) -> int:
"""
You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it... |
HumanExtension/60 | def extended_strange_sort_list(lst: list[int]) -> list[int]:
"""Given list of integers, return list in strange order.
Extended strange sorting, is when you start with the minimum value,
then maximum of the remaining integers, then maximum and minimum and so on.
Examples:
>>> extended_strange_so... | extended_strange_sort_list | strange_sort_list | def strange_sort_list(lst: list[int]) -> list[int]:
"""
Given list of integers, return list in strange order.
Strange sorting, is when you start with the minimum value,
then maximum of the remaining integers, then minimum and so on.
Examples:
>>> strange_sort_list([1, 2, 3, 4])
[1, 4, 3, 2]... |
HumanExtension/61 | from typing import List
def sum_of_triangle_areas(triangles: List[List[int]]) -> float:
"""Return the sum of the areas of all given triangles.
Each triangle is given as a list of the lengths of its three sides.
If the input includes any invalid triangles, return -1.
Example:
>>> sum_of_triangle_ar... | sum_of_triangle_areas | triangle_area | from typing import List
def triangle_area(a: int, b: int, c: int) -> float:
"""
Given the lengths of the three sides of a triangle. Return the area of
the triangle rounded to 2 decimal points if the three sides form a valid triangle.
Otherwise return -1
Three sides make a valid triangle when the s... |
HumanExtension/62 | from typing import List
def is_palindrome(q: List[int]) -> bool:
"""Write a function that determines whether a given list is a palindrome.
Example:
>>> is_palindrome([1, 2])
False
>>> is_palindrome([1, 2, 1])
True""" | is_palindrome | will_it_fly | from typing import List
def will_it_fly(q: List[int], w: int) -> bool:
"""
Write a function that returns True if the object q will fly, and False otherwise.
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.
... |
HumanExtension/63 | from typing import List
def is_palindrome(arr: List[int]) -> bool:
"""Write a function that determines whether a given list is a palindrome.
Example:
>>> is_palindrome([1, 2])
False
>>> is_palindrome([1, 2, 1])
True""" | is_palindrome | smallest_change | from typing import List
def smallest_change(arr: List[int]) -> int:
"""
Given an array arr of integers, find the minimum number of elements that
need to be changed to make the array palindromic. A palindromic array is an array that
is read the same backwards and forwards. In one change, you can change... |
HumanExtension/64 | from typing import List
def total_match_three(lst1: List[str], lst2: List[str], lst3: List[str]) -> List[str]:
"""Return the list of strings with the smallest total number of characters
among the three string lists.
If some lists have the same total number of characters,
return the list that appears e... | total_match_three | total_match | from typing import List
def total_match(lst1: List[str], lst2: List[str]) -> List[str]:
"""
Write a function that accepts two lists of strings and returns the list that has
total number of chars in the all strings of the list less than the other list.
if the two lists have the same number of chars, r... |
HumanExtension/65 | from typing import List
def sum_of_multiply_primes(nums: List[int]) -> int:
"""Return the sum of numbers among the given numbers
that can be expressed as the product of three prime numbers.
Examples:
>>> sum_of_multiply_prime([30, 42])
72
>>> sum_of_multiply_prime([30, 35, 40, 42])
72""" | sum_of_multiply_primes | is_multiply_prime | from typing import List
def is_multiply_prime(a: int) -> bool:
"""Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise.
Knowing that (a) is less then 100.
Example:
>>> is_multiply_prime(30)
True
30 = 2 * 3 * 5
"""
def ... |
HumanExtension/66 | def log(n: int, x: int) -> int:
"""Implement a function that calculates the value log_n(x)
and returns it if it is an integer, otherwise returns -1.
Examples:
>>> log(2, 8)
3
>>> log(2, 3)
-1""" | log | is_simple_power | def is_simple_power(x: int, n: int) -> bool:
"""Your task is to write a function that returns true if a number x is a simple
power of n and false in other cases.
x is a simple power of n if n**int=x
For example:
>>> is_simple_power(1, 4)
True
>>> is_simple_power(2, 2)
True
>>> is_sim... |
HumanExtension/67 | from typing import List
def num_cube_pairs(nums1: List[int], nums2: List[int]) -> int:
"""Find the number of pairs (n1, n2) where n1 + n2 equals to
a cube of some integer number. (n1 in nums1 and n2 in nums2)
Examples:
>>> num_cube_pairs([1, 2, 3], [1, 2, 3])
0
>>> num_cube_pairs([1, 2, 3], [5... | num_cube_pairs | iscube | from typing import List
def iscube(a: int) -> bool:
"""
Write a function that takes an integer a and returns True
if this ingeger is a cube of some integer number.
Note: you may assume the input is always valid.
Examples:
>>> iscube(1)
True
>>> iscube(2)
False
>>> iscube(-1)
... |
HumanExtension/68 | def num_not_hex_primes(num: str) -> int:
"""Count the number of hexadecimal digits in the given hexadecimal string
that are not prime.
Examples:
>>> num_not_hex_primes('AB')
1
>>> num_not_hex_primes('1077E')
3""" | num_not_hex_primes | hex_key | def hex_key(num: str) -> int:
"""You have been tasked to write a function that receives
a hexadecimal number as a string and counts the number of hexadecimal
digits that are primes (prime number, or a prime, is a natural number
greater than 1 that is not a product of two smaller natural numbers).
He... |
HumanExtension/69 | def num_1s_in_binary(decimal: int) -> int:
"""Return the count of digit 1 in the binary representation of the given number.
Examples:
>>> num_1s_in_binary(15)
4
>>> num_1s_in_binary(32)
1""" | num_1s_in_binary | decimal_to_binary | def decimal_to_binary(decimal: int) -> str:
"""You will be given a number in decimal form and your task is to convert it to
binary format. The function should return a string, with each character representing a binary
number. Each character in the string will be '0' or '1'.
There will be an extra coupl... |
HumanExtension/70 | def num_happy_sentences(d: str) -> int:
"""Implement a function that, given a document d where sentences are concatenated
with newlines as separators, returns the count of happy sentences.
Examples:
>>> num_happy_sentences('a
aa')
0
>>> num_happy_sentences('abcd
aabb
... | num_happy_sentences | is_happy | def is_happy(s: str) -> bool:
"""You are given a string s.
Your task is to check if the string is happy or not.
A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
For example:
>>> is_happy('a')
False
>>> is_happy('aa')
False
>>> is_happy('abcd'... |
HumanExtension/71 | from typing import List
def num_students_above_C(grades: List[float]) -> int:
"""Given a list of students' GPAs, return the number of students
who will receive a grade of B- or higher.
Examples:
>>> num_students_above_C([4.0, 3, 1.7, 2, 3.5])
3""" | num_students_above_C | numerical_letter_grade | from typing import List
def numerical_letter_grade(grades: List[float]) -> List[str]:
"""It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
S... |
HumanExtension/72 | from typing import List
def is_concat_length_prime(strings: List[str]) -> bool:
"""Implement a function that checks whether the length of the string
obtained by concatenating the given strings is a prime number.
Examples:
>>> is_concat_length_prime(['He', 'llo'])
True
>>> is_concat_length_prim... | is_concat_length_prime | prime_length | from typing import List
def prime_length(string: str) -> bool:
"""Write a function that takes a string and returns True if the string
length is a prime number or False otherwise
Examples
>>> prime_length('Hello')
True
>>> prime_length('abcdcba')
True
>>> prime_length('kittens')
Tru... |
HumanExtension/73 | def non_starts_or_ends_with_one_count(n: int) -> int:
"""Return the count of n-digit positive integers
that do not start or end with 1.
Examples:
>>> non_starts_or_ends_with_one_count(1)
8
>>> non_starts_or_ends_with_one_count(2)
72""" | non_starts_or_ends_with_one_count | starts_one_ends | def starts_one_ends(n: int) -> int:
"""
Given a positive integer n, return the count of the numbers of n-digit
positive integers that start or end with 1.
"""
if n == 1:
return 1
return 18 * 10 ** (n - 2)
def non_starts_or_ends_with_one_count(n: int) -> int:
"""
Return the coun... |
HumanExtension/74 | def sum_digits_to_binary(string: str) -> str:
"""Calculate the sum of numerical characters in the given string
and return it as a binary representation.
Examples:
>>> sum_digits_to_binary('10a00')
'1'
>>> sum_digits_to_binary('a1b5c0d')
'110'""" | sum_digits_to_binary | solve | def solve(N: int) -> str:
"""Given a positive integer N, return the total sum of its digits in binary.
Example
>>> solve(1000)
'1'
>>> solve(150)
'110'
>>> solve(147)
'1100'
Variables:
@N integer
Constraints: 0 ≤ N ≤ 10000.
Output:
a string of bina... |
HumanExtension/75 | from typing import List
def sum_even_second_digits(number: int) -> int:
"""Return the sum of even numbers among every second digit in the given number.
Examples:
>>> sum_even_second_digits(4267)
2""" | sum_even_second_digits | add | from typing import List
def add(lst: List[int]) -> int:
"""Given a non-empty list of integers lst. add the even elements that are at odd indices..
Examples:
>>> add([4, 2, 6, 7])
2
"""
return sum([lst[i] for i in range(1, len(lst), 2) if lst[i] % 2 == 0])
def sum_even_second_digits(number:... |
HumanExtension/76 | from typing import List
def sort_and_concatenate_strings(strings: List[str]) -> str:
"""Implement a function that takes a list of strings,
sorts each string in ascending order,
and then concatenates them using a space as the separator.
Examples:
>>> sort_and_concatenate_strings(['hello'])
'ehl... | sort_and_concatenate_strings | anti_shuffle | from typing import List
def anti_shuffle(s: str) -> str:
"""
Write a function that takes a string and returns an ordered version of it.
Ordered version of string, is a string where all words (separated by space)
are replaced by a new word where all the characters arranged in
ascending order based ... |
HumanExtension/77 | from typing import List, Tuple
def count_integer_in_nested_lists(lst: List[List[int]], x: int) -> int:
"""Implement a function that counts how many times an integer x appears
in a list of lists of integers.
Examples:
>>> count_integer_in_nested_lists([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, ... | count_integer_in_nested_lists | get_row | from typing import List, Tuple
def get_row(lst: List[List[int]], x: int) -> List[Tuple[int, int]]:
"""
You are given a 2 dimensional data, as a nested lists,
which is similar to matrix, however, unlike matrices,
each row may contain a different number of columns.
Given lst, and integer x, find int... |
HumanExtension/78 | from typing import List
def count_elements_in_original_position(array: List[int]) -> int:
"""Given an integer array, return the count of elements that remain in their original positions
when the array is sorted in ascending order if the sum of the first and last elements is odd,
or in descending order if ... | count_elements_in_original_position | sort_array | from typing import List
def sort_array(array: List[int]) -> List[int]:
"""
Given an array of non-negative integers, return a copy of the given array after sorting,
you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
or sort it in descending order i... |
HumanExtension/79 | def is_start_of_end_with_x_after_encryption(string: str) -> bool:
"""Implement a function that determines whether a given string starts or ends with 'x' after encryption.
Examples:
>>> is_start_of_end_with_x_after_encryption('gf')
False
>>> is_start_of_end_with_x_after_encryption('et')
True""" | is_start_of_end_with_x_after_encryption | encrypt | def encrypt(s: str) -> str:
"""Create a function encrypt that takes a string as an argument and
returns a string encrypted with the alphabet being rotated.
The alphabet should be rotated in a manner such that the letters
shift down by two multiplied to two places.
For example:
>>> encrypt('hi')
... |
HumanExtension/80 | from typing import List, Optional
def remove_second_smallest(lst: List[int]) -> List[int]:
"""Return the list obtained by removing the second smallest value(s) from the given integer list.
If there is no such value, return the original integer list.
Examples:
>>> remove_second_smallest([1, 2, 3, 4, 5]... | remove_second_smallest | next_smallest | from typing import List, Optional
def next_smallest(lst: List[int]) -> Optional[int]:
"""
You are given a list of integers.
Write a function next_smallest() that returns the 2nd smallest element of the list.
Return None if there is no such element.
>>> next_smallest([1, 2, 3, 4, 5])
2
>>> ... |
HumanExtension/81 | def count_non_boredoms(string: str) -> int:
"""Return the count of non-boredoms in the given string.
Here, boredom refers to sentences starting with the word 'I',
and sentences are separated by '.', '?', or '!'.
Note that empty sentences are not counted.
Examples:
>>> is_bored('Hello world')
... | count_non_boredoms | is_bored | def is_bored(S: str) -> int:
"""
You'll be given a string of words, and your task is to count the number
of boredoms. A boredom is a sentence that starts with the word "I".
Sentences are delimited by '.', '?' or '!'.
For example:
>>> is_bored('Hello world')
0
>>> is_bored('The sky is bl... |
HumanExtension/82 | from typing import List
def count_integer_sum_cases(xs: List[float], ys: List[float], zs: List[float]) -> int:
"""Return the count of cases where,
by selecting one element from each of the three given lists,
if all three selected elements are integers
and one element can be expressed as the sum of the... | count_integer_sum_cases | any_int | from typing import List
def any_int(x: float, y: float, z: float) -> bool:
"""
Create a function that takes 3 numbers.
Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
Returns false in any other cases.
Examples
>>> any_int(5, 2, 7)
Tru... |
HumanExtension/83 | def count_changed_alphabet_characters(message: str) -> int:
"""Return the count of characters in the given string
that change their alphabet after encoding.
Examples:
>>> count_changed_alphabet_characters('test')
1
>>> count_changed_alphabet_characters('This is a message')
6""" | count_changed_alphabet_characters | encode | def encode(message: str) -> str:
"""
Write a function that takes a message, and encodes in such a
way that it swaps case of all letters, replaces all vowels in
the message with the letter that appears 2 places ahead of that
vowel in the english alphabet.
Assume only letters.
Examples:
>... |
HumanExtension/84 | from typing import List
def sum_of_digits_of_largest_prime_substring(integer: str) -> int:
"""Given a string representing non-negative integers,
return the sum of digits of the largest prime number among all the contiguous substrings of length 3.
Examples:
>>> sum_of_digits_of_largest_prime_substring(... | sum_of_digits_of_largest_prime_substring | skjkasdkd | from typing import List
def skjkasdkd(lst: List[int]) -> int:
"""You are given a list of integers.
You need to find the largest prime value and return the sum of its digits.
Examples:
>>> skjkasdkd([0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3])
10
>>> skjkasdkd([1,... |
HumanExtension/85 | from typing import Dict, List
def check_case_consistency(lst: List[str]) -> bool:
"""Implement a function that returns true if all the strings in the given list
are either all lowercase or all uppercase, and false otherwise.
Examples:
>>> check_case_consistency(['Name', 'Age', 'City'])
False
>... | check_case_consistency | check_dict_case | from typing import Dict, List
def check_dict_case(dict: Dict[str, str]) -> bool:
"""
Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Examples:
>>> ... |
HumanExtension/86 | from typing import List
def sum_of_primes_smaller_than(number: int) -> int:
"""Calculate the sum of all prime numbers smaller than the given number.
Examples:
>>> sum_of_primes_smaller_than(5)
5
>>> sum_of_primes_smaller_than(11)
17""" | sum_of_primes_smaller_than | count_up_to | from typing import List
def count_up_to(n: int) -> List[int]:
"""Implement a function that takes an non-negative integer and returns an array of the first n
integers that are prime numbers and less than n.
for example:
>>> count_up_to(5)
[2, 3]
>>> count_up_to(11)
[2, 3, 5, 7]
>>> coun... |
HumanExtension/87 | def calculate_sum_or_difference_based_on_product(a: int, b: int) -> int:
"""Implement an efficient function that returns the sum of the two numbers
if their product is even, and the difference of the two numbers if their product is odd.
Examples:
>>> calculate_sum_or_difference_based_on_product(3, 4)
... | calculate_sum_or_difference_based_on_product | multiply | def multiply(a: int, b: int) -> int:
"""Complete the function that takes two integers and returns
the product of their unit digits.
Assume the input is always valid.
Examples:
>>> multiply(148, 412)
16
>>> multiply(19, 28)
72
>>> multiply(2020, 1851)
0
>>> multiply(14, -15)
... |
HumanExtension/88 | from typing import List
def find_string_with_highest_uppercase_vowel_count_at_even_indices(strings: List[str]) -> str:
"""Return the string from the given list of strings
that has the highest count of uppercase vowels at even indices.
In the case of having the same count, return the string that is located... | find_string_with_highest_uppercase_vowel_count_at_even_indices | count_upper | from typing import List
def count_upper(s: str) -> int:
"""
Given a string s, count the number of uppercase vowels in even indices.
For example:
>>> count_upper('aBCdEf')
1
>>> count_upper('abcdefg')
0
>>> count_upper('dBBE')
0
"""
count = 0
for i in range(0, len(s), 2... |
HumanExtension/89 | def find_largest_rearranged_decimal_number(number: str) -> int:
"""Given a positive decimal number represented as a string,
return the rounded value of the largest decimal number that can be obtained
by rearranging the order of digits, excluding the decimal point (.).
Examples:
>>> find_largest_rear... | find_largest_rearranged_decimal_number | closest_integer | def closest_integer(value: str) -> int:
"""
Create a function that takes a value (string) representing a number
and returns the closest integer to it. If the number is equidistant
from two integers, round it away from zero.
Examples
>>> closest_integer('10')
10
>>> closest_integer('15.3... |
HumanExtension/90 | from typing import List
def get_last_elements_of_piles(numbers: List[int]) -> List[int]:
"""Given a list of positive integers,
return a list of the last elements of the piles corresponding to each integer.
Examples:
>>> get_last_elements_of_piles([2, 3])
[4, 7]""" | get_last_elements_of_piles | make_a_pile | from typing import List
def make_a_pile(n: int) -> List[int]:
"""
Given a positive integer n, you have to make a pile of n levels of stones.
The first level has n stones.
The number of stones in the next level is:
- the next odd number if n is odd.
- the next even number if n is even.
... |
HumanExtension/91 | from typing import List
def words_string_lower(s: str) -> List[str]:
"""You will be given a string of words separated by commas or spaces. Your task is
to split the lowercased version of the string into words and return an array of the words.
For example:
>>> words_string_lower('Hi, my name is Jo... | words_string_lower | words_string | from typing import List
def words_string(s: str) -> List[str]:
"""
You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words.
For example:
>>> words_string('Hi, my name is John')
['Hi', 'my', 'name', 'is', '... |
HumanExtension/92 | def choose_num_two_intervals(x: int, y: int, z: int, w: int) -> int:
"""This function takes two positive numbers x, y, z, and w and returns the
biggest even integer number that is in the ranges [x, y] and [z, w] inclusive.
If there's no such number, then the function should return -1.
For example:
... | choose_num_two_intervals | choose_num | def choose_num(x: int, y: int) -> int:
"""This function takes two positive numbers x and y and returns the
biggest even integer number that is in the range [x, y] inclusive. If
there's no such number, then the function should return -1.
For example:
>>> choose_num(12, 15)
14
>>> choose_num(... |
HumanExtension/93 | from typing import Union
def biggest_multiplier_of_two(n: int, m: int) -> int:
"""You are given two positive integers n and m, and your task is to compute the
the biggest multiplier of 2 among the numbers that are smaller than
the average of [n, m] rounded to the nearest integer.
If n is greater than ... | biggest_multiplier_of_two | rounded_avg | from typing import Union
def rounded_avg(n: int, m: int) -> Union[str, int]:
"""You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater... |
HumanExtension/94 | from typing import List
def unique_sum_of_digits(x: List[int]) -> List[int]:
"""Given a list of positive integers x. Compute a sorted list of all
elements that hasn't any even digit, and convert each element into the
sum of digits of the number.
For example:
>>> unique_sum_of_digits([15, 33, ... | unique_sum_of_digits | unique_digits | from typing import List
def unique_digits(x: List[int]) -> List[int]:
"""Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order.
For example:
>>> unique_digits([15, 33, 1422, 1])
[1, 15, 3... |
HumanExtension/95 | from typing import List
def by_length_csv(arr: List[int]) -> str:
"""Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Ni... | by_length_csv | by_length | from typing import List
def by_length(arr: List[int]) -> List[str]:
"""
Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eigh... |
HumanExtension/96 | from typing import List
def sorted_f(n: int) -> List[int]:
"""Implement the function f that takes n as a parameter,
and compute a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
Sort the ... | sorted_f | f | from typing import List
def f(n: int) -> List[int]:
"""Implement the function f that takes n as a parameter,
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
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of... |
HumanExtension/97 | from typing import Tuple
def even_odd_palindrome_interval(m: int, n: int) -> Tuple[int, int]:
"""Given two positive integers m and n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(m+1, n), inclusive.
If m is greater than n, return (0, 0).
Exampl... | even_odd_palindrome_interval | even_odd_palindrome | from typing import Tuple
def even_odd_palindrome(n: int) -> Tuple[int, int]:
"""
Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
Example 1:
>>> even_odd_palindrome(3)
(1, 2)
Explanation:
... |
HumanExtension/98 | from typing import List
def count_nums_union(arr1: List[int], arr2: List[int]) -> int:
"""Write a function count_nums_union which takes two arrays of integers and returns
the number of elements which has a sum of digits > 0 from union of the arrays (without repetition of elements).
If a number is negative... | count_nums_union | count_nums | from typing import List
def count_nums(arr: List[int]) -> int:
"""
Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2... |
HumanExtension/99 | from typing import List
def move_one_ball_any_order(arr: List[int]) -> bool:
"""We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing or non-increasing order
... | move_one_ball_any_order | move_one_ball | from typing import List
def move_one_ball(arr: List[int]) -> bool:
"""We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the followi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.