# 執位

## 例子

### 對稱群一

${\displaystyle e={\begin{bmatrix}1&2&3\\1&2&3\\\end{bmatrix}}}$${\displaystyle a={\begin{bmatrix}1&2&3\\2&3&1\\\end{bmatrix}}}$${\displaystyle a^{2}={\begin{bmatrix}1&2&3\\3&1&2\\\end{bmatrix}}}$

${\displaystyle b={\begin{bmatrix}1&2&3\\1&3&2\\\end{bmatrix}}}$${\displaystyle ab={\begin{bmatrix}1&2&3\\2&1&3\\\end{bmatrix}}}$${\displaystyle a^{2}b={\begin{bmatrix}1&2&3\\3&2&1\\\end{bmatrix}}}$

${\displaystyle ab={\begin{bmatrix}1&2&3\\2&3&1\\\end{bmatrix}}{\begin{bmatrix}1&2&3\\1&3&2\\\end{bmatrix}}={\begin{bmatrix}1&2&3\\2&1&3\\\end{bmatrix}}}$

${\displaystyle ba={\begin{bmatrix}1&2&3\\1&3&2\\\end{bmatrix}}{\begin{bmatrix}1&2&3\\2&3&1\\\end{bmatrix}}={\begin{bmatrix}1&2&3\\1&3&2\\\end{bmatrix}}}$

### 對稱群二

${\displaystyle S_{n}}$嘅嘢係咁嘅樣${\displaystyle \sigma ={\begin{bmatrix}1&2&\cdots &n\\\sigma (1)&\sigma (2)&\cdots &\sigma (n)\end{bmatrix}}}$

### 正方形旋轉反射群

${\displaystyle D_{4}}$${\displaystyle S_{4}}$嘅子群。

## Python列舉執位

def permutations(elements):
if len(elements) <= 1:
return [elements]
else:
perms = []
for i in range(len(elements)):
current = elements[i]
remaining = elements[:i] + elements[i+1:]
for p in permutations(remaining):
perms.append([current] + p)
return perms

# Prompt the user to input elements
input_str = input("Enter a list of elements (space-separated): ")
input_list = input_str.split()

# Convert input elements to integers
input_list = [int(e) for e in input_list]

# Generate permutations
result = permutations(input_list)
total_permutations = len(result)

# Print permutations and total count
for permutation in result:
print(permutation)

print("Total permutations:", total_permutations)