Skip to content

Latest commit

 

History

History
203 lines (201 loc) · 4.88 KB

File metadata and controls

203 lines (201 loc) · 4.88 KB

Results of GPT-3.5 on HumanEval/65

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

Prompt

Tokens: 108

def circular_shift(x, shift):
    """Circular shift the digits of the integer x, shift the digits right by shift
    and return the result as a string.
    If shift > number of digits, return digits reversed.
    >>> circular_shift(12, 1)
    "21"
    >>> circular_shift(12, 2)
    "12"
    """

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

Correct solution

def circular_shift(x, shift):
    """Circular shift the digits of the integer x, shift the digits right by shift
    and return the result as a string.
    If shift > number of digits, return digits reversed.
    >>> circular_shift(12, 1)
    "21"
    >>> circular_shift(12, 2)
    "12"
    """s = str(x)
    if shift > len(s):
        return s[::-1]
    else:
        return s[len(s) - shift:] + s[:len(s) - shift]

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate(100, 2) == "001"
    assert candidate(12, 2) == "12"
    assert candidate(97, 8) == "79"
    assert candidate(12, 1) == "21", "This prints if this assert fails 1 (good for debugging!)"

    # Check some edge cases that are easy to work out by hand.
    assert candidate(11, 101) == "11", "This prints if this assert fails 2 (also good for debugging!)"

Runs

✅ Run 1

Start time: 2023-07-18 17:17:52
Duration: 2.15s
Completion tokens: 45
Result: Pass

def circular_shift(x, shift):
    x_str = str(x)
    if shift > len(x_str):
        return x_str[::-1]
    else:
        return x_str[-shift:] + x_str[:-shift]

❌ Run 2

Start time: 2023-07-18 17:17:47
Duration: 4.36s
Completion tokens: 64
Result: Fail

def circular_shift(x, shift):
    x_str = str(x)
    num_digits = len(x_str)
    shift = shift % num_digits
    if shift == 0:
        return x_str
    else:
        shifted_str = x_str[-shift:] + x_str[:-shift]
        return shifted_str

❌ Run 3

Start time: 2023-07-18 17:17:44
Duration: 3.05s
Completion tokens: 64
Result: Fail

def circular_shift(x, shift):
    x_str = str(x)
    num_digits = len(x_str)
    shift = shift % num_digits
    if shift == 0:
        return x_str
    else:
        shifted_str = x_str[-shift:] + x_str[:-shift]
        return shifted_str

❌ Run 4

Start time: 2023-07-18 17:17:41
Duration: 3.34s
Completion tokens: 64
Result: Fail

def circular_shift(x, shift):
    x_str = str(x)
    num_digits = len(x_str)
    shift = shift % num_digits
    if shift == 0:
        return x_str
    else:
        shifted_str = x_str[-shift:] + x_str[:-shift]
        return shifted_str

✅ Run 5

Start time: 2023-07-18 17:17:39
Duration: 2.1s
Completion tokens: 40
Result: Pass

def circular_shift(x, shift):
    x = str(x)
    if shift > len(x):
        return x[::-1]
    else:
        return x[-shift:] + x[:-shift]

❌ Run 6

Start time: 2023-07-18 17:17:36
Duration: 2.86s
Completion tokens: 64
Result: Fail

def circular_shift(x, shift):
    x_str = str(x)
    num_digits = len(x_str)
    shift = shift % num_digits
    if shift == 0:
        return x_str
    else:
        shifted_str = x_str[-shift:] + x_str[:-shift]
        return shifted_str

✅ Run 7

Start time: 2023-07-18 17:17:33
Duration: 2.41s
Completion tokens: 45
Result: Pass

def circular_shift(x, shift):
    x_str = str(x)
    if shift > len(x_str):
        return x_str[::-1]
    else:
        return x_str[-shift:] + x_str[:-shift]

✅ Run 8

Start time: 2023-07-18 17:17:31
Duration: 2.17s
Completion tokens: 40
Result: Pass

def circular_shift(x, shift):
    x = str(x)
    if shift > len(x):
        return x[::-1]
    else:
        return x[-shift:] + x[:-shift]

✅ Run 9

Start time: 2023-07-18 17:17:25
Duration: 5.03s
Completion tokens: 127
Result: Pass

def circular_shift(x, shift):
    """Circular shift the digits of the integer x, shift the digits right by shift
    and return the result as a string.
    If shift > number of digits, return digits reversed.
    >>> circular_shift(12, 1)
    "21"
    >>> circular_shift(12, 2)
    "12"
    """
    x_str = str(x)
    num_digits = len(x_str)
    if shift > num_digits:
        return x_str[::-1]
    else:
        shifted_str = x_str[-shift:] + x_str[:-shift]
        return shifted_str

✅ Run 10

Start time: 2023-07-18 17:17:23
Duration: 2.26s
Completion tokens: 40
Result: Pass

def circular_shift(x, shift):
    x = str(x)
    if shift > len(x):
        return x[::-1]
    else:
        return x[-shift:] + x[:-shift]