测试编程人工智能模型LocoOperator
仓库地址:https://modelscope.cn/models/LocoreMind/LocoOperator-4B-GGUF/summary
本仓库包含 LocoOperator-4B 的官方 GGUF 量化版本。
LocoOperator-4B 是一个拥有 40 亿参数的代码探索智能体,由 Qwen3-Coder-Next 蒸馏而来。它专为本地智能体循环(类似 Claude Code 风格)优化,可实现高速代码库导航,并保证 100% JSON 工具调用的有效性。
我下载的是量化版本
https://modelscope.cn/models/LocoreMind/LocoOperator-4B-GGUF/resolve/master/LocoOperator-4B.Q4_K_M.gguf
文件约2.49G。用如下命令行调用
root@kylin-pc:/par# /par/llama.cpp/build/bin/llama-server -m /par/LocoOperator-4B.Q4_K_M.gguf --jinja --ctx-size 16384 --host 127.0.0.1 --port 8033 --reasoning-budget 0
对于已有明确答案的现成算法,表现还不错
用python编写快速排序算法程序,不做别的。
当然可以,以下是一个纯 Python 编写的快速排序算法程序,不包含任何额外功能或注释,仅实现快速排序的核心逻辑:
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)
这个版本使用了分治法,每次选择中间元素作为基准,将数组分为小于、等于、大于基准的三部分,递归排序后合并。
如果你希望一个原地排序的版本(不使用额外空间),也可以使用如下版本:
def quicksort_inplace(arr, low=0, high=None):
if high is None:
high = len(arr) - 1
if low < high:
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] < pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
pivot_index = i + 1
quicksort_inplace(arr, low, pivot_index - 1)
quicksort_inplace(arr, pivot_index + 1, high)
调用方式示例:
arr = [3, 6, 8, 10, 1, 2, 1]
quicksort_inplace(arr)
print(arr)
根据你的需求,我可以提供其中任意一个版本。你希望用哪种?
先测试第一个版本正确,
nbs@kylin-pc:~$ python3 qsortlo.py
[1, 1, 2, 3, 6, 8, 10]
再测试第二个原地排序的版本,也正确
nbs@kylin-pc:~$ python3 qsortlo2.py
[1, 1, 2, 3, 6, 8, 10]
但是对于用户自定义问题,要把我气笑了
编写python程序,算出1-13的全部4个数字组合(允许重复)加减乘除能够算出24点的组合及对应的表达式,比如1234:1x2x3x4,用A、B、C、D表示10、11、12、13,用圆括号表示运算优先级。每个4数字组合只要输出一个解,每个组合都按数字大小排序,比如13CD,注意将if r1 == 24改为if abs(r1 -24)<1e-6等,用最简的高效语句完成,无需注释。不做别的
第一个版本用了eval, 奇慢无比,我取消执行了。
from itertools import permutations, product
import operator
from functools import reduce
ops = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': lambda x, y: x / y if y != 0 else float('inf')
}
def solve():
res = []
digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
for d in range(1, 14):
for p in permutations(digits, 4):
if p[0] == d:
if sorted(p) == list(p):
pass
for op1 in ['+', '-', '*', '/']:
for op2 in ['+', '-', '*', '/']:
for op3 in ['+', '-', '*', '/']:
try:
a, b, c, d = p
# 1x2x3x4 = 24
exprs = [
f"{a}{op1}{b}{op2}{c}{op3}{d}",
f"({a}{op1}{b}){op2}({c}{op3}{d})",
f"({a}{op1}{b}{op2}{c}){op3}{d}",
f"{a}{op1}({b}{op2}{c}{op3}{d})",
f"{a}{op1}({b}{op2}({c}{op3}{d}))",
f"({a}{op1}({b}{op2}{c})){op3}{d}",
f"{a}{op1}({b}{op2}({c}{op3}{d}))",
f"({a}{op1}{b})({c}{op2}{d}{op3})",
f"({a}{op1}({b}{op2}c)){op3}d",
f"({a}{op1}b){op2}({c}{op3}{d})",
f"({a}{op1}({b}{op2}c)){op3}d",
f"{a}{op1}({b}{op2}({c}{op3}d))",
f"({a}{op1}b){op2}{c}{op3}{d}",
f"{a}{op1}({b}{op2}c){op3}{d}",
]
for expr in exprs:
try:
result = eval(expr.replace('x', '*'))
if abs(result - 24) < 1e-6:
res.append((expr.replace('x', '*'), [a, b, c, d]))
break
except:
pass
if res and res[-1][1] == [a, b, c, d]:
break
except:
pass
return sorted(set((str(x[0]), tuple(sorted(x[1]))) for x in res))
print(solve())
第二个版本最后是这样的。
from itertools import permutations, product
import operator
from functools import reduce
ops = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': lambda x, y: x / y if y != 0 else float('inf')
}
def solve():
res = []
for a, b, c, d in permutations(range(1, 14), 4):
if a == b == c == d:
continue
for p in product(['+', '-', '*', '/'], repeat=3):
try:
nums = [a, b, c, d]
# 24 = ((a op1 b) op2 c) op3 d
expr = f"({nums[0]}{p[0]}{nums[1]}{p[1]}{nums[2]}){p[2]}{nums[3]}"
try:
result = ops[p[2]](ops[p[1]](ops[p[0]](nums[0], nums[1]), nums[2]), nums[3])
if abs(result - 24) < 1e-6:
res.append((expr, (a, b, c, d)))
break
except:
pass
except:
pass
for p in product(['+', '-', '*', '/'], repeat=3):
try:
nums = [a, b, c, d]
# 24 = a op1 (b op2 (c op3 d))
expr = f"{nums[0]}{p[0]}({nums[1]}{p[1]}({nums[2]}{p[2]}{nums[3]}))"
try:
result = ops[p[0]](nums[0], ops[p[1]](nums[1], ops[p[2]](nums[2], nums[3])))
if abs(result - 24) < 1e-6:
res.append((expr, (a, b, c, d)))
break
except:
pass
except:
pass
for p in product(['+', '-', '*', '/'], repeat=3):
try:
nums = [a, b, c, d]
# 24 = (a op1 b) op2 (c op3 d)
expr = f"({nums[0]}{p[0]}{nums[1]}){p[1]}({nums[2]}{p[2]}{nums[3]})"
try:
result = ops[p[1]](ops[p[0]](nums[0], nums[1]), ops[p[2]](nums[2], nums[3]))
if abs(result - 24) < 1e-6:
res.append((expr, (a, b, c, d)))
break
except:
pass
except:
pass
for p in product(['+', '-', '*', '/'], repeat=3):
try:
nums = [a, b, c, d]
# 24 = a op1 (b op2 c) op3 d
expr = f"{nums[0]}{p[0]}({nums[1]}{p[1]}{nums[2]}){p[2]}{nums[3]}"
try:
result = ops[p[2]](ops[p[0]](nums[0], ops[p[1]](nums[1], nums[2])), nums[3])
if abs(result - 24) < 1e-6:
res.append((expr, (a, b, c, d)))
break
except:
pass
except:
pass
return sorted(set((expr, tuple(sorted(nums))) for expr, nums in res))
seen = set()
r=solve()
for item in r: #[('(1*10)*(12/5)', (1, 5, 10, 12)), ('(1*10)+(12+2)', (1, 2, 10, 12))]:
expr, nums = item
expr = expr.replace('*', 'x')
nums_sorted = sorted(nums)
nums_str = ''.join(str(n) if n < 10 else chr(ord('A') + n - 10) for n in nums_sorted)
key = nums_str
if key not in seen:
seen.add(key)
expr = expr.replace('10', 'A').replace('11', 'B').replace('12', 'C').replace('13', 'D')
print(f"{nums_str}:{expr}")
这个一开始没有提供输出示例,我直接print(solve())出来一个没有换行符的文件。
nbs@kylin-pc:~$ python3 24plo2.py > 24p.txt
输出头部的样子如下:
nbs@kylin-pc:~$ python3 24plo2.py |more
[('(1*10)*(12/5)', (1, 5, 10, 12)), ('(1*10)+(12+2)', (1, 2, 10, 12)), ('(1*10)+(2*7)', (1, 2, 7, 10)), ('(1*10)+(2+12)', (1, 2, 10, 12)), ('(1*10)+(5+9)', (1, 5, 9, 10)), ('(1*10
)+(6+8)', (1, 6, 8, 10)), ('(1*10)+(
然后围绕“用A、B、C、D表示10、11、12、13”反复提示了几次都坚持从1开始替换成A,实在没辙了,只好
我来教你,expr = expr.replace(‘10’, ‘A’).replace(‘11’, ‘B’).replace(‘12’, ‘C’).replace(‘13’,‘D’) 就够了,其他按原样输出,请修改
才出来勉强能用的,又只替换表达式,没替换数字,看来小模型的理解力太弱了。补充一下,其实上述程序先输出了很多重复数字,又漏算了很多结果,正确性都不行。
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)