Skip to main content
deleted 79 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 99 8 bytes

2_y|:q^=aq^m

Try it online!Try it online! Or verify all test casesverify all test cases.

How it works

Consider input -8 as an example

2_    % Push -2
      % STACK: -2
y     % Implicit input. Duplicate from below
      % STACK: -8, -2, -8
|     % Absolute value
      % STACK: -8, -2, 8
:     % Range
      % STACK: -8, -2, [1 2 3 4 5 6 7 8]
q     % Subtract 1, element-wise
      % STACK: -8, -2, [0 1 2 3 4 5 6 7]
^     % Power, element-wise
      % STACK: -8, [1 -2 4 -8 16 -32 64 -128]
=     % Is equal? Element-wise
      % STACK: [0 0 0 1 0 0 0 0]
am     % Any: true if some elementIsmember. isImplicit nonzerodisplay
      % STACK: 1

MATL, 9 bytes

2_y|:q^=a

Try it online! Or verify all test cases.

How it works

Consider input -8 as an example

2_    % Push -2
      % STACK: -2
y     % Implicit input. Duplicate from below
      % STACK: -8, -2, -8
|     % Absolute value
      % STACK: -8, -2, 8
:     % Range
      % STACK: -8, -2, [1 2 3 4 5 6 7 8]
q     % Subtract 1, element-wise
      % STACK: -8, -2, [0 1 2 3 4 5 6 7]
^     % Power, element-wise
      % STACK: -8, [1 -2 4 -8 16 -32 64 -128]
=     % Is equal? Element-wise
      % STACK: [0 0 0 1 0 0 0 0]
a     % Any: true if some element is nonzero
      % STACK: 1

MATL, 9 8 bytes

2_y|:q^m

Try it online! Or verify all test cases.

How it works

Consider input -8 as an example

2_    % Push -2
      % STACK: -2
y     % Implicit input. Duplicate from below
      % STACK: -8, -2, -8
|     % Absolute value
      % STACK: -8, -2, 8
:     % Range
      % STACK: -8, -2, [1 2 3 4 5 6 7 8]
q     % Subtract 1, element-wise
      % STACK: -8, -2, [0 1 2 3 4 5 6 7]
^     % Power, element-wise
      % STACK: -8, [1 -2 4 -8 16 -32 64 -128]
m     % Ismember. Implicit display
      % STACK: 1
added 621 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 9 bytes

2_y|:q^=a

Try it online! Or verify all test cases.

How it works

Consider input -8 as an example

2_    % Push -2
      % STACK: -2
y     % Implicit input. Duplicate from below
      % STACK: -8, -2, -8
|     % Absolute value
      % STACK: -8, -2, 8
:     % Range
      % STACK: -8, -2, [1 2 3 4 5 6 7 8]
q     % Subtract 1, element-wise
      % STACK: -8, -2, [0 1 2 3 4 5 6 7]
^     % Power, element-wise
      % STACK: -8, [1 -2 4 -8 16 -32 64 -128]
=     % Is equal? Element-wise
      % STACK: [0 0 0 1 0 0 0 0]
a     % Any: true if some element is nonzero
      % STACK: 1

MATL, 9 bytes

2_y|:q^=a

Try it online! Or verify all test cases.

MATL, 9 bytes

2_y|:q^=a

Try it online! Or verify all test cases.

How it works

Consider input -8 as an example

2_    % Push -2
      % STACK: -2
y     % Implicit input. Duplicate from below
      % STACK: -8, -2, -8
|     % Absolute value
      % STACK: -8, -2, 8
:     % Range
      % STACK: -8, -2, [1 2 3 4 5 6 7 8]
q     % Subtract 1, element-wise
      % STACK: -8, -2, [0 1 2 3 4 5 6 7]
^     % Power, element-wise
      % STACK: -8, [1 -2 4 -8 16 -32 64 -128]
=     % Is equal? Element-wise
      % STACK: [0 0 0 1 0 0 0 0]
a     % Any: true if some element is nonzero
      % STACK: 1
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 9 bytes

2_y|:q^=a

Try it online! Or verify all test cases.