Skip to main content
added 98 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Python 2, 7272 62 bytes

n=s=1;x=[]n=2;x=[] exec'x+=[s]*n+[s*1j]*n;n+=1;s=-s;'*inputexec'x+=n/2*[1j**n];n+=1;'*input() print -sum(x[:n-1]2]) 

Thanks to @xnor for suggesting and implementing the quarter-turn idea, which saved 10 bytes.

Indexing is 0-based, output is a complex number. Test it on Ideone.

Python 2, 72 bytes

n=s=1;x=[] exec'x+=[s]*n+[s*1j]*n;n+=1;s=-s;'*input() print sum(x[:n-1]) 

Indexing is 0-based, output is a complex number. Test it on Ideone.

Python 2, 72 62 bytes

n=2;x=[] exec'x+=n/2*[1j**n];n+=1;'*input() print-sum(x[:n-2]) 

Thanks to @xnor for suggesting and implementing the quarter-turn idea, which saved 10 bytes.

Indexing is 0-based, output is a complex number. Test it on Ideone.

Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Python 2, 72 bytes

n=s=1;x=[] exec'x+=[s]*n+[s*1j]*n;n+=1;s=-s;'*input() print sum(x[:n-1]) 

Indexing is 0-based, output is a complex number. Test it on Ideone.