What is the most succinct way (in pseudocode) to create the following map f from the naturals to the integers
f(0) = 0;
f(1) = 1;
f(2) = -1;
f(3) = 2;
f(4) = -2;
f(5) = 3;
etc
You can imagine them as the zero crossing of a double symmetric Archimedean spiral.
Oh, and no float math allowed! Float math would be… ugly in this situation.
Wolfram Alpha found a closed form for calculating the nth term directly:
The expression -1n can also be written as
(n % 2 == 0 ? 1 : -1)if n is a positive integer.