Your program must take an input (n
for the purpose of description) and output all permutations of a number that is n
digits long with no repeating digits, where each of the digits preceding and including its index are divisible by the place in the number that it falls.
You can read about magic numbers here.
Rules:
1 <= n <= 10
- No digits may be repeated
- The leading 0 must be present (if applicable)
- The 1st through
x
th digit of the number (starting with the first character as 1) must be divisible byx
, i.e. in30685
,3
is divisible by 1,30
is divisible by 2,306
is divisible by 3,3068
is divisible by 4, and30685
is divislbe by 5. - The program must take an integer as input (through the command line, as a function argument, etc.) and print all permutations that satisfy the rules.
- Output must be separated by 1 or more white space character
- Permutations may start and with zero (so they're not technically magic numbers).
- The order of output does not matter
- You do not need to handle unexpected input
- Least characters in bytes wins
Examples
Given 1:
0
1
2
3
4
5
6
7
8
9
Given 2:
02
04
06
08
10
12
14
16
18
20
24
26
28
30
32
34
36
38
40
42
46
48
50
52
54
56
58
60
62
64
68
70
72
74
76
78
80
82
84
86
90
92
94
96
98
Given 10:
3816547290
Credit to Pizza Hut & John H. Conway for the original puzzle (Option A). Thanks to @Mego and @sp3000 for their links.