_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This increasesconverts positive b byinto 1b+1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". This trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This increases positive b by 1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". This trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This converts positive b into b+1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". This trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This increases positive b by 1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". TrimsThis trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This increases positive b by 1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". Trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This increases positive b by 1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". This trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
Try it online! Inputs are a
, then b
.
Explanation
This uses inputs 3
, 1
as an example. The stack contents are shown in each step. The stack is shown upside down, with the top (i.e. most recent) element down.
_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This increases positive b by 1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". Trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
Inputs are a
, then b
.
Explanation
This uses inputs 3
, 1
as an example. The stack contents are shown in each step. The stack is shown upside down, with the top (i.e. most recent) element down.
_Zvt % Implicit input: a. Symmetric range [a a-1 ... 2 1 2 ... a-1 a]. Duplicate
% STACK: [3 2 1 2 3],
[3 2 1 2 3]
&+ % Duplicate. Add to itself transposed, elementwise with broadcast
% STACK [3 2 1 2 3],
[6 5 4 5 6
5 4 3 4 5
4 3 2 3 4
5 4 3 4 5
6 5 4 5 6]
o % Modulo 2, elementwise. Gives checkered matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
y % Duplicate second-top element
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[3 2 1 2 3]
&= % Equal? to itself transposed, elementwise with broadcast. Gives "X" matrix
% STACK: [3 2 1 2 3],
[0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1]
b % Bubble up third-top element
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3]
i % Input: b
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
1
tg+ % Duplicate, convert to logical, add. This increases positive b by 1
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[3 2 1 2 3],
2
> % Greater than?, elementwise
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[1 0 0 0 1]
&+ % Add to itself transposed, elementwise with broadcast
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[1 0 0 0 1]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1],
[2 1 1 1 2
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
2 1 1 1 2]
> % Greater than?, elementwise. Equivalent to "and not". Trims the "X" matrix
% STACK: [0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0],
[0 0 0 0 0]
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
0 0 0 0 0],
E+ % Multiply by 2, element-wise. Add, element-wise. Implicit display
% STACK: [0 1 0 1 0
1 2 1 2 1
0 1 2 1 0
1 2 1 2 1
0 1 0 1 0]
Loading
Loading