text:
Up and down, up and down
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, so the shortest code in each language wins! Explanations are encouraged as always!

Relevant: OEIS A196199.

R, 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!
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

Perl 6,  60  26 bytes
{flat {((1,-*...*)ZX*(-$++...0...$++)xx$_)}(),$_*($_%2||-1)}

Try it
{[...] (-1,-*...*)Z*0..$_}

Try it
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

05AB1E, 9 7 bytes
Saved 2 bytes thanks to @Emigna
Ýā®sm*Ÿ

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 Ÿ, otherwise I may not probably would never have known about it...

Nice :)! I got ÝεDÈi®*}}Ÿ without checking, ā®sm is crazy smart haha.

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!
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

Python 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!
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.

05AB1E, 15 14 bytes
ÝDÉ·<*Ý€û˜ÔsF¨

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

Jelly, 11 9 bytes
²ḶÆ½-*0;Ä

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.

Haskell, 48 42 bytes
f n=0:[(-1)^i*x|i<-[0..n-1],x<-[1-i..i+1]]

Try it online!
Thanks to Οurous 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

You can save a byte by using 1-i instead of -i+1 in the .. expression.

Haskell, 43 bytes
f n=scanl(-)0[(-1)^k|k<-[1..n],_<-[2..2*k]]

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…

J, 25 bytes
-5 bytes thanks to FrownyFrog!
>:@*:$i.;@(<@i:@*_1&^)@,]

Try it online!
J, 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 ith 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!

would you consider writing the same code as a zero based n version? e.g *:{.;@([:(i:@*_1&^)&.>i.) .. the specification allows that

"n = 1 would then give 0  1  0 -1 -2"

@FrownyFrog - Hmm, I didn't check it. I reverted to my first solution. Thank you for the observation!

25
Use $ for the cut-off, no need for &.> because * is rank-0.

C# (.NET Core), 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!
// 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();
}

You can make this a lot shorter if you only count the using statements and the function. This is allowed by default unless the challenge specifies it must be a full program (even if it did, you could shorten the containing class name).

Thank you!  Thanks to your suggestion, I figured out the meaning of the "header" and "footer" sections of the TIO site.  That cut my submission size in half!

Welcome to PPCG! (this looks like your first post.) Don't worry about the other languages, just try to be as good as possible in your language. / Tips: Remove unnecessary spaces. In C# you can remove all spaces surrounding symbols ([](){};.) (n-1)*2 is just 2*n-2 and with some rearrangement you can remove the parentheses there.

Besides, != has precedence less than % so you can remove a pair of parens. And you can use >0 instead of `!=0, saves a byte.

Also from me: welcome to PPCG! Tips for golfing in C# and Tips for golfing in all languages might be interesting to read through. :) As for some golfing tips: static int[] f(int n) can become f=n=> by using a (recursive) lambda, and (n-1)*2 can become ~-n*2 to save on the parenthesis. I got it down to 155 (137 + 18)  bytes: Try it online. The 18 bytes are for using System.Linq;, because required imports are mandatory for the byte-count. Enjoy your stay!

Python 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!

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.
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

Nice approach. I was working on such approach right now, to improve my answer, but you beat me to it (despite your meeting), well done! ;-)

83 bytes (I just removed j).

79 bytes: I made i go up instead of down to remove a redundant n*n.

Hi. Writing this to inform me you that I basically ripped off your answer. (port to JavaScript). Hope it's ok

@MuhammadSalman Sure, np. I port answers from others pretty often as well. :) As long as the original answer is mentioned, like you did, it's all fine by me.

R, 48 46 42 bytes
for(i in 1:scan())F=c(F,-(-1)^i*(2-i):i);F

Try it online!
A port of the Ruby answer by Kirill L. - and saved 6 bytes thanks to the same Kirill L.!  Now shorter than Giuseppe's solution ;)
A port of this Octave answer 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, 56 bytes
f=function(n)approx((0:n)^2+1,-(-1)^(0:n)*0:n,n=n^2+1)$y

Try it online!

I think approx will work here in a similar manner to Luis Mendo's Octave solution as well.

@Giuseppe Thanks! It does work though it's longer. I've learned diffinv and approx from this question...

Although I also don't know a golfier way to do -1 power (in R ~ doesn't work as a complement operator :(), you can still save another 2 bytes by switching to a full program.

...and since it is a full program we can also use and spoil a predefined built-in: 42 bytes - finally, shorter than Giuseppe's!

APL (Dyalog Unicode), 17 bytes
+\0,¯1*⍳(/⍨)1+2×⍳

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), 19 bytes
+\0,∊⊢∘-\⍴∘1¨1+2×⍳⎕

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

Checking other answers now, I see many also use the +\ method, but generate the sequence of 1s and ¯1s with ¯1*⌊.5*⍨×⍨⍳ which happens to be at least 3 bytes shorter.

+\0,¯1*⍳(/⍨)1+2×⍳ is 17

I knew my solution felt long

Haskell, 47 bytes
(#0)
m#n|m>n=[-n..n]++map(0-)(m#(n+1))|1>0=[-m]

Try it online!

MATL, 17 15 bytes
-2 bytes thanks to Luis Mendo!
0i:oEqG:EqY"Ysh

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

Octave, 44 42 41 bytes
2 bytes removed thanks to @StewieGriffin, and 1 byte further removed thanks to @Giuseppe!
@(n)interp1((t=0:n).^2,-t.*(-1).^t,0:n^2)

Try it online!

Java (JDK 10), 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!

Ah, while I was in my meeting you sneaked in an answer before me.. ;) Will leave mine as well through, because we use a completely different approach. +1 either way.

Ruby, 52 47 bytes
f=->n{n<1?[0]:f[n-1]+(2-n..n).map{|x|-~0**n*x}}

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!
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
}

I don't know Ruby - can you explain what this does especially the map(&:-@) portion?

@JayCe Added an explanation. Basically, this is just negation, what in R would be simply -r.

Thanks for the explanation - it helped me port this to R.

Prolog (SWI), 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!

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])

Husk, 18 17 bytes
:ṁoṡ₁ŀ⁰_₁⁰
*^⁰_1⁰

Try it online!

Charcoal, 19 bytes
Ｆ⊕ＮＩ×∨﹪ι²±¹…·∧ι⁻²ιι

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.

Jelly,  11  12 bytes
Bah, I thought I had 11 wih _2+ỊrN)N;¥/
_2+ỊrN×-*$)Ẏ

Try it online!
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]

APL (Dyalog Unicode), 34 32 bytes
⎕CY'dfns'⋄-0,∘∊1↓¨2to/S×¯1*S←⍳,⊢

Try it online!
Requires ⎕IO←0
-2 bytes thanks to @FrownyFrog

32 as a train

Stax, 10 bytes
╗)SΘ█☼₧ΘP(

Run and debug it

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.

Stacked, 44 bytes
[~>0\:2%\#,2*1-tr[...rep]flatmap,$sumonpref]

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. 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.
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 1s and -1s 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. ^-^

Julia 0.6, 44 bytes
n->[(i%2*2-1)*[0:i;(n>i)*~-i:-1:1]for i=1:n]

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!

JavaScript (Node.js), 83 bytes
n=>[v=0].concat(...[...Array(n),c=d=-1].map(t=>[...Array(c+=2)].map(t=>v+=d,d=-d)))

Try it online!

Jelly, 17 16 15 bytes
-*N×ŒḄ)j00;ḣN‘$

Try it online!

Wolfram Language (Mathematica), 56 51 bytes
-5 bytes thanks to user202729
Join@@MapAt[-#&,Table[Range[-k,k],{k,#}],1;;-1;;2]&

Try it online!

Flatten@ can be Join@@. Table can use prefix notation. Range can be shortened by calculating the reverse range and then negate.

Clean, 59 bytes
import StdEnv
$m=foldr(\a=(++)[~a..a]o map~)[][0..m-1]++[m]

Try it online!
Defines the function $ :: Int -> [Int] generating the required list.
A direct port of user1472751's Haskell solution ended up being slightly better:
Clean, 53 bytes
import StdEnv
$n m|m>n=[~n..n]++map~($(n+1)m)=[~m]

$0

Try it online!

Ruby, 59 bytes
->n{a,*b=-1;n.times{|z|b+=[*(z*a).step(z*a=-a,a)]};b+[n*a]}

Try it online!

C# (.NET Core), 97 bytes
n=>{var r="";int m=0,a=0,i=0;for(;++i<=n;)for(m=i%2>0?1:-1;a!=i*m;a+=m)r+=a+" ";r+=n*m;return r;}

Try it online!
Another different approach in C#.

CJam, 59 bytes
1]q~:X*ee{~[\_-1\#@*](2*)*}%:+W%~[]\_@+{@@+_@+}XX*(*W%0\+p;

Try it online!
Suggestions for improvement are welcome!
EDIT: forgot leading zero

Python 3, 83 bytes
lambda n:numpy.cumsum([0]+sum([[(-1)**i]*(i-~i)for i in range(n)],[]))
import numpy

Try it online!
I'll throw in a numpy solution, just for fun.

Swift, 293 bytes
let odd = n % 2 != 0
var i = 0
var inc = 1
var s : [Int] = [0]
repeat {
    i += inc
    if (inc == 1 && i % 2 != 0) || (inc == -1 && i % 2 == 0) {
        if !s.contains(i) {
            inc = -inc
        }
    }
    s.append(i)
} while !((odd && i == n) || (!odd && i == -n))
print("\(s)")

Welcome to PPCG! This isn't currently a valid submission as it is neither a full program nor a function (it assumes n is a predefined variable, which isn't allowed by default), and you can save a lot of bytes by shortening variable names and removing white-space.

Attache, 38 bytes
Collapse@@{`::&>Pairs!On[Even,`-,0:_]}

Try it online!
I'm struggling to break 38 bytes... I'll post an explanation once I'm convinced I can't get lower than this (or if I golf it!).

JavaScript (Node.js), 51 bytes
n=>{for(p=i=0;i<=n*n;p+=1-(i++**.5|0)%2*2)alert(p)}

Try it online!
I stole toke ripped off used @KevinCruijssen's answer.
Thanks to @StewieGriffin for adding one more byte to my count (I forgot to output the last number) read the comments

Yabasic, 83 bytes
An anonymous function that takes Input, n as an integer and outputs to the console.
Input""n
For i=1To n
For j=-i To i-1
k=i-Abs(j)
?(-1)^(i+1)*k;
If k=n End
Next
Next

Try it online!


text:
The Ever-Increasing Graph
Consider a one-dimensional sequence of numbers within a fixed range, i.e.
[1, 2, 4, 6, 8, 0, 2, 7, 3] in range [0, 10⟩

The Ever-Increasing Graph* ** is a line that connects all the points in this sequence left to right, and always goes upwards or stays level. If necessary, the line wraps around from top to bottom and continues going up from there to meet the next point.
The goal of this challenge is to split the sequence in different subsequences that are all nondecreasing, so that when plotted together with a limited vertical axis they will form an Ever-Increasing Graph. This is done by adding an a point to the end of one subsequence and to the beginning of the next subsequence, so that the angle of the line that crosses the top boundary aligns with the line that crosses the bottom boundary, and the two crossing points have the same horizontal coordinate. The example above would give the following output:
[1, 2, 4, 6, 8, 10]
[-2, 0, 2, 7, 13]
[-3, 3]

And the corresponding graph will look as follows:

And with the axis extended for a better view:

The required output is a list of subsequences that form the parts of the Ever-Increasing Graph. Making a plot is not required but will earn you bonus points ;). The output must clearly separate the subsequences in some way.
Notes

The range will be always have zero as the left (inclusive) boundary, and the right boundary will be some integer N.
The sequence will never contain values that are not within the range.
The first subsequence does not have an additional point at the beginning.
The last subsequence does not have an additional point at the end.
It is not required to provide the starting indices that would be required to plot the subsequences.

Test cases
Input: [0, 2, 4, 6, 1, 3, 5, 0], 7
Output: [0, 2, 4, 6, 8], [-1, 1, 3, 5, 7], [-2, 0]
Input: [1, 1, 2, 3, 5, 8, 3, 1], 10
Output: [1, 1, 2, 3, 5, 8, 13],[-2, 3, 11],[-7, 1]
Input: [5, 4, 3, 2, 1], 10
Output: [5, 14],[-5, 4, 13],[-6, 3, 12],[-7, 2, 11],[-8, 1]
Input: [0, 1, 4, 9, 16, 15, 0], 17
Output: [0, 1, 4, 9, 16, 32], [-1, 15, 17], [-2, 0]

Scoring
This is code-golf, the shortest code in bytes wins.
*Not actual jargon
**Actually should be called Ever Non-Decreasing Graph, as @ngm pointed out, but that sounds less impressive.

Welcome to PPCG! Nice first challenge!

Looks like that I misunderstood some part of the challenge. I think this should be what you intended.

Can you extend the y axis in your sample graph below 0 and above 10 to make the challenge easier to understand?

@JayCe Yes, good suggestion.

The second test case suggests you intend the sequences to be non-decreasing, as opposed to increasing? In other words, a repeated value in the input doesn't stop that current subsequence, and if the last two values in a subsequence are equal than the "angle" to start the next subsequence is 0 (so it would start with a repeated value as well)?

@ngm you are correct, non-decreasing is the correct term! I didn't think about this and will edit the question.

It would be good if you could also make that clear in the title.

Do [1,1],2 be one or two part?

@l4m2 It is a nondecreasing sequence, so the output would be just one sequence: [1,1]

Jelly, 20 bytes
⁹;+⁴,N¤j.x>ṭḷ
çƝF;Ṫ{

Try it online!
Subsequences are splitted by 0.5.

R, 179 158 151 bytes
function(s,m){p=1;t=c(which(diff(s)<0),length(s));for(i in t){d=c(s[p]-m,s[(p+1):i],s[i+1]+m);if(p==1)d[1]=s[1];if(p==t[-1])d=head(d,-1);print(d);p=i}}

Try it online!
Edit: Code is now a function and takes input. (Thanks to Giuseppe, user202729 and JayCe for calmly pointing that out)
Edit: -21 bytes suggested by Giuseppe.
Edit: -7 bytes by removing d=NULL;.

welcome to PPCG! This answer is currently not valid as it must take input in some manner (currently they are hard-coded in the environment). Additionally, you may find these tips for golfing in R helpful. Feel free to ping me here or in chat once you get enough reputation!

Just to be clear on what would be a valid submission: this would be. Welcome and enjoy your time here :)

I think s[p+1]-((m+s[p+1])-s[p]) simplifies to s[p]-m, and you have d=c(c(...)) where only d=c(...) is required. I strongly suspect there's a golfier way but this is still a nice answer.

@Giuseppe Thank you for the warm welcome, tips and great suggestion. I'm sure there is still room for improvement (for example d=NULL which could have been d=0, I hope it'll come with experience.

@P.A does d even need to be initialized?

@JayCe It didn't even need to be initialized, silly mistake. Thanks!

@P.A happy to help! I just re-opened an R golfing chatroom so feel free to get in touch with me and all the other R golfers for specific questions you might have :-)

Python 2, 60 bytes
Input is N, followed by all points as individual arguments. Subsequences in the output are seperated by 0.5.
f=lambda N,k,*l:(k,)+(l and(l[0]+N,.5,k-N)*(l[0]<k)+f(N,*l))

Try it online!

Python 2, 92 77 68 bytes
Subsequences are seperated by [...].
l,N=input();r=[];k=0
for a in l:r+=[a+N,r,k-N]*(a<k)+[a];k=a
print r

Try it online!

Nice anwser! I really like the use of the variable k for selectively appending items, learned something new here!

JavaScript (Node.js), 104 82 bytes
n=>a=>a.map((e,i)=>e>a[s.push(e),++i]&&s.push(a[r.push(s=[e-n]),i]+n),r=[s=[]])&&r

Try it online! Port of @ovs's Python answer.

Clean, 279 269 258 bytes
import StdEnv
s=snd o unzip
$[]=[]
$l#(a,b)=span(uncurry(<))(zip2[-1:l]l)
=[s a: $(s b)]
?l n#[h:t]= $l
=[h:if(t>[])(?(map((+)n)(flatten t))n)t]
@l n#l= ?l n
=[[e-i*n\\e<-k]\\k<-[a++b++c\\a<-[[]:map(\u=[last u])l]&b<-l&c<-tl(map(\u=[hd u])l)++[[]]]&i<-[0..]]

Try it online!

Haskell, 82 81 80 bytes
This is a port of my Clean answer.
r!n|let f x(r@(a:_):s)|x>a=[x,n+a]:(x-n:r):s|y<-x:r=y:s=foldr f[[last r]]$init r

Try it online!
-1, -1 thanks to Laikoni

@Laikoni it's a pity we cannot define f locally without parentheses around the : pattern, as in let x<r@(a:_):s|....

Clean, 92 bytes
import StdEnv
@r n=foldr(\x[r=:[a:_]:s]|x>a=[[x,n+a]:[x-n:r]:s]=[[x:r]:s])[[last r]](init r)

Try it online!
The operator argument to foldr is a lambda with guard; it is parsed as:
\x [r=:[a:_]:s]
    | x > a     = [[x,n+a]:[x-n:r]:s]
    | otherwise = [[x:run]:s]

I ported this to Haskell.

Clean, 110 109 104 100 97 bytes
import StdEnv
@[x:r]n=let$s=:[x:r]a|x<last a=[a++[n+x]: $s[last a-n]]= $r(a++[x]);$_ a=[a]in$r[x]

Try it online!
-1 byte thanks to Keelan

Haskell, 82 bytes
(x:r)#n|let b@(a:_)%s@(x:r)|x<a=(n+x:b):[a-n]%s|c<-x:b=c%r;a%_=[a]=reverse<$>[x]%r

Try it online! Port of my Clean answer.

Alternative, also 82 bytes
(x:r)#n|let a%s@(x:r)|x<last a=(a++[n+x]):[last a-n]%s|c<-a++[x]=c%r;a%_=[a]=[x]%r

Try it online!

JavaScript (Node.js), 98 bytes
a=>m=>(r=[],b=[],a.map((e,i)=>e<a[--i]?(b[p](m+e),r[p](b),b=[a[i]-m,e]):b[p='push'](e)),r[p](b),r)

Try it online! This is quite a bit longer than the other JS answer, but it uses a different approach.
Ungolfed and simplified explanation
g=(a,m)=>{
    // r is the final array of arrays to return.
    // b is the current subset of only ascending numbers.
    r=[],b=[];

    a.map((e,i)=>{
        if(e<a[i-1]){
            // if the current value is less than the previous one,
            // then we're descending, so start a new array b.
            // add the proper value to b to match slopes with the next
            b.push(m+e);
            // add r to b, and restart b with the starter value and the current value in a
            r.push(b);
            b=[a[i-1]-m,e];
        } else{
            // otherwise, we're ascending, so just addd to to b.
            b.push(e);
        }
    });
    r.push(b); // add the final b to r, and return r
    return r;
}

JavaScript (Node.js), 48 bytes, arrays separated by ,,
s=>n=>s.map(r=t=>(t<r?[t+n,,r-n,,]:``)+(r=t))+``

Try it online!
JavaScript (Node.js), 50 bytes, arrays separated by |
s=>n=>s.map(r=t=>(t<r?t+n+`|${r-n},`:``)+(r=t))+``

Try it online!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Where is that snake going?
Write a function (using as few bytes as possible) that takes a bi-dimensional array of any number of columns and rows in which:

0 represents empty block,
1 represents snake block.

The function must return the number of possible paths the snake traveled.
Example 1:
Input:
[
  [1,1,1,1,1],
  [0,0,0,0,1],
  [0,0,0,0,1],
]

Output: 2
In the example above, the function will return 2 because the answer is either one of:

Example 2:
Input:
[
  [1,1,1,1],
  [0,0,1,1],
  [0,0,1,1],
]

Output: 6
In this example the function will return 6 because the answer is either one of:

Note:
When assessing the input, you can assume that:

The arrays representing columns will always have the same sizes (so the arrays are rectangular);
There exists at least 1 valid path;
The snake cannot walk through the edges (as can happen in some versions of snake);
The snake will always have at least 2 blocks;
The snake cannot move diagonally;
The paths are directed. (so, two paths ending at different positions but otherwise looking exactly the same are not the same path, it’ll add up to the total)

Welcome to PPCG! Nice first challenge.

Minor note: "There will always be at least one row and one column" is redundant, given that the snake will always have at least 2 blocks.

What's the correct output for a 3-by-3 square of 1's? One solution return 28, one returns 40. The last one times out, so I'm not sure what that would give...

Can the input have no possible answer and require a 0?

Suggested test cases: the one given by @StewieGriffin and [[0,0,1,1],[0,0,1,1],[0,0,1,1]]. Most answers give 16, but one gives 15.

What's the expected output for this?

It seems like everybody so far (including me) has made the assumption that 2 paths ending at different positions but otherwise looking exactly the same are not the same path. I think this needs to be explicitly specified.

@Arnauld - that’s right. Two paths ending at different positions but otherwise looking exactly the same are not the same path, it’ll add up to the total. In your example the total should be 16 if I’m not mistaken - I can’t accuratelly calculate right now but you get the point

The last condition is equivalent to "paths are directed".

Is it possible that the result is 0? (for example: input [[0,1,0],[1,1,1],[0,1,0]])

@user202729 no, it’s not possible. You should always expect a valid snake.  Actually all those notes I’ve written was so that you don’t need to validate the input yourself

I edited the post to add that (because it's not deducible from the other facts) and also remove some redundant rules.

@user202729 ok thanks but just so you know, with the minimum 2 blocks snake we can already have 2 paths (minimum)

Are cycles counted multiple times? E.g. should [[1,1],[1,1]] return 2 or 8?

@MooseBoys yes, multiple times, as they are unique paths nonetheless. That would be an 8 indeed

Wolfram Language (Mathematica), 16+83=99 bytes
Library import statement (16 bytes):
<<Combinatorica`

Actual function body (83 bytes):
Length@HamiltonianCycle[MakeGraph[#~Position~1~Join~{1>0},##||Norm[#-#2]==1&],All]&

Try it online!

Note that the question just ask for the number of Hamiltonian path in the graph.
However, (for some reason) the HamiltonianPath function doesn't really work with directed graph (example). So, I used the workaround described in this Mathematica.SE question:

Add an vertex (called True) that is connected to all other vertices.
Count the number of Hamiltonian cycle on the resulting graph.

The graph is constructed using MakeGraph (annoyingly there are no directly equivalent built-in), using the boolean function ##||Norm[#-#2]==1&, which returns True if and only if one of the arguments is True or the distance between the two vertices are 1.

Tr[1^x] cannot be used instead of Length@x, and <2 cannot be used instead of ==1.

HamiltonianPath can be used if the graph is undirected, with the function body takes 84 bytes (exactly 1 byte more than the current submission):
Length@HamiltonianPath[MakeGraph[#~Position~1,Norm[#-#2]==1&,Type->Undirected],All]&

Try it online!

Jelly, 12 11 bytes
ŒṪŒ!ạƝ€§ÐṂL

Try it online!

Explanation.
ŒṪ               Positions of snake blocks.
  Œ!             All permutations.
                 For each permutation:
    ạƝ€             Calculate the absolute difference for each neighbor pair
       §            Vectorized sum.
                 Now we have a list of Manhattan distance between snake
                    blocks. Each one is at least 1.
        ÐṂL      Count the number of minimum values.
                    Because it's guaranteed that there exists a valid snake,
                    the minimum value is [1,1,1,...,1].

New features prove to be extremely useful.

How about §ỊML instead of §ỊP€S to save a byte - I think it should work?

...or §ÐṂL which is a little faster.

@JonathanAllan Only works if the result is nonzero.

@JonathanAllan So it ends up actually works.

JavaScript (ES6), 154 134 bytes
m=>m.map((r,Y)=>r.map(g=(_,x,y,r=m[y=1/y?y:Y])=>r&&r[x]&&[-1,0,1,2].map(d=>r[r[x]=0,/1/.test(m)?g(_,x+d%2,y+~-d%2):++n,x]=1)),n=0)|n/4

Try it online!
How?
Method
Starting from each possible cell, we flood-fill the matrix, clearing all cells on our way. Whenever the matrix contains no more 1's, we increment the number n of possible paths.
Each valid path is counted 4 times because of the direction chosen on the last cell, which actually doesn't matter. Therefore, the final result is n / 4.
Recursive function
Instead of calling the recursive function g() from the callback of the second map() like this...
m=>m.map((r,y)=>r.map((_,x)=>(g=(x,y,r=m[y])=>...g(x+dx,y+dy)...)(x,y)))

...we define the recursive function g() directly as the callback of map():
m=>m.map((r,Y)=>r.map(g=(_,x,y,r=m[y=1/y?y:Y])=>...g(_,x+dx,y+dy)...))

Despite the rather long formula y=1/y?y:Y which is needed to set the initial value of y, this saves 2 bytes overall.
Commented code
m =>                           // given the input matrix m[][]
  m.map((r, Y) =>              // for each row r[] at position Y in m[][]:
    r.map(g = (                //   for each entry in r[], use g() taking:
      _,                       //     - the value of the cell (ignored)
      x,                       //     - the x coord. of this cell
      y,                       //     - either the y coord. or an array (1st iteration),
                               //       in which case we'll set y to Y instead
      r = m[y = 1 / y ? y : Y] //     - r = the row we're currently located in
    ) =>                       //       (and update y if necessary)
      r && r[x] &&             //     do nothing if this cell doesn't exist or is 0
      [-1, 0, 1, 2].map(d =>   //     otherwise, for each direction d,
        r[                     //     with -1 = West, 0 = North, 1 = East, 2 = South:
          r[x] = 0,            //       clear the current cell
          /1/.test(m) ?        //       if the matrix still contains at least one '1':
            g(                 //         do a recursive call to g() with:
              _,               //           a dummy first parameter (ignored)
              x + d % 2,       //           the new value of x
              y + ~-d % 2      //           the new value of y
            )                  //         end of recursive call
          :                    //       else (we've found a valid path):
            ++n,               //         increment n
          x                    //       \_ either way,
        ] = 1                  //       /  do r[x] = 1 to restore the current cell to 1
      )                        //     end of map() over directions
    ),                         //   end of map() over the cells of the current row
    n = 0                      //   start with n = 0
  ) | n / 4                    // end of map() over the rows; return n / 4

Python 2, 257 246 241 234 233 227 214 210 bytes
lambda b:sum(g(b,i,j)for j,l in e(b)for i,_ in e(l))
e=enumerate
def g(b,x,y):d=len(b[0])>x>-1<y<len(b);c=eval(`b`);c[d*y][d*x]=0;return d and b[y][x]and('1'not in`c`or sum(g(c,x+a,y)+g(c,x,y+a)for a in(1,-1)))

Try it online!

Saved

-8 bytes, thanks to Kevin Cruijssen
-14 bytes, thanks to user202729

249 bytes by removing w and h

The right language for the job?

Python 2, 158 bytes
E=enumerate
g=lambda P,x,y:sum(g(P-{o},*o)for o in P if x<0 or abs(x-o[0])+abs(y-o[1])<2)+0**len(P)
lambda L:g({(x,y)for y,r in E(L)for x,e in E(r)if e},-1,0)

Try it online!

Haskell, 187 155 bytes
r=filter
l=length
(a,b)?(x,y)=abs(a-x)+abs(b-y)==1
l#x=sum[p!r(/=p)l|p<-x]
p![]=1
p!l=l#r(p?)l
f x|l<-[(i,j)|i<-[0..l x-1],j<-[0..l(x!!0)-1],x!!i!!j>0]=l#l

Try it online!

APL (Dyalog Extended), 28 bytes
+/×/1=2(1⊥∘|-)/x[⌂pmat≢x←⍸⎕]

Try it online!
A full program that accepts a matrix.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Random numbers with fixed sum
Your task is to write a program or a function that outputs n random numbers from interval [0,1] with fixed sum s.
Input
n, n≥1, number of random numbers to generate
s, s>=0, s<=n, sum of numbers to be generated
Output
A random n-tuple of floating point numbers with all elements from the interval [0,1] and sum of all elements equal to s, output in any convenient unambiguous way. All valid n-tuples have to be equally likely within the limitations of floating point numbers.
This is equal to uniformly sampling from the intersection of the points inside the n-dimensional unit cube and the n-1-dimensional hyperplane that goes through (s/n, s/n, …, s/n) and is perpendicular to the vector (1, 1, …, 1) (see red area in Figure 1 for three examples).

Figure 1: The plane of valid outputs with n=3 and sums 0.75, 1.75 and 2.75
Examples
n=1, s=0.8 → [0.8]
n=3, s=3.0 → [1.0, 1.0, 1.0]
n=2, s=0.0 → [0.0, 0.0]
n=4, s=2.0 → [0.2509075946818119, 0.14887693388076845, 0.9449661625992032, 0.6552493088382167]
n=10, s=9.999999999999 → [0.9999999999999,0.9999999999999,0.9999999999999,0.9999999999999,0.9999999999999,0.9999999999999,0.9999999999999,0.9999999999999,0.9999999999999,0.9999999999999]

Rules

Your program should finish under a second on your machine at least with n≤10 and any valid s.
If you so wish, your program can be exclusive on the upper end, i.e. s<n and the output numbers from the half-open interval [0,1) (breaking the second example)
If your language doesn't support floating point numbers, you can fake the output with at least ten decimal digits after the decimal point.
Standard loopholes are disallowed and standard input/output methods are allowed.
This is code-golf, so the shortest entry, measured in bytes, wins.

Related.

When you say This is equal to uniformly sampling from the intersection - i can see a program choosing randomly from just the corners of that intersection. Would that be valid ?

Because not all languages have floating point support, (at least) how many digit of accuracy/precision must be supported? (the suggested test case above implies 13, but you may want a softer restriction)

@KevinCruijssen No, that's only true for s==0 or s==3. For all other values of s, the plane has nonzero area and you have to uniform-randomly choose a point on that plane.

@JayCe that would be invalid, since all valid n-tuples have to be equally likely.

One way to do this is to use this approach mirrored at the centre and then using rejection sampling

"Integer"? But the question ask for floating point output.

All valid n-tuples have to be equally likely within the limitations of floating point numbers. do you mean same probably for same size? (usually such definition, but not always)

@l4m2 when the parameters n and s are fixed, the valid outputs should be about equally likely. The order matters, so for instance (0.2, 0.3, 0.1) and (0.3, 0.2, 0.1) both should be as common as (0.6, 0.0, 0.0) for n=3, s=0.6

@Angs so any distribution is allowed as the possibility are all zero?

@l4m2, no, equally likely == uniform distribution, of course with the understanding that there isn't a total uniformness with floating point errors and the like.

@Angs or should same size area near zero have higher possibility as float precision is higher near zero?

Requiring the interval to be closed or half-closed (as opposed to open) is a theoretically unobservable requirement. Many random number generators give the output in (0,1). How to test that the output interval is [ 0,1) and not (0,1)? The value 0 "never" occurs anyway

Is it OK if our code uses rejection sampling, and so takes very long  for test cases likes=2.99999999999, n=3? May we generate random reals in multiples of, say, 1e-9?

@xnor Only if you have a supercomputer ("1 second"). | OP said 10 digits.

@xnor none of the test cases may take longer than a second on your machine, so at least the most naive rejection sampling is out of the question. The implementation details don't matter if the output is correct. And like user202729 mentioned, 10 digits of precision is needed so multiples of 1e-10 or smaller work.

@LuisMendo the same applies to any number really, not just for 0. For instance, Java.Random has a 48-bit seed, so it can't produce all double-precision floating-point numbers ∈[0,1] since they have 52 bits of precision. Some common sense is required since it's hard to make a rule that would cover all cases. Maybe rounded to 10 digits after the comma, all cases should be equally common with an error margin of 1%.

Wolfram Language (Mathematica), 92 90 bytes
If[2#2>#,1-#0[#,#-#2],While[Max[v=Differences@Sort@Join[{0,#2},RandomReal[#2,#-1]]]>1];v]&

Try it online!
Un-golfed code:
R[n_, s_] := Module[{v},
  If[s <= n/2,             (* rejection sampling for s <= n/2:                        *)
    While[
      v = Differences[Sort[
            Join[{0},RandomReal[s,n-1],{s}]]];         (* trial randoms that sum to s *)
      Max[v] > 1           (* loop until good solution found                          *)
    ];
    v,                     (* return the good solution                                *)
    1 - R[n, n - s]]]      (* for s > n/2, invert the cube and rejection-sample       *)

Here is a solution that works in 55 bytes but for now (Mathematica version 12) is restricted to n=1,2,3 because RandomPoint refuses to draw points from higher-dimensional hyperplanes (in TIO's version 11.3 it also fails for n=1). It may work for higher n in the future though:
RandomPoint[1&~Array~#~Hyperplane~#2,1,{0,1}&~Array~#]&

Try it online!
Un-golfed code:
R[n_, s_] :=
  RandomPoint[                           (* draw a random point from *)
    Hyperplane[ConstantArray[1, n], s],  (* the hyperplane where the sum of coordinates is s *)
    1,                                   (* draw only one point *)
    ConstantArray[{0, 1}, n]]            (* restrict each coordinate to [0,1] *)

JavaScript (Node.js), 122 115 bytes
N=>W=S=>2*S>N?W(N-S).map(t=>1-t):(t=(Q=s=>n?[r=s-s*Math.random()**(1/--n),...r>1?[++Q]:Q(s-r)]:[])(S,n=N),Q?t:W(S))

Try it online!

Python 2, 144 128 119 bytes
from random import*
def f(n,s):
 r=min(s,1);x=uniform(max(0,r-(r-s/n)*2),r);return n<2and[s]or sample([x]+f(n-1,s-x),n)

Try it online!

-20 bytes, thanks to Kevin Cruijssen

@LuisMendo Should be fixed now

they still seem not uniform

@l4m2 I ran g(4, 2.0) 1,000 times to get 4,000 points and the results look like this which appears fairly uniform.

122 bytes?

@EngineerToast I ran g(3,1.0) and find the first coord strongly near 1

and their averages are 0.5, 0.25, 0.25

Yeah, chaining uniform for each coordinate will never be uniform in later dimensions

@l4m2 Good catch. I got 9,000 data points and it is definitely skewed.

You don't need the variable l: r=min(s,1);x=uniform(max(0,r-(r-((s-s/n)/~-n))*2),r); (-4 bytes).

And ((s-s/n)/~-n) can be s/n for another -10 bytes. Try it online: 114 bytes.

One more thing, you can combine both return-statements: Try it online: 108 bytes.

Still wrong

I fell you are shuffling your old answer?

Java 8, 194 188 196 237 236 bytes
n->s->{double r[]=new double[n+1],d[]=new double[n],t;int f=0,i=n,x=2*s>n?1:0;for(r[n]=s=x>0?n-s:s;f<1;){for(f=1;i-->1;)r[i]=Math.random()*s;for(java.util.Arrays.sort(r);i<n;d[i++]=x>0?1-t:t)f=(t=Math.abs(r[i]-r[i+1]))>1?0:f;}return d;}

+49 bytes (188 → 196 and 196 → 237) to fix the speed of test cases nearing 1, as well as fix the algorithm in general.
Try it online
Explanation:
Uses the approach in this StackoverFlow answer, inside a loop as long as one of the items is still larger than 1.
Also, if 2*s>n, s will be changed into n-s, and a flag is set to indicate we should use 1-diff instead of diff in the result-array (thanks for the tip @soktinpk and @l4m2).
n->s->{              // Method with integer & double parameters and Object return-type
  double r[]=new double[n+1]
                     //  Double-array of random values of size `n+1`
         d[]=new double[n],
                     //  Resulting double-array of size `n`
         t;          //  Temp double
  int f=0,           //  Integer-flag (every item below 1), starting at 0
      i=n,           //  Index-integer, starting at `n`
      x=             //  Integer-flag (average below 0.5), starting at:
        2*s>n?       //   If two times `s` is larger than `n`:
         1           //    Set this flag to 1
        :            //   Else:
         0;          //    Set this flag to 0
  for(r[n]=s=        //  Set both the last item of `r` and `s` to:
       x>0?          //   If the flag `x` is 1:
        n-s          //    Set both to `n-s`
       :             //   Else:
        s;           //    Set both to `s`
      f<1;){         //  Loop as long as flag `f` is still 0
    for(f=1;         //   Reset the flag `f` to 1
        i-->1;)      //   Inner loop `i` in range (n,1] (skipping the first item)
      r[i]=Math.random()*s;
                     //    Set the i'th item in `r` to a random value in the range [0,s)
    for(java.util.Arrays.sort(r);
                     //   Sort the array `r` from lowest to highest
        i<n;         //   Inner loop `i` in the range [1,n)
        ;d[i++]=     //     After every iteration: Set the i'th item in `d` to:
          x>0?       //      If the flag `x` is 1:
           1-t       //       Set it to `1-t`
          :          //      Else:
           t)        //       Set it to `t`
      f=(t=Math.abs( //    Set `t` to the absolute difference of:
            r[i]-r[i+1]))
                     //     The i'th & (i+1)'th items in `r`
        >1?          //    And if `t` is larger than 1 (out of the [0,1] boundary)
         0           //     Set the flag `f` to 0
        :            //    Else:
         f;}         //     Leave the flag `f` unchanged
  return d;}         //  Return the array `d` as result

Time out for test(10, 9.99);

@l4m2 Yeah, noticed the same with 10, 9.0 right after I edited to fix the n=10, s=9.999999999999 test case.. Not sure if there is a fix in Java while still holding its uniformly randomness.. Will have to think about it for a while. For now I'll edit it to state it times out.

If n-s<1 you can call f(n,n-s) and flip every number over 1/2 (i.e. replace x with 1-x) like l4m2 did. This might solve the issue for numbers where s is close to n.

@soktinpk Thanks for the tip. It's actually s+s>n instead of n-s<1, but when I looked at the other JavaScript answers it indeed made sense. Everything is fixed now, including another bug that was still present. Bytes went up quite a bit, but every works now. Will work the byte-count down from here. :)

I don't know of a general proof but I believe this algorithm works because an N-dimensional hypercube can be cut into N N-dimensional hyperpyramids.

JavaScript (Node.js), 153 bytes
(n,s)=>s+s>n?g(n,n-s).map(r=>1-r):g(n,s)
g=(n,s)=>{do(a=[...Array(n-1)].map(_=>Math.random()*(s<1?s:1))).map(r=>t-=r,t=s);while(t<0|t>=1);return[...a,t]}

Try it online!

C++11, 284 267 bytes
-17 bytes thanks to Zacharý
Uses C++ random library, output on the standard output
#include<iostream>
#include<random>
typedef float z;template<int N>void g(z s){z a[N],d=s/N;int i=N;for(;i;)a[--i]=d;std::uniform_real_distribution<z>u(.0,d<.5?d:1-d);std::default_random_engine e;for(;i<N;){z c=u(e);a[i]+=c;a[++i]-=c;}for(;i;)std::cout<<a[--i]<<' ';}

To call, you just need to do that :
g<2>(0.0);

Where the template parameter ( here, 2 ) is N, and the actual parameter ( here, 0.0 ) is S

I think you can remove the space between <z> and u

I got it down further: typedef float z;template<int N>void g(z s){z a[N],d=s/N;int i=N;for(;i;)a[--i]=d;std::uniform_real_distribution<z>u(.0,d<.5?d:1-d);std::default_random_engine e;for(;i<N;){z c=u(e);a[i]+=c;a[++i]-=c;}for(;i;)std::cout<<a[--i]<<' ';}. A newline doesn't have to be the separator between items

Suggest get rid of d completely by changing d=s/N to s/=N
Suggest reworking the second loop for(z c;i<N;a[++i%N]-=c)a[i]+=c=u(e); instead of for(;i<N;){z c=u(e);a[i]+=c;a[++i]-=c;} (note the added %N in order to make the program calculate the first number correctly)

C, 132 127 125 118 110 107 bytes
-2 bytes thanks to @ceilingcat
i;f(s,n,o,d)float*o,s,d;{for(i=n;i;o[--i]=d=s/n);for(;i<n;o[++i%n]-=s)o[i]+=s=(d<.5?d:1-d)*rand()/(1<<31);}

Try it online!

Unfortunately, this answer does not meet the challenge specification.  The output random numbers are not restricted to [0,1], and their joint distribution is not uniform.

@Nitrodon hey, could you please provide an input for which the output is not restricted to [0,1]? I tried a couple different examples and they all seemed to be correct, unless I misunderstood the objective.

With the RNG state on TIO, and keeping your n=4, the values s=3.23 and s=0.89 gives outputs outside of the range.  More to the point, the distribution of X-s/n should depend on s, but it doesn't.

@Nitrodon Oops, my bad. I was converting some parts from the C++ answer above and forgot to add a thing. It should be fixed now? Also golfed a few bytes in the process.

Clean, 221 201 bytes
Clean, code-golf, or random numbers. Pick two.
import StdEnv,Math.Random,System._Unsafe,System.Time
g l n s#k=toReal n
|s/k>0.5=[s/k-e\\e<-g l n(k-s)]
#r=take n l
#r=[e*s/sum r\\e<-r]
|all((>)1.0)r=r=g(tl l)n s

g(genRandReal(toInt(accUnsafe time)))

Try it online!
Partial function literal :: (Int Real -> [Real]). Will only produce new results once per second.
Accurate up to at least 10 decimal places.

R, 99 bytes (with gtools package)
f=function(n,s){if(s>n/2)return(1-f(n,n-s))
while(any(T>=1)){T=gtools::rdirichlet(1,rep(1,n))*s}
T}

Try it online!
We wish to sample uniformly from the set \$\tilde{\mathcal A}=\{w_1,\ldots,w_n: \forall i, 0<w_i<1; \sum w_i=s\}\$. I'll divide all the \$w_i\$ by \$s\$ and instead sample from \$\mathcal A=\{w_1,\ldots,w_n: \forall i, 0<w_i<\frac1s; \sum w_i=1\}\$.
If \$s=1\$, this is easy: it corresponds to sampling from the \$Dirichlet(1, 1, \ldots, 1)\$ distribution (which is the uniform over the simplex). For the general case \$s\neq 1\$, we use rejection sampling: sample from the Dirichlet distribution until all entries are \$<1/s\$, then multiply by \$s\$.
The trick to mirror when \$s>n/2\$ (which I think l4m2 was the first to figure out) is essential. Before I saw that, the number of iterations in the rejection sampler exploded for the last test case, so I spent a lot of time trying to sample efficiently from well-chosen truncated Beta distributions, but it is not necessary in the end.

Haskell, 122 217 208 bytes
import System.Random
r p=randomR p
(n#s)g|n<1=[]|(x,q)<-r(max 0$s-n+1,min 1 s)g=x:((n-1)#(s-x)$q)
g![]=[]
g!a|(i,q)<-r(0,length a-1)g=a!!i:q![x|(j,x)<-zip[0..]a,i/=j]
n%s=uncurry(!).(n#s<$>).split<$>newStdGen

Try it online!
Sometimes the answers are slightly off due, I assume, to floating point error. If it's an issue I can fix it at a cost of 1 byte. I'm also not sure how uniform this is (pretty sure it's fine but I'm not all that good at this kind of thing), so I'll describe my algorithm.
Basic idea is to generate a number x then subtract it from s and recur until we have n elements then shuffle them. I generate x with an upper bound of either 1 or s (whichever is smaller) and a lower bound of s-n+1 or 0 (whichever is greater). That lower bound is there so that on the next iteration s will still be less than or equal to n (derivation: s-x<=n-1 -> s<=n-1+x -> s-(n-1)<=x -> s-n+1<=x).
EDIT: Thanks to @michi7x7 for pointing out a flaw in my uniformity. I think I've fixed it with shuffling but let me know if there's another problem
EDIT2: Improved byte count plus fixed type restriction

Chaining uniform samples will never lead to a uniform distribution (the last coordinate is almost always bigger than 0.99 in your example)

@michi7x7 I see your point. What if I shuffled the order of the list after generating it? I should've taken more stats classes

The numbers doesn't look very uniform. Here, 8 results are >0.99, 1 is 0.96, and the last is 0.8. This is what it looks like.

@user1472751 there are several good answers here: https://stackoverflow.com/q/8064629/6774250

Uniformness still has some problem, see here - there are too many zeroes generated (plot of sorted values from 1000%500)

Haskell, 188 bytes
import System.Random
import Data.List
n!s|s>n/2=map(1-)<$>n!(n-s)|1>0=(zipWith(-)=<<tail).sort.map(*s).(++[0,1::Double])<$>mapM(\a->randomIO)[2..n]>>= \a->if all(<=1)a then pure a else n!s

Ungolfed:
n!s
 |s>n/2       = map (1-) <$> n!(n-s)       --If total more than half the # of numbers, mirror calculation
 |otherwise   = (zipWith(-)=<<tail)        --Calculate interval lengths between consecutive numbers
              . sort                       --Sort
              . map(*s)                    --Scale
              . (++[0,1::Double])          --Add endpoints
              <$> mapM(\a->randomIO)[2..n] --Calculate n-1 random numbers
              >>= \a->if all(<=1)a then pure a else n!s   --Retry if a number was too large

Try it online!


text:
Not just a four fours puzzle
In this variant of the Four fours puzzle your should use up to x x's (and no other number) and a defined set of operations to reach every number from 0 to 100. If x = 4 then you can use up to four 4s and this question becomes the classic four fours puzzle (except you can use up to four 4s rather than having to use exactly four of them).  We assume 1 < x <= 9.
In this version, only the following operators are allowed:

Addition (+), Subtraction (-), Multiplication (*), Division (/). Note this is real division, so that 5/2 = 2.5.
Exponentiation (e.g. 4^4) as this would involve no extra symbols if written normally by hand.
You can make new integers by concatenating xs. E.g. you can make the integers 4, 44, 444, 4444.

You may also use parentheses  to group numbers simply in order to control the order of evaluation of the operators.  You can't for example combine parentheses with concatenation as in (4/4)(4/4) = (1)(1) = 11.
No other symbols may be used and standard order of operations applies.
Your program should generate, given an x in the defined range and an n between 0 and 100 inclusive, a correct solution for that input if it exists. Otherwise your code must output something to indicate no such solution exists.
You must be able to run your submission to completion on your machine for any input values of x and n in the allowed range. This is code golf, so shortest solution wins.
This old related question uses more operators (and only 4s) and hence all numbers from 0 to 100 are solvable which won't be true for this challenge.
Input and output
Your code takes two integers x and n as input and should output a solution (or an indication there is no solution) in any human readable format you find convenient.  Input 4 6 would mean "Using up to four 4s, make the number 6" for example. So if the input is 4 6 the output could be (4+4)/4+4.

Parentheses allowed: yes or no?

@DigitalTrauma Thank you I should have said. Yes.

Helpful Reference

Can parens be combined with concatenation?  e.g. `(4/4)(4/4) = (1)(1) = 11 ?

@DigitalTrauma Oh wow. No! I will clarify.

Adding parentheses (and disallowing parentheses + concatenation) does make this significantly harder

Can we use the negation operator? (-4)

@mbomb007 Yes you can.

I guess a more important question is this: is it be necessary to use the negation operator to reach a result for a possible input?

@mbomb007 No .

Adding the exponentiation operator and an outer loop over the number of times the digit is used don't IMO add anything non-trivial over https://codegolf.stackexchange.com/q/82884/194

Personally, I think it'd be better to output every possible integer in the range, or given an integer output a Boolean whether it's possible to arrive at. Outputting an expression has been done before.

@PeterTaylor Do you think the use of parentheses and the requirement that it terminates in reasonable time for all input values makes a difference?  Certainly no one has offered a 23 byte solution to this question.

I don't think the parentheses make much of a difference, and the time limit is really quite lax (there aren't so many distinct expressions when all the values are the same). OTOH I'm not the only person who can cast a reopen vote: you're welcome to make your case in the chat room and get some third, fourth, etc. opinions.

@PeterTaylor I just tried the ones I could test from the linked question with [4,4,4,4] 4. It seems they give no solution. That is they can neither find 4 (because they have to use all the numbers) nor (4*(4-4)+4) (because they can't use parentheses).

See "outer loop" in my first comment.

@PeterTaylor The parentheses seem to make quite a lot of difference. I would vote to reopen if I could.

Python 3, 265 bytes
def f(x,n):
 for e in g(x,x-(x>7)):
  try:
   if eval(e)==n:return e
  except:1
g=lambda x,d:{str(x)*-~i for i in range(d)}|{s%(a,b)for a in g(x,d-1)for b in g(x,d-a.count(str(x)))for s in'%s**%s (%s/%s) (%s+%s) (%s-%s) %s*%s %s/%s'.split()['**'in a+b:]}if d else{}

Try it online!
Works for all numbers in the reference linked by Engineer Toast.
Runs up to x=8 on tio, x=9 takes a couple of minutes on my machine.

The function g returns a set of all combinations with at most x number of x's. f then loops through them and returns the first which evaluates to the number n.
The number of possible values i found for each x are:
x  possible numbers
------
2  5
3  17
4  35
5  56
6  83
7  101
8  101
9  101

All the numbers above can be generated from (a+b), (a-b), (a+b), a*b, a/b, (a/b), and a^b.
a+b and a-b do not give more numbers.
a^b is also only used once, as otherwise huge numbers are created (this is also verified in the reference document above)

An alternate version which short-circuits as soon as it finds a solution (not as golfed):
This is much faster as for x=7..9 all numbers can be created.
Python 3, 338 289 bytes
def f(x,n,d=-1):
 d=[d,x][d<0];X=str(x);r=set()
 for E in{X*-~i for i in range(d)}|{s%(a,b)for a in[0]*d and f(x,n,d-1)for b in f(x,n,d-a.count(X))for s in'%s**%s (%s/%s) (%s+%s) (%s-%s) %s*%s %s/%s'.split()['**'in a+b:]}:
  try:e=eval(E)
  except:e=-1
  if e==n:exit(E)
  r|={E}
 return r

Try it online!

This is a very nice answer! I thought you were always using exactly (as opposed to up to) x xs (e.g. (4/4**(4-4)) for 4) but it turns out that isn't the case.

exit(e) is shorter than return e


text:
Make Three from One
Given a single digit integer and a three digit integer, output a mathematical formula that uses only the single digit and a given list of operators to equal the three digit integer.
Input: A one digit positive integer (1-9) and a three digit integer (100-999)
Output: A mathematical formula meeting the following requirements:

The only number used is the one digit integer
There no more than 15 instances of that integer (Prevents trivial solutions of the format (a+a+...+a+a)/a=n)
The mathematical solution of the formula is the three digit integer
The only operations allowed are as follows:

Addition: 1+1
Subtraction: 2-2
Multiplication: 3×3, 3*3, (3)3
Division: 4÷4, 4/4
Exponentiation: 5⁵, 5^5, 5**5
Concatenation: 66, 6||6
Brackets: (7+7)

Clarifications:

Input and Output can be in any standard format.
The symbols for each operation do not need to be what is shown above; they can be whatever makes sense for your language.
Explain any input or output formats that you think may not be immediately understood.
Standard loopholes are forbidden.
If your output doesn't follow the standard order of operations, it shouldn't matter but do make a note. It would help to include brackets as needed to make the order clear.
You can not concatenate calculated values: (8+8)8 is 128, not 168. However, 88+88−8=168 is valid.
You may assume the input will always be valid.
You may assume a valid output will always be possible.
It does not have to be the shortest possible formula so long as it's valid and uses <16 instances of the single digit

Examples:

Input         Output
[1,123]       11^(1+1)+1+1
999,2         (2+2/2)2×222/2
3 729         3^(3+3)
['4','300']   ['|','+','**']   where there is a 4 before and after each element and | is concatenate. (4|4+4**4 = 44+4**4 = 44+256 = 300)
255 5         ((5×(5×(5+5)))+5)
6 333         6*666/(6+6)
7,952         7×(7+((7+7)/7)7)+7
8|517         8 × 8 × 8 + 8 − ( 8 + 8 + 8 ) / 8
999 9         999

Scoring
This is code-golf so the shortest code wins.

Related, related

@BradC Since it's tagged [tag:code-golf] and not [tag:metagolf], I'd assume it's the former.

@fəˈnɛtɪk Hmm, you're right. The first sentence seems to be at odds with the rest of the challenge though (the second output rule seems to imply that people would be looking for trivial formulas, rather than short ones)

@fəˈnɛtɪk I think I must have changed my mind halfway through writing it and it wasn't picked up in the sandbox. Is it better now?

Edit looks good, voted to reopen. No idea how I would do this in T-SQL, though :(

Adding the exponentiation operator and an outer loop over the number of times the digit is used don't IMO add anything non-trivial over https://codegolf.stackexchange.com/q/82884/194

@PeterTaylor I suppose this is a specialized case of the other. You could just run one of those solutions for 15 different arrays with each value being the input and output the first one that has an output. I didn't find that question in my search but don't disagree with the closure.


text:
Find the Fibonacci Patterns
You are probably familiar with the Fibonacci sequence where the first two terms are 0, 1 (or sometimes 1, 1) and every term after that is the sum of the previous two. It starts like this:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Sometimes, the sequence contains numbers that have a particular pattern that I find interesting: the difference between any pair of adjacent digits is the same as any other pair. For instance, in the sequence starting with 0, 1, the 18th term is 987. 9-8=1 and 8-7=1. I am mildly satisfied.
Challenge
Given two initial values F(0) and F(1), output every number in the sequence generated by F(n) = F(n-1) + F(n-2) that meets the following criteria:

The difference between any pair of adjacent digits is the same as any other pair
It is as least three digits long (1 and 2 digit numbers are not interesting for this pattern)

Input

Two non-negative integers less than 10**10 (10 billion)

Output

All integers that are less than 10**10 and meet the criteria in the Challenge section
It is acceptable to output digits greater than 10**10 but it is not a requirement
Given that repeated digits meet the pattern (e.g. 777), it is possible that there are infinite numbers that meet the criteria but your program is not required to output forever
If no such integers exist, output whatever you want so long as it's not a number (nothing, null, empty array, error message, sad face, etc.)
If a number matching the pattern appears more than once in the sequence, you can output it once or as many times as it occurs
If any input meets the criteria, it should be included in the output

Rules

Input and Output can be in any standard format
Standard loopholes are forbidden
This is code-golf so the shortest code in bytes wins

Examples / Test Cases
Input , Output
[1,10] , []

[0,1] , [987]
[2,1] , [123]
[2,3] , [987]

[61,86] , [147]
[75,90] , [420]
[34,74] , [1234]
[59,81] , [2468]
[84,85] , [7531]

[19,46] , [111]
[60,81] , [222]
[41,42] , [333]
[13,81] , [444]
[31,50] , [555]
[15,42] , [666]
[94,99] , [777]
[72,66] , [888]
[3189,826] , [888888888]

[15,3] , [159,258]
[22,51] , [321,1357]
[74,85] , [159,4444]
[27,31] , [147,11111]

[123,0] , [123,123,123,246,369]
[111,0] , [111,111,111,222,333,555,888]
[111,222] , [111,222,333,555,888]

[33345,692] , [987654321]
[3894621507,5981921703] , [9876543210]
[765432099,111111111] , [111111111,876543210,987654321]

[1976,123] , [123, 2222, 4321, 6543, 45678]

Suggested test cases: [1976, 123] -> [123, 2222, 4321, 6543, 45678], [3189, 826] -> [888888888], [33345, 692] -> [987654321]

@Arnauld Great find! I wonder which starting pair has the most output values less than 10B. Anything above that will be repdigits and that's boring.

@Arnauld Thanks for the test case corrections. In my original generator, I didn't include the inputs. I clearly missed those two when I went back and added them.

MATL, 14 bytes
Thanks to Emigna for pointing out a mistake, now corrected
`yVdd~?yD]wy+T

Infinite loop that outputs the numbers as they are found.
Try it online! Note that in the online interpreter the results are displayed after the 1-minute time-out.
Explanation
Let F(n) and F(n+1) denote two generic consecutive terms of the Fibonacci sequence. Each iteration of the loop starts with the stack containing F(n), F(n+1) for some n.
`         % Do...while
  y       %   Duplicate from below. Takes the two inputs F(0), F(1) (implicitly)
          %   in the first iteration
          %   STACK: F(n), F(n+1), F(n)
  V       %   Convert to string. Let the digits of F(n) be '3579' for example
          %   STACK: F(n), F(n+1), '3579'
  d       %   Consecutive differences (of ASCII codes)
          %   STACK: F(n), F(n+1), [2 2 2]
  d       %   Consecutive differences
          %   STACK: F(n), F(n+1),  [0 0]
  ~       %   Logical negate, element-wise
          %   STACK: F(n), F(n+1), [1 1]
  ?       %   If top of the stack is non-empty and only contains non-zero entries
          %   (this is the case for digits '3579', but not for '3578' or '33')
          %   STACK: F(n), F(n+1)
    y     %     Duplicate from below
          %     STACK: F(n), F(n+1), F(n)
    D     %     Display immediately. This prints the copy of F(n)
          %     STACK: F(n), F(n+1)
  ]       %   End
  w       %   Swap
          %   STACK: F(n+1), F(n)
  y       %   Duplicate from below
          %   STACK: F(n+1), F(n), F(n+1)
  +       %   Add. Note that F(n)+F(n+1) is F(n+2)
          %   STACK: F(n+1), F(n+2)
  T       %   Push true. This will be used as loop condition
          %   STACK: F(n+1), F(n+2), true
          % End (implicit). The top of the stack is consumed as loop condition.
          % Since it is true, a new iteration will begin, with the stack
          % containing F(n+1), F(n+2)

05AB1E, 17 16 15 bytes
тFÂ2£O¸«}ʒS¥¥_W

Try it online!
Explanation
                  # implicitly input list of F(0) and F(1)
тF      }         # 100 times do:
  Â               # bifurcate current list
   2£             # take the first 2 items
     O            # sum
      ¸«          # append to list
         ʒ        # filter, keep only elements that are true after:
          S¥¥     # delta's of delta's of digits
             _    # logically negate each
              W   # min

JavaScript (ES6), 85 84 81 bytes
f=(p,q,a=[])=>p|q?f(q,p+q,![...p+''].some(x=d=n=>r=d-(d=x-(x=n)))/r?[...a,p]:a):a

Try it online!
Testing adjacent digits
![...p + ''].some(x = d = n => r = d - (d = x - (x = n))) / r

Both x and d are initialized to an anonymous function, which forces NaN for all arithmetic operations they're involved in. The first iteration of some() always gives (d = [function] - n) === NaN and (r = [function] - d) === NaN (falsy). On the second iteration, we have d = x - n (an integer) and (r = NaN - d) === NaN (falsy again). Starting from the third iteration, r is set to an integer which is non-zero if the difference between digit #3 and digit #2 is not equal to the difference between digit #2 and digit #1.
The number p is meeting the required criteria if and only if some() is falsy (all adjacent digits have the same difference) and the final value of r is 0 (there were at least 3 iterations). This gives !false / 0 === true / 0 === Infinity (truthy).
We may otherwise have:

!true / r with r > 0 or r < 0, which gives false / r === 0 (falsy)
!false / NaN, which gives true / NaN === NaN (falsy)

Halting condition
The recursion stops when p | q evaluates to 0. This is guaranteed to happen when both p and q reach values around 1025 which are 84-bit long. Because JS has 52 bits of mantissa, the last 32 bits are zeroed. So, the 32-bit bitwise OR evaluates to 0.
Due to the fast growing rate of the sequence, this happens rather quickly.

Octave, 91 90 83 bytes
Saved 7 bytes thanks to Luis Mendo!

@(t)eval"for i=3:99,if~diff(diff(+num2str(t(1))))disp(t(1))end,t=[t(2) sum(t)];end"

Try it online!
Well, it works!
eval with for loop inside to save a few bytes. Skipping colons and semicolons to save a few. Uses the fact that a vector is considered truthy iff all elements are non-zero to save any or all.
Other than that, it's pretty much a straight forward implementation of Fibonacci.

Jelly,  20 19 18 bytes
>ȷ2ȧDIEƊ
+ƝḢ;Ɗȷ¡ÇƇ

Try it online!
+ƝḢ;Ɗȷ¡ produces the first thousand (ȷ) terms in the series which will always be sufficient. I think there is probably a shorter way to do this. +ȷ¡ gets close but only works if the first term is zero.
I am assuming we can take in the two numbers in reverse which allows one byte to DIE.
If we aren't required to output either of the inputs:
Jelly, 15 bytes
>ȷ2ȧDIEƊ
+ṄÇ¡ß@

Try it online!

Our thoughts to all fearless bytes that DIEƊ during the golfing process.

Java 8, 151 144 140 136 130 bytes
(a,b)->{for(long n,m,d,p;;System.out.print(m>99&p==d?m+" ":""),m=a+b,a=b,b=m)for(m=n=a,d=p=10;n>9&d==p|p>9;d=n%10-(n/=10)%10)p=d;}

Infinite loop outputting the numbers when it finds them.
Try it online (times out after 60 sec).
136 bytes version with added 1010 limit (a<1e10):
(a,b)->{for(long n,m,d,p;a<1e10;System.out.print(m>99&p==d?m+" ":""),m=a+b,a=b,b=m)for(m=n=a,d=p=10;n>9&d==p|p>9;d=n%10-(n/=10)%10)p=d;}

Try it online.
Explanation:
(a,b)->{         // Method with two long parameters and no return-type
  for(long n,m,  //  Temp numbers
           d,p;  //  Current and previous differences
      a<1e10;    //  Loop as long as `a` is still below 10^10
      ;          //    After every iteration:
       System.out.print(
                 //     Print:
        m>99     //      If the number has at least three digits,
        &p==d?   //      and the previous and current differences are still the same
         m+" "   //       Print the current number with a space delimiter
        :        //      Else:
         ""),    //       Print nothing
                 //     Go to the next Fibonacci iteration by:
       m=a+b,    //      Setting the temp-number `m` to `a+b`
       a=b,      //      Replacing `a` with `b`
       b=m)      //      And then setting `b` to the temp number `m`
    for(m=n=a,   //   Set both `m` and `n` to `a`
        d=p=10;  //   Set both `d` and `p` to 10
        n>9      //   Inner loop as long as `n` has at least two digits,
        &d==p    //   and `p` and `d` are still the same,
         |p>9    //   or `p` is still 10
        ;        //     After every iteration:
         d=n%10-(n/=10)%10)
                 //      Set `d` to the difference between the last two digits of `n`
                 //      And integer-divide `n` by 10 at the same time
      p=d;}      //    Set the previous difference `p` to `d`

Python 2, 102 98 bytes
f=lambda x,y:x<1e10and[x]*(len(set(int(a)-int(b)for a,b in zip(`x`,`x`[1:])))<2<99<x)+f(y,x+y)or[]

Try it online!
Thx for 4 bytes from ovs

CJam, 55 bytes
q~{1$_99>"_`2\ew{{-}*}%""3,"?~_(+="0$p"*~;_@+_11_#<}g;;

Try it online!
My first CJam submission, not very short but a lot of fun. Any suggestions are welcome!

That's good to know, thanks for the tip! I've updated the submission.

Haskell, 105 bytes
u%v|let s=u:scanl(+)v s=[n|n<-s,d<-[f(-).map fromEnum.show$n],length d>1,and$f(==)d]
f g=zipWith g=<<tail

Defines the operator (%) which returns an infinite list with all the solutions. To actually see the result on stdout we need to disable buffering (or run it in ghci or with runhaskell), try it online!
Explanation/Ungolfed
The function f is just a helper function that expects a binary function and a list, it applies the function g to all adjacent pairs. It's essentially the same as:
adjacent g xs = zipWith (tail xs) xs

The operator (%) is just a list comprehension that does some filtering (making sure that there are at least 3 digits & that the adjacent digits have the same distance):
u % v
  -- recursively define s as the "Fibonacci sequence" with f(0) = u and f(1) = v
  | let sequence = u : scanl (+) v sequence
  -- take all numbers from that sequence using the filters below
  = [ number | number <- sequence
  -- convert to string, get the ASCII codepoints and build a list of the adjacent differences
        , let differences = adjacent (-) . map fromEnum . show $ number
  -- numbers with > 3 digits have >= 2 adjacent digits (or rather differences of digits)
        , length differences > 1
  -- make sure all of these are equal by comparing them and reducing with logical and
        , and $ adjacent (==) differences
    ]

Stax, 26 24 bytes
Ç╕SôεPN^:·░ßⁿ {@ÿ}Ü╫╣1╣X

Run and debug it
Explanation
E{b+}99*L{E%2>|cd_E:-u%1=!C_Qf    # Full program, unpacked, implicit input
E                                 # Push all elements from array onto stack.
 {b+}99*L                         # Generate the first 99 numbers of the  Fibonacci sequence given the input
         {                   f    # Loop through all Fibonacci elements
          E                       # Array of decimal digit
           %2>                    # Does the array have at least 3 digits
              |c                  # Assume Truthy past this point
                d                 # discard top of stack
                 _E               # Copy the current element of the Fibonacci sequence and Digitize it
                  :-              # Pairwise difference of array.
                    :u            # Is there exactly 1 unique number
                        !C        # Flip the comparison, if truthy proceed
                          _Q      # Copy the current element of the Fibonacci sequence and Peek and print with a newline.

Not as short as I would like it and can probably be golfed a bit more, but it works.

Ruby, 79 bytes
->a,b{loop{a>99&&!(a.digits.each_cons(2).map{|a,b|a-b}|[])[1]&&p(a);a,b=b,a+b}}

Try it online!

Julia 0.6, 86  81 bytes
a<b=b>=0&&((n->n>99&&2>endof(∪(diff(digits(n))))&&println(n)).([a,b]);a+b<a+2b)

Try it online!
Pretty straightforward - check if input has at least 3 digits (n>99), then take the difference between each digit pair in the number (diff(digits(n))), check that the length of (endof) a unique set of (∪) those differences is 1 (i.e. all the differences are the same), and if so print the number. Do that for both the given numbers, then recursively call the function with the next two numbers.
(Unfortunately, it looks like ± has higher precedence than +, or else the final call could have been a+b±a+2b, saving 3 bytes.) Now overloads the < operator, thus saving on both the operator bytes and the precedence brackets. (Can't use < in our code though, so just rearranged endof(...)<2 to 2>endof(...)).
If some extraneous output is allowed, we can save 2 bytes using @show instead of println, printing n = 987 instead of just 987. We could even use dump for 1 byte lower than that, but dump prints the type information along with the value, so output will be Int64 987 instead of just 987.


text:
Progression of Matrix Columns
Consider the infinite matrix:
0  1  0  1  0  1  0  1  0  1  0  1  0  1  0  1
0  0  2  3  0  0  2  3  0  0  2  3  0  0  2  3
0  0  0  4  5  6  0  0  0  4  5  6  0  0  0  4 ...
0  0  0  0  7  8  9 10  0  0  0  0  7  8  9 10
0  0  0  0  0 11 12 13 14 15  0  0  0  0  0 11
              ...

Each new row of the matrix is constructed by starting with z zeros, where z is the length of positive digits we're using in that row. The positive digits are constructed by starting with 1 and incrementing and adding an additional digit each time you iterate rows. That pattern is repeated infinitely to the right. So, for example, the first row starts 0, 1, 0, 1... while the second row starts 0,0, 2,3, 0,0, 2,3.... Following the pattern, the third row starts 0,0,0, 4,5,6, 0,0,0, 4,5,6....
Given two integers as input, n and x, output the first (top-most) x numbers of the nth column of the above matrix. (You can choose 0- or 1-indexing for the columns, just specify which in your submission.)
For example, for input n = 0 (0-indexed), the column is entirely 0s, so the output would just be x 0s.
For input n = 15 and x = 6, the output would be [1, 3, 4, 10, 11, 0].
For input n = 29 and x = 15, the output would be [1, 0, 6, 8, 15, 0, 0, 34, 39, 0, 0, 0, 0, 0, 120].
For input n = 99 and x = 25, the output would be [1, 3, 4, 0, 15, 0, 0, 0, 37, 55, 56, 0, 87, 93, 0, 0, 151, 163, 176, 0, 0, 0, 0, 0, 325].
I/O and Rules

The input and output can be given by any convenient method.
The input and output can be assumed to fit in your language's native number type.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

JavaScript (ES6), 45 bytes
Takes input in currying syntax (n)(x).
n=>g=x=>x?[...g(x-1),n/x&1&&n%x+x*~-x/2+1]:[]

Try it online!
How?
We use a direct formula to get the value of the cell at column n (0-indexed) and row x (1-indexed):
n / x & 1 &&     // is this cell zero or non-zero?
n % x +          // column modulo row --> increment for a non-zero value at this position
x * ~-x / 2 + 1  // minimum value of non-zero values for this row:
                 // ∑(i=1...x-1)(i) + 1 = x(x - 1) / 2 + 1

R, 80 76 bytes
Thanks to @JayCe for pointing out a bug!
function(n,x)for(a in 1:x)print(rep(c(rep(0,a),((y=sum(1:a))-a+1):y),,n)[n])

Try it online!
Uses 1-based indexing for n. Very likely a golfier algorithm exists but rep is the enabler for the naive solution.

It errors for n=1 since the result of sapply in no longer a matrix. this fix is costly I wonder if there is a golfier one?

Oh, yeah, you're right. Well, luckily there is one!

The for loop, yeah! And you golfed 4 bytes in the process :)

@JayCe yeah my original thought was to index the outermost rep with an n inside the sapply, which saved a byte, but then I remembered that for loops are shorter than sapply since I wouldn't have to define a function.

Python 2, 69 bytes
n,x=input()
a=i=1
exec"print(([0]*i+range(a,a+i))*n)[n];a+=i;i+=1;"*x

Try it online!

APL (Dyalog Classic), 27 24 23 bytes
-1 thanks to @FrownyFrog

⊢∘⍳(<×(+\⊣)--){+\⍵/2}|⊣

Try it online!

1 shorter {+\⍵/2}|⊣

MATL, 25 18 bytes
x:"@:t~ys:b@-)h1G)

Try it online!
Thanks to Luis Mendo for golfing out 6 bytes!
This is essentially a MATL port of my R answer.
x		 % implicit input, read n and delete
:		 % implicit input, read x and push [1..x]
"		 % for loop with i = 1..x
 @:		 % push [1..i]
   t		 % duplicate
    ~		 % logical negate, turn to array of zeros
		 % stack: [[1..i], [0 .. (i times)]]
     y		 % duplicate from below
		 % stack: [[1..i], [0 .. (i times)], [1..i]]
      s:	 % sum and range
		 % stack: [[1..i], [0 .. (i times)], [1..(i * (i + 1)/2)]]
	b	 % bubble up
		 % stack: [[0 .. (i times)], [1..(i * (i + 1)/2)], [1..i]]
	 @-	 % push i and subtract. This will be used as a modular index to get the last i elements
		 % stack: [[0 .. (i times)], [1..(i * (i + 1)/2)], [1-i..0]]
	   )	 % index into array modularly to get the last i elements
		 % stack: [[0 .. (i times)], [(i-1)*i/2 + 1, .. (i * (i + 1)/2)]]
	    h	 % horizontally concatenate the array
	     1G) % push n and index modularly, leaving the result on the stack
		 % implicit end of for loop. The stack now contains the appropriate elements in order
		 % implicit end. Print stack contents

05AB1E, 25 bytes
LO©LsL£¹£¹LÅ0s)øε˜®Ì∍}ø¹è

Try it online!

05AB1E goes with matrices like toothpaste and orange juice, but not a bad byte-count considered how bad my implementation is. Even my code is laughing at me "LO©L".

Jelly, 11 bytes
ṖS+R¬;$)⁹ịⱮ

Try it online!
-1 thanks to Jonathan Allan.
Argument 1: x
Argument 2: n + 1

0ṁ;Ɗ -> ¬;$ saves a byte.

@JonathanAllan And I suspect that's not yet enough. At least I removed the humiliating ’R...(that is, at least for me) The weird thing is that during the last few days I've been thinking of the Thue-Morse sequence (which, in Jelly, contains ;¬$).

Husk, 14 bytes
↑!Tzo¢+MRN0CNN

The argument n (first) is 1-indexed, try it online!
Alternatively we could use ↑!TṠzo¢+†K0CNN for the same number of bytes.
Explanation
↑!Tz(¢+)MRN0CNN -- example inputs n=4, x=3
            C N -- cut the natural numbers: [1,2,3,4,…]
             N  -- | using the natural numbers
                -- : [[1],[2,3],[4,5,6],[7,8,9,10],…]
        M N     -- map over the naturals
         R 0    -- | replicate 0 that many times
                -- : [[0],[0,0],[0,0,0],[0,0,0,0],…]
   z(  )        -- zip these two lists
      +         -- | concatenate
     ¢          -- | cycle
                -- : [[0,1,0,1,…],[0,0,2,3,0,0,2,3,…],…]
  T             -- transpose: [[0,0,0,0,…],[1,0,0,0,…],[0,1,0,0,…],[1,3,4,0,…],…]
 !              -- index into that list using n: [1,3,4,0,…]
↑               -- take x: [1,3,4]

Husk, 21 19 bytes
↑mȯ!⁰¢§+`R0§…ȯ→Σ←ΣN

Takes arguments as n (1-indexed), then x.
Saved 2 bytes thanks to BMO, but still not as short as BMO's answer.
My first attempt at using Husk.
Try it online!

K (ngn/k), 33 31 bytes
{(a>i)*(+\i)-i-a:(2*1+i:!y)!'x}

Try it online!

Haskell, 75 bytes
u!v=take v[cycle((0<$l)++l)!!u|n<-[1..],l<-[take n$drop(sum[1..n-1])[1..]]]

Try it online!

Python 2, 55 bytes
lambda n,x:[n/y%2*(n%y+y*~-y/2+1)for y in range(1,x+1)]

Try it online!
Developed independently; but I note that this ends up being a port of Arnauld's Javascript answer.

Perl 5 -n, 52 bytes
/ /;say+(((0)x$_,($.+=--$_)..$.+$_)x$`)[$`]for 1..$'

Try it online!

Java 8, 65 63 60 bytes
n->x->{for(;x>0;)System.out.println(n/x%2*(n%x+x*--x/2+1));}

n is 0-indexed, x is 1-indexed, outputs the numbers new-line delimited and reversed.
Port of @Arnauld's JavaScript (ES6) answer.
Try it online.
A pretty-printed result in correct order is 8 6 bytes longer: Try it online.

Haskell, 67 bytes
i#l=cycle((++)=<<(0<$)$[i..l-1]):l#(l+l-i+1)
n!x=take x$(!!n)<$>1#2

Try it online!
i#l                  -- function # builds the infinite matrix
                     -- input: i and l are lowest and highest+1 non-zero number of
                     -- the current line
   = cycle           -- for the current line, repeat infinitely
           [i..l-1]  --   the non-zero numbers of the line appended
     (++)=<<(0<$)    --   to a list of 0s with the same length
   :                 -- append next row of the matrix
     l#(l+l-i+1)     --   which is a recursive call with i and l adjusted

n!x =                -- main function
              1#2    -- create matrix
      (!!n)<$>       -- pick nth element of each row
  take x             -- take the first x numbers thereof

Charcoal, 19 bytes
ＩＥ…·¹Ｎ§⁺Ｅι⁰ＥιＬ⊞Ｏυωη

Try it online! Link is to verbose version of code. Explanation:
    ¹               Literal 1
     Ｎ              First input (`x`) as a number
  …·                Inclusive range
 Ｅ                  Map (value `i`, 0-indexed counter `k`)
         ι          Current value
        Ｅ           Map over implicit range
          ⁰         Literal 0 (i.e. create array of `i` zeros)
            ι       Current value
           Ｅ        Map over implicit range
                 ω  Arbitrary variable
                υ   Predefined array
              ⊞Ｏ    Push
             Ｌ      Length
       ⁺            Concatenate arrays
      §           η Index by second input (`n`)
Ｉ                   Cast to string and implicitly print on separate lines

The snippet ＥιＬ⊞Ｏυω generates the next i integers by the expedient of pushing a dummy value to an array each pass through the loop and taking the length of the resulting array.