Factor Command and Function

This object contains a single-line command which uses a function that outputs a sorted list of factorised numbers.

Author: Wisdom@BrazilMUX
Category: Functions

Instructions

Copy and paste the below code into a compatible MUSH or MUX.

MUSHCode for Factor Command and Function

@create Factor Command and Function
@lock Factor Command and Function==me
@Desc Factor Command and Function=This object contains a single-line command which uses a function that outputs a sorted list of factorised numbers.%r%rUsage: factor <integer>%r%rFor example "factor 78" will @pemit the string "1 2 3 6 13 26 39 78" to you. I formatted it for giggles.%r%rThere is also a function FN.FACTOR on this object which does the same thing if called as factor%(<integer>%) which outputs a 0 if the number is not an integer.%r%rEnjoy!%r%r[repeat(-,78)]%r&cmd.factor [name(me)]=$factor *:@switch %[isint%(%%0)%]=0,%{@pemit %%#=Sorry, but '%%0' is not a valid integer number.%},1,@pemit %%#=%[setq%(x,lnum%(1,ceil%(sqrt%(%%0))))%]%[setq%(y,%[iter%(%[r%(x)%],switch%(%[mod%(%%0,##)%],0,##,))%])%]%[setq%(z,iter%(%[r%(y)%],switch%(%[mod%(%%0,##)%],0,div%(%%0,##),)))%]The factors of %%0 are: %[sort%(r%(y) %[r(z)%])%]%r%r%r&fn.factor [name(me)]=@switch %[isint%(%%0)%]=0,0,1,%[setq%(x,lnum%(1,ceil%(sqrt%(%%0))))%]%[setq%(y,%[iter%(%[r%(x)%],switch(%[mod%(%%0,##)%],0,##,)%)%])%]%[setq%(z,iter%(%[r%(y)%],switch(%[mod%(%%0,##)%],0,div%(%%0,##),)))%]%[sort%(r%(y) %[r%(z)%])%]%r[repeat(-,78)]%r%rIt might be useful for calculating width%(%) on a user's screen and formatting the output of a table%(%) so that it always has exactly the right column width to divide evenly, depending on the number of columns desired.
&CMD.FACTOR Factor Command and Function=$factor *:@switch [isint(%0)]=0,{@pemit %#=Sorry, but '%0' is not a valid integer number.},1,@pemit %#=[setq(x,lnum(1,ceil(sqrt(%0))))][setq(y,[iter([r(x)],switch([mod(%0,##)],0,##,))])][setq(z,iter([r(y)],switch([mod(%0,##)],0,div(%0,##),)))]The factors of %0 are: [sort(r(y) [r(z)])]
&FN.FACTOR Factor Command and Function=@switch [isint(%0)]=0,0,1,[setq(x,lnum(1,ceil(sqrt(%0))))][setq(y,[iter([r(x)],switch([mod(%0,##)],0,##,))])][setq(z,iter([r(y)],switch([mod(%0,##)],0,div(%0,##),)))][sort(r(y) [r(z)])]
&CREDIT Factor Command and Function=Wisdom@BrazilMUX
@set Factor Command and Function=COMMANDS