Skip to main content

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 command-line.

Status

https://travis-ci.org/rob-smallshire/factoradic.svg?branch=master https://coveralls.io/repos/github/rob-smallshire/factoradic/badge.svg?branch=master

Installation

The factoradic package is available on the Python Package Index (PyPI):

https://badge.fury.io/py/factoradic.svg

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 zero-based 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 least-significant to most-significant. 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

Command-Line Interface

There’s also a handy command-line interface. Run factoradic --help to see a list of commands:

$ factoradic --help
Factoradic.

Convert to and from the factorial number system.

Usage:
  factoradic from-integer <integer> [--expression]
  factoradic to-integer <coefficient-0> [<coefficient-1> [<coefficient-n>...]]

Options:
  -e --expression  Show as a mathematical expression.

To convert from an integer to factoradic, use the from-integer subcommand:

$ factoradic from-integer 1729
0 1 0 0 2 2 2

The coefficients are reported from least-significant to most-significant. The see the results as a math expression, specify the --expression flag:

$ factoradic from-integer 1729 --expression
2*6! + 2*5! + 2*4! + 0*3! + 0*2! + 1*1! + 0*0!

To convert from factoradic representation use the to-integer subcommand, specifying the coefficients from least-significant to most-significant:

$ factoradic to-integer 0 1 0 0 2 2 2
1729

Release files for factoradic 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for factoradic 1.0.3
File Size Uploaded
factoradic-1.0.3.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for factoradic 1.0.3
File Interpreter ABI Platform
factoradic-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / factoradic-1.0.3.tar.gz

Download URL factoradic-1.0.3.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
132dbfc88363daca6e2007f5c572fe019fcdbb0705e10f239a0461b53346b618
BLAKE2b-256 checksum
How to use checksums
b50de06b2702cc7c66d9cebc4ba31e575419cd24abb1132698ab1ddbab1a8e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / factoradic-1.0.3-py3-none-any.whl

Download URL factoradic-1.0.3-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
378e3822a0b3149bc4709d2822d038d82bf5b138db19868dfe96df20fc5af50b
BLAKE2b-256 checksum
How to use checksums
6c81c237352a4eda57515be7015a54240ae0a00504e0db206e9918da0619e50b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page