Skip to content

Latest commit

 

History

History
204 lines (201 loc) · 4.84 KB

103.md

File metadata and controls

204 lines (201 loc) · 4.84 KB

Results of GPT-4 on HumanEval/103

Date: 18 July, 2023
Model: gpt-4
Temperature: 0.2
Passing runs: 10
Total runs: 10
Success rate: 100%

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 18:13:13
Duration: 4.18s
Completion tokens: 43
Result: Pass

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

✅ Run 2

Start time: 2023-07-18 18:13:08
Duration: 4.7s
Completion tokens: 43
Result: Pass

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

✅ Run 3

Start time: 2023-07-18 18:13:03
Duration: 5.23s
Completion tokens: 43
Result: Pass

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

✅ Run 4

Start time: 2023-07-18 18:12:59
Duration: 3.95s
Completion tokens: 43
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 18:12:54
Duration: 4.61s
Completion tokens: 43
Result: Pass

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

✅ Run 6

Start time: 2023-07-18 18:12:50
Duration: 3.99s
Completion tokens: 43
Result: Pass

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

✅ Run 7

Start time: 2023-07-18 18:12:46
Duration: 3.69s
Completion tokens: 43
Result: Pass

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

✅ Run 8

Start time: 2023-07-18 18:12:42
Duration: 4.6s
Completion tokens: 43
Result: Pass

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

✅ Run 9

Start time: 2023-07-18 18:12:38
Duration: 3.83s
Completion tokens: 43
Result: Pass

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

✅ Run 10

Start time: 2023-07-18 18:12:22
Duration: 16.06s
Completion tokens: 170
Result: Pass

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
    else:
        avg = round((n + m) / 2)
        return bin(avg)