Skip to content

Latest commit

 

History

History
253 lines (250 loc) · 6.81 KB

File metadata and controls

253 lines (250 loc) · 6.81 KB

Results of Code LLama 34B on HumanEval/103

Date: 01 September, 2023
Model: codellama-34b-instruct
Temperature: 0.2
Passing runs: 0
Total runs: 10
Success rate: 0%

Prompt

def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m). 
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """

The above is an incomplete Python code fragment. Return the complete and correct code with no additional text.

Correct solution

def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m). 
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """if m < n:
        return -1
    summation = 0
    for i in range(n, m+1):
        summation += i
    return bin(round(summation/(m - n + 1)))

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate(1, 5) == "0b11"
    assert candidate(7, 13) == "0b1010"
    assert candidate(964,977) == "0b1111001010"
    assert candidate(996,997) == "0b1111100100"
    assert candidate(560,851) == "0b1011000010"
    assert candidate(185,546) == "0b101101110"
    assert candidate(362,496) == "0b110101101"
    assert candidate(350,902) == "0b1001110010"
    assert candidate(197,233) == "0b11010111"


    # Check some edge cases that are easy to work out by hand.
    assert candidate(7, 5) == -1
    assert candidate(5, 1) == -1
    assert candidate(5, 5) == "0b101"

Runs

❌ Run 1

Start time: 2023-09-01 02:46:58
Duration: 11.27s
Result: Fail

def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m). 
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = total / (m-n+1)
    return bin(int(average))[2:]

❌ Run 2

Start time: 2023-09-01 02:49:58
Duration: 4.79s
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = total / (m-n+1)
    return "0b" + bin(int(average))[2:]

❌ Run 3

Start time: 2023-09-01 02:52:55
Duration: 6.11s
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = total / (m-n+1)
    return "0b" + bin(int(average))[2:]

❌ Run 4

Start time: 2023-09-01 02:55:53
Duration: 10.07s
Result: Fail

def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m). 
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = total / (m-n+1)
    return bin(int(average))[2:]

❌ Run 5

Start time: 2023-09-01 02:58:49
Duration: 5.0s
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    total = 0
    for i in range(n, m + 1):
        total += i
    average = total / (m - n + 1)
    return "0b" + bin(int(average))[2:]

❌ Run 6

Start time: 2023-09-01 03:01:53
Duration: 10.5s
Result: Fail

def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m). 
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = total / (m-n+1)
    return bin(int(average))[2:]

❌ Run 7

Start time: 2023-09-01 03:04:52
Duration: 5.09s
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = total / (m-n+1)
    return bin(int(average))[2:]

❌ Run 8

Start time: 2023-09-01 03:07:56
Duration: 10.8s
Result: Fail

def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m). 
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = total / (m-n+1)
    return bin(int(average))

❌ Run 9

Start time: 2023-09-01 03:10:54
Duration: 6.38s
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    total = 0
    for i in range(n, m + 1):
        total += i
    average = total / (m - n + 1)
    return "0b" + bin(int(average))[2:]

❌ Run 10

Start time: 2023-09-01 03:13:53
Duration: 10.79s
Result: Fail

def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m). 
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """
    if n > m:
        return -1
    total = 0
    for i in range(n, m+1):
        total += i
    average = int(total / (m-n+1))
    return bin(average)[2:]