g | x | w | all
Bytes Lang Time Link
023TIBASIC TI84 Plus CE Python250912T174522Zmadeforl
019Juby230711T192807ZJordan
043Setanta240720T235346Zbb94
009Uiua231221T022932Zchunes
015ForWhile230711T202018Zbsoelch
045Desmos230816T195539Zfwoosh
036C gcc230718T213356ZSaladin
020Alice230711T211003ZJulian
026Julia 1.0230712T151026ZAshlin H
025Raku230717T214406Zbb94
027Perl 5230717T131954ZNahuel F
010Dyalog APL230711T205320ZRubenVer
056Go230713T180032Zbigyihsu
073sed230712T201806ZYelp
017x8664 machine code230712T195709Zengineer
029Haskell230712T181405ZMagma
010J230712T071648Zsouth
068Python + vyxal230712T110922ZThe Empt
006Japt h230712T104827ZShaggy
008Brachylog230712T093015ZFatalize
035Python 2230711T204554Zxnor
020Wolfram Language Mathematica230712T074226ZJSorngar
048Brainfuck230711T230720Zanderium
004MathGolf230712T065703ZKevin Cr
175Vyxal R230711T200413ZThe Thon
006BQN230711T200456ZDominic
004Nekomata230712T000118Zalephalp
062Python 3230711T183737ZEthan C
034Ruby230711T210949ZG B
013Charcoal230711T202638ZNeil
018Retina230711T202216ZNeil
033R≥4.1230711T201918ZDominic
005MATL230711T201857ZLuis Men
00305AB1E230711T200844ZThe Thon
052Racket –230711T200651ZEd The &
003Thunno 2230711T200235ZThe Thon
026Factor + math.unicode230711T194536Zchunes
006Pyth230711T193538ZCursorCo
042Python 3230711T190906Zspooky_s
005Husk230711T183531ZDominic
023><> Fish230711T181551Zmousetai
029JavaScript Node.js230711T175525Zl4m2
004Jelly230711T174710Zcaird co

TI-BASIC (TI-84 Plus CE Python), 23 bytes

Input A
For(N,1,A
.5(A+A²→A
End
A

the sequence basically is $$ a(0)=n\\ a(k)=\frac{a(k-1)+a(k-1)^2}{2} $$ while \$k \le n\$ (take it with a grain of salt i'm not good with this stuff)

J-uby, 19 bytes

~:^%(:**&(:+|:sum))

Attempt This Online!

Explanation

With some whitespace:

~:^ % (:** & (:+ | :sum))

The core function here is :** & (:+ | :sum), where :+ constructs a range and :sum sums it, and :** applies that function to its own result n times. The rest is just argument shuffling.

Setanta, 43 bytes

gniomh(n){le i idir(0,n)n*=(n+1)/2toradh n}

Try on try-setanta.ie

Uiua, 9 bytes

⍥(/++1⇡).

Try it!

ForWhile, 15 bytes

{:(.0'(+:):)}1$

same length, but faster (uses formula for sum of first n numbers):

{:(.::*+2/:)}1$

online Interpreter

Explanation

{ }1$ defines a function, store it at id 1

the argument is read from the stack

: duplicate the argument

(. loop but ignore the loop counter

0'(+:) compute the triangle number corresponding to the top value on the stack

:) end of for loop, now the next triangle number is on the stack

returns the result on the stack

Example for how to call the function

{:(.0'(+:):)}1$ \ the actual function

4 1@? \ call the function with argument 4

\ print the top stack value as an integer, displaying stack values directly is not supported by this version of the interpreter
0;1+(.;10%"0".+;2+~,1+'10/';)'.(,#)10#. 
\ alternatively you can read the stack contents in the browser console from the 'valueStack' variable

The interpreter is newer than the challenge, but it implements he same language as the original C interpreter.

Desmos, 45 bytes

Input is in a variable n. Output is placed in variable f.

Start the ticker to run the program. To reset, run the action in the "reset" folder.

Ticker:

\left\{k<n:f->f(f+1)/2\right\},k->k+1

Expression List:

f=n
k=0

Try it on Desmos!


Explaination:

Applies \$f\to T(f)\$ n times, using a ticker because Desmos does not support recursion.

C (gcc), 36 bytes

x;a(n){for(x=n;n--;x/=2)x+=x*x;n=x;}

Try it online!

Was missing a semicolon, so now it's 36 bytes.

Alice, 24 20 bytes

/O
\I@/.!wrd&+?t.!$K

Try it online!

Times out for larger values as it creates a range from 0 to the sum of the last range.

Alice, 21 bytes

/O
\I@/.!w.h*2:?t.!$K

Try it online!

Does not time out as it uses the n*(n+1)/2 formula instead

Julia 1.0, 33 26 bytes

~x=(1:x.|>_->x*=(x+1)/2;x)

Try it online!

-7 bytes thanks to MarcMush: replace for loop with pipe operator |>

Alternate approach, 39 35 bytes

~x=x|>∘(fill(n->n*(n+1)÷2,x)...)

Attempt This Online!

-4 bytes thanks to MarcMush: remove call to reduce

Raku, 25 bytes

{($_,{.++*$_/2}...*)[$_]}

Try it online!

Perl 5, 27 bytes

$\=$_;$\*=$\++/2while$_--}{

Try it online!

Dyalog APL, 10 bytes

{+/⍤⍳⍣⍵⊢⍵}

Explanation

   ⍤        ⍝ ‎⁡Function composition:
 +/         ⍝ ‎⁢  sum reduce
    ⍳       ⍝ ‎⁣  the numbers from 1 to the argument of the composed function
     ⍣⍵     ⍝ ‎⁤repeated input times
       ⊢⍵   ⍝ ‎⁢⁡starting from the input

💎 Created with the help of Luminespire at https://vyxal.github.io/Luminespire

Go, 56 bytes

func(n int)int{k,i:=n,0
for;i<n;i++{k=k*-^k/2}
return k}

Attempt This Online!

Maxes out at n=5.

Go, 138 bytes, math/big

import."math/big"
func f(n int)*Int{N:=NewInt
k,i,z:=N(int64(n)),0,N(0)
for;i<n;i,z=i+1,N(0){k.Div(z.Mul(k,z.Add(k,N(1))),N(2))}
return k}

Attempt This Online!

sed, 73 bytes

s/!*/&''&/g
:a
s/<(!*)''!(!*>)/<'\1'\2/
s/(<!*)'(!*)!/\1\2!'\2/
ta
s/'//g

Try it online!

Input is unary, with exclamation marks, surrounded by angle brackets. Output is unary with exclamation marks, surrounded by angle brackets. In the TIO link I made it convert to decimal for the output, so that it's easier to see. If you would like to see the unary output, just delete everything in the footer section.

x86-64 machine code, 17 bytes

Standard System V ABI, signature long fsor(int n) (n is taken in edi, and the output is placed in rax).

57 58 50 5e ff c6 48 f7 e6 48 d1 e8 ff cf 7f f2 c3

Try it online!

Explanation

0000000000000000 <fsor>:
   0:   57                      push   rdi           ; cnt (edi)
   1:   58                      pop    rax           ; n = cnt
                                                     ;
0000000000000002 <__fsor_lp>:                        ; start_loop:
   2:   50                      push   rax           ;
   3:   5e                      pop    rsi           ; n1 = n
   4:   ff c6                   inc    esi           ; n1++
   6:   48 f7 e6                mul    rsi           ; n *= n1
   9:   48 d1 e8                shr    rax,1         ; n >>= 1
   c:   ff cf                   dec    edi           ; cnt--
   e:   7f f2                   jg     2 <__fsor_lp> ; if (cnt > 0) goto start_loop
  10:   c3                      ret                  ; return

Haskell, 29 bytes

(!!)=<<iterate(\x->sum[0..x])

Expands to

\n -> iterate (\x -> sum [0..x]) n !! n

Try it online!

J, 11 10 bytes

(-:*>:)^:]

Requires extended precision integer as input. -1 thanks to @Bubbler.

Attempt This Online!

(-:*>:)^:]­⁡​‎‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁤‏‏​⁡⁠⁡‌­
       ^:   NB. ‎⁡repeat
         ]  NB. ‎⁢y times
    >:      NB. ‎⁣increment
 -:         NB. ‎⁤halve
   *        NB. ‎⁢⁡multiply

J, 12 11 bytes

(-:*>:)^:x:

Attempt This Online!

(-:*>:)^:]­⁡​‎‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁤‏‏​⁡⁠⁡‌­
       ^:    NB. ‎⁡repeat
         x:  NB. ‎⁢y times but promote to extended precision
    >:       NB. ‎⁣increment
 -:          NB. ‎⁤halve
   *         NB. ‎⁢⁡multiply

Python + vyxal, 68 Bytes

lambda x:execute_vyxal("","eR"+"s"*x,str(x))
from vyxal.main import*

With the power of Python, I can make dynamic flags!*

The vyxal package can be installed using pip install vyxal.


*Oh wait dynamic flags sound very useful

Japt -h, 6 bytes

õ@=ô x

Try it

5 bytes

If we could output undefined for 0
(or I could use the -hF0 flags to output 0 but I hate Japt's -E & -F flags!)

Æ=õ x

Try it

Brachylog, 8 bytes

;?{⟦+}ⁱ⁾

Try it online!

Explanation

;?{  }ⁱ⁾         Iterate <Input> times on the Input:
   ⟦               Range
    +              Sum

Python 2, 35 bytes

def f(n):exec"n=n*-~n/2;"*n;print n

Try it online!

A function that prints.

Python 3, 39 bytes

lambda n:eval("(n:=n*-~n//2)*0+"*n+"n")

Try it online!

The annoying thing in Python 3 here is that exec within a function is its own scope and doesn't affect variables outside the exec, so we can't port the code like def f(n):exec("n=n*-~n/2;"*n);print(n) -- the n will be unchanged.

The code above works around this by evaluating a string like (n:=n*-~n//2)*0+(n:=n*-~n//2)*0+n that modifies n using the walrus := and evaluates to n within its own scope. If we didn't need n=0, we could do:

37 bytes, fails n=0

lambda n:eval("(n:=n*-~n//2),"*n)[-1]

Try it online!

Here were some other attempts.

39 bytes

lambda n:eval('('*n+'n'+'+.5)**2//2'*n)

Try it online!

Based on @dingledooper's comment.

40 bytes

def f(n):exec("n*=n/2+.5;"*n+"print(n)")

Try it online!

41 bytes

lambda n:0*[n:=n*-~n//2for _ in[1]*n]or n

Try it online!

Wolfram Language (Mathematica), 20 bytes

Nest[#(#+1)/2&,#,#]&

Try it online!

This code simply nests the short-hand expression for the triangular numbers the given number of times. The computation time starts to become noticeable around n=20 and my laptop takes around 50 seconds to compute n=27, which is a number that takes 63.5 MB to store.

Brainfuck, 64 48 bytes

[>+>+<<-]>[->[[>+>+<<-]>>-[<<+>>-]<<]>[<+>-]<<]>

Try it online! (Up to n = 3 with 8 bit numbers, n = 4 with 32 bit, n = 5 with 64 bit, n = 6 possibly never [with BigInt].)

Rather simple brainfuck answer. Assumes you initialise the tape with the input on cell 0 and stores the output in cell 2. If input given in binary, just wrap the code in , and . for +2 bytes. If the input should be the number in ASCII this would also involve writing the parser, I feel that is not in the spirit of the challenge.

The input in the first cell (0) is duplicated and then the loop simply iterates on cell 1. Each value of the triangle is added to cell 3 and copied back with 1 removed to cell 2. At the end of the loop that new value is stored in cell 2.

Header: give N here
++++

Actual code
[>+>+<<-]          # Duplicate
>[-                # Repeat input times:
  >[                 # While x = n can be decremented
    [>+>+<<-]          # Accumulate result and make copy
    >>-[<<+>>-]<<      # Move copy minus 1 back
  ]>[<+>-]<<         # Move back accumulated T(n) as new x
]>

MathGolf, 6 4 bytes

_Å╒Σ

Try it online.

Explanation:

_      # Duplicate the (implicit) input-integer†
 Å     # Pop one, and loop that many of times,
       # using the following two characters as inner code-block:
  ╒    #  Pop an integer, and push a list in the range [1,integer]
   Σ   #  Pop a list, and push its sum
       # (after the loop, the entire stack is output implicitly as result)

† The initial duplicate _ is necessary despite having implicit inputs for two reasons:

  1. MathGolf uses 0 if a stack is empty and it needs an integer. Although I think it's a bug in MathGolf (I'm not 100% sure), unfortunately that 0 will take priority over the implicit input-integer in the first iteration of a for-loop. So for any \$n>0\$, just Å╒Σ will result in 0 because Å will push a 0 in its first iteration and use it for the , instead of using the (implicit) input-integer.
  2. For \$n=0\$, the Å╒Σ will only pop the (implicit) input-integer and leave the stack empty, and thus it'll output an empty string as result. The initial _ will ensure a second 0 is still on the stack to be output instead.

Vyxal R, 14 bitsv2, 1.75 bytes

(∑

Try it Online!

Yeah...

(   # Input number of times:
 ∑  #  Sum top of stack
    #  (R flag makes it take the range instead of the digits)

BQN, 9 6 bytes

Edit: -3 bytes thanks to ovs

+´⟜↕⍟⊣

Try it at BQN REPL

+´⟜↕⍟⊣
     ⍟  # Repeat
      ⊣ # number of times equal to argument
+´⟜↕    # this function:
    ↕   #   range 0..(arg-1)
  ⟜     #   as left arg to 
+´      #   fold-addition
        #   with starting value of function arg
        #   (so: sum of 0..arg)

Nekomata, 4 bytes

ᵑ{R∑

Attempt This Online!

ᵑ{R∑
ᵑ{      Repeat
  R     Range
   ∑    Sum

Python 3, 63 62 bytes

f=lambda x,y=-1:f(x,x)if y<0else x if y<1else f(x*(x+1)/2,y-1)

Try it online!

Calculates a(n) using the OEIS definition given in the OP, probably still golfable

Edit: fixed inputs and added "f="

Ruby, 34 bytes

f=->x,y=x{y<1?x:f[(1..x).sum,y-1]}

Try it online!

Charcoal, 13 bytes

NθFθ≔Σ…·¹θθIθ

Try it online! Link is to verbose version of code. Explanation:

Nθ

Input n.

Fθ

Repeat n times...

≔Σ…·¹θθ

... replace the current value the sum of its range.

Iθ

Output the final value.

14 bytes for an efficient version:

NθFθ≔÷×⊕θθ²θIθ

Try it online! Link is to verbose version of code. Explanation: Uses the triangle formula to sum the range.

Retina, 18 bytes

.+
*
"$+"+`_
$>`
_

Try it online! No test suite due to the way the program uses history. Explanation:

.+
*

Convert n to unary.

"$+"+`

Repeat n times.

_
$>`

Replace the current value with its range, effectively taking the sum.

_

Convert to decimal.

R≥4.1, 33 bytes

\(x){Map(\(i)x<<-sum(0:x),1:x);x}

Attempt This Online!

R afficionados should wince when they see Map used for it's out-of-scope side-effect due to <<- assignment, and the result discarded...

R<4.1, 42 bytes

f=function(x,y=x)`if`(y,f(sum(1:x),y-1),x)

Attempt This Online!

Without the short \ form, it's too expensive to define two functions.

MATL, 5 bytes

t:":s

Try it online!

How it works

t      % Input (implicit). Duplicate
:      % Range
"      % For each
  :    %   Range
  s    %   Sum
       % End (implicit). Display (implicit)

05AB1E, 3 bytes

FLO

Try it online!

Explanation

     # Implicit input
F    # Repeat input number of times:
 L   #  Push the one-range of top of stack
  O  #  Sum the resulting list
     # Implicit output

Racket – 52 bytes

(define(f x y)(if(= y 0)x(f(/(*(+ x 1)x)2)(- y 1))))

Try it online!

Explanation

We define a function f that receives two arguments: x and y where y is used as decrementing iterator that when equal to zero will make f return the result of x.

(define (f x y)
  (if (= y 0)
      x
      (f (/ (* (+ x 1) x) 2)
         (- y 1))))

We can represent this function mathematically using the following:

$$ f(x, y) = \begin{cases} x & y = 0 \\ f(\frac{x(x+1)}{1}, y - 1) & y > 0 \end{cases} $$

Sub-optimal variations

To allow user input I could've done:

(let([n(read)])(let f([x n][y n])(if(= y 0)x(f(/(*(+ x 1)x)2)(- y 1)))))

Which consists of 72 bytes when minified. We could also have used a combination of a lambda and let statement to save one byte:

((λ(n)(let f([x n][y n])(if(= y 0)x(f(/(*(+ x 1)x)2)(- y 1)))))(read))

(The λ character equals two bytes.)

Conclusion

Have an amazing day! I am still mind blown at Racket's speed and capability of handling large numbers. At \$n = 17\$, TIO can't seem to render all the digits alongside all iterations of the for loop in the footer.

Thunno 2, 3 bytes

{RS

Attempt This Online!

Explanation

{RS  # Implicit input
{    # Repeat input number of times:
 R   #  One-range of top of stack (initially the input number)
  S  #  Sum the resulting list and leave it for the next iteration
     # Implicit output 

Factor + math.unicode, 26 bytes

[ dup [ [1,b] Σ ] times ]

Try it online!

Literally just take the sum of the range of the input <input> number of times. Since sum dispatches on ranges to use the arithmetic formula, it's even efficient.

Pyth, 6 bytes

LsSbyF

Try it online!

Alternative 6 byte solution

usSGQQ

Try it online!

Another alternative 6 byte solution

.v*"sS

Try it online!

This one's my favorite.

Another alternative 6 byte solution

em=sSQ

Try it online!

Feels like there's gotta be a 5 byte solution but I got nothing

Python 3, 42 bytes

think i might be able to get it down further... lmk if you guys see anything !!

lambda x:eval("sum(range("*x+"x"+"+1))"*x)

Try it online!

Husk, 5 bytes

!→¹¡Σ

Try it online!

><> (Fish), 23 bytes

i::?\~n;
-10.\r:1+*2,r1

Try it

enter image description here

JavaScript (Node.js), 29 bytes

f=(x,y=x)=>y?f(x*++x/2,y-1):x

Try it online!

Jelly, 4 bytes

RS$¡

Try it online!

Full program, takes \$n\$ as the first argument and outputs \$f(n, n)\$

How it works

RS$¡ - Main link. Takes n on the left
  $  - Last two links as a monad f(n):
R    -   Range [1, ..., n]
 S   -   Sum; T(n)
   ¡ - Apply f n times, beginning with n