Convert integers to and from the factoradic number system
Project description
The factorial number system (also known as factoradic) is a way of representing an integer as the sum of multiples of factorials. All integers have a unique representation in the factoradic number system. For example, the number 1337 can be represented as:
1*6! + 5*5! + 0*4! + 2*3! + 2*2! + 1*1! + 0*0!
with coefficients 1 5 0 2 2 1 0. This is the unique factoradic representation of decimal 1337.
Factoradic numbers have uses in combinatorics, particularly in the numbering of permutations. This factoradic library is useful for converting to and from factoradic number representations both in Python and from the commandline.
Status
Installation
The factoradic package is available on the Python Package Index (PyPI):
The package supports Python 3 only. To install:
$ pip install factoradic
Python Interface
For full help:
>>> import factoradic >>> help(factoradic)
In the meantime, here are some highlights.
To convert from an integer to factoradic use to_factoradic():
>>> factoradic.to_factoradic(1337) [0, 1, 2, 2, 0, 5, 1]
The result is the list of coefficients where the factorial of each zerobased index gives a place value, and the item at that index is the coefficient by with the place value is to be multiplied. The elements are from leastsignificant to mostsignificant. Since the coefficient at any index must be less that or equal to the index, the coefficient at index 0 is always 0.
To convert from factoradic use from_factoradic():
>>> factoradic.from_factoradic([0, 1, 2, 2, 0, 5, 1]) 1337
CommandLine Interface
There’s also a handy commandline interface. Run factoradic help to see a list of commands:
$ factoradic help Factoradic. Convert to and from the factorial number system. Usage: factoradic frominteger <integer> [expression] factoradic tointeger <coefficient0> [<coefficient1> [<coefficientn>...]] Options: e expression Show as a mathematical expression.
To convert from an integer to factoradic, use the frominteger subcommand:
$ factoradic frominteger 1729 0 1 0 0 2 2 2
The coefficients are reported from leastsignificant to mostsignificant. The see the results as a math expression, specify the expression flag:
$ factoradic frominteger 1729 expression 2*6! + 2*5! + 2*4! + 0*3! + 0*2! + 1*1! + 0*0!
To convert from factoradic representation use the tointeger subcommand, specifying the coefficients from leastsignificant to mostsignificant:
$ factoradic tointeger 0 1 0 0 2 2 2 1729
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for factoradic1.0.3py3noneany.whl
Algorithm  Hash digest  

SHA256  378e3822a0b3149bc4709d2822d038d82bf5b138db19868dfe96df20fc5af50b 

MD5  a569bce239c27c7c5ec1eb0b7ba681b0 

BLAKE2b256  6c81c237352a4eda57515be7015a54240ae0a00504e0db206e9918da0619e50b 