1 Star 1 Fork 0

lengyanju8/buffer-of-thought-llm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_templates.py 5.55 KB
一键复制 编辑 原始数据 按行查看 历史
lengyanju8 提交于 2024-06-22 16:56 . 添加中文注释
# game24的模板
game24="""
from itertools import permutations, product
def perform_operation(a, b, operation):
# Define the operation logic (e.g., addition, subtraction, etc.).
pass
def evaluate_sequence(sequence, operations):
# Apply operations to the sequence and check if the result meets the criteria.
pass
def generate_combinations(elements, operations):
# Generate all possible combinations of elements and operations.
pass
def format_solution(sequence, operations):
# Format the sequence and operations into a human-readable string.
pass
def find_solution(input_elements, target_result):
# Data Input Handling
# Validate and preprocess input data if necessary.
# Core Algorithm Logic
for sequence in permutations(input_elements):
for operation_combination in generate_combinations(sequence, operations):
try:
if evaluate_sequence(sequence, operation_combination) == target_result:
# Data Output Formatting
return format_solution(sequence, operation_combination)
except Exception as e:
# Error Handling
# Handle specific exceptions that may occur during evaluation.
continue
# If no solution is found after all iterations, return a default message.
return "No solution found."
# Example instantiation:
def calculate(a, b, op):
if op == '+': return a + b
if op == '-': return a - b
if op == '*': return a * b
if op == '/': return a / b
def find_solution(numbers):
ops = '+-*/'
for nums in permutations(numbers):
for op1, op2, op3 in product(ops, repeat=3):
try:
result = calculate(calculate(calculate(nums[0], nums[1], op1), nums[2], op2), nums[3], op3)
if abs(result - 24) < 1e-6:
return f"(({nums[0]} {op1} {nums[1]}) {op2} {nums[2]}) {op3} {nums[3]} = 24"
result = calculate(calculate(nums[0], calculate(nums[1], nums[2], op2), op1), nums[3], op3)
if abs(result - 24) < 1e-6:
return f"({nums[0]} {op1} ({nums[1]} {op2} {nums[2]})) {op3} {nums[3]} = 24"
result = calculate(nums[0], calculate(calculate(nums[1], nums[2], op2), nums[3], op3), op1)
if abs(result - 24) < 1e-6:
return f"{nums[0]} {op1} (({nums[1]} {op2} {nums[2]}) {op3} {nums[3]}) = 24"
result = calculate(nums[0], calculate(nums[1], calculate(nums[2], nums[3], op3), op2), op1)
if abs(result - 24) < 1e-6:
return f"{nums[0]} {op1} ({nums[1]} {op2} ({nums[2]} {op3} {nums[3]})) = 24"
result = calculate(calculate(nums[0], nums[1], op1), calculate(nums[2], nums[3], op3), op2)
if abs(result - 24) < 1e-6:
return f"({nums[0]} {op1} {nums[1]}) {op2} ({nums[2]} {op3} {nums[3]}) = 24"
except ZeroDivisionError:
continue
return "No solution found."
numbers = [1, 7, 10, 13]
print(find_solution(numbers))
"""
checkmate = """
import chess
def find_checkmate_move(moves_san):
# Initialize a new chess board
board = chess.Board()
# Apply the moves to the board
for move_san in moves_san:
# Remove move numbers and periods (e.g., "1." or "2.")
if len(move_san.split('. ')) > 1:
move_san = move_san.split('. ')[1]
# Skip empty strings resulting from the removal
if move_san:
# Apply each move in SAN format to the board
move = board.parse_san(move_san)
board.push(move)
# Generate all possible legal moves from the current position
for move in board.legal_moves:
# Make the move on a copy of the board to test the result
board_copy = board.copy()
board_copy.push(move)
# Check if the move results in a checkmate
if board_copy.is_checkmate():
# Return the move that results in checkmate in SAN format
return board.san(move)
return "No checkmate move found"
#Example usage:
input = '1. d4 d5 2. Nf3 Nf6 3. e3 a6 4. Nc3 e6 5. Bd3 h6 6. e4 dxe4 7. Bxe4 Nxe4 8. Nxe4 Bb4+ 9. c3 Ba5 10. Qa4+ Nc6 11. Ne5 Qd5 12. f3 O-O 13. Nxc6 bxc6 14. Bf4 Ra7 15. Qb3 Qb5 16. Qxb5 cxb5 17. a4 bxa4 18. Rxa4 Bb6 19. Kf2 Bd7 20. Ke3 Bxa4 21. Ra1 Bc2 22. c4 Bxe4 23. fxe4 c5 24. d5 exd5 25. exd5 Re8+ 26. Kf3 Rae7 27. Rxa6 Bc7 28. Bd2 Re2 29. Bc3 R8e3+ 30. Kg4 Rxg2+ 31. Kf5'
# Check input format and transform the input into legal format
# Remove move numbers and periods (e.g., "1." or "2.")
moves_san = [input]
moves_san = moves_san[0].split(' ')
moves_san = [move for move in moves_san if '.' not in move]
checkmate_move = find_checkmate_move(moves_san)
print(checkmate_move)
"""
word_sorting = """
def sort_words(words):
\"""
Sorts a list of words alphabetically and returns them as a single line of text separated by spaces.
Args:
words (list): A list of words to be sorted.
Returns:
str: A single line of text with words sorted alphabetically and separated by spaces.
\"""
# Sort the list of words alphabetically
sorted_words = sorted(words)
# Join the sorted words into a single line of text separated by spaces
sorted_line = ' '.join(sorted_words)
return sorted_line
# Example usage
input_list = 'thrill splutter panicking scorch same dot prod obstetric malton onus drumhead delmarva barn embezzle it&t damp guru subsist entirety greene'
words_list = input_list.split(' ')
sorted_line = sort_words(words_list)
print(sorted_line)
"""
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lengyanju8/buffer-of-thought-llm.git
git@gitee.com:lengyanju8/buffer-of-thought-llm.git
lengyanju8
buffer-of-thought-llm
buffer-of-thought-llm
main

搜索帮助