Skip to main content
Commonmark migration
Source Link

#MATL, 35 34 characters

MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

Explanation

This takes care of the reflections using the formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, Nx is the maximum size along the x direction and px is the computed x position. Analogous formulas are used for the y coordinate.

A char matrix of spaces is initially created, and then it is filled with character * at the computed x and y positions.

Z" % Implicitly take [width height]. Push char matrix of spaces with that size 42 % Push 42. ASCII for character `*` G % Push first input again, that is, [width height] i % Take number of movements, M :q % Range [0 1 ... M-1] i! % Take initial position [x y]. Transpose into column vector + % Add element-wise with broadcast. Gives 2-row vector lG % Push first input, [width height] qE! % Transform into column vector [2*width-2; 2*height-2] / % Divide element-wise with broadcast tYo % Duplicate. Round to closest integer - % Subtract KM! % Push [2*width-2; 2*height-2] again * % Multiply element-wise with broadcast | % Absolute value Q % Add 1 Yo % Round to closest integer Z} % Separate 2-row array into two row arrays. These contain row and column % indices, respectively, of the ball positions X] % Convert row and colummn indices to linear index ( % Assign 42 to those positions of the matrix of spaces 

#MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

This takes care of the reflections using the formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, Nx is the maximum size along the x direction and px is the computed x position. Analogous formulas are used for the y coordinate.

A char matrix of spaces is initially created, and then it is filled with character * at the computed x and y positions.

Z" % Implicitly take [width height]. Push char matrix of spaces with that size 42 % Push 42. ASCII for character `*` G % Push first input again, that is, [width height] i % Take number of movements, M :q % Range [0 1 ... M-1] i! % Take initial position [x y]. Transpose into column vector + % Add element-wise with broadcast. Gives 2-row vector lG % Push first input, [width height] qE! % Transform into column vector [2*width-2; 2*height-2] / % Divide element-wise with broadcast tYo % Duplicate. Round to closest integer - % Subtract KM! % Push [2*width-2; 2*height-2] again * % Multiply element-wise with broadcast | % Absolute value Q % Add 1 Yo % Round to closest integer Z} % Separate 2-row array into two row arrays. These contain row and column % indices, respectively, of the ball positions X] % Convert row and colummn indices to linear index ( % Assign 42 to those positions of the matrix of spaces 

MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

Explanation

This takes care of the reflections using the formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, Nx is the maximum size along the x direction and px is the computed x position. Analogous formulas are used for the y coordinate.

A char matrix of spaces is initially created, and then it is filled with character * at the computed x and y positions.

Z" % Implicitly take [width height]. Push char matrix of spaces with that size 42 % Push 42. ASCII for character `*` G % Push first input again, that is, [width height] i % Take number of movements, M :q % Range [0 1 ... M-1] i! % Take initial position [x y]. Transpose into column vector + % Add element-wise with broadcast. Gives 2-row vector lG % Push first input, [width height] qE! % Transform into column vector [2*width-2; 2*height-2] / % Divide element-wise with broadcast tYo % Duplicate. Round to closest integer - % Subtract KM! % Push [2*width-2; 2*height-2] again * % Multiply element-wise with broadcast | % Absolute value Q % Add 1 Yo % Round to closest integer Z} % Separate 2-row array into two row arrays. These contain row and column % indices, respectively, of the ball positions X] % Convert row and colummn indices to linear index ( % Assign 42 to those positions of the matrix of spaces 
added 1109 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

#MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

This takes care of the reflections using the formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, Nx is the maximum size along the x direction and px is the computed x position. Analogous formulas are used for the y coordinate.

A 2D char arraymatrix of spaces is initially created, and then it is filled with character * at the computed x and y positions.

Z" % Implicitly take [width height]. Push char matrix of spaces with that size 42 % Push 42. ASCII for character `*` G % Push first input again, that is, [width height] i % Take number of movements, M :q % Range [0 1 ... M-1] i! % Take initial position [x y]. Transpose into column vector + % Add element-wise with broadcast. Gives 2-row vector lG % Push first input, [width height] qE! % Transform into column vector [2*width-2; 2*height-2] / % Divide element-wise with broadcast tYo % Duplicate. Round to closest integer - % Subtract KM! % Push [2*width-2; 2*height-2] again * % Multiply element-wise with broadcast | % Absolute value Q % Add 1 Yo % Round to closest integer Z} % Separate 2-row array into two row arrays. These contain row and column % indices, respectively, of the ball positions X] % Convert row and colummn indices to linear index ( % Assign 42 to those positions of the matrix of spaces 

#MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

This takes care of the reflections using the formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, Nx is the maximum size along the x direction and px is the computed x position. Analogous formulas are used for the y coordinate.

A 2D char array of spaces is initially created, and then it is filled with character * at the computed x and y positions.

#MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

This takes care of the reflections using the formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, Nx is the maximum size along the x direction and px is the computed x position. Analogous formulas are used for the y coordinate.

A char matrix of spaces is initially created, and then it is filled with character * at the computed x and y positions.

Z" % Implicitly take [width height]. Push char matrix of spaces with that size 42 % Push 42. ASCII for character `*` G % Push first input again, that is, [width height] i % Take number of movements, M :q % Range [0 1 ... M-1] i! % Take initial position [x y]. Transpose into column vector + % Add element-wise with broadcast. Gives 2-row vector lG % Push first input, [width height] qE! % Transform into column vector [2*width-2; 2*height-2] / % Divide element-wise with broadcast tYo % Duplicate. Round to closest integer - % Subtract KM! % Push [2*width-2; 2*height-2] again * % Multiply element-wise with broadcast | % Absolute value Q % Add 1 Yo % Round to closest integer Z} % Separate 2-row array into two row arrays. These contain row and column % indices, respectively, of the ball positions X] % Convert row and colummn indices to linear index ( % Assign 42 to those positions of the matrix of spaces 
added 11 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

#MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

This takes care of the reflections using the formula px = abs(t/nx-round(t/nx))*nx,formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, nxNx is the maximum size along the x direction and px is the computed x position. An analogous formula isAnalogous formulas are used for the y coordinate.

A 2D char array of spaces is initially created, and then it is filled with character * at the computed x and y positions.

#MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

This takes care of the reflections using the formula px = abs(t/nx-round(t/nx))*nx, where t is a time variable that increases in steps of 1, nx is the maximum size along the x direction and px is the x position. An analogous formula is used for the y coordinate.

A 2D char array of spaces is initially created, and then it is filled with character * at the computed x and y positions.

#MATL, 35 34 characters

Z"42Gi:qi!+lGqE!/tYo-KM!*|QYoZ}X]( 

Try it online!

###Explanation

This takes care of the reflections using the formulas

nx = 2*(Nx-1) px = abs(t/nx-round(t/nx))*nx 

where t is a time variable that increases in steps of 1, Nx is the maximum size along the x direction and px is the computed x position. Analogous formulas are used for the y coordinate.

A 2D char array of spaces is initially created, and then it is filled with character * at the computed x and y positions.

added 11 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 4 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 424 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 8 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading