Skip to content

Latest commit

 

History

History
208 lines (181 loc) · 5.62 KB

File metadata and controls

208 lines (181 loc) · 5.62 KB

Results of GPT-3.5 on HumanEval/144

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

Prompt

Tokens: 181

def simplify(x, n):
    """Your task is to implement a function that will simplify the expression
    x * n. The function returns True if x * n evaluates to a whole number and False
    otherwise. Both x and n, are string representation of a fraction, and have the following format,
    <numerator>/<denominator> where both numerator and denominator are positive whole numbers.

    You can assume that x, and n are valid fractions, and do not have zero as denominator.

    simplify("1/5", "5/1") = True
    simplify("1/6", "2/1") = False
    simplify("7/10", "10/2") = False
    """

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

Correct solution

def simplify(x, n):
    """Your task is to implement a function that will simplify the expression
    x * n. The function returns True if x * n evaluates to a whole number and False
    otherwise. Both x and n, are string representation of a fraction, and have the following format,
    <numerator>/<denominator> where both numerator and denominator are positive whole numbers.

    You can assume that x, and n are valid fractions, and do not have zero as denominator.

    simplify("1/5", "5/1") = True
    simplify("1/6", "2/1") = False
    simplify("7/10", "10/2") = False
    """a, b = x.split("/")
    c, d = n.split("/")
    numerator = int(a) * int(c)
    denom = int(b) * int(d)
    if (numerator/denom == int(numerator/denom)):
        return True
    return False

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate("1/5", "5/1") == True, 'test1'
    assert candidate("1/6", "2/1") == False, 'test2'
    assert candidate("5/1", "3/1") == True, 'test3'
    assert candidate("7/10", "10/2") == False, 'test4'
    assert candidate("2/10", "50/10") == True, 'test5'
    assert candidate("7/2", "4/2") == True, 'test6'
    assert candidate("11/6", "6/1") == True, 'test7'
    assert candidate("2/3", "5/2") == False, 'test8'
    assert candidate("5/2", "3/5") == False, 'test9'
    assert candidate("2/4", "8/4") == True, 'test10'


    # Check some edge cases that are easy to work out by hand.
    assert candidate("2/4", "4/2") == True, 'test11'
    assert candidate("1/5", "5/1") == True, 'test12'
    assert candidate("1/5", "1/5") == False, 'test13'

Runs

✅ Run 1

Start time: 2023-07-18 17:03:53
Duration: 2.65s
Completion tokens: 61
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 2

Start time: 2023-07-18 17:03:51
Duration: 2.66s
Completion tokens: 58
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 3

Start time: 2023-07-18 17:03:47
Duration: 2.97s
Completion tokens: 58
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 4

Start time: 2023-07-18 17:03:45
Duration: 2.52s
Completion tokens: 58
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 5

Start time: 2023-07-18 17:03:42
Duration: 2.52s
Completion tokens: 58
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 6

Start time: 2023-07-18 17:03:39
Duration: 2.76s
Completion tokens: 58
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 7

Start time: 2023-07-18 17:03:36
Duration: 2.88s
Completion tokens: 58
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 8

Start time: 2023-07-18 17:03:34
Duration: 2.83s
Completion tokens: 58
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 9

Start time: 2023-07-18 17:03:31
Duration: 2.99s
Completion tokens: 61
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()

✅ Run 10

Start time: 2023-07-18 17:03:27
Duration: 3.08s
Completion tokens: 61
Result: Pass

def simplify(x, n):
    x_num, x_den = map(int, x.split('/'))
    n_num, n_den = map(int, n.split('/'))
    
    result = x_num * n_num / (x_den * n_den)
    
    return result.is_integer()