Skip to content

Latest commit

 

History

History
246 lines (243 loc) · 7.26 KB

File metadata and controls

246 lines (243 loc) · 7.26 KB

Results of GPT-3.5 on HumanEval/117

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

Prompt

Tokens: 207

def select_words(s, n):
    """Given a string s and a natural number n, you have been tasked to implement 
    a function that returns a list of all words from string s that contain exactly 
    n consonants, in order these words appear in the string s.
    If the string s is empty then the function should return an empty list.
    Note: you may assume the input string contains only letters and spaces.
    Examples:
    select_words("Mary had a little lamb", 4) ==> ["little"]
    select_words("Mary had a little lamb", 3) ==> ["Mary", "lamb"]
    select_words("simple white space", 2) ==> []
    select_words("Hello world", 4) ==> ["world"]
    select_words("Uncle sam", 3) ==> ["Uncle"]
    """

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

Correct solution

def select_words(s, n):
    """Given a string s and a natural number n, you have been tasked to implement 
    a function that returns a list of all words from string s that contain exactly 
    n consonants, in order these words appear in the string s.
    If the string s is empty then the function should return an empty list.
    Note: you may assume the input string contains only letters and spaces.
    Examples:
    select_words("Mary had a little lamb", 4) ==> ["little"]
    select_words("Mary had a little lamb", 3) ==> ["Mary", "lamb"]
    select_words("simple white space", 2) ==> []
    select_words("Hello world", 4) ==> ["world"]
    select_words("Uncle sam", 3) ==> ["Uncle"]
    """result = []
    for word in s.split():
        n_consonants = 0
        for i in range(0, len(word)):
            if word[i].lower() not in ["a","e","i","o","u"]:
                n_consonants += 1 
        if n_consonants == n:
            result.append(word)
    return result

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate("Mary had a little lamb", 4) == ["little"], "First test error: " + str(candidate("Mary had a little lamb", 4))      
    assert candidate("Mary had a little lamb", 3) == ["Mary", "lamb"], "Second test error: " + str(candidate("Mary had a little lamb", 3))  
    assert candidate("simple white space", 2) == [], "Third test error: " + str(candidate("simple white space", 2))      
    assert candidate("Hello world", 4) == ["world"], "Fourth test error: " + str(candidate("Hello world", 4))  
    assert candidate("Uncle sam", 3) == ["Uncle"], "Fifth test error: " + str(candidate("Uncle sam", 3))


    # Check some edge cases that are easy to work out by hand.
    assert candidate("", 4) == [], "1st edge test error: " + str(candidate("", 4))
    assert candidate("a b c d e f", 1) == ["b", "c", "d", "f"], "2nd edge test error: " + str(candidate("a b c d e f", 1))

Runs

✅ Run 1

Start time: 2023-07-18 17:09:17
Duration: 4.19s
Completion tokens: 85
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for char in word:
            if char.lower() not in ['a', 'e', 'i', 'o', 'u'] and char.isalpha():
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 2

Start time: 2023-07-18 17:09:12
Duration: 5.31s
Completion tokens: 80
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for letter in word:
            if letter.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 3

Start time: 2023-07-18 17:09:09
Duration: 3.29s
Completion tokens: 80
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for letter in word:
            if letter.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 4

Start time: 2023-07-18 17:09:04
Duration: 3.91s
Completion tokens: 80
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for letter in word:
            if letter.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 5

Start time: 2023-07-18 17:09:00
Duration: 4.03s
Completion tokens: 85
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for char in word:
            if char.isalpha() and char.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 6

Start time: 2023-07-18 17:08:57
Duration: 2.86s
Completion tokens: 83
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonant_count = 0
        for letter in word:
            if letter.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonant_count += 1
        if consonant_count == n:
            result.append(word)
    return result

✅ Run 7

Start time: 2023-07-18 17:08:53
Duration: 4.21s
Completion tokens: 80
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for char in word:
            if char.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 8

Start time: 2023-07-18 17:08:49
Duration: 3.76s
Completion tokens: 80
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for char in word:
            if char.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 9

Start time: 2023-07-18 17:08:45
Duration: 3.2s
Completion tokens: 80
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for char in word:
            if char.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result

✅ Run 10

Start time: 2023-07-18 17:08:42
Duration: 3.55s
Completion tokens: 80
Result: Pass

def select_words(s, n):
    words = s.split()
    result = []
    for word in words:
        consonants = 0
        for letter in word:
            if letter.lower() not in ['a', 'e', 'i', 'o', 'u']:
                consonants += 1
        if consonants == n:
            result.append(word)
    return result