blob: 53e21976d0fbbd82c6a59f54449fca71265e3fa5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env lua
local function count_factors(n)
local c,count = 2,0
while n > 1 do
if n % c == 0 then n = n // c count = count + 1 else c = c + 1 end
end
return count
end
local function prime_order(t)
assert(type(t) == 'table','t must be a table!')
table.sort(t,function(a,b)
local fa,fb = count_factors(a),count_factors(b)
return fa == fb and a < b or fa < fb
end)
return table.concat(t,',')
end
print(prime_order{11,8,27,4})
|