发布于 2016-05-22 05:38:58
o-1.’d3ạ/ḞSo-1.’d3ạ/ḞS Main link. Argument: [a, b] (list of integers)
-1. Yield -1.5.
o Take the logical OR of a and b with -1.5.
This maps 0 to -1.5, and all other integers to themselves.
’ Decrement the results.
d3 Divmod; compute quotient and remainder of each result divided by 3.
ạ/ Reduce by absolute difference across columns.
Ḟ Floor; round all differences down to the nearest integer.
S Sum; add the rounded absolute differences.发布于 2016-05-22 05:44:29
不幸的是,javascript中没有divmod。事实上,没有整数div,也没有mod:%并不完全是mod。但就这一次而言,带有负数的%的奇怪行为是有用的。
(a,b,A=Math.abs)=>A(~(--a/3)-~(--b/3))+A(a%3-b%3)-(a*b%3<0)f=(a,b,A=Math.abs)=>A(~(--a/3)-~(--b/3))+A(a%3-b%3)-(a*b%3<0)
for(i=0;i<10;console.log(r),i++)
for(r='',j=0;j<10;j++)
r+=[i,j,f(i,j)]+' 'https://codegolf.stackexchange.com/questions/80357
复制相似问题