Skip to content

Latest commit

 

History

History
188 lines (185 loc) · 4.32 KB

File metadata and controls

188 lines (185 loc) · 4.32 KB

Results of GPT-3.5 on HumanEval/103

Date: 18 July, 2023
Model: gpt-3.5-turbo
Temperature: 0.2
Passing runs: 2
Total runs: 10
Success rate: 20%

Prompt

Tokens: 166

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-07-18 17:12:12
Duration: 2.28s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)

❌ Run 2

Start time: 2023-07-18 17:12:10
Duration: 2.13s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)

❌ Run 3

Start time: 2023-07-18 17:12:08
Duration: 2.17s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)

✅ Run 4

Start time: 2023-07-18 17:12:06
Duration: 1.75s
Completion tokens: 39
Result: Pass

def rounded_avg(n, m):
    if n > m:
        return -1
    else:
        avg = round((n + m) / 2)
        return bin(avg)

❌ Run 5

Start time: 2023-07-18 17:12:04
Duration: 2.03s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)

✅ Run 6

Start time: 2023-07-18 17:12:01
Duration: 2.37s
Completion tokens: 53
Result: Pass

def rounded_avg(n, m):
    if n > m:
        return -1
    else:
        avg = (n + m) / 2
        rounded_avg = round(avg)
        binary_avg = bin(rounded_avg)
        return binary_avg

❌ Run 7

Start time: 2023-07-18 17:12:00
Duration: 1.63s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)

❌ Run 8

Start time: 2023-07-18 17:11:57
Duration: 2.07s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)

❌ Run 9

Start time: 2023-07-18 17:11:56
Duration: 1.82s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)

❌ Run 10

Start time: 2023-07-18 17:11:54
Duration: 1.75s
Completion tokens: 35
Result: Fail

def rounded_avg(n, m):
    if n > m:
        return -1
    avg = (n + m) // 2
    return bin(avg)