The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.
Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:
- d2d3d4=406 is divisible by 2
- d3d4d5=063 is divisible by 3
- d4d5d6=635 is divisible by 5
- d5d6d7=357 is divisible by 7
- d6d7d8=572 is divisible by 11
- d7d8d9=728 is divisible by 13
- d8d9d10=289 is divisible by 17
Find the sum of all 0 to 9 pandigital numbers with this property.
analyse:
We can create a list with all 0-9 pan-digitals, see problem 41, then extract the 3 digit
subgroups and check for divisibility by apropiate prime. However this will yield to a hell
of a lot loops (about 10! fac). So we have to think of something smarter.
more analyse lead to the following axioma's:
axioma 1: a 10 digit pandigital can't start with a zero. d1 <> 0.
axioma 2: d4 must be even. d4 = {0,2,4,6,8}
axioma 3: d456 must be div by 5. d6 = {0,5}
axioma 4: d678 must be div by 11. With d6=0 we get 011,022,033. This is div by 11 but contains dual digits.
So d6 must be a 5.
Solution:
Create a array with digit d1 to d10.
Increment each digit starting with digit one.
Check for unique digit and apply dividible rules recursive.
Problem43 = 16695334890 elapsed time: 8 ms. Test Passed.
Geen opmerkingen:
Een reactie posten