mob/verb/Factors(n as num)
var/list/L = getfactors(n)
And if n was 12, L would contain "1,3,4,6,12" (I don't really want negative numbers - I don't even know if they count as factors or not).
I can't really think of any smart way of doing it, all that comes to mind is something like:
proc/getfactors(n)
var/list/result = list()
for(var/i=1,i<=n,i++)
var/a = n/i
var/b = round(a)
if(a==b)
result += i
return result
There are, however, ways of making a factorization algorithm that is not quite as slow. Somewhere on the internet is an excellent site, which I sadly don't have a bookmark to. :(
A few of the tricks on that site included first checking for 2 specifically, then skipping even numbers from then on. There were also a few binary-related things to help look for multiples of 3 and some other similar numbers.