[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 wanghan519 于 2023-9-6 05:30 编辑

awk写了个幂集,不知道对不对,可以存入文件a.awk再运行echo asdfg | awk -f a.awk试一下
只考虑了组合,没考虑排列。。。
  1. function powerset(x, y) {
  2.     if (length(x) > 3 || y > length($0)) {
  3.         print x
  4.         return
  5.     }
  6.     powerset(x, y + 1)
  7.     powerset(x substr($0, y, 1), y + 1)
  8. }
  9. {
  10.     powerset("", 1)
  11. }
复制代码

TOP

本帖最后由 wanghan519 于 2023-9-7 09:29 编辑

python最简单,因为有itertools,
  1. import itertools
  2. s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
  3. with open(r'a.txt','w') as f:
  4.     for i in range(1, 5):
  5.         for j in itertools.permutations(s, i):
  6.             f.write(''.join(j)+'\n')
复制代码
前两天刚提过的nushell可以方便的写sql,似乎sql写递归也很方便
  1. with recursive c as (
  2. select x, 1 n from t
  3. union all
  4. select c.x || t.x, c.n + 1
  5. from c join t
  6. where c.n < 4 and c.x not like '%' || t.x || '%'
  7. )
  8. select x from c;
复制代码
或者就像上面那样再试试awk递归怎么写,上面那是列出所有组合,没考虑全排列

TOP

返回列表