Skip to content

Latest commit

 

History

History
317 lines (315 loc) · 7.29 KB

44.md

File metadata and controls

317 lines (315 loc) · 7.29 KB

Results of GPT-4 on HumanEval/44

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

Prompt

Tokens: 117

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """

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

Correct solution

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """ret = ""
    while x > 0:
        ret = str(x % base) + ret
        x //= base
    return ret

Unit tests

METADATA = {}


def check(candidate):
    assert candidate(8, 3) == "22"
    assert candidate(9, 3) == "100"
    assert candidate(234, 2) == "11101010"
    assert candidate(16, 2) == "10000"
    assert candidate(8, 2) == "1000"
    assert candidate(7, 2) == "111"
    for x in range(2, 8):
        assert candidate(x, x + 1) == str(x)

Runs

✅ Run 1

Start time: 2023-07-18 18:39:44
Duration: 11.93s
Completion tokens: 132
Result: Pass

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    digits = []
    while x:
        digits.append(str(x % base))
        x //= base
    digits.reverse()
    return ''.join(digits)

✅ Run 2

Start time: 2023-07-18 18:39:32
Duration: 11.82s
Completion tokens: 140
Result: Pass

def change_base(x: int, base: int) -> str:
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    else:
        result = ''
        while x > 0:
            result = str(x % base) + result
            x = x // base
        return result

✅ Run 3

Start time: 2023-07-18 18:39:19
Duration: 13.03s
Completion tokens: 137
Result: Pass

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    else:
        result = ''
        while x > 0:
            result = str(x % base) + result
            x = x // base
        return result

✅ Run 4

Start time: 2023-07-18 18:39:06
Duration: 12.4s
Completion tokens: 140
Result: Pass

def change_base(x: int, base: int) -> str:
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    else:
        result = ''
        while x > 0:
            result = str(x % base) + result
            x = x // base
        return result

✅ Run 5

Start time: 2023-07-18 18:38:55
Duration: 10.78s
Completion tokens: 137
Result: Pass

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    else:
        result = ''
        while x > 0:
            result = str(x % base) + result
            x = x // base
        return result

✅ Run 6

Start time: 2023-07-18 18:38:45
Duration: 10.3s
Completion tokens: 132
Result: Pass

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    digits = []
    while x:
        digits.append(str(x % base))
        x //= base
    digits.reverse()
    return ''.join(digits)

✅ Run 7

Start time: 2023-07-18 18:38:33
Duration: 11.74s
Completion tokens: 137
Result: Pass

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    else:
        result = ''
        while x > 0:
            result = str(x % base) + result
            x = x // base
        return result

✅ Run 8

Start time: 2023-07-18 18:38:21
Duration: 11.7s
Completion tokens: 140
Result: Pass

def change_base(x: int, base: int) -> str:
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    else:
        result = ''
        while x > 0:
            result = str(x % base) + result
            x = x // base
        return result

✅ Run 9

Start time: 2023-07-18 18:38:11
Duration: 10.41s
Completion tokens: 135
Result: Pass

def change_base(x: int, base: int) -> str:
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    digits = []
    while x:
        digits.append(str(x % base))
        x //= base
    digits.reverse()
    return ''.join(digits)

✅ Run 10

Start time: 2023-07-18 18:37:58
Duration: 12.86s
Completion tokens: 137
Result: Pass

def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """
    if x == 0:
        return '0'
    else:
        result = ''
        while x > 0:
            result = str(x % base) + result
            x = x // base
        return result