task_id
stringlengths
36
40
entry_point
stringlengths
1
30
prompt
stringlengths
116
1.98k
suffix
stringlengths
0
837
canonical_solution
stringlengths
6
859
test
stringlengths
117
1.8k
MultiLineInfilling/HumanEval/25/L7_L8
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i
if n > 1: fact.append(n) return fact
else: i += 1
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L7_L10
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i
fact.append(n) return fact
else: i += 1 if n > 1:
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L7_L11
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i
return fact
else: i += 1 if n > 1: fact.append(n)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L7_L12
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i
else: i += 1 if n > 1: fact.append(n) return fact
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L8_L8
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else:
if n > 1: fact.append(n) return fact
i += 1
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L8_L10
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else:
fact.append(n) return fact
i += 1 if n > 1:
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L8_L11
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else:
return fact
i += 1 if n > 1: fact.append(n)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L8_L12
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else:
i += 1 if n > 1: fact.append(n) return fact
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L10_L10
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else: i += 1
fact.append(n) return fact
if n > 1:
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L10_L11
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else: i += 1
return fact
if n > 1: fact.append(n)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L10_L12
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else: i += 1
if n > 1: fact.append(n) return fact
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L11_L11
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else: i += 1 if n > 1:
return fact
fact.append(n)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L11_L12
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else: i += 1 if n > 1:
fact.append(n) return fact
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/25/L12_L12
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 of all factors >>> factorize(8) [2, 2, 2] >>> factorize(25) [5, 5] >>> factorize(70) [2, 5, 7] """ import math fact = [] i = 2 while i <= int(math.sqrt(n) + 1): if n % i == 0: fact.append(i) n //= i else: i += 1 if n > 1: fact.append(n)
return fact
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate(2) == [2] assert candidate(4) == [2, 2] assert candidate(8) == [2, 2, 2] assert candidate(3 * 19) == [3, 19] assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19] assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19] assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19] assert candidate(3 * 2 * 3) == [2, 3, 3]
MultiLineInfilling/HumanEval/26/L0_L0
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] """
c = collections.Counter(numbers) return [n for n in numbers if c[n] <= 1]
import collections
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]
MultiLineInfilling/HumanEval/26/L0_L1
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] """
return [n for n in numbers if c[n] <= 1]
import collections c = collections.Counter(numbers)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]
MultiLineInfilling/HumanEval/26/L0_L2
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 = collections.Counter(numbers) return [n for n in numbers if c[n] <= 1]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]
MultiLineInfilling/HumanEval/26/L1_L1
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
return [n for n in numbers if c[n] <= 1]
c = collections.Counter(numbers)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]
MultiLineInfilling/HumanEval/26/L1_L2
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 = collections.Counter(numbers) return [n for n in numbers if c[n] <= 1]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]
MultiLineInfilling/HumanEval/26/L2_L2
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 = collections.Counter(numbers)
return [n for n in numbers if c[n] <= 1]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == [] assert candidate([1, 2, 3, 4]) == [1, 2, 3, 4] assert candidate([1, 2, 3, 2, 4, 3, 5]) == [1, 4, 5]
MultiLineInfilling/HumanEval/27/L0_L0
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()
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate('') == '' assert candidate('Hello!') == 'hELLO!' assert candidate('These violent delights have violent ends') == 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'
MultiLineInfilling/HumanEval/28/L0_L0
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)
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([]) == '' assert candidate(['x', 'y', 'z']) == 'xyz' assert candidate(['x', 'y', 'z', 'w', 'k']) == 'xyzwk'
MultiLineInfilling/HumanEval/29/L0_L0
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'] """
return [x for x in strings if x.startswith(prefix)]
METADATA = { 'author': 'jt', 'dataset': 'test' } def check(candidate): assert candidate([], 'john') == [] assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx']
MultiLineInfilling/HumanEval/30/L0_L0
get_positive
def get_positive(l: list): """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]
METADATA = {} def check(candidate): assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6] assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1] assert candidate([-1, -2]) == [] assert candidate([]) == []
MultiLineInfilling/HumanEval/31/L0_L0
is_prime
def is_prime(n): """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 """
return False for k in range(2, n - 1): if n % k == 0: return False return True
if n < 2:
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L0_L1
is_prime
def is_prime(n): """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 """
for k in range(2, n - 1): if n % k == 0: return False return True
if n < 2: return False
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L0_L2
is_prime
def is_prime(n): """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 """
if n % k == 0: return False return True
if n < 2: return False for k in range(2, n - 1):
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L0_L3
is_prime
def is_prime(n): """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 """
return False return True
if n < 2: return False for k in range(2, n - 1): if n % k == 0:
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L0_L4
is_prime
def is_prime(n): """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 """
return True
if n < 2: return False for k in range(2, n - 1): if n % k == 0: return False
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L0_L5
is_prime
def is_prime(n): """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 """
if n < 2: return False for k in range(2, n - 1): if n % k == 0: return False return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L1_L1
is_prime
def is_prime(n): """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 """ if n < 2:
for k in range(2, n - 1): if n % k == 0: return False return True
return False
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L1_L2
is_prime
def is_prime(n): """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 """ if n < 2:
if n % k == 0: return False return True
return False for k in range(2, n - 1):
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L1_L3
is_prime
def is_prime(n): """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 """ if n < 2:
return False return True
return False for k in range(2, n - 1): if n % k == 0:
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L1_L4
is_prime
def is_prime(n): """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 """ if n < 2:
return True
return False for k in range(2, n - 1): if n % k == 0: return False
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L1_L5
is_prime
def is_prime(n): """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 """ if n < 2:
return False for k in range(2, n - 1): if n % k == 0: return False return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L2_L2
is_prime
def is_prime(n): """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 """ if n < 2: return False
if n % k == 0: return False return True
for k in range(2, n - 1):
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L2_L3
is_prime
def is_prime(n): """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 """ if n < 2: return False
return False return True
for k in range(2, n - 1): if n % k == 0:
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L2_L4
is_prime
def is_prime(n): """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 """ if n < 2: return False
return True
for k in range(2, n - 1): if n % k == 0: return False
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L2_L5
is_prime
def is_prime(n): """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 """ if n < 2: return False
for k in range(2, n - 1): if n % k == 0: return False return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L3_L3
is_prime
def is_prime(n): """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 """ if n < 2: return False for k in range(2, n - 1):
return False return True
if n % k == 0:
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L3_L4
is_prime
def is_prime(n): """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 """ if n < 2: return False for k in range(2, n - 1):
return True
if n % k == 0: return False
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L3_L5
is_prime
def is_prime(n): """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 """ if n < 2: return False for k in range(2, n - 1):
if n % k == 0: return False return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L4_L4
is_prime
def is_prime(n): """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 """ if n < 2: return False for k in range(2, n - 1): if n % k == 0:
return True
return False
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L4_L5
is_prime
def is_prime(n): """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 """ if n < 2: return False for k in range(2, n - 1): if n % k == 0:
return False return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/31/L5_L5
is_prime
def is_prime(n): """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 """ if n < 2: return False for k in range(2, n - 1): if n % k == 0: return False
return True
METADATA = {} def check(candidate): assert candidate(6) == False assert candidate(101) == True assert candidate(11) == True assert candidate(13441) == True assert candidate(61) == True assert candidate(4) == False assert candidate(1) == False assert candidate(5) == True assert candidate(11) == True assert candidate(17) == True assert candidate(5 * 17) == False assert candidate(11 * 7) == False assert candidate(13441 * 19) == False
MultiLineInfilling/HumanEval/32/L0_L0
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin, end = -1., 1.
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L1
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L2
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L3
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L4
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L5
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L6
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
begin = center else: end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L7
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
else: end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L8
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
end = center return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L9
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
return begin
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L0_L10
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """
begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L1
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
while poly(xs, begin) * poly(xs, end) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L2
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L3
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L4
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L5
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L6
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
begin = center else: end = center return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L7
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
else: end = center return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L8
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
end = center return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L9
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
return begin
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L1_L10
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1.
while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L2
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin *= 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L3
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin *= 2.0 end *= 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L4
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L5
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L6
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
begin = center else: end = center return begin
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L7
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
else: end = center return begin
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L8
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
end = center return begin
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L9
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
return begin
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L2_L10
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0:
begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L3
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
end *= 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L4
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
end *= 2.0 while end - begin > 1e-10:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L5
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L6
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
begin = center else: end = center return begin
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L7
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
else: end = center return begin
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L8
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
end = center return begin
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L9
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
return begin
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L3_L10
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0
end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L4_L4
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
while end - begin > 1e-10:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L4_L5
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
while end - begin > 1e-10: center = (begin + end) / 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L4_L6
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
begin = center else: end = center return begin
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L4_L7
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
else: end = center return begin
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L4_L8
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
end = center return begin
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L4_L9
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
return begin
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L4_L10
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0
while end - begin > 1e-10: center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L5_L5
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
center = (begin + end) / 2.0
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L5_L6
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
begin = center else: end = center return begin
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L5_L7
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
else: end = center return begin
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L5_L8
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
end = center return begin
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L5_L9
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
return begin
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L5_L10
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10:
center = (begin + end) / 2.0 if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center return begin
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L6_L6
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
begin = center else: end = center return begin
if poly(xs, center) * poly(xs, begin) > 0:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L6_L7
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
else: end = center return begin
if poly(xs, center) * poly(xs, begin) > 0: begin = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L6_L8
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
end = center return begin
if poly(xs, center) * poly(xs, begin) > 0: begin = center else:
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4
MultiLineInfilling/HumanEval/32/L6_L9
find_zero
import math def poly(xs: list, x: float): """ Evaluates polynomial with coefficients xs at point x. return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n """ return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)]) def find_zero(xs: list): """ xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. >>> round(find_zero([1, 2]), 2) # f(x) = 1 + 2x -0.5 >>> round(find_zero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3 1.0 """ begin, end = -1., 1. while poly(xs, begin) * poly(xs, end) > 0: begin *= 2.0 end *= 2.0 while end - begin > 1e-10: center = (begin + end) / 2.0
return begin
if poly(xs, center) * poly(xs, begin) > 0: begin = center else: end = center
METADATA = {} def check(candidate): import math import random rng = random.Random(42) import copy for _ in range(100): ncoeff = 2 * rng.randint(1, 4) coeffs = [] for _ in range(ncoeff): coeff = rng.randint(-10, 10) if coeff == 0: coeff = 1 coeffs.append(coeff) solution = candidate(copy.deepcopy(coeffs)) assert math.fabs(poly(coeffs, solution)) < 1e-4