Skip to content

Latest commit

 

History

History
283 lines (272 loc) · 12.3 KB

153.md

File metadata and controls

283 lines (272 loc) · 12.3 KB

Results of GPT-4 on HumanEval/153

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

Prompt

Tokens: 303

def Strongest_Extension(class_name, extensions):
    """You will be given the name of a class (a string) and a list of extensions.
    The extensions are to be used to load additional classes to the class. The
    strength of the extension is as follows: Let CAP be the number of the uppercase
    letters in the extension's name, and let SM be the number of lowercase letters 
    in the extension's name, the strength is given by the fraction CAP - SM. 
    You should find the strongest extension and return a string in this 
    format: ClassName.StrongestExtensionName.
    If there are two or more extensions with the same strength, you should
    choose the one that comes first in the list.
    For example, if you are given "Slices" as the class and a list of the
    extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
    return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension 
    (its strength is -1).
    Example:
    for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'
    """

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

Correct solution

def Strongest_Extension(class_name, extensions):
    """You will be given the name of a class (a string) and a list of extensions.
    The extensions are to be used to load additional classes to the class. The
    strength of the extension is as follows: Let CAP be the number of the uppercase
    letters in the extension's name, and let SM be the number of lowercase letters 
    in the extension's name, the strength is given by the fraction CAP - SM. 
    You should find the strongest extension and return a string in this 
    format: ClassName.StrongestExtensionName.
    If there are two or more extensions with the same strength, you should
    choose the one that comes first in the list.
    For example, if you are given "Slices" as the class and a list of the
    extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
    return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension 
    (its strength is -1).
    Example:
    for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'
    """strong = extensions[0]
    my_val = len([x for x in extensions[0] if x.isalpha() and x.isupper()]) - len([x for x in extensions[0] if x.isalpha() and x.islower()])
    for s in extensions:
        val = len([x for x in s if x.isalpha() and x.isupper()]) - len([x for x in s if x.isalpha() and x.islower()])
        if val > my_val:
            strong = s
            my_val = val

    ans = class_name + "." + strong
    return ans

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) == 'Watashi.eIGHt8OKe'
    assert candidate('Boku123', ['nani', 'NazeDa', 'YEs.WeCaNe', '32145tggg']) == 'Boku123.YEs.WeCaNe'
    assert candidate('__YESIMHERE', ['t', 'eMptY', 'nothing', 'zeR00', 'NuLl__', '123NoooneB321']) == '__YESIMHERE.NuLl__'
    assert candidate('K', ['Ta', 'TAR', 't234An', 'cosSo']) == 'K.TAR'
    assert candidate('__HAHA', ['Tab', '123', '781345', '-_-']) == '__HAHA.123'
    assert candidate('YameRore', ['HhAas', 'okIWILL123', 'WorkOut', 'Fails', '-_-']) == 'YameRore.okIWILL123'
    assert candidate('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) == 'finNNalLLly.WoW'

    # Check some edge cases that are easy to work out by hand.
    assert candidate('_', ['Bb', '91245']) == '_.Bb'
    assert candidate('Sp', ['671235', 'Bb']) == 'Sp.671235'

Runs

❌ Run 1

Start time: 2023-07-18 17:49:24
Duration: 8.6s
Completion tokens: 127
Result: Fail

def Strongest_Extension(class_name, extensions):
    strongest_extension = extensions[0]
    max_strength = sum(1 if c.isupper() else -1 for c in strongest_extension)

    for extension in extensions[1:]:
        strength = sum(1 if c.isupper() else -1 for c in extension)
        if strength > max_strength:
            max_strength = strength
            strongest_extension = extension

    return class_name + '.' + strongest_extension

print(Strongest_Extension('my_class', ['AA', 'Be', 'CC'])) # Expected output 'my_class.AA'

✅ Run 2

Start time: 2023-07-18 17:49:02
Duration: 21.13s
Completion tokens: 322
Result: Pass

def Strongest_Extension(class_name, extensions):
    """You will be given the name of a class (a string) and a list of extensions.
    The extensions are to be used to load additional classes to the class. The
    strength of the extension is as follows: Let CAP be the number of the uppercase
    letters in the extension's name, and let SM be the number of lowercase letters 
    in the extension's name, the strength is given by the fraction CAP - SM. 
    You should find the strongest extension and return a string in this 
    format: ClassName.StrongestExtensionName.
    If there are two or more extensions with the same strength, you should
    choose the one that comes first in the list.
    For example, if you are given "Slices" as the class and a list of the
    extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
    return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension 
    (its strength is -1).
    Example:
    for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'
    """
    strongest_extension = max(extensions, key=lambda x: sum(1 for c in x if c.isupper()) - sum(1 for c in x if c.islower()))
    return class_name + '.' + strongest_extension

❌ Run 3

Start time: 2023-07-18 17:48:52
Duration: 9.77s
Completion tokens: 101
Result: Fail

def Strongest_Extension(class_name, extensions):
    strongest_extension = extensions[0]
    max_strength = sum(1 if c.isupper() else -1 for c in extensions[0])
    
    for extension in extensions[1:]:
        strength = sum(1 if c.isupper() else -1 for c in extension)
        if strength > max_strength:
            max_strength = strength
            strongest_extension = extension
            
    return class_name + '.' + strongest_extension

✅ Run 4

Start time: 2023-07-18 17:48:24
Duration: 28.69s
Completion tokens: 323
Result: Pass

def Strongest_Extension(class_name, extensions):
    """You will be given the name of a class (a string) and a list of extensions.
    The extensions are to be used to load additional classes to the class. The
    strength of the extension is as follows: Let CAP be the number of the uppercase
    letters in the extension's name, and let SM be the number of lowercase letters 
    in the extension's name, the strength is given by the fraction CAP - SM. 
    You should find the strongest extension and return a string in this 
    format: ClassName.StrongestExtensionName.
    If there are two or more extensions with the same strength, you should
    choose the one that comes first in the list.
    For example, if you are given "Slices" as the class and a list of the
    extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
    return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension 
    (its strength is -1).
    Example:
    for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'
    """
    strongest_extension = max(extensions, key=lambda x: sum(1 for c in x if c.isupper()) - sum(1 for c in x if c.islower()))
    return f'{class_name}.{strongest_extension}'

✅ Run 5

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

def Strongest_Extension(class_name, extensions):
    """You will be given the name of a class (a string) and a list of extensions.
    The extensions are to be used to load additional classes to the class. The
    strength of the extension is as follows: Let CAP be the number of the uppercase
    letters in the extension's name, and let SM be the number of lowercase letters 
    in the extension's name, the strength is given by the fraction CAP - SM. 
    You should find the strongest extension and return a string in this 
    format: ClassName.StrongestExtensionName.
    If there are two or more extensions with the same strength, you should
    choose the one that comes first in the list.
    For example, if you are given "Slices" as the class and a list of the
    extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
    return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension 
    (its strength is -1).
    Example:
    for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'
    """
    strongest_extension = max(extensions, key=lambda x: sum(1 for c in x if c.isupper()) - sum(1 for c in x if c.islower()))
    return f'{class_name}.{strongest_extension}'

❌ Run 6

Start time: 2023-07-18 17:47:50
Duration: 8.46s
Completion tokens: 100
Result: Fail

def Strongest_Extension(class_name, extensions):
    strongest_extension = extensions[0]
    max_strength = sum(1 if c.isupper() else -1 for c in extensions[0])
    for extension in extensions[1:]:
        strength = sum(1 if c.isupper() else -1 for c in extension)
        if strength > max_strength:
            max_strength = strength
            strongest_extension = extension
    return class_name + '.' + strongest_extension

❌ Run 7

Start time: 2023-07-18 17:47:40
Duration: 9.49s
Completion tokens: 100
Result: Fail

def Strongest_Extension(class_name, extensions):
    strongest_extension = extensions[0]
    max_strength = sum(1 if c.isupper() else -1 for c in extensions[0])
    for extension in extensions[1:]:
        strength = sum(1 if c.isupper() else -1 for c in extension)
        if strength > max_strength:
            max_strength = strength
            strongest_extension = extension
    return class_name + '.' + strongest_extension

❌ Run 8

Start time: 2023-07-18 17:47:33
Duration: 7.33s
Completion tokens: 100
Result: Fail

def Strongest_Extension(class_name, extensions):
    strongest_extension = extensions[0]
    max_strength = sum(1 if c.isupper() else -1 for c in extensions[0])

    for extension in extensions[1:]:
        strength = sum(1 if c.isupper() else -1 for c in extension)
        if strength > max_strength:
            max_strength = strength
            strongest_extension = extension

    return class_name + '.' + strongest_extension

✅ Run 9

Start time: 2023-07-18 17:47:26
Duration: 6.24s
Completion tokens: 78
Result: Pass

def Strongest_Extension(class_name, extensions):
    def strength(extension):
        CAP = sum(1 for c in extension if c.isupper())
        SM = sum(1 for c in extension if c.islower())
        return CAP - SM

    strongest_extension = max(extensions, key=strength)
    return f'{class_name}.{strongest_extension}'

✅ Run 10

Start time: 2023-07-18 17:47:01
Duration: 25.49s
Completion tokens: 323
Result: Pass

def Strongest_Extension(class_name, extensions):
    """You will be given the name of a class (a string) and a list of extensions.
    The extensions are to be used to load additional classes to the class. The
    strength of the extension is as follows: Let CAP be the number of the uppercase
    letters in the extension's name, and let SM be the number of lowercase letters 
    in the extension's name, the strength is given by the fraction CAP - SM. 
    You should find the strongest extension and return a string in this 
    format: ClassName.StrongestExtensionName.
    If there are two or more extensions with the same strength, you should
    choose the one that comes first in the list.
    For example, if you are given "Slices" as the class and a list of the
    extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
    return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension 
    (its strength is -1).
    Example:
    for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'
    """
    strongest_extension = max(extensions, key=lambda x: sum(1 for c in x if c.isupper()) - sum(1 for c in x if c.islower()))
    return f'{class_name}.{strongest_extension}'