Skip to content

Latest commit

 

History

History
227 lines (224 loc) · 5.79 KB

File metadata and controls

227 lines (224 loc) · 5.79 KB

Results of GPT-3.5 on HumanEval/147

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

Prompt

Tokens: 191

def get_max_triples(n):
    """
    You are given a positive integer n. You have to create an integer array a of length n.
        For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
        Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, 
    and a[i] + a[j] + a[k] is a multiple of 3.

    Example :
        Input: n = 5
        Output: 1
        Explanation: 
        a = [1, 3, 7, 13, 21]
        The only valid triple is (1, 7, 13).
    """

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

Correct solution

def get_max_triples(n):
    """
    You are given a positive integer n. You have to create an integer array a of length n.
        For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
        Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, 
    and a[i] + a[j] + a[k] is a multiple of 3.

    Example :
        Input: n = 5
        Output: 1
        Explanation: 
        a = [1, 3, 7, 13, 21]
        The only valid triple is (1, 7, 13).
    """A = [i*i - i + 1 for i in range(1,n+1)]
    ans = []
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if (A[i]+A[j]+A[k])%3 == 0:
                    ans += [(A[i],A[j],A[k])]
    return len(ans)

Unit tests

def check(candidate):

    assert candidate(5) == 1
    assert candidate(6) == 4
    assert candidate(10) == 36
    assert candidate(100) == 53361

Runs

✅ Run 1

Start time: 2023-07-18 17:03:39
Duration: 4.92s
Completion tokens: 118
Result: Pass

def get_max_triples(n):
    count = 0
    for i in range(1, n+1):
        a_i = i * i - i + 1
        for j in range(i+1, n+1):
            a_j = j * j - j + 1
            for k in range(j+1, n+1):
                a_k = k * k - k + 1
                if (a_i + a_j + a_k) % 3 == 0:
                    count += 1
    return count

✅ Run 2

Start time: 2023-07-18 17:03:34
Duration: 4.84s
Completion tokens: 118
Result: Pass

def get_max_triples(n):
    count = 0
    for i in range(1, n+1):
        a_i = i * i - i + 1
        for j in range(i+1, n+1):
            a_j = j * j - j + 1
            for k in range(j+1, n+1):
                a_k = k * k - k + 1
                if (a_i + a_j + a_k) % 3 == 0:
                    count += 1
    return count

✅ Run 3

Start time: 2023-07-18 17:03:28
Duration: 5.7s
Completion tokens: 118
Result: Pass

def get_max_triples(n):
    count = 0
    for i in range(1, n+1):
        a_i = i * i - i + 1
        for j in range(i+1, n+1):
            a_j = j * j - j + 1
            for k in range(j+1, n+1):
                a_k = k * k - k + 1
                if (a_i + a_j + a_k) % 3 == 0:
                    count += 1
    return count

✅ Run 4

Start time: 2023-07-18 17:03:24
Duration: 4.17s
Completion tokens: 94
Result: Pass

def get_max_triples(n):
    count = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0:
                    count += 1
    return count

✅ Run 5

Start time: 2023-07-18 17:03:19
Duration: 4.56s
Completion tokens: 118
Result: Pass

def get_max_triples(n):
    count = 0
    for i in range(1, n+1):
        a_i = i * i - i + 1
        for j in range(i+1, n+1):
            a_j = j * j - j + 1
            for k in range(j+1, n+1):
                a_k = k * k - k + 1
                if (a_i + a_j + a_k) % 3 == 0:
                    count += 1
    return count

❌ Run 6

Start time: 2023-07-18 17:03:16
Duration: 2.83s
Completion tokens: 56
Result: Fail

def get_max_triples(n):
    count = 0
    for i in range(1, n+1):
        a = i * i - i + 1
        if a % 3 == 0:
            count += 1
    return count

✅ Run 7

Start time: 2023-07-18 17:03:12
Duration: 4.0s
Completion tokens: 99
Result: Pass

def get_max_triples(n):
    a = [i * i - i + 1 for i in range(1, n+1)]
    count = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if (a[i] + a[j] + a[k]) % 3 == 0:
                    count += 1
    return count

✅ Run 8

Start time: 2023-07-18 17:03:08
Duration: 4.3s
Completion tokens: 99
Result: Pass

def get_max_triples(n):
    a = [i * i - i + 1 for i in range(1, n+1)]
    count = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if (a[i] + a[j] + a[k]) % 3 == 0:
                    count += 1
    return count

✅ Run 9

Start time: 2023-07-18 17:03:04
Duration: 3.9s
Completion tokens: 99
Result: Pass

def get_max_triples(n):
    a = [i * i - i + 1 for i in range(1, n+1)]
    count = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if (a[i] + a[j] + a[k]) % 3 == 0:
                    count += 1
    return count

✅ Run 10

Start time: 2023-07-18 17:03:00
Duration: 3.36s
Completion tokens: 118
Result: Pass

def get_max_triples(n):
    count = 0
    for i in range(1, n+1):
        a_i = i * i - i + 1
        for j in range(i+1, n+1):
            a_j = j * j - j + 1
            for k in range(j+1, n+1):
                a_k = k * k - k + 1
                if (a_i + a_j + a_k) % 3 == 0:
                    count += 1
    return count