Skip to content

Latest commit

 

History

History
262 lines (236 loc) · 7.02 KB

File metadata and controls

262 lines (236 loc) · 7.02 KB

Results of GPT-3.5 on HumanEval/158

Date: 18 July, 2023
Model: gpt-3.5-turbo
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:01:54
Duration: 3.06s
Completion tokens: 81
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:01:50
Duration: 3.52s
Completion tokens: 78
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:
            max_word = min(max_word, word)
    return max_word

✅ Run 3

Start time: 2023-07-18 17:01:46
Duration: 3.86s
Completion tokens: 83
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:01:43
Duration: 3.41s
Completion tokens: 81
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:01:40
Duration: 2.83s
Completion tokens: 83
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:01:36
Duration: 3.43s
Completion tokens: 83
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:01:32
Duration: 4.15s
Completion tokens: 78
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:
            max_word = min(max_word, word)

    return max_word

✅ Run 8

Start time: 2023-07-18 17:01:28
Duration: 3.71s
Completion tokens: 80
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:
            max_word = min(max_word, word)
    
    return max_word

✅ Run 9

Start time: 2023-07-18 17:01:24
Duration: 4.01s
Completion tokens: 81
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:
            max_word = min(max_word, word)
    
    return max_word

✅ Run 10

Start time: 2023-07-18 17:01:21
Duration: 3.75s
Completion tokens: 81
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