I'm in the "early phase" of learning prolog and came across a logic riddle that seams easy to implement:
Link to the riddle | Link to solution
We are looking for the 10-digit number which satisfies the following conditions:
- All digits from 0-9 occur exactly once.
- The first 2 digits are divisible by 2.
- The first 3 digits are divisible by 3.
...
- The first 10 digits are divisible by 10.
I think I would first need to implement the rules to the .pl file right? The rules from the solution are:
- An integer can be divided by 1 without remainder.
- An integer is divisible by 2 without remainder, if the last digit is straight.
- An integer can be divided by 3 without a remainder if its transverse sum is divisible by 3.
- An integer can be divided by 4 without a remainder if the last two digits are divisible by 4.
- An integer is divisible by 5 if the last digit is divisible by 5.
- An integer is divisible by 6 without a remainder if its transverse sum is divisible by 3 and the last digit by 2.
- An integer is divisible by 8 without a remainder if the last three digits are divisible by 8.
- An integer is divisible by 9 without a remainder if its transverse sum is divisible by 9.
- An integer is divisible by 10 without a remainder if the last digit is a 0.
I read multiple introductions to rules in prolog but still dont get how do it. Can anyone help? Would be great :)