##Lua, 154 Bytes
Lua, 154 Bytes
###Explanations
Explanations
##Lua, 154 Bytes
###Explanations
Lua, 154 Bytes
Explanations
##Lua, 154 Bytes
I should have some ways to golf this down, I'm experimenting right now.
n=...z=table
while n+0>9 do
t={}T={}n=n..''n:gsub(".",function(c)t[#t+1]=c T[#T+1]=c
end)z.sort(t)x=t[#t]z.remove(T,n:find(x))n=z.concat(T)*x
end
print(n)
###Explanations
n=... -- define n as a shorthand for the argument
z=table -- define z as a pointer to the object table
while n+0>9 -- iterate as long as n is greater than 9
do -- n+0 ensure that we're using a number to do the comparison
t={} -- intialise two tables, one is used to find the greatest digit
T={} -- the other one is used to remove it from the string
n=n..'' -- ensure that n is a string (mandatory after the first loop)
n:gsub(".",function(c) -- apply an anonymous function to each character in n
t[#t+1]=c -- fill our tables with the digits
T[#T+1]=c
end)
z.sort(t) -- sort t to put the greatest digit in the last index
x=t[#t] -- intialise x to the value of the greatest digit
z.remove(T,n:find(x)) -- remove the first occurence of x from the table T
-- based on its position in the input string
n=z.concat(T)*x -- assign the new value to n
end -- if it still isn't a single digit, we're looping over again
print(n) -- output the answer