Lesson goal: Divisibility Rules

Previous: Adding two fractions | Home | Next: Find the factorial

In a past lesson you used the % (or mod) operator to test numbers for divisibility. The mod operator makes this easy, since if it's zero, it means a number divided into another with no remainder. And, no remainder means the original number is divisibile by the number being tested for divisibility.

Let's look again at divisibility using Prolog. This approach will allow us to think more about the logic of divisibility, rather than just blindly using the power of the % operator.

For this, we'll use Wikipedia's article on divisibility. This lesson is about seeing if we can adapt the rules found here directly into Prolog.
[item1,item2,item3,item4,item5,item6,...]
Move the mouse over a dotted box for more information.

We'll use a list here to contain the digits of a 7-digit number that you want to test for divisibility.

Now you try. Test a few numbers for divisibility

Type your code here:


See your results here: