Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

MATL, 7 bytes

BJ*Y'^s

Try it online!

###How it works

How it works

Consider input 4538 for example.

B % Implicit input. Convert to binary
 % STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
 % STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
 % STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
 % STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
 % STACK: -1+1i

MATL, 7 bytes

BJ*Y'^s

Try it online!

###How it works

Consider input 4538 for example.

B % Implicit input. Convert to binary
 % STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
 % STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
 % STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
 % STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
 % STACK: -1+1i

MATL, 7 bytes

BJ*Y'^s

Try it online!

How it works

Consider input 4538 for example.

B % Implicit input. Convert to binary
 % STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
 % STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
 % STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
 % STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
 % STACK: -1+1i
added 276 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 7 bytes

BJ*Y'^s

Try it online!

###How it works

Consider input 4538 for example.

B % Implicit input. Convert to binary
 % STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
 % STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
 % STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
 % STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
 % STACK: -1+1i

MATL, 7 bytes

BJ*Y'^s

Try it online!

###How it works

B % Implicit input. Convert to binary
J* % Multiply by 1i
Y' % Run-length encoding
^ % Power, element-wise
s % Sum of array. Implicit display

MATL, 7 bytes

BJ*Y'^s

Try it online!

###How it works

Consider input 4538 for example.

B % Implicit input. Convert to binary
 % STACK: [1 0 0 0 1 1 0 1 1 1 0 1 0]
J* % Multiply by 1i
 % STACK: [1i 0 0 0 1i 1i 0 1i 1i 1i 0 1i 0]
Y' % Run-length encoding
 % STACK: [1i 0 1i 0 1i 0 1i 0], [1 3 2 1 3 1 1 1]
^ % Power, element-wise
 % STACK: [1i 0 -1 0 -1i 0 1i 0]
s % Sum of array. Implicit display
 % STACK: -1+1i
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATL, 7 bytes

BJ*Y'^s

Try it online!

###How it works

B % Implicit input. Convert to binary
J* % Multiply by 1i
Y' % Run-length encoding
^ % Power, element-wise
s % Sum of array. Implicit display

AltStyle によって変換されたページ (->オリジナル) /