Files

26 lines
839 B
Python

# HumanEval/106
# Loki Mode Multi-Agent Solution
# Attempts: 1
# Passed: True
def f(n):
""" Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
Example:
f(5) == [1, 2, 6, 24, 15]
"""
result = []
for i in range(1, n + 1):
if i % 2 == 0:
# Even i: compute factorial
factorial = 1
for j in range(1, i + 1):
factorial *= j
result.append(factorial)
else:
# Odd i: compute sum from 1 to i
result.append(i * (i + 1) // 2)
return result