Skip to main content
Commonmark migration
Source Link

MATL, 13 12 bytes

|stE:-GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is strictly less than the sum of absolute values of the coefficients.

###Explanation

Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
E    % Multiply by 2
     % STACK: 12, 24
:    % Range
     % STACK: 12, [1 2 ... 23 24]
-    % Subtract, elemet-wise
     % STACK: [11 10 ... -11 -12]
G    % Push input again
     % STACK: [11 10 ... -11 -12], [1 5 6]
y    % Duplicate from below
     % STACK: [11 10 ... -11 -12], [1 5 6], [11 10 ... -11 -12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [11 10 ... -11 -12], [182 156 ... 72 90]
~    % Logical negation: turns nonzero into zero
     % STACK: [11 10 ... -11 -12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]

MATL, 13 12 bytes

|stE:-GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is strictly less than the sum of absolute values of the coefficients.

###Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
E    % Multiply by 2
     % STACK: 12, 24
:    % Range
     % STACK: 12, [1 2 ... 23 24]
-    % Subtract, elemet-wise
     % STACK: [11 10 ... -11 -12]
G    % Push input again
     % STACK: [11 10 ... -11 -12], [1 5 6]
y    % Duplicate from below
     % STACK: [11 10 ... -11 -12], [1 5 6], [11 10 ... -11 -12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [11 10 ... -11 -12], [182 156 ... 72 90]
~    % Logical negation: turns nonzero into zero
     % STACK: [11 10 ... -11 -12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]

MATL, 13 12 bytes

|stE:-GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is strictly less than the sum of absolute values of the coefficients.

Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
E    % Multiply by 2
     % STACK: 12, 24
:    % Range
     % STACK: 12, [1 2 ... 23 24]
-    % Subtract, elemet-wise
     % STACK: [11 10 ... -11 -12]
G    % Push input again
     % STACK: [11 10 ... -11 -12], [1 5 6]
y    % Duplicate from below
     % STACK: [11 10 ... -11 -12], [1 5 6], [11 10 ... -11 -12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [11 10 ... -11 -12], [182 156 ... 72 90]
~    % Logical negation: turns nonzero into zero
     % STACK: [11 10 ... -11 -12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]
deleted 2 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 1313 12 bytes

|st_w&|stE:-GyZQ~)

Try it online!Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is bounded bystrictly less than the sum of absolute values of the coefficients.

###Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
_E    % ArithmeticalMultiply negationby 2
     % STACK: 12, -1224
w:    % SwapRange
     % STACK: -12, 12[1 2 ... 23 24]
&:-    % BinarySubtract, rangeelemet-wise
     % STACK: [-12[11 -1110 ... -11 -12]
G    % Push input again
     % STACK: [-12[11 -1110 ... -11 -12], [1 5 6]
y    % Duplicate from below
     % STACK: [-12[11 -1110 ... -11 -12], [1 5 6], [-12[11 -1110 ... -11 -12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [-12[11 -1110 ... -11 -12], [90[182 72156 ... 210]72 90]
~    % Logical negation: turns nonzero into zero
     % STACK: [-12[11 -1110 ... -11 -12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]

MATL, 13 bytes

|st_w&:GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is bounded by the sum of absolute values of the coefficients.

###Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
_    % Arithmetical negation
     % STACK: 12, -12
w    % Swap
     % STACK: -12, 12
&:   % Binary range
     % STACK: [-12 -11 ... 12]
G    % Push input again
     % STACK: [-12 -11 ... 12], [1 5 6]
y    % Duplicate from below
     % STACK: [-12 -11 ... 12], [1 5 6], [-12 -11 ... 12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [-12 -11 ... 12], [90 72 ... 210]
~    % Logical negation: turns nonzero into zero
     % STACK: [-12 -11 ... 12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]

MATL, 13 12 bytes

|stE:-GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is strictly less than the sum of absolute values of the coefficients.

###Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
E    % Multiply by 2
     % STACK: 12, 24
:    % Range
     % STACK: 12, [1 2 ... 23 24]
-    % Subtract, elemet-wise
     % STACK: [11 10 ... -11 -12]
G    % Push input again
     % STACK: [11 10 ... -11 -12], [1 5 6]
y    % Duplicate from below
     % STACK: [11 10 ... -11 -12], [1 5 6], [11 10 ... -11 -12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [11 10 ... -11 -12], [182 156 ... 72 90]
~    % Logical negation: turns nonzero into zero
     % STACK: [11 10 ... -11 -12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]
edited body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214

MATL, 13 bytes

|st_w&:GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is bounded by the sum of absolute values of the coefficients.

###Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
_    % ArithemticalArithmetical negation
     % STACK: 12, -12
w    % Swap
     % STACK: -12, 12
&:   % Binary range
     % STACK: [-12 -11 ... 12]
G    % Push input again
     % STACK: [-12 -11 ... 12], [1 5 6]
y    % Duplicate from below
     % STACK: [-12 -11 ... 12], [1 5 6], [-12 -11 ... 12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [-12 -11 ... 12], [90 72 ... 210]
~    % Logical negation: turns nonzero into zero
     % STACK: [-12 -11 ... 12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]

MATL, 13 bytes

|st_w&:GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is bounded by the sum of absolute values of the coefficients.

###Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
_    % Arithemtical negation
     % STACK: 12, -12
w    % Swap
     % STACK: -12, 12
&:   % Binary range
     % STACK: [-12 -11 ... 12]
G    % Push input again
     % STACK: [-12 -11 ... 12], [1 5 6]
y    % Duplicate from below
     % STACK: [-12 -11 ... 12], [1 5 6], [-12 -11 ... 12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [-12 -11 ... 12], [90 72 ... 210]
~    % Logical negation: turns nonzero into zero
     % STACK: [-12 -11 ... 12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]

MATL, 13 bytes

|st_w&:GyZQ~)

Try it online!

This uses the fact that, for integer coefficients, the absolute value of any root is bounded by the sum of absolute values of the coefficients.

###Explanation

Consider input [1 5 6] as an example.

|    % Implicit input. Absolute value
     % STACK: [1 5 6]
s    % Sum
     % STACK: 12
t    % Duplicate
     % STACK: 12, 12
_    % Arithmetical negation
     % STACK: 12, -12
w    % Swap
     % STACK: -12, 12
&:   % Binary range
     % STACK: [-12 -11 ... 12]
G    % Push input again
     % STACK: [-12 -11 ... 12], [1 5 6]
y    % Duplicate from below
     % STACK: [-12 -11 ... 12], [1 5 6], [-12 -11 ... 12]
ZQ   % Polyval: values of polynomial at specified inputs
     % STACK: [-12 -11 ... 12], [90 72 ... 210]
~    % Logical negation: turns nonzero into zero
     % STACK: [-12 -11 ... 12], [0 0 ... 0] (contains 1 for roots)
)    % Index: uses second input as a mask for the first. Implicit display
     % STACK: [-3 -2]
added 902 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading