除了 (^ or _dvl) analog in k4, 8 Queens example
Except (^ or _dvl) analog in k4, 8 Queens example
我刚刚玩了 8 Queens 谜题,发现 k(v4)
中似乎没有 _dvl
运算符(来自 k(v2)
)。我还检查了来自 ngn k impls and found ^
operator in k(v6)
, for example at JohnEarnest's impl:
的其他 k
版本
l^a or l^l is except. Remove all instances of each of y from x.
k) 1 3 2 5 1 2 3^1 3 5
2 2
我真的很喜欢 SQL 风格并且想在 q
中应用它。但是下面的方式在 q/k(v4)
中是惯用的吗?它是一个好的解决方案吗?或者也许有 更短的方法 可以做到这一点 list comparison/exclusion exists:
q)show s:til 8
0 1 2 3 4 5 6 7
q)s where not s in 2 4 6 /bother about this line, can it be shorter?
0 1 3 5 7
我的 q8
代码版本比 nsl k2 代码长一点,没有递归也没有条件:
f:{raze {(x,) each (til 8) where not (til 8) in {x,(x-f),x+f:reverse 1+til count x} x} each x}
\ts:10 7 f/til 8 /248 100128
count 7 f/til 8 /92
first 7 f/til 8 /0 4 7 5 2 6 1 3
Upd: 我正在寻找的命令是 except:
q)f:{raze {(x,) each (til 8) except {x,(x-f),x+f:reverse 1+til count x} x} each x}
Upd2: k(v4)
:
中的广义 8 皇后解决方案
k){(x-1){,/{(x,)'(!y)@&~(!y)in{x,(x-f),x+f:|1+!#x}x}[;y]'x}[;x]/!x}8
Upd3: 将 8 queens 谜题添加到博客
只是关键字except
。
如何找到它:我们知道惯用的 k
构造 @&
,所以只需搜索 .q
命名空间即可:
q)qfind:{([] q:k;k:.q k:key[.q] where (string value .q) like "*",x,"*")}
q)qfind "@&"
q k
-----------------------------------
inter k){x@&x in y}
except k){x@&~x in y}
xcols k){(x,f@&~(f:cols y)in x)#y}
q) (til 8) except 2 4 6
0 1 3 5 7
我刚刚玩了 8 Queens 谜题,发现 k(v4)
中似乎没有 _dvl
运算符(来自 k(v2)
)。我还检查了来自 ngn k impls and found ^
operator in k(v6)
, for example at JohnEarnest's impl:
k
版本
l^a or l^l is except. Remove all instances of each of y from x.
k) 1 3 2 5 1 2 3^1 3 5 2 2
我真的很喜欢 SQL 风格并且想在 q
中应用它。但是下面的方式在 q/k(v4)
中是惯用的吗?它是一个好的解决方案吗?或者也许有 更短的方法 可以做到这一点 list comparison/exclusion exists:
q)show s:til 8
0 1 2 3 4 5 6 7
q)s where not s in 2 4 6 /bother about this line, can it be shorter?
0 1 3 5 7
我的 q8
代码版本比 nsl k2 代码长一点,没有递归也没有条件:
f:{raze {(x,) each (til 8) where not (til 8) in {x,(x-f),x+f:reverse 1+til count x} x} each x}
\ts:10 7 f/til 8 /248 100128
count 7 f/til 8 /92
first 7 f/til 8 /0 4 7 5 2 6 1 3
Upd: 我正在寻找的命令是 except:
q)f:{raze {(x,) each (til 8) except {x,(x-f),x+f:reverse 1+til count x} x} each x}
Upd2: k(v4)
:
k){(x-1){,/{(x,)'(!y)@&~(!y)in{x,(x-f),x+f:|1+!#x}x}[;y]'x}[;x]/!x}8
Upd3: 将 8 queens 谜题添加到博客
只是关键字except
。
如何找到它:我们知道惯用的 k
构造 @&
,所以只需搜索 .q
命名空间即可:
q)qfind:{([] q:k;k:.q k:key[.q] where (string value .q) like "*",x,"*")}
q)qfind "@&"
q k
-----------------------------------
inter k){x@&x in y}
except k){x@&~x in y}
xcols k){(x,f@&~(f:cols y)in x)#y}
q) (til 8) except 2 4 6
0 1 3 5 7