Skip to main content
1 of 2
ovs
  • 60.6k
  • 3
  • 47
  • 161

Ruby, 56 bytes

->n{d=[];v=0;n.times{|i|d<<v+=v<i||(d-[v-i]!=d)?i:-i};d}

Try it online!

Commented:

->n{ ... }                         # lambda function taking an integer
  d=[];v=0                         # initialize list of sequence values d and previous value v
  n.times{|i| ... }                # run the following code for i = 0,1,...,n-1:
          v<i||(d-[v-i]!=d)?i:-i   #   i IF (v < i OR v-i in d) ELSE -i
       v+=                         #   add this to v
    d<<                            #   and append the new value of v to d
  d                                # return d
ovs
  • 60.6k
  • 3
  • 47
  • 161