Skip to content

Latest commit

 

History

History
254 lines (237 loc) · 7.2 KB

118.md

File metadata and controls

254 lines (237 loc) · 7.2 KB

Results of GPT-4 on HumanEval/118

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

Prompt

Tokens: 175

def get_closest_vowel(word):
    """You are given a word. Your task is to find the closest vowel that stands between 
    two consonants from the right side of the word (case sensitive).
    
    Vowels in the beginning and ending doesn't count. Return empty string if you didn't
    find any vowel met the above condition. 

    You may assume that the given string contains English letter only.

    Example:
    get_closest_vowel("yogurt") ==> "u"
    get_closest_vowel("FULL") ==> "U"
    get_closest_vowel("quick") ==> ""
    get_closest_vowel("ab") ==> ""
    """

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

Correct solution

def get_closest_vowel(word):
    """You are given a word. Your task is to find the closest vowel that stands between 
    two consonants from the right side of the word (case sensitive).
    
    Vowels in the beginning and ending doesn't count. Return empty string if you didn't
    find any vowel met the above condition. 

    You may assume that the given string contains English letter only.

    Example:
    get_closest_vowel("yogurt") ==> "u"
    get_closest_vowel("FULL") ==> "U"
    get_closest_vowel("quick") ==> ""
    get_closest_vowel("ab") ==> ""
    """if len(word) < 3:
        return ""

    vowels = {"a", "e", "i", "o", "u", "A", "E", 'O', 'U', 'I'}
    for i in range(len(word)-2, 0, -1):
        if word[i] in vowels:
            if (word[i+1] not in vowels) and (word[i-1] not in vowels):
                return word[i]
    return ""

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate("yogurt") == "u"
    assert candidate("full") == "u"
    assert candidate("easy") == ""
    assert candidate("eAsy") == ""
    assert candidate("ali") == ""
    assert candidate("bad") == "a"
    assert candidate("most") == "o"
    assert candidate("ab") == ""
    assert candidate("ba") == ""
    assert candidate("quick") == ""
    assert candidate("anime") == "i"
    assert candidate("Asia") == ""
    assert candidate("Above") == "o"

    # Check some edge cases that are easy to work out by hand.
    assert True

Runs

✅ Run 1

Start time: 2023-07-18 18:04:58
Duration: 7.18s
Completion tokens: 80
Result: Pass

def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    word = word[::-1]
    for i in range(1, len(word) - 1):
        if word[i] in vowels and word[i - 1] not in vowels and word[i + 1] not in vowels:
            return word[i]
    return ""

❌ Run 2

Start time: 2023-07-18 18:04:48
Duration: 9.98s
Completion tokens: 91
Result: Fail

def get_closest_vowel(word):
    vowels = 'aeiouAEIOU'
    closest_vowel = ''
    for i in range(len(word) - 1, 0, -1):
        if word[i] in vowels and word[i - 1] not in vowels and word[i + 1] not in vowels:
            closest_vowel = word[i]
            break
    return closest_vowel

❌ Run 3

Start time: 2023-07-18 18:04:37
Duration: 10.21s
Completion tokens: 126
Result: Fail

```python
def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    for i in range(len(word) - 1, 0, -1):
        if word[i] in vowels and word[i - 1] not in vowels and word[i + 1] not in vowels:
            return word[i]
    return ""

print(get_closest_vowel("yogurt")) # "u"
print(get_closest_vowel("FULL")) # "U"
print(get_closest_vowel("quick")) # ""
print(get_closest_vowel("ab")) # ""```

❌ Run 4

Start time: 2023-07-18 18:04:28
Duration: 9.61s
Completion tokens: 127
Result: Fail

def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    for i in range(len(word) - 1, 0, -1):
        if word[i] in vowels and word[i-1].isalpha() and word[i+1].isalpha():
            return word[i]
    return ""

print(get_closest_vowel("yogurt"))  # "u"
print(get_closest_vowel("FULL"))  # "U"
print(get_closest_vowel("quick"))  # ""
print(get_closest_vowel("ab"))  # ""

❌ Run 5

Start time: 2023-07-18 18:04:14
Duration: 13.32s
Completion tokens: 134
Result: Fail

```python
def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    word = word[::-1]
    for i in range(1, len(word) - 1):
        if word[i] in vowels and word[i - 1] not in vowels and word[i + 1] not in vowels:
            return word[i]
    return ""

print(get_closest_vowel("yogurt")) #==> "u"
print(get_closest_vowel("FULL")) #==> "U"
print(get_closest_vowel("quick")) #==> ""
print(get_closest_vowel("ab")) #==> ""```

❌ Run 6

Start time: 2023-07-18 18:04:03
Duration: 10.89s
Completion tokens: 129
Result: Fail

def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    for i in range(len(word) - 1, 0, -1):
        if word[i] in vowels and word[i - 1].isalpha() and word[i + 1].isalpha():
            return word[i]
    return ""

print(get_closest_vowel("yogurt"))  # "u"
print(get_closest_vowel("FULL"))  # "U"
print(get_closest_vowel("quick"))  # ""
print(get_closest_vowel("ab"))  # ""

❌ Run 7

Start time: 2023-07-18 18:03:51
Duration: 11.93s
Completion tokens: 123
Result: Fail

```python
def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    for i in range(len(word) - 1, 0, -1):
        if word[i] in vowels and word[i-1].isalpha() and word[i+1].isalpha():
            return word[i]
    return ""

print(get_closest_vowel("yogurt")) # "u"
print(get_closest_vowel("FULL")) # "U"
print(get_closest_vowel("quick")) # ""
print(get_closest_vowel("ab")) # ""```

❌ Run 8

Start time: 2023-07-18 18:03:42
Duration: 8.82s
Completion tokens: 125
Result: Fail

def get_closest_vowel(word):
    vowels = 'aeiouAEIOU'
    for i in range(len(word)-1, 0, -1):
        if word[i] in vowels and word[i-1].isalpha() and word[i+1].isalpha():
            return word[i]
    return ""

print(get_closest_vowel("yogurt")) #==> "u"
print(get_closest_vowel("FULL")) #==> "U"
print(get_closest_vowel("quick")) #==> ""
print(get_closest_vowel("ab")) #==> ""

❌ Run 9

Start time: 2023-07-18 18:03:32
Duration: 10.62s
Completion tokens: 127
Result: Fail

```python
def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    for i in range(len(word) - 1, 0, -1):
        if word[i] in vowels and word[i-1].isalpha() and word[i+1].isalpha():
            return word[i]
    return ""

print(get_closest_vowel("yogurt")) #==> "u"
print(get_closest_vowel("FULL")) #==> "U"
print(get_closest_vowel("quick")) #==> ""
print(get_closest_vowel("ab")) #==> ""```

❌ Run 10

Start time: 2023-07-18 18:03:21
Duration: 10.62s
Completion tokens: 126
Result: Fail

def get_closest_vowel(word):
    vowels = "aeiouAEIOU"
    for i in range(len(word)-1, 0, -1):
        if word[i] in vowels and word[i-1] not in vowels and word[i+1] not in vowels:
            return word[i]
    return ""

print(get_closest_vowel("yogurt"))  # "u"
print(get_closest_vowel("FULL"))  # "U"
print(get_closest_vowel("quick"))  # ""
print(get_closest_vowel("ab"))  # ""