Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
9 edited body
source | link

MATL, 14 11 10 55 4 bytes

dt_v>tP->

This solution accepts input in the form of two arrays:

  1. A 2 x 2 matrix that contains the coordinates of the corners [x1, y1; x2, y2]
  2. A 2 x 1 array containing the square dimensions [k1;[k2; k2]k1]

Try it OnlineTry it Online

Slightly modified version to run all test casesSlightly modified version to run all test cases

Explanation

        % Implicitly grab the first input
dt       % Compute the difference alongDuplicate the first dimension (x2-x1, y2-y1)input
t_P      % Copy% andFlip negatealong the resultfirst dimension (columns)
v-       % Vertically combineSubtract the resulttwo to createyield [x2[x1-x1x2, x1y1-x2;y2; y2x2-y1x1, y1y2-y2]y1]
        % Implicitly grab the second input
>       % Compare with [k1[k2, k2]k1] (automatically broadcasts)
        % Implicitly display the truthy/falsey result

MATL, 14 11 10 5 bytes

dt_v>

This solution accepts input in the form of two arrays:

  1. A 2 x 2 matrix that contains the coordinates of the corners [x1, y1; x2, y2]
  2. A 2 x 1 array containing the square dimensions [k1; k2]

Try it Online

Slightly modified version to run all test cases

Explanation

        % Implicitly grab the first input
d       % Compute the difference along the first dimension (x2-x1, y2-y1)
t_      % Copy and negate the result
v       % Vertically combine the result to create [x2-x1, x1-x2; y2-y1, y1-y2]
        % Implicitly grab the second input
>       % Compare with [k1, k2] (automatically broadcasts)
        % Implicitly display the truthy/falsey result

MATL, 14 11 10 5 4 bytes

tP->

This solution accepts input in the form of two arrays:

  1. A 2 x 2 matrix that contains the coordinates of the corners [x1, y1; x2, y2]
  2. A 2 x 1 array containing the square dimensions [k2; k1]

Try it Online

Slightly modified version to run all test cases

Explanation

        % Implicitly grab the first input
t       % Duplicate the input
P       % Flip along the first dimension (columns)
-       % Subtract the two to yield [x1-x2, y1-y2; x2-x1, y2-y1]
        % Implicitly grab the second input
>       % Compare with [k2, k1] (automatically broadcasts)
        % Implicitly display the truthy/falsey result
8 deleted 293 characters in body
source | link

MATL, 14 11 1010 5 bytes

3&Z)dt_&v>dt_v>

This solution accepts the input in the form of a matrixtwo arrays: [x1, y1, k1; x2, y2, k2]. It will return a truthy or falsey value.

This solution also takes advantage of the new & meta-function in MATL which is a "secondary default" number of inputs/outputs for a given function. In this solution, that has saved 2 bytes. Specifically, 3&Z) would have had to previously be 3H$Z) and t_&v would have been t_2$v or !t_h!.

  1. A 2 x 2 matrix that contains the coordinates of the corners [x1, y1; x2, y2]
  2. A 2 x 1 array containing the square dimensions [k1; k2]

Try it OnlineTry it Online

Slightly modified version to run all test casesSlightly modified version to run all test cases

Explanation

        % Implicitly grab input
3&Z)    % Split the input at the third column. Creates [k1; k2] and [x1, y1; x2, y2] pushes 
        % them to thefirst stackinput
d       % Compute the difference along the first dimension (x2-x1, y2-y1)
t_      % Copy and negate the result
&vv       % Vertically combine the result to create [x2-x1, x1-x2; y2-y1, y1-y2]
        % Implicitly grab the second input
>       % Compare with [k1, k2] (automatically broadcasts)
        % Implicitly display the truthy/falsey result

MATL, 14 11 10 bytes

3&Z)dt_&v>

This solution accepts the input in the form of a matrix: [x1, y1, k1; x2, y2, k2]. It will return a truthy or falsey value.

This solution also takes advantage of the new & meta-function in MATL which is a "secondary default" number of inputs/outputs for a given function. In this solution, that has saved 2 bytes. Specifically, 3&Z) would have had to previously be 3H$Z) and t_&v would have been t_2$v or !t_h!.

Try it Online

Slightly modified version to run all test cases

Explanation

        % Implicitly grab input
3&Z)    % Split the input at the third column. Creates [k1; k2] and [x1, y1; x2, y2] pushes 
        % them to the stack
d       % Compute the difference along the first dimension (x2-x1, y2-y1)
t_      % Copy and negate the result
&v      % Vertically combine the result to create [x2-x1, x1-x2; y2-y1, y1-y2]
>       % Compare with [k1, k2] (automatically broadcasts)
        % Implicitly display the truthy/falsey result

MATL, 14 11 10 5 bytes

dt_v>

This solution accepts input in the form of two arrays:

  1. A 2 x 2 matrix that contains the coordinates of the corners [x1, y1; x2, y2]
  2. A 2 x 1 array containing the square dimensions [k1; k2]

Try it Online

Slightly modified version to run all test cases

Explanation

        % Implicitly grab the first input
d       % Compute the difference along the first dimension (x2-x1, y2-y1)
t_      % Copy and negate the result
v       % Vertically combine the result to create [x2-x1, x1-x2; y2-y1, y1-y2]
        % Implicitly grab the second input
>       % Compare with [k1, k2] (automatically broadcasts)
        % Implicitly display the truthy/falsey result
7 edited body
source | link

MATL, 14 11 10 bytes

3&Z)dt_&v>

This solution accepts the input in the form of a matrix: [x1, y1, k1; x2, y2, k2]. It will return a truthy or falsey value.

This solution also takes advantage of the new & meta-function in MATL which is a "secondary default" number of inputs/outputs for a given function. In this solution, that has saved 2 bytes. Specifically, 3&Z) would have had to previously be 3H$Z) and t_&v would have been t_2$v or !t_h!.

Try it Online

Slightly modified version to run all test cases

Explanation

        % Implicitly grab input
3&Z)    % Split the input at the third column. Creates [k1; k2] and [x1, y1; x2, y2] pushes 
        % them to the stack
d       % Compute the difference along the first dimension (y1x2-x1, y2-x2y1)
t_      % Copy and negate the result
&v      % Vertically combine the result to create [y1[x2-x1, y2x1-x2; x1y2-y1, x2y1-y2]
>       % Compare with [k1, k2] (automatically broadcasts)
        % Implicitly display the truthy/falsey result

MATL, 14 11 10 bytes

3&Z)dt_&v>

This solution accepts the input in the form of a matrix: [x1, y1, k1; x2, y2, k2]. It will return a truthy or falsey value.

This solution also takes advantage of the new & meta-function in MATL which is a "secondary default" number of inputs/outputs for a given function. In this solution, that has saved 2 bytes. Specifically, 3&Z) would have had to previously be 3H$Z) and t_&v would have been t_2$v or !t_h!.

Try it Online

Slightly modified version to run all test cases

Explanation

        % Implicitly grab input
3&Z)    % Split the input at the third column. Creates [k1; k2] and [x1, y1; x2, y2] pushes 
        % them to the stack
d       % Compute the difference along the first dimension (y1-x1, y2-x2)
t_      % Copy and negate the result
&v      % Vertically combine the result to create [y1-x1, y2-x2; x1-y1, x2-y2]
>       % Compare with [k1, k2] (automatically broadcasts)
        % Implicitly display the truthy/falsey result

MATL, 14 11 10 bytes

3&Z)dt_&v>

This solution accepts the input in the form of a matrix: [x1, y1, k1; x2, y2, k2]. It will return a truthy or falsey value.

This solution also takes advantage of the new & meta-function in MATL which is a "secondary default" number of inputs/outputs for a given function. In this solution, that has saved 2 bytes. Specifically, 3&Z) would have had to previously be 3H$Z) and t_&v would have been t_2$v or !t_h!.

Try it Online

Slightly modified version to run all test cases

Explanation

        % Implicitly grab input
3&Z)    % Split the input at the third column. Creates [k1; k2] and [x1, y1; x2, y2] pushes 
        % them to the stack
d       % Compute the difference along the first dimension (x2-x1, y2-y1)
t_      % Copy and negate the result
&v      % Vertically combine the result to create [x2-x1, x1-x2; y2-y1, y1-y2]
>       % Compare with [k1, k2] (automatically broadcasts)
        % Implicitly display the truthy/falsey result
6 deleted 1 character in body
source | link
5 deleted 33 characters in body
source | link
4 added 328 characters in body
source | link
3 added 623 characters in body
source | link
2 added 623 characters in body
source | link
1
source | link