File Exchange

image thumbnail


version (1.77 KB) by Darren Rowland
Obtain the factorial radix representation of a number.

1 Download

Updated 27 Apr 2009

View License

F = factoradic(M,N) returns the conversion of integer M into factorial radix. F is a 1-by-N vector. The factoradic is also known as the Lehmer Code. The factoradic of M is best understood by example.

Example: 89 = 3x4! + 2x3! + 2x2! + 1x1! + 0x0!
therefore factoradic(89,5) = (3,2,2,1,0)

M must lie in the range [0 : N!-1].
Leading zeros will be present in F when M < (N-1)!-1.

Example: factoradic(19,6) = (0,0,3,0,1,0)

A practical use of the factoradic is the generation of permutations. See ONEPERM on the File Exchange.

Cite As

Darren Rowland (2020). FACTORADIC (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

John D'Errico

A useful tool when generating permutations. In fact, I was thinking of putting up this myself. No need to do so now.

Good help. Error checks. Simple engine.


Thanks to Stefano Bolli for noticing a typo in the error-checking.

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux