Skip to content

Latest commit

 

History

History
280 lines (277 loc) · 7.19 KB

77.md

File metadata and controls

280 lines (277 loc) · 7.19 KB

Results of GPT-4 on HumanEval/77

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

Prompt

Tokens: 136

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''

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

Correct solution

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''a = abs(a)
    return int(round(a ** (1. / 3))) ** 3 == a

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate(1) == True, "First test error: " + str(candidate(1))
    assert candidate(2) == False, "Second test error: " + str(candidate(2))
    assert candidate(-1) == True, "Third test error: " + str(candidate(-1))
    assert candidate(64) == True, "Fourth test error: " + str(candidate(64))
    assert candidate(180) == False, "Fifth test error: " + str(candidate(180))
    assert candidate(1000) == True, "Sixth test error: " + str(candidate(1000))


    # Check some edge cases that are easy to work out by hand.
    assert candidate(0) == True, "1st edge test error: " + str(candidate(0))
    assert candidate(1729) == False, "2nd edge test error: " + str(candidate(1728))

Runs

✅ Run 1

Start time: 2023-07-18 18:25:14
Duration: 13.6s
Completion tokens: 135
Result: Pass

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    cube_root = round(abs(a) ** (1. / 3))
    return cube_root ** 3 == abs(a)

❌ Run 2

Start time: 2023-07-18 18:25:05
Duration: 8.95s
Completion tokens: 124
Result: Fail

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    return round(a ** (1/3)) ** 3 == a

❌ Run 3

Start time: 2023-07-18 18:24:54
Duration: 11.01s
Completion tokens: 132
Result: Fail

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    cube_root = round(a ** (1. / 3))
    return cube_root ** 3 == a

❌ Run 4

Start time: 2023-07-18 18:24:45
Duration: 8.76s
Completion tokens: 124
Result: Fail

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    return round(a ** (1/3)) ** 3 == a

✅ Run 5

Start time: 2023-07-18 18:24:34
Duration: 11.31s
Completion tokens: 139
Result: Pass

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    if a < 0:
        a = -a
    return round(a ** (1. / 3)) ** 3 == a

✅ Run 6

Start time: 2023-07-18 18:24:22
Duration: 11.95s
Completion tokens: 139
Result: Pass

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    if a < 0:
        a = -a
    return round(a ** (1. / 3)) ** 3 == a

❌ Run 7

Start time: 2023-07-18 18:24:10
Duration: 12.04s
Completion tokens: 124
Result: Fail

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    return round(a ** (1/3)) ** 3 == a

✅ Run 8

Start time: 2023-07-18 18:23:57
Duration: 13.19s
Completion tokens: 137
Result: Pass

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    if a < 0:
        a = -a
    return round(a ** (1/3)) ** 3 == a

❌ Run 9

Start time: 2023-07-18 18:23:44
Duration: 12.71s
Completion tokens: 126
Result: Fail

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    return round(a ** (1. / 3)) ** 3 == a

✅ Run 10

Start time: 2023-07-18 18:23:33
Duration: 10.48s
Completion tokens: 135
Result: Pass

def iscube(a):
    '''
    Write a function that takes an integer a and returns True 
    if this ingeger is a cube of some integer number.
    Note: you may assume the input is always valid.
    Examples:
    iscube(1) ==> True
    iscube(2) ==> False
    iscube(-1) ==> True
    iscube(64) ==> True
    iscube(0) ==> True
    iscube(180) ==> False
    '''
    if a < 0:
        a = -a
    return round(a**(1/3))**3 == a