Skip to content

Latest commit

 

History

History
248 lines (243 loc) · 7.13 KB

158.md

File metadata and controls

248 lines (243 loc) · 7.13 KB

Results of GPT-4 on HumanEval/158

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

Prompt

Tokens: 146

def find_max(words):
    """Write a function that accepts a list of strings.
    The list contains different words. Return the word with maximum number
    of unique characters. If multiple strings have maximum number of unique
    characters, return the one which comes first in lexicographical order.

    find_max(["name", "of", "string"]) == "string"
    find_max(["name", "enam", "game"]) == "enam"
    find_max(["aaaaaaa", "bb" ,"cc"]) == ""aaaaaaa"
    """

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

Correct solution

def find_max(words):
    """Write a function that accepts a list of strings.
    The list contains different words. Return the word with maximum number
    of unique characters. If multiple strings have maximum number of unique
    characters, return the one which comes first in lexicographical order.

    find_max(["name", "of", "string"]) == "string"
    find_max(["name", "enam", "game"]) == "enam"
    find_max(["aaaaaaa", "bb" ,"cc"]) == ""aaaaaaa"
    """return sorted(words, key = lambda x: (-len(set(x)), x))[0]

Unit tests

def check(candidate):

    # Check some simple cases
    assert (candidate(["name", "of", "string"]) == "string"), "t1"
    assert (candidate(["name", "enam", "game"]) == "enam"), 't2'
    assert (candidate(["aaaaaaa", "bb", "cc"]) == "aaaaaaa"), 't3'
    assert (candidate(["abc", "cba"]) == "abc"), 't4'
    assert (candidate(["play", "this", "game", "of","footbott"]) == "footbott"), 't5'
    assert (candidate(["we", "are", "gonna", "rock"]) == "gonna"), 't6'
    assert (candidate(["we", "are", "a", "mad", "nation"]) == "nation"), 't7'
    assert (candidate(["this", "is", "a", "prrk"]) == "this"), 't8'

    # Check some edge cases that are easy to work out by hand.
    assert (candidate(["b"]) == "b"), 't9'
    assert (candidate(["play", "play", "play"]) == "play"), 't10'

Runs

✅ Run 1

Start time: 2023-07-18 17:45:43
Duration: 7.16s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 2

Start time: 2023-07-18 17:45:31
Duration: 12.26s
Completion tokens: 137
Result: Pass

def find_max(words):
    max_unique = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique:
            max_unique = unique_chars
            max_word = word
        elif unique_chars == max_unique:
            if word < max_word:
                max_word = word
    return max_word

print(find_max(["name", "of", "string"]))  # "string"
print(find_max(["name", "enam", "game"]))  # "enam"
print(find_max(["aaaaaaa", "bb" ,"cc"]))  # "aaaaaaa"

✅ Run 3

Start time: 2023-07-18 17:45:24
Duration: 7.19s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 4

Start time: 2023-07-18 17:45:16
Duration: 7.82s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 5

Start time: 2023-07-18 17:45:09
Duration: 6.91s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 6

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

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 7

Start time: 2023-07-18 17:44:55
Duration: 7.6s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 8

Start time: 2023-07-18 17:44:45
Duration: 10.07s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 9

Start time: 2023-07-18 17:44:38
Duration: 6.86s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word

✅ Run 10

Start time: 2023-07-18 17:44:28
Duration: 9.58s
Completion tokens: 86
Result: Pass

def find_max(words):
    max_unique_chars = 0
    max_word = ""
    for word in words:
        unique_chars = len(set(word))
        if unique_chars > max_unique_chars:
            max_unique_chars = unique_chars
            max_word = word
        elif unique_chars == max_unique_chars:
            if word < max_word:
                max_word = word
    return max_word