Skip to main content
Commonmark migration
Source Link

#MATL, 23 22 27 bytes

MATL, 23 22 27 bytes

1 Byte saved thanks to @Luis

UtEYPwY$IbH+&:)GetGi-&R!g)!

Try it Online

Explanation

        % Implicitly grab input (n)
Ut      % Square n and duplicate
E       % Multiply n^2 by 2
YP      % Pi literal
w       % Flip the stack
Y$      % Compute the first 2 * (n^2) digits of pi (accounts for rounding)
IbH+&:) % Grab the first n^2 digits after the decimal
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display

#MATL, 23 22 27 bytes

1 Byte saved thanks to @Luis

UtEYPwY$IbH+&:)GetGi-&R!g)!

Try it Online

Explanation

        % Implicitly grab input (n)
Ut      % Square n and duplicate
E       % Multiply n^2 by 2
YP      % Pi literal
w       % Flip the stack
Y$      % Compute the first 2 * (n^2) digits of pi (accounts for rounding)
IbH+&:) % Grab the first n^2 digits after the decimal
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display

MATL, 23 22 27 bytes

1 Byte saved thanks to @Luis

UtEYPwY$IbH+&:)GetGi-&R!g)!

Try it Online

Explanation

        % Implicitly grab input (n)
Ut      % Square n and duplicate
E       % Multiply n^2 by 2
YP      % Pi literal
w       % Flip the stack
Y$      % Compute the first 2 * (n^2) digits of pi (accounts for rounding)
IbH+&:) % Grab the first n^2 digits after the decimal
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display
added 70 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52

#MATL, 23 2222 27 bytes

1 Byte saved thanks to @Luis

YPiUY$4LQUtEYPwY$IbH+&:)GetGi-&R!g)!

Try it OnlineTry it Online

Explanation

YP        % PiImplicitly literalgrab input (n)
iUUt      % GrabSquare then firstand inputduplicate
E and square it    % Multiply n^2 by 2
YP      % Pi literal
w       % Flip the stack
Y$      % Compute thisthe manyfirst decimal2 points* for(n^2) digits of pi (returnsaccounts afor stringrounding)
4LQIbH+&:) % Grab the %first Removen^2 alldigits butafter the decimal part
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display

#MATL, 23 22 bytes

1 Byte saved thanks to @Luis

YPiUY$4LQ)GetGi-&R!g)!

Try it Online

Explanation

YP      % Pi literal
iU      % Grab the first input and square it
Y$      % Compute this many decimal points for pi (returns a string)
4LQ)    % Remove all but the decimal part
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display

#MATL, 23 22 27 bytes

1 Byte saved thanks to @Luis

UtEYPwY$IbH+&:)GetGi-&R!g)!

Try it Online

Explanation

        % Implicitly grab input (n)
Ut      % Square n and duplicate
E       % Multiply n^2 by 2
YP      % Pi literal
w       % Flip the stack
Y$      % Compute the first 2 * (n^2) digits of pi (accounts for rounding)
IbH+&:) % Grab the first n^2 digits after the decimal
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display
added 42 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52

#MATL, 2323 22 bytes

1 Byte saved thanks to @Luis

YPit*Y$4LQYPiUY$4LQ)GetGi-&R!g)!

Try it OnlineTry it Online

Explanation

YP      % Pi literal
it*iU      % Grab the first input and square it
Y$      % Compute this many decimal points for pi (returns a string)
4LQ)    % Remove all but the decimal part
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display

#MATL, 23 bytes

YPit*Y$4LQ)GetGi-&R!g)!

Try it Online

Explanation

YP      % Pi literal
it*     % Grab the first input and square it
Y$      % Compute this many decimal points for pi (returns a string)
4LQ)    % Remove all but the decimal part
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display

#MATL, 23 22 bytes

1 Byte saved thanks to @Luis

YPiUY$4LQ)GetGi-&R!g)!

Try it Online

Explanation

YP      % Pi literal
iU      % Grab the first input and square it
Y$      % Compute this many decimal points for pi (returns a string)
4LQ)    % Remove all but the decimal part
Ge      % Reshape it into an n x n matrix in row-major ordering
t       % Duplicate this matrix
Gi-     % Grab the second input (y) and compute the difference between n and y
&R!     % Get the upper diagonal part and transpose to convert to lower diagonal
g)      % Convert it to a logical array and use it to select the digits of interest
!       % Transpose the result and implicitly display
deleted 5 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52
Loading
deleted 5 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52
Loading
Source Link
Suever
  • 11.2k
  • 1
  • 23
  • 52
Loading