I wrote some code that should find number k (10 digits long), where each digit (0-9) is used only once and satisfying the following conditions:
- The first digit of k should be divisible by 1 (duh)
- The first two digits of k should be divisible by 2
- ...
- The first ten digits of k should be divisible by 10
Here is the code:
k = Table[i, {i, 0, 9999999999}];
Select[%, IntegerLength[#, 10] == 10 &];
Select[%, Divisible[#, 10] &];
Select[%, Divisible[IntegerPart[#/10], 9] &];
Select[%, Divisible[IntegerPart[#/100], 8] &];
Select[%, Divisible[IntegerPart[#/1000], 7] &];
Select[%, Divisible[IntegerPart[#/10000], 6] &];
Select[%, Divisible[IntegerPart[#/100000], 5] &];
Select[%, Divisible[IntegerPart[#/1000000], 4] &];
Select[%, Divisible[IntegerPart[#/10000000], 3] &];
Select[%, Divisible[IntegerPart[#/100000000], 2] &]
Unfortunately I got an error: SystemException["MemoryAllocationFailure"]
What can I do to avoid this error? Is there a more neat way to solve my problem in Mathematica?
Thanks a lot!
EDIT: I am a real beginner with Mathematica, so even basic tips for improvement are appreciated!