Divisible by Three

This problem asks the user to return a list of integers that are divisible by 3. The input is a list of integers, and the output is also a list of integers.

Problem

Given a list of integers, return a list of the integers that are divisible by 3.
Example input:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Example output:
[3, 6, 9]

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
# Solution:
# The solution below is optimal because it uses a list comprehension to iterate through the list and return a new list with only the numbers that are divisible by 3.
# This solution is optimal because it is a one-liner and is easy to read.

def divisible_by_3(numbers):
    return [number for number in numbers if number % 3 == 0]

print(divisible_by_3([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))

A.I. Evaluation of the Solution

The candidate's solution is correct and uses a list comprehension, which is an efficient way to solve the problem.

Evaluated at: 2022-11-18 12:16:24