g | x | w | all
Bytes Lang Time Link
119ForWhile230719T152539Zbsoelch
014Nekomata230720T110454Zalephalp
086Python230718T174106Zmousetai
015Jelly230719T200259ZJonathan
134Perl 5230719T192734Zascheple
02505AB1E230719T095557ZKevin Cr
066Raku Perl 6 rakudo230718T192959Zbb94
059JavaScript V8230718T184845ZArnauld
027Charcoal230718T195602ZNeil
021Pyth230718T191348ZCursorCo

ForWhile, 119 bytes

{1:2$4$[2@4;+'[1-:@48+#)1-:@[48#.]2@[1+:@48'-#).10#.4::@1+'$2@[:@2=[0~;$1+::@1+'$]:)2@4+=[3::@~'$@![2:@1+'$]2@3+1'$]1)}

Input: integer n on the stack

Prints the first n numbers of the sequence in balanced ternary with / as symbol for -1

Online Interpreter

Explanation:

Memory:

{  \ procedure
  1:2$4$  \ store 1 in cells 2 (length) and 4 (start of value)
  [                                  \ loop-without pushing the loop-counter
    2@4;+'[1-:@48+#)                 \ write the first digits of the number
    1-:@[48#.]                       \ write 0 if number has odd length
    2@[1+:@48'-#).10#.4              \ write digits reversed and mirrored
    ::@1+'$2@[:@2=[0~;$1+::@1+'$]:)  \ increment number
    2@4+=[                           \ check for overflow
      3::@~'$                        \ flip cell 3
      @![2:@1+'$]                    \ increase length if new length is even
      2@3+1'$                        \ set top trit (ternary digit) to 1
    ] 
  1)                                 \ go back to start of loop
}

Nekomata, 14 bytes

Ňᵐ{3r~←}1c:↔_=

Attempt This Online!

Outputs the numbers in balanced ternary (as lists of digits).


Nekomata, 16 bytes

Ňᵐ{3r~←}1c:↔_=3b

Attempt This Online!

Outputs the numbers in the usual form.

Ňᵐ{3r~←}1c:↔_=3b
Ň                   Choose a natural number n
 ᵐ{    }            Map the following function to the range [0, n)
   3r~                  Choose a random number from [0, 3)
      ←                 Decrement
                        (These two steps generate any tuple of [-1, 0, 1])
        1c          Prepends 1
                        (This ensures that it is the balanced ternary representation of a positive number)
          :         Duplicate
           ↔        Reverse
            _       Negate
             =      Check equality
              3b    Convert from base 3

Python, 86 bytes

f=lambda x:x and[-~x%3]+f(-~x//3)or[]
i=1
while i:
 if f(i:=i+1)==f(-i)[::-1]:print(i)

Attempt This Online!

Jelly, 15 bytes

Port of Neil's Charcoal answer - go show your love.

b3’µḢR¬;ṚN⁸;Ø+j

A monadic Link that accepts a positive integer, \$n\$, and yields the \$n^{\text{th}}\$ reverse-negate-invariant number in balanced ternary as a list of integers from \$\{-1,0,1\}\$.

Try it online! Or see the test-suite (first 100 converted to integers).

How?

b3’µḢR¬;ṚN⁸;Ø+j - Link: positive integer, n            e.g. 21
b3              - convert {n} to base three                 [2,1,0]
  ’             - decrement {each digit}                D = [1,0,-1]
   µ            - start a new monadic chain - f(D=that)
    Ḣ           - pop the head off {D} and yield it         1  (and D -> [0,-1])
     R          - range {that} (1 -> [1] else [])           [1]
      ¬         - logical NOT {that} ([] -> []; [1] -> [0]) [0]
        Ṛ       - reverse {modified D}                      [-1,0]
       ;        - concatenate                               [0,-1,0]
         N      - negate {that}                             [0,1,0]
          ⁸     - chain's left argument -> modified D       [0,-1]
           ;    - concatenate                               [0,-1,0,1,0]
            Ø+  - signs literal -> [1,-1]                   [1,-1]
              j - join                                      [1,0,-1,0,1,0,-1]

Perl 5, 134 bytes

while(++$n){for$c("",0){$_="T"x$n;s/T/1/;do{($b=reverse)=~y/1T/T1/;print"$_$c$b$/"}while(/(?=[T0]1*$)/g&&substr($_,pos)=~y/T01/01T/)}}

Like some other answers, it uses string manipulations only, no math, to produce the reflected pattern of the sequence elements.

Try it online!

05AB1E, 25 bytes

∞ʒD(‚ε[©_#®>D3%s3/ï})}`RQ

Inspired by @mousetail's Python answer and @CursorCoercer's Pyth answer.

Outputs the infinite sequence.

Try it online.

Unfortunately 05AB1E rounds towards 0 for integer-division of negative values, unlike Python which always floors. Otherwise [©_#®>D3%s3/ï} could have been [©_#®>3‰R`} for -3 bytes by using divmod builtin .
See that it gives the expected result for positive integers, but not for negative ones.

Explanation:

∞              # Push an infinite positive list: [1,2,3,...]
 ʒ             # Filter it by:
    ‚          #  Pair the current value
   (           #  with a negative
  D            #  copy of that value
  ε            #  Map over this [n,-n] pair:
   [           #   Start an infinite loop:
    ©          #    Store the current value in variable `®` (without popping)
     _         #    Pop and if it's 0:
      #        #     Stop the infinite loop
    ®          #    If not, push `®` again
     >         #    Increase it by 1
      D        #    Duplicate it
       3%      #    Modulo-3
         s     #    Swap so the value+1 is at the top again
          3/   #    Divide by 3
            ï  #    Floor (by casting to an integer)
   })          #   After the infinite loop: wrap all values on the stack into a list
  }`           #  After the map: pop and push both lists to the stack
    R          #  Reverse the second list
     Q         #  Then check if the two lists are the same
               # (after which the filtered infinite list is output implicitly as result)

Raku (Perl 6) (rakudo), 69 66 bytes

.&(my&g={1 x?$_&&g(-+^$_ div 3)~$_%3})==g(-$_).flip&&.say for 1..*

Attempt This Online!

JavaScript (V8), 59 bytes

Prints the sequence infinitely.

for(k=1;v=++k;t+k||print(k))for(t=0;v;v=v/3|0)t=++v%3-1+t*3

Try it online!

How?

We convert \$k\ge2\$ to balanced ternary. Each produced digit is immediately used to convert the reversed balanced ternary representation of \$k\$ back to a decimal value \$t\$. If we end up with \$k=-t\$, we print \$k\$.

Commented

for(                // outer loop:
  k = 1;            //   start with k = 1
  v = ++k;          //   increment k and set v = k
                    //   (this is > 0, so we loop forever)
  t + k || print(k) //   after each iteration: print k if t + k = 0
)                   //
  for(              //   inner loop:
    t = 0;          //     start with t = 0
    v;              //     stop when v = 0
    v = v / 3 | 0   //     after each iteration: update v to ⌊v/3⌋
  )                 //
    t =             //     update t:
      ++v % 3 - 1 + //       increment v and compute the next balanced
                    //       ternary digit (v mod 3) - 1
      t * 3         //       add t * 3

C (gcc), 74 bytes

v;t;main(k){for(;v=++k;t+k||printf("%d ",k))for(t=0;v;v/=3)t=++v%3-1+t*3;}

Try it online!

Charcoal, 27 bytes

Nθ1Φ⍘θT01κF⊖⊟⮌↨θ³0⮌Φ⍘θ10TκT

Try it online! Link is to verbose version of code. Outputs the nth term of the sequence. Explanation:

Nθ

Input n.

1

Start by printing a 1.

Φ⍘θT01κ

Print n in base 3, decrementing all of the digits (so 0 becomes T), but skipping the first digit.

F⊖⊟⮌↨θ³0

Print a 0 if n's first digit in base 3 is 2.

⮌Φ⍘θ10Tκ

Print n in base 3, again decrementing after skipping the first digit, but then negating and reversing the result.

T

Print a T.

Pyth, 21 bytes

L?b+y/hb3%b3Y.fq_yZy_

Try it online!

Outputs the first n terms of the sequence.

Explanation

L?b+y/hb3%b3Y.fq_yZy_ZQ    # implicitly add ZQ
                           # implicitly assign Q = eval(input())
L                          # define y(b)
 ?b                        #   conditional, if b:
    y/hb3                  #     y((b+1) / 3)
   +     %b3               #     append b % 3
            Y              #   else: []
             .f       Q    # return the first Q inputs where lambda Z is true
                _yZ        #   y(Z) reversed
               q           #   equals
                   y_Z     #   y(-Z)