[Question]
  [
### Challenge:
Given a positive integer input **n**, create a vector that follows this pattern:
```
0  1  0 -1 -2 -1  0  1  2  3  2  1  0 -1 -2 -3 -4 -3 -2 -1 ... ±(n-1) ±n
```
Or, explained with words: The vector starts at `0`, and makes increments of `1` until it reaches the smallest odd positive integer that isn't part of the sequence, then it makes decrements until it reaches the smallest (in magnitude) even negative integer that isn't part of the sequence. It continues this way until `n` is reached. The sequence will end on positive `n` if `n` is odd, and negative `n` if `n` is even.
The output format is flexible. 
### Test cases:
```
n = 1
0  1
-----------
n = 2
0  1  0 -1 -2
-----------
n = 3
0  1  0 -1 -2 -1  0  1  2  3
-----------
n = 4
0  1  0 -1 -2 -1  0  1  2  3  2  1  0 -1 -2 -3 -4
-----------
n = 5
0  1  0 -1 -2 -1  0  1  2  3  2  1  0 -1 -2 -3 -4 -3 -2 -1  0  1  2  3  4  5
```
You may choose to take the **n** zero-indexed. `n = 1` would then give `0 1 0 -1 -2`. 
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in each language wins! Explanations are encouraged as always!
  
[Answer]
# [R](https://www.r-project.org/), ~~58~~ ~~54~~ ~~50~~ ~~48~~ 43 bytes
*-2 bytes thanks to MickyT*
```
function(n)diffinv(rep(1:n%%2*2-1,1:n*2-1))
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNPMyUzLS0zr0yjKLVAw9AqT1XVSMtI11AHyATRmpr/0zRMNf8DAA "R – Try It Online")
```
function(n)
 diffinv(                           # take cumulative sum, starting at 0 of
             1:n%%2*2-1,            # a vector of alternating 1,-1
         rep(                       # repeated
                        1:n*2-1))   # 1, 3, 5, etc. times
```
[Answer]
# [Perl 6](https://perl6.org), ~~60~~ 26 bytes
```
{flat {((1,-*...*)ZX*(-$++...0...$++)xx$_)}(),$_*($_%2||-1)}
```
[Try it](https://tio.run/##FY3BCoJAFEX3fsVdjM1748wjhdyEfkdEIGK6Sg21UNRvn2xx4JzVedfDK/WfscY3leoatAtOVf@skfm1eZUTVqLYOiMihu83Q05F0RHng8N4nlXBO7FVhSFVhMm2uZh33/QDYpELXI5HhzUAxnJBJ007kQ6TUbOFRpZDW/yH1HGw@x8 "Perl 6 – Try It Online")
```
{[...] (-1,-*...*)Z*0..$_}
```
[Try it](https://tio.run/##Fcy7DoIwAAXQvV9xB6GPtDdiIouBDxGJMVgmKYaKCSF8e8XtTOftp1eZ5ujxLdldxLAg78anR5XWhmQL5QrrzE6jr@ZIHu5b6scJBXmGq3ELWAUQHwsC@@GjZHaKUltIVDWkxb9TQYst/QA "Perl 6 – Try It Online")
## Expanded:
```
{  # bare block lambda with implicit parameter $_
  [...]  # reduce using &infix:«...» (sequence generator)
          ( -1, -* ... * ) # (-1, 1, -1, 1 ... *)
      Z*                   # zip multiplied with
          0 .. $_          # range up to and including input
}
```
`(-1,-*...*)Z*0..$_` generates the sequence `0 1 -2 3 -4 5`
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~9~~ 7 bytes
*Saved 2 bytes thanks to @Emigna*
```
Ýā®sm*Ÿ
```
[Try it online!](https://tio.run/##MzBNTDJM/f//8NwjjYfWFedqHd3x/78pAA "05AB1E – Try It Online")
My first 05AB1E answer (I think), so I may be missing some tricks...
### Explanation
```
Ý         # push range [0 ... n]   stack: [[0 ... n]]
 ā        # push range [1 ... len(prev)]  [[0 ... n], [1 ... n+1]]
  ®       # push value of register        [[0 ... n], [1 ... n+1], -1]
   s      # swap top two values           [[0 ... n], -1, [1 ... n+1]]
    m     # power                         [[0 ... n], [-1, 1, -1, 1, ...]]
     *    # multiply                      [[0, 1, -2, 3, -4, 5, ...]]
      Ÿ   # range interpolation           [[0, 1, 0, -1, -2, -1, ...]]
```
I have to thank @Dennis for [the original usage of `Ÿ`](https://codegolf.stackexchange.com/a/74860/42545), otherwise I ~~may not~~ probably would never have known about it...
[Answer]
# [Python 2](https://docs.python.org/2/), ~~69~~ ~~57~~ 56 bytes
```
f=lambda n:[0][n:]or f(n-1)+range(-n,n+1)[::n%2*2-1][2:]
```
[Try it online!](https://tio.run/##JcoxDoQgEAXQq0yzERQSodhijCdBCswuu5Po1xAbT48mVq95@3n8N/ha87ikdf4kAoc@BnDcCmUF63RXEn5fZWHQOR2Y8fKtty4Gz7Hm@wkJ6FnOvDXvRXCQDI9ZiTbNhKZe "Python 2 – Try It Online")
For each `n` up to the `input` the `range(-n,n)` (inclusive) is calculated, inverted when `n` is an even number, has the fist two numbers (after the inversion) removed, and then appended to the output.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~15~~ 14 bytes
```
ÝDÉ·<*Ý€û˜ÔsF¨
```
[Try it online!](https://tio.run/##ASUA2v8wNWFiMWX//8OdRMOJwrc8KsOd4oKsw7vLnMOUc0bCqP/Dr/81 "05AB1E – Try It Online")
**Explanation**
```
Ý                # push range [0 ... n]
 D               # duplicate
  É·<            # (x % 2 == 1)*2-1 for each
     *           # multiply
      Ý          # range [0 ... a] for each
       €û        # palendromize each
         ˜       # flatten
          Ô      # connected uniqueified
           sF¨   # remove the last n elements
```
[Answer]
# JavaScript (ES6), 56 bytes
```
f=(n,b=d=1,k=0)=>[k,...k-d*n?f(n,k-b?b:(d=-d)-b,k+d):[]]
```
[Try it online!](https://tio.run/##Dcw9DoMwDEDhnVN4I25@VIYuFJeDIAaCSQVBTgVVl6pnTzO94ZPeNn2mcz7W19tK4iXnQEqMJ6bGRLoiPYZonHPR8kX6UCxa3/tWMVlG603UjO0wjjmkQwkQNHcQ6AhupVojfCuAOcmZ9sXt6anKA92WVlG1gRqx@uU/ "JavaScript (Node.js) – Try It Online")
### Commented
```
f = (               // f = recursive function taking:
  n,                //   n = input
  b =               //   b = boundary value, initialized to 1
  d = 1,            //   d = current direction, initialized to 1
  k = 0             //   k = current sequence value, initialized to 0
) =>                //
  [                 // update the sequence:
    k,              //   append the current value
    ...k - d * n ?  //   if |k| is not equal to |n|:
      f(            //     append the (spread) result of a recursive call:
        n,          //       use the original input
        k - b ?     //       if k has not reached the boundary value:
          b         //         leave b unchanged
        :           //       else:
          (d = -d)  //         reverse the direction
          - b,      //         and use a boundary of higher amplitude and opposite sign
        k + d       //       update k
      )             //     end of recursive call
    :               //   else:
      []            //     stop recursion and append nothing
  ]                 // end of sequence update
```
[Answer]
# [Haskell](https://www.haskell.org/), 43 bytes
```
f n=scanl(-)0[(-1)^k|k<-[1..n],_<-[2..2*k]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz7Y4OTEvR0NX0yBaQ9dQMy67JttGN9pQTy8vViceyDLS0zPSyo6N/Z@bmJmnYKtQUJSZV6KgkaZgovkfAA "Haskell – Try It Online")
Computes the negated cumulative sums of the list `[(-1)^k|k<-[1..n],_<-[2..2*k]]`, which is the first `n` rows of
```
[-1,
 +1, +1, +1,
 -1, -1, -1, -1, -1,
 +1, +1, +1, +1, +1, +1, +1…
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ 9 bytes
```
²ḶÆ½-*0;Ä
```
[Try it online!](https://tio.run/##ASwA0/9qZWxsef//wrLhuLbDhsK9LSowO8OE/8OH4oKsR///MSwgMiwgMywgNCwgNQ "Jelly – Try It Online")
### How it works
```
²ḶÆ½-*0;Ä  Main link. Argument: n
²          Square; yield n².
 Ḷ         Unlength; yield [0, ..., n²-1].
  Æ½       Take the integer square root of each k in the range.
    -*     Compute (-1)**r for each integer square root r.
      0;   Prepend a zero.
        Ä  Accumulate; take the sums of all prefixes.
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~48~~ 42 bytes
```
f n=0:[(-1)^i*x|i<-[0..n-1],x<-[1-i..i+1]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz9bAKlpD11AzLlOroibTRjfaQE8vT9cwVqcCyDbUzdTTy9Q2jI39n5uYmadgq1BQlJlXoqCikKZg8h8A "Haskell – Try It Online") 
*Thanks to [Οurous](https://codegolf.stackexchange.com/users/18730/%ce%9furous) for -1 byte*
Even though it's kind of obvious in hindsight, it took me a while to arrive at `(-1)^i*x` which is `x` when `i` is even and `-x` when `i` is odd. Previous iterations where:
```
(-1)^i*x
x-2*mod i 2*x
(-1)^mod i 2*x
[x,-x]!!mod i 2
(1-sum[2|odd i])*x
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), ~~300~~ 167 bytes
I've never done any of these before, but this one seemed fun. I see why people use those "golfing" languages as 167 seems way higher than some of the other answers. But, you gotta go with what you know.
```
static int[] f(int n){if (n==1) return new int[]{0,1};var a=f(n-1);return a.Concat(a.Skip(a.Length-(n-1)*2).Select(x=>-x)).Concat(new int[]{(n%2)!=0?n:-n}).ToArray();}
```
[Try it online!](https://tio.run/##TY9BS8NAEIXv@RVjQdiRZkmKJ5dUxJtUKETwUHoY1k26mM7q7ra2hPz2uMSKDgzDwPce7@mQa@fNeAiWW6jPIZq9yv5/cmX5U2W6oxBg7V3raZ/1Y4gUrQbLcbOFRqQLjL1tQHBVlQjexINnYPP1w/TFvBzUkTxQ1QjOS1QXhOSjY01RkKzf7Uc6K8Nt3OUTdbNAWZvO6ChO1TI/If7if9aCrxd4VRX3fJfzgPLFPXhPZ4FqGAEuSY/OvsEzWRYh@lQvxSbMAPq0AMkzuM7IV2@jSY2NqCdKPrmkmMFsPnWUa/LBCNoUW0yjknbIhnG8/QY "C# (.NET Core) – Try It Online")
```
// Recursive Worker Function
static public int[] f( int n )
{
    // Start with the simple case
    if ( n == 1 ) return new int[]{0,1};
    // Recusively build off of that
    var a = f(n-1);
    // To be added at the end
    int[] b = { (n%2) !=0 ? n : -n };
    // Skip some based on length
    int s = a.Length - (n-1)*2;
    // With the rest, multiply by -1 and then append to the end
    // And append the part
    return a.Concat( a.Skip(s).Select( x => -x ) ).Concat( b ).ToArray();
}
```
[Answer]
# [J](http://jsoftware.com/), 25 bytes
-5 bytes thanks to FrownyFrog! 
```
>:@*:$i.;@(<@i:@*_1&^)@,]
```
[Try it online!](https://tio.run/##y/qfVmyrp2CgYKVg8N/OykHLSiVTz9pBw8YhE8iJN1SL03TQif2vyaWkp6CeZqunrqCjUGulkFbMxZWanJGvoKOXpqCmZ6dgqJ2pZ8b1HwA "J – Try It Online")
# [J](http://jsoftware.com/), 30 bytes
```
>:@*:{.;@([:(i:@*_1&^)&.>i.,])
```
Explanation:
`i.,]` creates list 0..n
`&.>` for each number in the list execute the verb in (...) and box the result (I need boxing because the results have different length) 
`[:( _1&^)` find -1 to the `i`th power (-1 or 1)
`i:@*` make a list -n..n or n..-n, depending on the sign of the above
`;@` unbox
`>:@*:` find n^2 + 1
`}.` and take so many numbers from the list
[Try it online!](https://tio.run/##y/qfVmyrp2CgYKVg8N/OykHLqlrP2kEj2kojE8iJN1SL01TTs8vU04nV/K/JpaSnoJ5mq6euoKNQa6WQVszFlZqcka@go5emAFSlYKidqWfG9R8A "J – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~65~~ 56 bytes
```
r=k=0;exec'print r;r+=1-k**.5//1%2*2;k+=1;'*-~input()**2
```
The output format is a bit ugly. **:/**
[Try it online!](https://tio.run/##HY3BCsIwEETP2a/IRaIrtSbaiyHHevXiD2hZaIikYUnRXvz1mHoZmIH3Ji15nKIp79G/SN55pguIzEtNQR8apFKqsAvuaNeqEvuYJVveO90ExEPXtnpj0NhQF6uw@fqY5rzdIZoiRMWr6U8BVONAKcv@du2ZJ15PnkyPUDQYOMEZuh8 "Python 2 – Try It Online")
[Answer]
# Java 8, ~~85~~ ~~83~~ 79 bytes
```
n->{for(int p=0,i=0;i<=n*n;p+=1-(int)Math.sqrt(i++)%2*2)System.out.println(p);}
```
-6 bytes thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##LY7LDoIwEEX3fsVsTFoQgiSuav0D2LA0LmoBLcJQaSExhG/H8khmFnPnJPdUYhBBlX9mWQtjIBEKxwOAQlt0pZAFpMsJMLQqB0lcDkiZiya3bowVVklIAYHDjMFtLNtuxTSPTopHTF05esi0z8/B8qCJsO/QfDtLlO/TY@zFNPsZWzRh29tQd46pkWjKppltJbp/1q5k71pVGidKMuvg1/0h6CaJoSSX3W6a/w)
**Explanation:**
```
n->{                            // Method with integer parameter and no return-type
  for(int p=0,                  //  Set both `p` to 0
      i=0;i<=n*n;               //  Loop `i` in the range [0, `n*n`]
      p+=                       //    After every iteration, increase `p` by:
         1-                     //     1, minus:
           (int)Math.sqrt(i++)  //     The square-root of `i`, truncated to its integer
           %2*2)                //     Modulo 2, and multiplied by 2
     System.out.println(p);}    //   Print integer `p` with a trailing new-line
```
[Answer]
# [R](https://www.r-project.org/), ~~48 46~~ 42 bytes
```
for(i in 1:scan())F=c(F,-(-1)^i*(2-i):i);F
```
[Try it online!](https://tio.run/##K/r/Py2/SCNTITNPwdCqODkxT0NT0802WcNNR1dD11AzLlNLw0g3U9MqU9Pa7b/ZfwA "R – Try It Online")
A port of [the Ruby answer](https://codegolf.stackexchange.com/a/165068/80010) by Kirill L. - and saved 6 bytes thanks to the same Kirill L.! Now shorter than [Giuseppe's solution](https://codegolf.stackexchange.com/a/165068/80010) ;)
A port of [this Octave answer](https://codegolf.stackexchange.com/a/165005/80010) by Luis Mendo using `approx` is less golfy. `n=n^2+1` can be replaced by `,,n^2+1`; or by `0:n^2+1`(positional argument `xout`) for the same byte count :
### [R](https://www.r-project.org/), 56 bytes
```
f=function(n)approx((0:n)^2+1,-(-1)^(0:n)*0:n,n=n^2+1)$y
```
[Try it online!](https://tio.run/##K/r/P802rTQvuSQzP08jTzOxoKAov0JDw8AqTzPOSNtQR1dD11AzDszXAhI6ebZ5IHFNlcr/xUDFOZUahlZmOnATKjSTE0s00oC0jhKXkqbmfwA "R – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 17 bytes
```
+\0,¯1*⍳(/⍨)1+2×⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/9OApHaMgc6h9YZaj3o3a@g/6l2haahtdHg6kPf/f5qCCQA "APL (Dyalog Unicode) – Try It Online")
Golfed 2 bytes thanks to @FrownyFrog by converting to a train. See the older answer and its explanation below.
---
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 19 bytes
```
+\0,∊⊢∘-\⍴∘1¨1+2×⍳⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkGXI862tP@a8cY6Dzq6HrUtehRxwzdmEe9W4C04aEVhtpGh6c/6t0MVP4fqPB/GpcJAA "APL (Dyalog Unicode) – Try It Online")
(Uses `⎕IO←0`)
My first approach was to construct multiple ranges and concatenate them together, this easily went over 30 bytes. Then I started analysing the sequence
```
      +\⍣¯1⊢0  1  0 ¯1 ¯2 ¯1  0  1  2  3  2  1  0 ¯1 ¯2 ¯3 ¯4
0 1 ¯1 ¯1 ¯1 1 1 1 1 1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1
```
`+\⍣¯1` denotes the inverse cumulative sum
There is a repeating pattern of 1s and ¯1s, where the length of each consecutive sequence of 1s or ¯1s is 1+2×n. And each subsequence alternates between 1 and ¯1. What I can do now is to create the 1s and ¯1s list, and then scan by +
```
      ⍳4 ⍝ creates range 0..4
0 1 2 3
      2×⍳4
0 2 4 6
      1+2×⍳4
1 3 5 7
      ⍴∘1¨1+2×⍳4 ⍝ for-each create that many 1s
┌─┬─────┬─────────┬─────────────┐
│1│1 1 1│1 1 1 1 1│1 1 1 1 1 1 1│
└─┴─────┴─────────┴─────────────┘
      ⊢∘-\⍴∘1¨1+2×⍳4 ⍝ alternate signs
┌─┬────────┬─────────┬────────────────────┐
│1│¯1 ¯1 ¯1│1 1 1 1 1│¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1│
└─┴────────┴─────────┴────────────────────┘
      ∊⊢∘-\⍴∘1¨1+2×⍳4 ⍝ flatten
1 ¯1 ¯1 ¯1 1 1 1 1 1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1
      0,∊⊢∘-\⍴∘1¨1+2×⍳4
0 1 ¯1 ¯1 ¯1 1 1 1 1 1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1
      +\0,∊⊢∘-\⍴∘1¨1+2×⍳4 ⍝ cumulative sum
0 1 0 ¯1 ¯2 ¯1 0 1 2 3 2 1 0 ¯1 ¯2 ¯3 ¯4
```
[Answer]
# [Haskell](https://www.haskell.org/), 47 bytes
```
(#0)
m#n|m>n=[-n..n]++map(0-)(m#(n+1))|1>0=[-m]
```
[Try it online!](https://tio.run/##DcmxCoAgEADQva8QbPAQxaDVfqQcJLIk75Bq9Nu7eus74n1upXDyCyvpoENJDSfysyFrKWiNsSpnQKFUpAeANkzuXwyMMZOvV6ZH9CKJkd81lbjfbNZaPw "Haskell – Try It Online")
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 98 bytes
```
n->{var s="0";for(int i=0,r=0,d=1;i++<n;s+=" "+r,d=-d)for(r+=d;r!=i&r!=-i;r+=d)s+=" "+r;return s;}
```
[Try it online!](https://tio.run/##ZU6xboMwFNz5iquHCuqCkqFLjDNW6tApY9XBhRA9CjayH0hRxLdTkzRdOtw73b3T6VozmbytvxfqB@cZbdTFyNQVTyr55zWjrZicXZ9J1ZkQ8G7I4pIAw/jVUYXAhiNNjmr08Zce2JM9fXzC@FPIrlHgzfLrb1d5C@zRQC82318m4xG02AjVOJ@SZZDePPuIWm8VSVlaFaQWENJHK6@zNeelrpV/0PQYT05q1dk9pvyRR28R1Lyo64C/amhsVaRS4yWylPeJwOEc@NgXbuRiiBO5sylBQuwgIjWFGYbunFKW3SrnZMW8/AA "Java (JDK 10) – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~17~~ 15 bytes
*-2 bytes thanks to Luis Mendo!*
```
0i:oEqG:EqY"Ysh
```
[Try it online!](https://tio.run/##y00syfn/3yDTKt@10N3KtTBSKbI44/9/UwA "MATL – Try It Online")
Explanation for `n=3`:
```
0		% push 0
 i:		% read input as integer, push range
		% stack: [0, [1 2 3]]
   o		% modulo 2, stack: [0, [1 0 1]]
    Eq		% double and decrement, stack: [0, [1 -1 1]]
      G:	% push input and range again
		% stack: [0, [1 -1 1], [1 2 3]]
        Eq	% double and decrement,
		% stack: [0, [1 -1 1], [1 3 5]]
	  Y"	% run-length decoding
		% stack: [0, [1 -1 -1 -1 1 1 1 1 1]]
	    Ys	% cumulative sum
		% stack: [0, [1  0 -1 -2 -1  0  1  2  3]]
	      h	% horizontally concatenate
		% end of program, automatically print the stack
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~44~~ ~~42~~ 41 bytes
*2 bytes removed thanks to [@StewieGriffin](https://codegolf.stackexchange.com/users/31516/stewie-griffin), and 1 byte further removed thanks to @Giuseppe!*
```
@(n)interp1((t=0:n).^2,-t.*(-1).^t,0:n^2)
```
[Try it online!](https://tio.run/##DYsxCsAgDAB3X@GYFBuqdBKEvkQoVcElig39vvWm4@DaI/eXZwlENC9grCx5dAsg4fCMFJ3ZhTbY7XIxq0WHs7ShWQdt/an0ItW3Q1k7qsxp/g "Octave – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~52~~ 47 bytes
```
f=->n{n<1?[0]:f[n-1]+(2-n..n).map{|x|-~0**n*x}}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6vOs/G0D7aINYqLTpP1zBWW8NIN09PL09TLzexoLqmoka3zkBLK0@rorb2v4ahnp6ppl5qYnJGdU1JTYFCWnRJbO1/AA "Ruby – Try It Online")
Below is the original 52-byte version with an explanation:
```
f=->n{n<1?[0]:f[n-1]+[(r=*2-n..n).map(&:-@),r][n%2]}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6vOs/G0D7aINYqLTpP1zBWO1qjyFbLSDdPTy9PUy83sUBDzUrXQVOnKDY6T9Uotva/hqGenqmmXmpickZ1TUlNgUJadAlQGAA "Ruby – Try It Online")
### Walkthrough
```
f=->n{           #Recursive approach
 n<1?[0]         #Init with 0 if n=0
 :f[n-1]         #else make a recursive call
 +               #and append an array of numbers
 [(r=*2-n..n)    #Init r as splatted range from 2-n to n
 .map(&:-@)      #"-@" is unary minus, so this a fancy way to do map{|x|-x} for -1 byte
                 #For even n use this negated r, e.g. for n=4: [2, 1, 0, -1, -2, -3, -4]
 ,r]             #For odd n use r directly, e.g. for n=3: [-1, 0, 1, 2, 3]
 [n%2]           #Odd/even selector
}
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 113 bytes
```
0-I-[0|I].
N-[H|T]-R:-N is -H*(-1)^N,A is N-1,A-[H|T]-R;I is H-(-1)^N,N-[I|[H|T]]-R.
N-O:-X is -N*(-1)^N,N-[X]-O.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/30DXUzfaoMYzVo/LTzfaoyYkVjfIStdPIbNYQddDS0PXUDPOT8cRxPXTNdRxhCmx9gQJeehCFQC1etaApYByIJP8rXQjwGb4aSGURMTq@uv9t9dVMDTQ9ddRKC/KLEnV8NfU@w8A "Prolog (SWI) – Try It Online")
[Answer]
## Python 3, 83 bytes
```
def c(n):print([(-1)**j*(abs(j-i)-j)for j in range(n+1)for i in range(2*j)][:-n+1])
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~18~~ 17 bytes
```
:ṁoṡ₁ŀ⁰_₁⁰
*^⁰_1⁰
```
[Try it online!](https://tio.run/##yygtzv7/3@rhzsb8hzsXPmpqPNrwqHFDPJABpLi04kAcQyDx//9/EwA "Husk – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 19 bytes
```
Ｆ⊕ＮＩ×∨﹪ι²±¹…·∧ι⁻²ιι
```
[Try it online!](https://tio.run/##FYwxDgIhEAC/QrmbYOHFzspYWdxpjB9AWM9NYDEL3PeRayZTTMZ/nfrsYu@frAZu4pUSSaUw/Nfq0tKbFBDRPJSlwtWVCi9OVOCuMOfQYga2ZkJrFlpdJTji8HGKrfBGTycrwUXCXs0srcBkDe/NAJ57P/XDFv8 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  Ｎ                 Input as a number
 ⊕                  Increment
Ｆ                   Loop over implicit range
                ²   Literal 2
                 ι  Current index
               ⁻    Subtract
              ι     Current index
             ∧      Logical And
                  ι Current index
           …·       Inclusive range
       ι            Current index
        ²           Literal 2
      ﹪             Modulo
          ¹         Literal 1
         ±          Negate
     ∨              Logical Or
    ×               Multiply
   Ｉ                Cast to string and implicitly print
```
Alternative explanation:
```
Ｆ⊕Ｎ
```
Loop over the integers from `0` to the input inclusive.
```
Ｉ
```
Cast the results to string before printing.
```
×∨﹪ι²±¹
```
Negate alternate sets of results.
```
…·∧ι⁻²ιι
```
Form a list from the previous index to the current index, excluding the previous index.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ 12 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
Bah, I thought I had 11 wih `_2+ỊrN)N;¥/`
```
_2+ỊrN×-*$)Ẏ
```
**[Try it online!](https://tio.run/##y0rNyan8/z/eSPvh7q4iv8PTdbVUNB/u6vv//78ZAA)**
### How?
```
_2+ỊrN×-*$)Ẏ - Main Link: n           e.g. 4
          )  - for x in [1...n]:           1       2          3               4
_2           -   subtract 2 from x        -1       0          1               2
   Ị         -   is x insignificant?       1       0          0               0
  +          -   add                       0       0          1               2
     N       -   negate x                 -1      -2         -3              -4
    r        -   inclusive range          [0,-1]  [0,-1,-2]  [1,0,-1,-2,-3]  [2,1,0,-1,-2,-3,-4]
         $   -   last two links as a monad:
       -     -     minus one              -1      -1         -1              -1
        *    -     raised to the power x  -1       1         -1               1
      ×      -   multiply                 [0,1]   [0,-1,-2]  [-1,0,1,2,3]    [2,1,0,-1,-2,-3,-4]
           Ẏ - tighten                    [0,1,0,-1,-2,-1,0,1,2,3,2,1,0,-1,-2,-3,-4]
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
╗)SΘ█☼₧ΘP(
```
[Run and debug it](https://staxlang.xyz/#p=bb2953e9db0f9ee95028&i=2%0A3&a=1&m=2)
[Answer]
### Scala, 119 Bytes
```
def a(n: Int)={lazy val s:Stream[Int]=0#::Stream.from(0).map{x=>s(x)+1 -2*(Math.sqrt(x).toInt%2)}
s.take(n*n+1).toList}
```
Ungolfed:
```
def a(n: Int)={
  lazy val s:Stream[Int]= 0#::Stream.from(0).map //Give the starting point and indexing scheme
  {
    x=>
    {
      val sign = 1-2*(Math.sqrt(x).toInt%2) //Determine whether we are adding or subtracting at the current index
      s(x)+sign
    }
  }
  s.take(n*n+1).toList //Take the desired values
}
```
This can probably be golfed much better, but I wanted a solution utilizing lazy Streams.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~34~~ 32 bytes
```
⎕CY'dfns'⋄-0,∘∊1↓¨2to/S×¯1*S←⍳,⊢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HfVOdI9ZS0vGL1R90tugY6jzpmPOroMnzUNvnQCqOSfP3gw9MPrTfUCn7UNuFR72adR12LQHo8/YF8Ay43IEmUHi6gHiDPTcH0PwA "APL (Dyalog Unicode) – Try It Online")
Requires `⎕IO←0`
-2 bytes thanks to @FrownyFrog
[Answer]
# [Stacked](https://github.com/ConorOBrien-Foxx/stacked), 44 bytes
```
[~>0\:2%\#,2*1-tr[...rep]flatmap,$sumonpref]
```
[Try it online!](https://tio.run/##Ky5JTM5OTfn/P7rOziDGykg1RlnHSMtQt6QoWk9Pryi1IDYtJ7EkN7FAR6W4NDc/r6AoNS32v4NVOheXqUKdnUK0lUJBaYmCuoKuHZAAMdMV8ktLYhXygHr@AwA "Stacked – Try It Online") It's been a while since I programmed in Stacked, but I think I still got it.
## Alternatives
**73 bytes:** `[0\|>:2%tmo*2 infixes[:...|>\rev...|>rev#,$#'sortby 1#behead]flatmap 0\,]`
This goes with the "ranges from generated indices" approach used in my [Attache answer.](https://codegolf.stackexchange.com/a/165122/31957) This proved to be pretty long, since Stacked has no builtin for reversed ranges nor collapsing. (That's what `:...|>\rev...|>rev#,$#'sortby 1#behead` does.)
**53 bytes:** `[0\|>:2%tmo _\tpo#,tr[...rep]flatmap 0\,inits$summap]`
...so I decided to go for an approach which instead finds the cumulative sum (`inits$summap`) over `1` and `-1` repeated by the odd integers, as in the [R answer](https://codegolf.stackexchange.com/a/164978/31957).
**46 bytes:** `[~>0\:2%\#,2*1-tr[...rep]flatmap,inits$summap]`
...but I realized that the negative integers *and* the odd integers could be made in one go, by multiplying both generated arrays (the mod 2 values of the range and the range itself) by `2` then subtracting `1`. This gives alternating `1`s and `-1`s for the first range and the odd integers for the second!
**44 bytes:** `[~>0\:2%\#,2*1-tr[...rep]flatmap,$sumonpref]`
... and then I remembered I had a builtin for mapping prefixes. ^-^
[Answer]
# [Julia 0.6](http://julialang.org/), 44 bytes
```
n->[(i%2*2-1)*[0:i;(n>i)*~-i:-1:1]for i=1:n]
```
[Try it online!](https://tio.run/##yyrNyUw0@x9q@z9P1y5aI1PVSMtI11BTK9rAKtNaI88uU1OrTjfTStfQyjA2Lb9IIdPW0Cov9n9BUWZeSU6eRqiGkaYmF4JnjMIzQeEZGmpqKiDzgdz/AA "Julia 0.6 – Try It Online")
Since OP mentions "the output format is flexible", this prints an array of sub arrays, eg. U(3) => `[[0, 1], [0, -1, -2, -1], [0, 1, 2, 3]]`.
`i%2*2-1` decides the sign of the current subarray - negative for even numbers, positive for odd.
`[0:i;(n>i)*~-i:-1:1]` is in two parts. 0:i is straightforward, the range of values from 0 to the current i. In the next part, ~-i:-1:1 is the descending range from i-1 to 1. But we want to append this only if we're not yet at the final value, so multiply the upper end of the range by (n>i) so that when n==i, the range will be 0:-1:1 which ends up empty (so the array stops at n correctly).
---
And here's a version that can support random access - the inner lambda here returns the i'th term of the sequence without having to have stored any of the terms before it. This one gives the output as a single neat array too.
### 49 47 bytes
```
n->map(i->((m=isqrt(i))%2*2-1)*(m-i+m^2),0:n^2)
```
[Try it online!](https://tio.run/##VcexCoAgEADQvf8I7iwhLRoC/QzHwPFCxcy@/3LM6fGuN5Df2RlO0kafgaQFiIaeu1QgxFELLRUKiJKmeGqclyM1eMiFUg0JHGjE39ZuWzelWvkD "Julia 0.6 – Try It Online")
]