×=
×
+ị1,-,0
A-r1¤ṗœs2ṚẎị@ȯµ€Uz0ZU⁹ŀ/ḅ3
一个完整的程序带有两个参数,[x,y]
和z
...这里z
是{A:-1, B:0, C:1}
打印出结果
在线尝试!注意:高尔夫球方法会使速度变慢-此更改的版本速度更快(对数乘以3,小数和增量在每个笛卡尔积之前)
怎么样?
×= - Link 1 (1), B: list of trits L, list of trits R
× - L multiplied by... (vectorises):
= - L equal R? (vectorises)
× - Link -1 (2), A: list of trits L, list of trits R
× - L multiplied by R (vectorises)
+ị1,-,0 - Link 0 (3), C: list of trits L, list of trits R
+ - L plus R (vectorises)
1,-,0 - list of integers = [1,-1,0]
ị - index into (vectorises) - 1-based & modular, so index -2 is equivalent to
- index 1 which holds the value 1.
A-r1¤ṗœs2ṚẎị@ȯµ€Uz0ZU⁹ŀ/ḅ3 - Main link: list of integers [X,Y], integer Z
µ€ - for each V in [X,Y]:
A - absolute value = abs(V)
¤ - nilad followed by link(s) as a nilad:
- - literal minus one
1 - literal one
r - inclusive range = [-1,0,1]
ṗ - Cartesian power, e.g. if abs(V)=3: [[-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0],[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1]]
- (corresponding to: [-13 ,-12 ,-11 ,-10 ,-9 ,-8 ,-7 ,-6 ,-5 ,-4 ,-3 ,-2 ,-1 ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ] )
2 - literal two
œs - split into equal chunks [[[-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0]],[[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1]]]
Ṛ - reverse [[[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1]],[[-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0]]]
Ẏ - tighten [[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1],[-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0]]
- (corresponding to: [1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,-13 ,-12 ,-11 ,-10 ,-9 ,-8 ,-7 ,-6 ,-5 ,-4 ,-3 ,-2 ,-1 ,0 ] )
ị@ - get item at index V (1-based & modular)
ȯ - logical OR with V (just handle V=0 which has an empty list)
U - upend (big-endian -> little-endian for each)
0 - literal zero }
z - transpose with filler } - pad with MSB zeros
Z - transpose }
U - upend (little-endian -> big-endian for each)
/ - reduce with:
ŀ - link number: (as a dyad)
⁹ - chain's right argument, Z
3 - literal three
ḅ - convert from base