Pursuant to the first problem in this series, this one involves checking for divisibility by 3.
Write a function to determine if a number is divisible by 3. This can be checked by at least two different methods:
- Sum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.
- From the wikipedia reference page: "Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number." If the resulting sum (absolute value) is a multiple of 3, then so is the original number.
Previous problem: divisible by 2. Next problem: divisible by 4.