Problem 42405. Divisible by 3

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:

  1. 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.
  2. 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.

Solution Stats

36.22% Correct | 63.78% Incorrect
Last Solution submitted on Jul 03, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers393

Suggested Problems

More from this Author139

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!