## Factorial Numbers and Factoradic Representation

In mathematics, factorial of a number $$n$$, denoted as $$n!$$, is the product of all positive integers less than or equal to $$n$$. For example, the factorial of 5, denoted as $$5!$$ is calculated as:

$$5! = 5 \times 4 \times 3 \times 2 \times 1 = 120$$

Factorial numbers are used in various mathematical and computational problems, especially in combinatorics and permutations.

## Factoradic Representation

Factoradic is a way to represent numbers using factorial numbers. It is a mixed radix numeral system, where the radix or base varies for each digit. The base of each digit is the factorial of its position.

For example, the factoradic representation of 23 is:

$$23 = 3 \times 3! + 2 \times 2! + 1 \times 1! + 0 \times 0! = 3210_{(factoradic)}$$

The factoradic representation of a number can be found using the `factoradic` library in Python.

```python
import factoradic

# Convert number to factoradic
factoradic.to_factoradic(23)
```

This will return `[3, 2, 1, 0]`, which is the factoradic representation of 23.

## Permutations and Factoradic

Permutations are the arrangements of a set of objects in a specific order. The number of permutations of a set of $$n$$ distinct objects is $$n!$$.

There is a one-to-one correspondence between the permutations of a set and the factoradic numbers of a certain length. For example, the 4-digit factoradic numbers correspond to the permutations of a 4-element set.

This property can be used to convert between permutations and factoradic numbers.

## Converting Sequence to List

The `seq2list` function converts a number to a list of characters, where the order of the characters corresponds to a permutation of the set.

```python
TEMPLATE = ':abcdefghijklmnopqrstuvwxyz'

def seq2list(number):
    # Convert number to factoradic
    new_numbers = (factoradic.to_factoradic(number) + [0] * 27)[:27][::-1]
    # Convert factoradic to permutation
    temp = list(TEMPLATE)
    return [temp.pop(i) for i in new_numbers]
```

In this function, the number is first converted to its factoradic representation. Then, each digit of the factoradic number is used to pop a character from the `TEMPLATE` string. The popped characters are returned as a list.

## Converting List to Sequence

The `list2seq` function does the reverse of `seq2list`. It converts a list of characters to a number.

```python
import bisect

def list2seq(mylist):
    # Convert permutation to factoradic
    new_strings = mylist[::-1]
    temp = []
    factoradic_numbers = [bisect.insort(temp, c) or temp.index(c) for c in new_strings]
    # Convert factoradic to number
    return factoradic.from_factoradic(factoradic_numbers)
```

In this function, each character in the input list is inserted into a temporary list. The index of the inserted character is used as a digit of the factoradic number. The factoradic number is then converted to a regular number.

## Using the Functions

The `seq2list` and `list2seq` functions can be used to convert between numbers and permutations.

```python
if __name__ == "__main__":
    result = seq2list(np.math.factorial(27)-np.math.factorial(24))
    print(result)
    result = list2seq(list(':abcdefghijklmnopqrstuvwxzy'))
    print(result)
```

In this example, the number $$27! - 24!$$ is converted to a permutation, and the permutation `:abcdefghijklmnopqrstuvwxzy` is converted to a number.