mlymath 0.1.4b1__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mlymath-0.1.4b1 → mlymath-0.2.0}/PKG-INFO +12 -1
- {mlymath-0.1.4b1 → mlymath-0.2.0}/README.md +11 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/math/math.py +2 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/mlymath.egg-info/PKG-INFO +12 -1
- {mlymath-0.1.4b1 → mlymath-0.2.0}/mlymath.egg-info/SOURCES.txt +2 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/mlymath.egg-info/top_level.txt +1 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/morse/morse.py +1 -0
- mlymath-0.2.0/puzzle/__init__.py +9 -0
- mlymath-0.2.0/puzzle/puzzle.py +90 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/setup.py +1 -1
- {mlymath-0.1.4b1 → mlymath-0.2.0}/sort/sort.py +2 -1
- {mlymath-0.1.4b1 → mlymath-0.2.0}/math/__init__.py +0 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/mlymath.egg-info/dependency_links.txt +0 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/morse/__init__.py +0 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/setup.cfg +0 -0
- {mlymath-0.1.4b1 → mlymath-0.2.0}/sort/__init__.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: mlymath
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0
|
4
4
|
Summary: 一个用于数学计算的Python库
|
5
5
|
Author: mly
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
@@ -49,6 +49,7 @@ Dynamic: summary
|
|
49
49
|
- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥
|
50
50
|
- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据
|
51
51
|
- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据
|
52
|
+
- math_help() -> None: 显示math帮助信息
|
52
53
|
- mlymath.sort 排序模块
|
53
54
|
- quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
54
55
|
- shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
@@ -60,9 +61,19 @@ Dynamic: summary
|
|
60
61
|
- selection_sort: 使用选择排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
61
62
|
- counting_sort: 使用计数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
62
63
|
- radix_sort: 使用基数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
64
|
+
- sort_help: 显示可用的排序算法列表
|
63
65
|
- mlymath.morse 摩斯电码模块
|
64
66
|
- morse(input_string): 将字符串转换为摩尔斯电码
|
65
67
|
- unmorse(morse_code): 将摩尔斯电码转换为字符串
|
68
|
+
- morse_help(): 打印摩尔斯电码的使用帮助信息
|
69
|
+
- mlymath.puzzle puzzle求解模块
|
70
|
+
- solve_24_num_puzzle(board):函数用于求解 5x5 数字华容道问题
|
71
|
+
- 参数:
|
72
|
+
- board: 初始 5x5 矩阵,格式为二维元组,例如 ((1, 2, 3, 4, 5), (6, 7, 8, 9, 10), ...)。
|
73
|
+
- 返回值:
|
74
|
+
- 如果有解,则返回解决方案路径(字符串形式),例如 'UURDL'。
|
75
|
+
- 如果无解,则返回空字符串。
|
76
|
+
- puzzle_help: puzzle_help函数用于打印可用函数的帮助信息。
|
66
77
|
#### mly万岁!!!🎉
|
67
78
|
#### mly万岁!!!🎉
|
68
79
|
#### mly万岁!!!🎉
|
@@ -32,6 +32,7 @@
|
|
32
32
|
- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥
|
33
33
|
- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据
|
34
34
|
- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据
|
35
|
+
- math_help() -> None: 显示math帮助信息
|
35
36
|
- mlymath.sort 排序模块
|
36
37
|
- quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
37
38
|
- shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
@@ -43,9 +44,19 @@
|
|
43
44
|
- selection_sort: 使用选择排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
44
45
|
- counting_sort: 使用计数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
45
46
|
- radix_sort: 使用基数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
47
|
+
- sort_help: 显示可用的排序算法列表
|
46
48
|
- mlymath.morse 摩斯电码模块
|
47
49
|
- morse(input_string): 将字符串转换为摩尔斯电码
|
48
50
|
- unmorse(morse_code): 将摩尔斯电码转换为字符串
|
51
|
+
- morse_help(): 打印摩尔斯电码的使用帮助信息
|
52
|
+
- mlymath.puzzle puzzle求解模块
|
53
|
+
- solve_24_num_puzzle(board):函数用于求解 5x5 数字华容道问题
|
54
|
+
- 参数:
|
55
|
+
- board: 初始 5x5 矩阵,格式为二维元组,例如 ((1, 2, 3, 4, 5), (6, 7, 8, 9, 10), ...)。
|
56
|
+
- 返回值:
|
57
|
+
- 如果有解,则返回解决方案路径(字符串形式),例如 'UURDL'。
|
58
|
+
- 如果无解,则返回空字符串。
|
59
|
+
- puzzle_help: puzzle_help函数用于打印可用函数的帮助信息。
|
49
60
|
#### mly万岁!!!🎉
|
50
61
|
#### mly万岁!!!🎉
|
51
62
|
#### mly万岁!!!🎉
|
@@ -447,3 +447,5 @@ def math_help():
|
|
447
447
|
print("- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥")
|
448
448
|
print("- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据")
|
449
449
|
print("- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据")
|
450
|
+
print("- math_help() -> None: 显示帮助信息")
|
451
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: mlymath
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0
|
4
4
|
Summary: 一个用于数学计算的Python库
|
5
5
|
Author: mly
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
@@ -49,6 +49,7 @@ Dynamic: summary
|
|
49
49
|
- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥
|
50
50
|
- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据
|
51
51
|
- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据
|
52
|
+
- math_help() -> None: 显示math帮助信息
|
52
53
|
- mlymath.sort 排序模块
|
53
54
|
- quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
54
55
|
- shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
@@ -60,9 +61,19 @@ Dynamic: summary
|
|
60
61
|
- selection_sort: 使用选择排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
61
62
|
- counting_sort: 使用计数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
62
63
|
- radix_sort: 使用基数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
64
|
+
- sort_help: 显示可用的排序算法列表
|
63
65
|
- mlymath.morse 摩斯电码模块
|
64
66
|
- morse(input_string): 将字符串转换为摩尔斯电码
|
65
67
|
- unmorse(morse_code): 将摩尔斯电码转换为字符串
|
68
|
+
- morse_help(): 打印摩尔斯电码的使用帮助信息
|
69
|
+
- mlymath.puzzle puzzle求解模块
|
70
|
+
- solve_24_num_puzzle(board):函数用于求解 5x5 数字华容道问题
|
71
|
+
- 参数:
|
72
|
+
- board: 初始 5x5 矩阵,格式为二维元组,例如 ((1, 2, 3, 4, 5), (6, 7, 8, 9, 10), ...)。
|
73
|
+
- 返回值:
|
74
|
+
- 如果有解,则返回解决方案路径(字符串形式),例如 'UURDL'。
|
75
|
+
- 如果无解,则返回空字符串。
|
76
|
+
- puzzle_help: puzzle_help函数用于打印可用函数的帮助信息。
|
66
77
|
#### mly万岁!!!🎉
|
67
78
|
#### mly万岁!!!🎉
|
68
79
|
#### mly万岁!!!🎉
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import heapq
|
2
|
+
|
3
|
+
def solve_24_num_puzzle(board_5):
|
4
|
+
"""
|
5
|
+
整合所有功能的函数,用于求解5x5数字华容道问题。
|
6
|
+
:param board_5: 初始5x5矩阵,格式为二维元组,例如 ((1, 2, 3, 4, 5), (6, 7, 8, 9, 10), ...)
|
7
|
+
:return: 解决方案路径或"无解"
|
8
|
+
"""
|
9
|
+
# 初始化方向和变量
|
10
|
+
dx = [1, -1, 0, 0]
|
11
|
+
dy = [0, 0, 1, -1]
|
12
|
+
directions = ['U', 'D', 'L', 'R'] # 修改为英文标准字母表示
|
13
|
+
hs = 0
|
14
|
+
|
15
|
+
def get_heuristic_best(state, target, n):
|
16
|
+
nonlocal hs
|
17
|
+
hs += 1
|
18
|
+
heuristic = 0
|
19
|
+
for i, char in enumerate(state):
|
20
|
+
if char != '0':
|
21
|
+
target_idx = target.index(char)
|
22
|
+
current_row, current_col = divmod(i, n)
|
23
|
+
target_row, target_col = divmod(target_idx, n)
|
24
|
+
heuristic += abs(current_row - target_row) + abs(current_col - target_col)
|
25
|
+
return heuristic
|
26
|
+
|
27
|
+
def swap(s, i, j):
|
28
|
+
chars = list(s)
|
29
|
+
chars[i], chars[j] = chars[j], chars[i]
|
30
|
+
return ''.join(chars)
|
31
|
+
|
32
|
+
def board_to_string(board, n):
|
33
|
+
def to_base_25(num):
|
34
|
+
if num == 0:
|
35
|
+
return '0'
|
36
|
+
base_25 = ''
|
37
|
+
while num > 0:
|
38
|
+
remainder = num % 25
|
39
|
+
base_25 = (chr(48 + remainder) if remainder < 10 else chr(65 + remainder - 10)) + base_25
|
40
|
+
num //= 25
|
41
|
+
return base_25
|
42
|
+
return ''.join(to_base_25(num) if num != 0 else '0' for row in board for num in row)
|
43
|
+
|
44
|
+
if board_5 is not None:
|
45
|
+
n = 5
|
46
|
+
target = "123456789ABCDEFGHIJKLMNO0"
|
47
|
+
start = board_to_string(board_5, n)
|
48
|
+
beam_width = 2000
|
49
|
+
|
50
|
+
heap = [(get_heuristic_best(start, target, n), 0, start, '', [])]
|
51
|
+
visited = set()
|
52
|
+
heapq.heapify(heap)
|
53
|
+
|
54
|
+
while heap:
|
55
|
+
next_level = []
|
56
|
+
for _ in range(min(len(heap), beam_width)):
|
57
|
+
_, steps, current, path, manhattan_distances = heapq.heappop(heap)
|
58
|
+
|
59
|
+
if current == target:
|
60
|
+
return f"{path}"
|
61
|
+
|
62
|
+
if current in visited:
|
63
|
+
continue
|
64
|
+
|
65
|
+
visited.add(current)
|
66
|
+
|
67
|
+
zero_pos = current.index('0')
|
68
|
+
x, y = divmod(zero_pos, n)
|
69
|
+
|
70
|
+
for i in range(4):
|
71
|
+
new_x, new_y = x + dx[i], y + dy[i]
|
72
|
+
new_pos = new_x * n + new_y
|
73
|
+
if 0 <= new_x < n and 0 <= new_y < n:
|
74
|
+
new_state = swap(current, zero_pos, new_pos)
|
75
|
+
if new_state not in visited:
|
76
|
+
new_manhattan_distance = get_heuristic_best(new_state, target, n)
|
77
|
+
new_manhattan_distances = manhattan_distances + [new_manhattan_distance]
|
78
|
+
new_cost = new_manhattan_distance + steps + 1
|
79
|
+
heapq.heappush(next_level, (
|
80
|
+
new_cost, steps + 1, new_state, path + directions[i], new_manhattan_distances))
|
81
|
+
|
82
|
+
heap = next_level
|
83
|
+
heapq.heapify(heap)
|
84
|
+
|
85
|
+
return ""
|
86
|
+
|
87
|
+
def puzzle_help():
|
88
|
+
print("以下是可用的函数:")
|
89
|
+
print("- solve_24_num_puzzle(board_5):\n solve_24_num_puzzle 函数用于求解 5x5 数字华容道问题。\n 参数:\n board_5: 初始 5x5 矩阵,格式为二维元组,例如 ((1, 2, 3, 4, 5), (6, 7, 8, 9, 10), ...)。\n 返回值:\n 如果有解,则返回解决方案路径(字符串形式),例如 'UURDL'。\n 如果无解,则返回空字符串。")
|
90
|
+
print("- puzzle_help:\n puzzle_help 函数用于打印可用函数的帮助信息。")
|
@@ -175,4 +175,5 @@ def sort_help():
|
|
175
175
|
print("- merge_sort: 使用归并排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)")
|
176
176
|
print("- selection_sort: 使用选择排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)")
|
177
177
|
print("- counting_sort: 使用计数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)")
|
178
|
-
print("- radix_sort: 使用基数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)")
|
178
|
+
print("- radix_sort: 使用基数排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)")
|
179
|
+
print("- sort_help: 显示可用的排序算法列表")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|