g | x | w | all
Bytes Lang Time Link
019Perl 5 MListUtil=sum p240123T184230ZXcali
015Trilangle230516T114728ZBbrk24
009Uiua SBCS240104T053049Zchunes
021AWK240104T051807ZBubbler
026Ruby230820T214424Zkait0u
020Desmos230516T161332ZAiden Ch
015K ngn/k230820T064511Zdoug
110brainf**k230718T133338ZShiran Y
038Racket + math230717T234913ZEd The &
020AArch64 machine code230712T094714Zlandfill
018Moonscript/Yuescript230713T110814ZUrNightm
019Bash/Zsh230712T061747ZUrNightm
012Juby230618T040522ZJordan
023AWK230608T070159ZMarius_C
025Scala230525T055951Z138 Aspe
009K ngn/k230524T142924Zcoltim
004Neim230524T132359ZLiefdeWe
013ARBLE230524T032731ZATaco
002Husk230522T101916ZDominic
019R230518T044416ZJonathan
007minigolf230521T053132Zuser1180
018SAS IML230520T204505ZBartosz
006BQN230516T152636ZDLosc
015Wolfram Language Mathematica230516T113000ZZaMoC
004Pyth230519T203222ZCursorCo
002Pyt230519T145242ZKip the
000Vyxal Rss230516T072255Zlyxal
021Factor + math.unicode230517T185257Zchunes
018Arturo230517T183212Zchunes
004Jelly230517T174729Zxigoi
017Haskell230516T172518Zxnor
036Nim230517T170528Zxigoi
032BrainFlak230517T164258ZDJMcMayh
037Go230516T132421Zbigyihsu
054Rockstar230516T111825ZShaggy
nanBinary Lambda Calculus230517T083425ZBubbler
016Julia230516T205929ZKirill L
013x8616 machine code230516T202139Z640KB
021Haskell230516T172243ZRoman Cz
019Retina 0.8.2230516T165313ZNeil
022C gcc230516T154710Zc--
023Python230516T093425Zsolid.py
024Nibbles230516T151731ZDLosc
004Vyxal230516T151309ZDLosc
022SAS 4GL230516T140738ZBartosz
016PARI/GP230516T074614Zalephalp
024Lua230516T113041Zbluswimm
025PHP230516T105331ZShaggy
004Thunno 2230516T104935Znoodle m
017Java230516T095420ZKevin Cr
017JavaScript Node.js230516T093451Ztsh
004MathGolf230516T094201ZKevin Cr
00405AB1E230516T092356ZKevin Cr
010Charcoal230516T090837ZNeil
005Japt x230516T085943ZShaggy
013><> Fish230516T071926Zmousetai
024Excel230516T070635ZJos Wool
006Ly230516T071723Zcnamejj
006APL Dyalog Unicode230516T065711ZAdá
065C230516T065230ZBreadlea

Perl 5 -MList::Util=sum -p, 19 bytes

$_=sum 1..sum 1..$_

Try it online!

Trilangle, 15 bytes

?22)d**2'd')2p@

Try it on the online interpreter!

Just the code for "sum range" twice.

Uiua SBCS, 9 bytes

⍥(/++1⇡)2

Try it!

AWK, 21 bytes

$0*=$0+1,$0*=($0+2)/8

Attempt This Online!

Given a positive integer as input, the following happens in sequence:

Ruby, 26 bytes

The following is probably the most direct approach to the problem given Ruby's basic methods.

->(n){(1..(1..n).sum).sum}

Try it online!

Another idea: Let T(n) be the n-th triangular number. Our answer is T(T(n)) - we're interested in the T(n)-th triangular number.

Desmos, 21 20 bytes

N=nn+n
f(n)=N(N+2)/8

Try It On Desmos!

K (ngn/k), 15 bytes

-8!*/0 2+*/0 1+

Try it online!

brainf**k, 110 bytes

,[>+>+>+<<<-]>>>[-[>+>+<<-]>>[-<<+>>]<<[-<+>]>[-<+>]<]<[>+>+>+<<<-]>>>[-[>+>+<<-]>>[-<<+>>]<<[-<+>]>[-<+>]<]<.

Try it online!

Probably not the shortest implementation but I'm too lazy to make this shorter lol...

Like most other b****fuck programs, it doesn't output the answer. Instead, it prints the ascii character corresponding to the numeric answer.

Check this out to see the running process.

Racket + math, 38 bytes

(sum(range(+(sum(range(+(read)1)))1)))

Try it online!

Although it's verbose and a bit slow, it's shorter than placing in the actual equation and/or using apply + instead of sum, and it doesn't cheat by using triangle-number:

AArch64 machine code, 20 bytes

00: 9b000000  madd x0, x0, x0, x0 // x = x * x + x
04: d341fc00  lsr x0, x0, #1      // x = x / 2
08: 9b000000  madd x0, x0, x0, x0 // x = x * x + x
0c: d341fc00  lsr x0, x0, #1      // x = x / 2
10: d65f03c0  ret

simple :)

use it as a function uint64_t f(uint64_t x). will overflow on inputs > 92681.

you could also use it as main (not _start unless you replace the ret with an exit syscall) and its input will be the argument count including the program name.

Moonscript/Yuescript, 18 bytes

(n)->(n^2-~n)^2//8

Try it online!

Bash/Zsh, 19 bytes

$[($1**2-~$1)**2/8]

Try it online!

J-uby, 12 bytes

(:+|:sum)**2

Attempt This Online!

AWK, 23 bytes

$0=int((1+$0^2+$0)^2/8)

Try it online!


This will also work if the input is 0 (28 thank to @Dominic van Essen 24 bytes):

$0=int((1+$0^2+$0)^2/8)a

Scala, 25 bytes

Saved 1 byte(s) thanks to the comment of @Jo King ♦


What's it?

Accroding to A002817, doubly triangular numbers are revealed in the sums of row sums of Floyd's triangle.

1, 1+5, 1+5+15, ...
             1
          2     3
       4     5     6
    7     8     9     10
11    12    13    14    15

Golfed version. Try it online!

n=>(1 to(1 to n).sum).sum

Ungolfed version. Try it online!

object Main {
  def main(args: Array[String]): Unit = {
    def t(n: Int): Int = (1 to (1 to n).sum).sum
    println((0 to 9).map(t).map(_.toString).mkString(" "))
  }
}

K (ngn/k), 9 bytes

2{x+/!x}/

Try it online!

Neim, 4 bytes

𝐈𝐬𝐈𝐬

Explanation:

𝐈     # inclusive range
 𝐬    # sum range
  𝐈   # inclusive range
   𝐬  # sum range

Try it online!

ARBLE, 13 bytes

(n^2-~n)^2//8

Direct port of bluswimmer's port of tsh's answer, utilising ARBLE's more terse extensions.

Try it online!

Husk, 2 bytes

‼Σ

Try it online!

‼         # Apply function twice:
Σ         # Triangular number

(the more-boring ΣΣ is also 2 bytes...)

R, 19 bytes

\(n)sum(1:sum(1:n))

Attempt This Online!

minigolf, 7 bytes

2,,n;+_

Try it online!

Explanation

2,    _  Repeat 2 times:
  ,n;    Generate a [1..n] range
     +   Sum it

Implicit output

SAS IML, 18 bytes

The code:

o=sum(1:sum(1:n));

The code plus "environment" and nice printout:

proc IML;
  do n= 1 to 10;
    o=sum(1:sum(1:n));
    print n " => " o;
  end;
quit;

The log:

1    proc IML;
NOTE: IML Ready
2      do n= 1 to 10;
3        o=sum(1:sum(1:n));
4        print n " => " o;
5      end;
6    quit;
NOTE: Exiting IML.
NOTE: PROCEDURE IML used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

Output:

SAS IML Output

Acknowledgement:

Thank you to Mr. Roman Czyborra for the Haskel inspiration!

BQN, 9 6 bytes

-3 bytes thanks to att

+´⟜↕⍟2

Anonymous tacit function that takes a number and returns a number. Try it at BQN online!

Explanation

Same idea as Adám's APL answer, slightly complicated by the fact that BQN's ranges are 0-based.

Call the argument N:

+´⟜↕⍟2
   ↕     Range (0 to N-1)
+´       Fold on addition...
  ⟜     ... with a starting value of N
    ⍟2  Apply that function twice

Wolfram Language (Mathematica), 15 bytes

#@*#&@Tr@*Range

Try it online!

-1 byte from @att

Wolfram Language (Mathematica), 16 bytes

(f=Tr@*Range)@*f

Try it online!

Pyth, 4 bytes

sSsS

Try it online!

Explanation

sSsSQ    # implicitly add Q
         # implicitly assign Q = eval(input())
   SQ    # range 1 to Q
  s      # sum
 S       # range 1 to result
s        # sum

Extra nice since when pronounced out loud it is the sound a python makes.

Pyt, 2 bytes

△△

Try it online!

Uses the built-in for triangle number twice. Implicit input and output.

Vyxal Rss, 0 bytes


Try it Online!

That's right - with the power of subscription models, this task can be done in 0 bytes!

but how does Really Simple Syndication help you sum a range twice?

Well technically speaking it doesn't - of course there's no rss feed involved. What's happening is that the R flag coerces numbers to ranges when an iterable is needed, and the two s flags sum the top of the stack at the end of execution. Due to the way the flag handler is implemented, duplicate flags apply the flag effect multiple times.

Factor + math.unicode, 21 bytes

[ [1,b] Σ [1,b] Σ ]

Try it online!

Arturo, 18 bytes

$=>[∑1..∑1..&]

Try it!

Jelly, 4 bytes

RSRS

Attempt This Online!

Nobody golfing in Jelly anymore?

Haskell, 17 bytes

g.g
g n=sum[1..n]

Try it online!

Just implementing the definition seems to be shorter than arithmetical expressions such as

21 bytes

f n=((n^2+n+1)^2-1)/8

Try it online!

With floats:

17 bytes

g.g
g n=n*(n+1)/2

Try it online!

Nim, 36 bytes

func a[I](n:I):I=(n*n+n)*(n*n+n+2)/8

Attempt This Online!

Takes and returns a float (so I can use / instead of div).

Brain-Flak, 32 bytes

({({}[()])()}{})
({({}[()])()}{})

Try it online!

(The newline isn't needed, but is included because it makes the answer pretty)

Polygonal numbers are one of the things that brain-flak uniquely excels at. This is just the code that calculates the N-th triangular number, repeated twice.

# Push (the sum of...)
(
    # While the top of stack is not 0...
    {
        # Decrement the top of the stack by 1
        # This adds n-1 to the running counter
        ({}[()])

        # Plus 1 (to the running counter)
        ()
    }

    # Pop the stack (which should contain a 0 now)
    {}
)

Go, 41 37 bytes

func(n int)int{n=n*n-^n
return n*n/8}

Attempt This Online!

Rockstar, 68 54 bytes

listen to N
cast N
let N be*N+1
let X be N+2
say N*X/8

Try it here (Code will need to be pasted in)

Saved 12 byes thanks to c--'s suggestion to use a different formula.

Binary Lambda Calculus, 125 bits = 15.625 bytes

01000001 11001110 10000101 01100001 10010000 00000101 10011111 01110010
11110111 10110000 00001110 01011110 11010000 10110001 00000100 00010

Verify it online!

Encodes the following lambda term:

main = 2 rangesum where
  succ = \n f x. f (n f x)
  pair = \x y f. f x y
  snd = \p. p (\x y. y)
  update = \p. p (\x y f. f (succ x) (x succ y))
  rangesum = \n. snd (n update (pair 1 0))

This is a function that takes a positive integer in Church numeral and outputs the answer in the same form. The numbers that appear in the Haskell-like code above are also Church numerals, e.g. 2 = \f x. f (f x).

Julia, 16 bytes

!n=(n^2-~n)^2÷8

Attempt This Online!

The formula looks a bit shorter than directly writing out the sums.

x86-16 machine code, 13 bytes

00000000: 8ad8 43f6 e340 f7e0 b103 d3e8 c3         ..C..@.......

Listing:

8A D8       MOV   BL, AL        ; BL = x 
43          INC   BX            ; BL = x + 1 
F6 E3       MUL   BL            ; AX = x * (x + 1) 
40          INC   AX            ; AX = x * (x + 1) + 1 
F7 E0       MUL   AX            ; AX = AX * AX 
B1 03       MOV   CL, 3 
D3 E8       SHR   AX, CL        ; AX = AX >> 3
C3          RET                 ; return to caller

Callable with input n in AL, output in AX.

Uses the formula (x*(x+1)+1)^2>>3.

enter image description here

Haskell, 21 bytes

t n=sum[1..sum[1..n]]

Try it online!

Retina 0.8.2, 19 bytes

.+
$*
1
1$`
1
1$`
1

Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

1
1$`

Sum of range.

1
1$`

Sum of range.

1

Convert to decimal.

C (gcc), 22 bytes

With unsequenced modification and access to n

f(n){n*=~n;n=--n*n/8;}

Try it online!

C (clang), 26 bytes

With unsequenced modification and access to n

f(n){n*=~n;return--n*n/8;}

Try it online!

C89, 28 bytes

f(n){n*=~n;return(n-2)*n/8;}

Try it online!

Explanation

f(n){n*=~n;return--n*n/8;}  // function which takes and returns an integer
     n*=~n;                 // n *= -(n + 1); here (n = -(n*n + n))
                 --n        // decrement n;   here (n = -(n*n + n + 1))
           return  n*n/8;   // return (n*n + n + 1)^2 / 8

Python, 23 bytes

-7 bytes thanks to c--'s suggestion based on tsh's answer.

lambda n:(n*n-~n)**2//8

Attempt This Online!

Python, 38 bytes

lambda n:sum(range(sum(range(n+1))+1))

Attempt This Online!

Nibbles, 2 bytes (4 nibbles)

+,+,

Attempt This Online!

Explanation

+,+,$
    $  Input number (implicit)
   ,   Range from 1 to that number
  +    Sum
 ,     Range from 1 to that number
+      Sum

Vyxal, 4 bytes

ɾ∑ɾ∑

Try it Online!

Uses the straightforward approach: ɾ gets the range from 1 through its argument, and sums. Rinse and repeat.

SAS 4GL, 22 23 bytes

The code:

o=n*(n+1)*(n*n+n+2)/8;

The code plus "environment" and nice printout:

data;
  do n = 1 to 10;
    o=n*(n+1)*(n*n+n+2)/8;
    put n "-> " o;
  end;
run;

The log:

1    data;
2      do n = 1 to 10;
3        o=n*(n+1)*(n*n+n+2)/8;
4        put n "-> " o;
5      end;
6    run;

1 -> 1
2 -> 6
3 -> 21
4 -> 55
5 -> 120
6 -> 231
7 -> 406
8 -> 666
9 -> 1035
10 -> 1540
NOTE: The data set WORK.DATA4 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

PARI/GP, 16 bytes

-2 byte thanks to @tsh.

n->(1+n^2+n)^2\8

Attempt This Online!

Lua, 24 bytes

print((...^2-~...)^2//8)

Try it online!

Based off tsh's answer, though it's been modified a bit to better fit Lua.

PHP, 25 bytes

fn($n)=>($n**2-~$n)**2>>3

Attempt This Online!

Thunno 2, 4 bytes

RSRS

Attempt This Online!

Range, sum, range, sum.

Java, 18 17 bytes

n->(n=n*n-~n)*n/8

Port of @tsh' JavaScript answer, so make sure to upvote him/her as well.
-1 byte thanks to @tsh.

Try it online.

(n=n*n-~n) could alternatively be (n+=n*n+1) for the same byte-count:
Try it online.

Explanation:

n->               // Method with integer as both parameter and return-type
  (n=             //  Replace `n` with:
     n*n          //   `n` squared
        -~n)      //   `+n+1`
            *n    //  Square that new `n`
              /8  //  Integer-divide that by 8 to get the result

A literal implementation would be 56 bytes in comparison:

n->{int t=0;for(;n>0;)t+=n--;for(;t>0;)n+=t--;return n;}

Try it online.

Explanation:

n->{          // Method with integer as both parameter and return-type
  int t=0;    //  Temp-integer, starting at 0
  for(;n>0;)  //  Loop `n` down until it's 0:
    t+=n      //   Add the current `n` to the temp-integer `t`
        --;   //   And then decrease `n` by 1
              //  (at this point, `n=0`)
  for(;t>0;)  //  Now loop `t` down until it's 0:
    n+=t      //   Add the current `t` to `n`
        --;   //   And then decrease `t` by 1
  return n;}  //  Return the modified `n` as result

JavaScript (Node.js), 17 bytes

x=>(x*x-~x)**2>>3

Try it online!

Thanks Kevin Cruijssen for -1 byte.

MathGolf, 4 bytes

╒Σ╒Σ

Try it online.

Explanation:

╒     # Push a list in the range [1, (implicit) input-integer]
 Σ    # Sum it together
  ╒   # Pop and push a list in the range [1, sum]
   Σ  # Sum it together again
      # (after which the entire stack is output implicitly as result)

05AB1E, 4 bytes

LOLO

Try it online or verify all test cases.

Explanation:

L     # Push a list in the range [1, (implicit) input-integer]
 O    # Sum this list together
  L   # Pop and push a list in the range [1, sum]
   O  # Sum this list together again
      # (after which the result is output implicitly)

Laughing Out Loud! Out??

An equal-bytes alternative could be: 2FLO, where 2F is loop 2 times:
Try it online or verify all test cases.

Charcoal, 10 bytes

I÷⍘12320N⁸

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

   12320    Literal string `12320`
  ⍘         Interpret as base
        N   First input as a number
 ÷          Integer divide by
         ⁸  Literal integer `8`
I           Cast to string
            Implicitly print

The boring solution is 8 bytes:

IΣ…·Σ…·N

Try it online! Link is to verbose version of code. Explanation: InclusiveRange prefers two arguments, but fortunately we can arrange to use the one-argument version (twice, saving two bytes).

       N    First input as a number
     …·     Inclusive range from `1` to that
    Σ       Take the sum
  …·        Inclusive range from `1` to that
 Σ          Take the sum
I           Cast to string
            Implcitly print

Japt -x, 5 bytes

õ x õ

Try it

><> (Fish), 13 bytes

i:1+*2,:1+*2,n;

Try it

Just the triangle number formula copied twice

Excel, 26 24 bytes

=A1*(A1+1)/8*(A1^2+A1+2)

Input in cell A1.

Ly, 6 bytes

R&+R&+

Try it online!

A pretty direct mapping of the rules of the contest to Ly instructions for this one...

R      - Generate range of numbers from 0 to STDIN
 &+    - Sum the stack
   R   - Generate range of numbers again, from 0 to top-of-stack
    &+ - Sum the stack
       - Top of stack printed as a number be default on exit

APL (Dyalog Unicode), 6 bytes

Anonymous tacit prefix function.

+/∘⍳⍣2

Try it online!

+/ the sum

 of

 the range

⍣2 twice

C, 65 bytes

f(n){int i=10;for(;i>1;)n+=i--;for(;n>1;)i+=n--;printf("%d",i);}

Earlier attempts

73 bytes

main(){int i=0,n=10;for(;n>0;)i+=n--;for(;i>0;)n+=i--;printf("%d\n",n);}

70 bytes

main(n){int i=10;for(;i>1;)n+=i--;for(;n>1;)i+=n--;printf("%d\n",i);}