MATL, (削除) 12 (削除ここまで) 10 bytes
Qt:ie=&fhq
Input is a, then b. Output is remainder, then quotient.
###Explanation
Explanation
This avoids both modulo and division. Instead it uses array reshaping:
- Build an array of
a+1nonzero elements. - Reshape as a 2D array of
brows. This automatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=3.
Q % Input a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 8, [1 4 7;
2 5 8]
3 6 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 1;
0 0 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 3
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 2]
MATL, (削除) 12 (削除ここまで) 10 bytes
Qt:ie=&fhq
Input is a, then b. Output is remainder, then quotient.
###Explanation
This avoids both modulo and division. Instead it uses array reshaping:
- Build an array of
a+1nonzero elements. - Reshape as a 2D array of
brows. This automatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=3.
Q % Input a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 8, [1 4 7;
2 5 8]
3 6 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 1;
0 0 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 3
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 2]
MATL, (削除) 12 (削除ここまで) 10 bytes
Qt:ie=&fhq
Input is a, then b. Output is remainder, then quotient.
Explanation
This avoids both modulo and division. Instead it uses array reshaping:
- Build an array of
a+1nonzero elements. - Reshape as a 2D array of
brows. This automatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=3.
Q % Input a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 8, [1 4 7;
2 5 8]
3 6 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 1;
0 0 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 3
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 2]
MATL, (削除) 12 (削除ここまで) 10 bytes
Qt:ie=&fhq
Input is a, then b. Output is remainder, then quotient.
###Explanation
This avoids both modulo and division, and instead. Instead it uses array reshapingarray reshaping:
- Build an array of
a+1nonzero elements. - Reshape as a 2D array of
brows. This automatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=3.
Q % Input a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 8, [1 4 7;
2 5 8]
3 6 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 1;
0 0 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 3
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 2]
MATL, (削除) 12 (削除ここまで) 10 bytes
Qt:ie=&fhq
Input is a, then b. Output is remainder, then quotient.
###Explanation
This avoids modulo and division, and instead uses array reshaping:
- Build an array of
a+1nonzero elements. - Reshape as a 2D array of
brows. This automatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=3.
Q % Input a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 8, [1 4 7;
2 5 8]
3 6 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 1;
0 0 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 3
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 2]
MATL, (削除) 12 (削除ここまで) 10 bytes
Qt:ie=&fhq
Input is a, then b. Output is remainder, then quotient.
###Explanation
This avoids both modulo and division. Instead it uses array reshaping:
- Build an array of
a+1nonzero elements. - Reshape as a 2D array of
brows. This automatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=3.
Q % Input a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 8, [1 4 7;
2 5 8]
3 6 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 1;
0 0 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 3
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 2]
MATL, 12(削除) 12 (削除ここまで) 10 bytes
Qt:0hie=&fhqie=&fhq
Input is a, then b. Output is remainder, then quotient.Try it online!
###Explanation
This avoids modulo and division. It works as follows, and instead uses array reshaping:
- Build an array of
a+1nonzero elements plus an appended0. - ReshapesReshape as a 2D array of
brows. This automaticallautomatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=2b=3.
Q % TakeInput a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
0h % Append a zero
% STACK: [1 2 3 4 5 6 7 8 0]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 78, [1 34 57;
7 0; 2 5 8]
2 43 6 8 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 0;1;
0 0 0 1 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 43
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 3]2]
MATL, 12 bytes
Qt:0hie=&fhq
Input is a, then b. Output remainder, quotient.Try it online!
This avoids modulo and division. It works as follows:
- Build an array of
a+1nonzero elements plus an appended0. - Reshapes as a 2D array of
brows. This automaticall pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=2.
Q % Take a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
0h % Append a zero
% STACK: [1 2 3 4 5 6 7 8 0]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 7, [1 3 5 7 0;
2 4 6 8 0]
= % Compare for equality
% STACK: [0 0 0 0 0;
0 0 0 1 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 4
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 3]
MATL, (削除) 12 (削除ここまで) 10 bytes
Qt:ie=&fhq
Input is a, then b. Output is remainder, then quotient.
###Explanation
This avoids modulo and division, and instead uses array reshaping:
- Build an array of
a+1nonzero elements. - Reshape as a 2D array of
brows. This automatically pads with zeros if needed. - The row and column indices of the last nonzero entry, minus
1, are respectively the remainder and quotient.
Consider for example a=7, b=3.
Q % Input a implicitly. Push a+1
% STACK: 8
t: % Duplicate. Range from 1 to that
% STACK: 8, [1 2 3 4 5 6 7 8]
ie % Input b. Reshape as a matrix with b rows (in column major order)
% STACK: 8, [1 4 7;
2 5 8]
3 6 0]
= % Compare for equality
% STACK: [0 0 0;
0 0 1;
0 0 0]
&f % Row and column indices (1-based) of nonzero element
% STACK: 2, 3
hq % Concatenate. Subtract 1. Implicitly display
% STACK: [1 2]