aboutsummaryrefslogtreecommitdiff
path: root/challenge-115/stuart-little/lua/ch-2.lua
blob: 8b739109130cfb8a8d363146ff95818d73ae6f5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env lua

-- run <script> <space-separated digits>

table.sort(arg)
s = table.concat(arg,"")
fst,odds,rest = s:match("(.)([13579]*)(.*)")

if fst and ("02468"):find(fst) then
   print(s:reverse())
   os.exit()
end

if rest and rest:sub(1,1) ~= "" and ("02468"):find(rest:sub(1,1)) then
   print(rest:sub(2):reverse() .. odds:reverse() .. fst .. rest:sub(1,1))
   os.exit()
end

print("No even digits.")