38 lines
936 B
Python
38 lines
936 B
Python
# HumanEval/96
|
|
# Loki Mode Multi-Agent Solution
|
|
# Attempts: 1
|
|
# Passed: True
|
|
|
|
def count_up_to(n):
|
|
"""Implement a function that takes an non-negative integer and returns an array of the first n
|
|
integers that are prime numbers and less than n.
|
|
for example:
|
|
count_up_to(5) => [2,3]
|
|
count_up_to(11) => [2,3,5,7]
|
|
count_up_to(0) => []
|
|
count_up_to(20) => [2,3,5,7,11,13,17,19]
|
|
count_up_to(1) => []
|
|
count_up_to(18) => [2,3,5,7,11,13,17]
|
|
"""
|
|
if n <= 2:
|
|
return []
|
|
|
|
def is_prime(num):
|
|
if num < 2:
|
|
return False
|
|
if num == 2:
|
|
return True
|
|
if num % 2 == 0:
|
|
return False
|
|
i = 3
|
|
while i * i <= num:
|
|
if num % i == 0:
|
|
return False
|
|
i += 2
|
|
return True
|
|
|
|
primes = []
|
|
for num in range(2, n):
|
|
if is_prime(num):
|
|
primes.append(num)
|
|
return primes |