1 | require ('table') |
---|
2 | require ('string') |
---|
3 | |
---|
4 | -- string iterator |
---|
5 | |
---|
6 | local nextchar = function (s, i) |
---|
7 | if i == nil then return 1, string.sub(s, 1, 1) end |
---|
8 | if i >= #s then return nil, nil end |
---|
9 | i = i + 1 |
---|
10 | return i, string.sub(s, i, i) |
---|
11 | end |
---|
12 | |
---|
13 | -- string explist |
---|
14 | |
---|
15 | chars = function (s) |
---|
16 | return nextchar, s, nil |
---|
17 | end |
---|
18 | |
---|
19 | -- full iteration |
---|
20 | |
---|
21 | charlist = function (s) |
---|
22 | local result = {} |
---|
23 | for _, c in chars(s) do |
---|
24 | table.insert(result, c) |
---|
25 | end |
---|
26 | return result |
---|
27 | end |
---|
28 | |
---|
29 | digits = function (n) |
---|
30 | local L = charlist(tostring(n)) |
---|
31 | table.sort(L) |
---|
32 | return table.concat(L) |
---|
33 | end |
---|
34 | |
---|
35 | local power = 100000 |
---|
36 | local i = power |
---|
37 | repeat |
---|
38 | local dig = digits(i) |
---|
39 | local found = true |
---|
40 | for j = 6, 2, -1 do |
---|
41 | if dig ~= digits(j*i) then |
---|
42 | found = false |
---|
43 | break |
---|
44 | end |
---|
45 | end |
---|
46 | if found then |
---|
47 | print(i, 2*i, 3*i, 4*i, 5*i, 6*i) |
---|
48 | break |
---|
49 | end |
---|
50 | i = i+1 |
---|
51 | if string.sub(tostring(i), 1, 1) == '2' then |
---|
52 | power = power * 10 |
---|
53 | i = power |
---|
54 | end |
---|
55 | until eternity |
---|
56 | |
---|
57 | -- 142857 285714 428571 571428 714285 857142 |
---|