信贷到哪里去信用到期
给定两个数字,x和y,计算在标准数字上从x到y的水平或垂直跳转的最短次数。
789
456
123
00您可以安全地假设所有输入都是0-9,并且不需要处理无效的输入。输入可以是同一数字的两倍,它的距离为0。
IO可以出现在任何合理的格式中,并且禁止标准漏洞。最短答案(以字节为单位)获胜!
1, 4: 1
1, 8: 3
3, 7: 4
8, 2: 2
6, 1: 3
0, 9: 4
4, 4: 0
0, 4: 2发布于 2016-05-22 05:38:58
o-1.’d3ạ/ḞS在网上试试!或验证所有测试用例.
o-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:41:02
发布于 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
复制相似问题