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 Revisions

5 of 5
Commonmark migration

MATL, 11 bytes

X/Z/0)2/YP/

Input is a sequence of complex numbers including the end point.

Try it online!

Explanation

Most of the work is done by the Z/ function (unwrap), which unwraps angles in radians by changing absolute jumps greater than or equal to pi to their 2*pi complement.

X/ % compute angle of each complex number
Z/ % unwrap angles
0) % pick last value. Total change of angle will be a multiple of 2*pi because 
 % the path is closed. Total change of angle coincides with last unwrapped
 % angle because the first angle is always 0
2/ % divide by 2
YP/ % divide by pi
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

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