The purpose of this task is to explore working with   complex numbers.



Task

Given   n,   find the   nth   roots of unity.




function unity_roots(n) {
	// nth-root(1) = cos(2 * k * pi / n) + i * sin(2 * k * pi / n)
	return map(range(n), function(idx, k) {
		return {
			"re": cos(2 * k * M_PI / n),
			"im": sin(2 * k * M_PI / n)
		};
	});
}
 
// pirnt 6th roots of unity
foreach(unity_roots(6), function(k, v) {
	printf("%.3f%+.3fi\n", v.re, v.im);
});