g | x | w | all
Bytes Lang Time Link
091Tcl180404T203616Zsergiol
033AWK250326T205042Zxrs
004Uiua250323T232014ZjanMakos
004250323T223608ZJoao-3
001Vyxal 3 s240129T193817Zpacman25
020Pari/GP170805T031909Zalephalp
002Thunno 2 S230615T171640ZThe Thon
006J170804T220414ZConor O&
008K ngn/k221014T012834Zoeuf
nanFig221013T145658ZSeggan
014Factor + math.unicode221013T055211Zchunes
002Vyxal221013T050600ZDialFros
060Zsh180807T042302ZNoskcaj
055EXCEL180807T023518Zremoel
050C gcc180312T153049Zvazt
008Gol><>180406T170133ZBubbler
006Add++180121T171958Zcaird co
029Ruby180121T193515ZAsone Tu
013Perl 6180210T025643ZJarrod F
052Common Lisp180121T074743ZRenzo
079SNOBOL4 CSNOBOL4170804T195443ZGiuseppe
nanPerl 5170804T200357ZXcali
075R180121T194151ZFlorian
106Python 3180121T163701ZNathan D
054Python 3180121T092117ZManish K
064Scala180121T131915Z6infinit
036BrainFlak170804T202219ZDJMcMayh
006Pyt171226T003926Zmudkip20
053Java 8170804T213154ZJakob
040TXR Lisp170804T221111ZKaz
021Röda170807T154143Zfergusq
057Excel VBA170808T121153ZTaylor R
056Math++170807T182011ZSuperJed
004TIBASIC170807T174953Zcalc84ma
026Clojure170807T153844ZMattPutn
032Vim170804T220501Zბიმო
1478Taxi170807T142239ZEngineer
060Excel VBA Immediate Window170807T135418ZEngineer
056Python 2170805T200828ZRohit-Pa
032Ruby170805T141454ZIdva
003Neim170805T111450ZOkx
046Python 2170805T060221Z0xffcour
028BrainFlak170805T044227ZWheat Wi
055PHP170804T233006ZWebSmith
013Haskell170804T213017ZH.PWiz
004APL170804T225615Zmarinus
049Mathematica170804T225539ZZaMoC
013Retina170804T221638ZNeil
002Husk170804T204432Zბიმო
024Bash + GNU utilities170804T204617ZDigital
035Python 3170804T205404ZJonathan
059C# .NET Core170804T205050ZKamil Dr
00305AB1E170804T195924ZAdnan
068C# .NET Core170804T203106ZGrzegorz
045Python 2170804T200829Ztotallyh
037Python 3170804T203318ZBusiness
025Haskell170804T202006ZWheat Wi
028JavaScript ES6170804T202828ZETHprodu
004Jelly170804T195837ZJonathan
004Pyth170804T201616ZMaltysen
003Jelly170804T202202ZETHprodu
058Python 3170804T201713ZHalvard
004Japt170804T195101ZETHprodu
003MATL170804T201055ZDJMcMayh
080C# .NET Core170804T200720ZIan H.
040PowerShell170804T195725ZAdmBorkB
003Gaia170804T200416ZBusiness
034JavaScript ES6170804T200013ZArnauld
056Python 2170804T195757ZRod

Tcl, 91 bytes

proc T n {time {append s +[join [split $n ""] +]
regsub .$ $n "" n} [string le $n]
expr $s}

Try it online!


# [Tcl], 91 bytes
proc T n {time {append s +[join [split $n ""] +]
regsub .$ $n "" n} [string le $n]
expr $s}

Try it online!


Tcl, 93 bytes

proc T n {time {incr s [expr [join [split $n ""] +]]
regsub .$ $n "" n} [string le $n]
set s}

Try it online!


# [Tcl], 97 bytes
proc T n {time {incr s [expr [regsub -all (.) $n +\\1]]
regsub .$ $n "" n} [string len $n]
set s}

Try it online!


# [Tcl], 105 bytes
proc T n {time {incr s [expr [join $L +]]
set L [lreplace $L e e]} [llength [set L [split $n ""]]]
set s}

Try it online!

AWK, 33 bytes

{for(;i++<NF;)g+=$i*(NF-i+1)}$0=g

Attempt This Online!

Uiua, 4 bytes

/+\+

Takes input as a list of digits.

Similar to many other entries, it computes the prefix sum, then sums the result.

, 4 chars

code

󷺹Ϝ+⨁

Test it here!

Takes input as a list of digits, but the test link above makes it take an actual integer. Simply does the sum of cumulative sums.

Vyxal 3 s, 1 byte

@

Try it Online!

yay

Pari/GP, 20 bytes

Takes the input as a list of digits.

a->a*Colrev([1..#a])

Try it online!


Pari/GP, 15 bytes

Takes the input as a polynomial. For example, 5*x^4 + 3*x^3 + 7*x^2 + x + 6 means 53716.

a->(a+a')%(x-1)

Try it online!

Thunno 2 S, 2 bytes

ƒʂ

Attempt This Online!

Explanation

ƒʂ  # implicit input  ->  654321
ƒ   # preƒixes        ->  [[6], [6,5], [6,5,4], [6,5,4,3], [6,5,4,3,2], [6,5,4,3,2,1]]
 ʂ  # ʂum each list   ->  [6, 11, 15, 18, 20, 21]
    # sum this list   ->  91
    # implicit output

J, 7 6 bytes

1#.+/\

Try it online! Takes a list of digits, such as f 6 5 4 3 2 1.

Explanation

The current explanation is same as the old, but noting that 1#.x+/x (both compute sum).

Old:

[:+/+/\    (for explanation, input = 6 5 4 3 2 1)
      \    over the prefixes of the input:
     /         reduce:
    +              addition (summation)
           this gives is the cumulative sum of the input:  6 11 15 18 20 21
[:         apply to the result:
  +/           summation
           this gives the desired result:   90

A little more true to the original problem would be [:+/@,]/, which is "sum" (+/) the flattened (,) prefixes of the input (]\).

K (ngn/k), 10 8 bytes

+/+\.'$:

Try it online!

-2 bytes thanks to ngn

Pretty basic train.

Explanation:

+/+\.'$:    Main function. Takes implicit input with Right (:)
      $     Convert input to string
     '      For each of the characters
    .       Eval them, converting them into a number
  +\        Cumulative sum
+/          Sum

Fig, \$2\log_{256}(96)\approx\$ 1.646 bytes

Sk

Try it online!

Sk # Takes a list of digits as input
 k # Prefixes
S  # Sum of the automagically flattened list

Factor + math.unicode, 14 bytes

[ cum-sum Σ ]

Try it online!

Vyxal, 2 bytes

¦∑

Try it Online!

Explained

¦∑
¦  # cumulative sum
 ∑ # sum

Zsh, 60 bytes

f(){echo $((${(j:+:)${(@f)$(for i in $@;echo $((x+=i)))}}))}

Try it online!

Takes input as individual parameters

EXCEL, 55 bytes

Using Immediate Window.

[A65:A89]="=MID(REPT(CHAR(ROW())&CHAR(ROW()+1),2),1,3)"

C (gcc), 51 50 bytes

-1 byte thanks to @ceilingcat

i,r;f(t,l)int*t;{for(;l;)for(i=--l;~i;)r+=t[i--];}

Try it online!

Gol><>, 8 bytes

IEh@+:@+

Try it online!

Input format is space-separated digits.

How it works

IEh@+:@+

I         Take next input as number
 E        If last input was EOF...
  h       Print the top as number and halt
          Otherwise...
          The stack looks like [sum_of_digits triangle digit]
   @      Move 3rd from top (sum_of_digits) to the top
    +     Add top two (update `sum_of_digits`)
     :    Duplicate top
      @+  Add `sum_of_digits` to `triangle`
          Repeat from the beginning

Add++, 11 6 bytes

L~,¬+s

Try it online!

Ruby 29 bytes

f=->n{*a,b=n;b ?n.sum+f[a]:0}

Try it online!

Perl 6, 13 bytes

Takes a list of digits

{[+] [\+] @_}

Try it online!

Perl 6 has a produce routine, which can be more tersely invoked using the 'triangle reduce' meta operator: [\ ]. Seems like it was made for this task.

Common Lisp, 53 52 bytes

(loop as(x . y)on(reverse(read))sum(+(reduce'+ y)x))

Input as list of digits.

Try it online!

-1 byte thanks to @ceilingcat.

SNOBOL4 (CSNOBOL4), 79 bytes

	N =INPUT
D	N LEN(1) . D REM . N	:F(O)
	X =X + D
	Y =Y + X	:(D)
O	OUTPUT =Y
END

Try it online!

Input from stdin, output to stdout.

Perl 5, 19 + 1 (-p) = 20 bytes

s/./$\+=$p+=$&/ge}{

Try it online!

How?

$\ holds the cumulative total, $p holds the total of the digits on the current line. Each line of the parallelogram is simply the previous line with the next digit of the number appended. Therefore, it is the sum of the previous line plus the new digit. This iterates over all of the digits, calculating the sums as it goes. The actual substitution is irrelevant; it's just a means to iterate over the digits without creating an actual loop. At the end, $\ is printed implicitly by the -p option.

R, 75 bytes

function(x,b=nchar(x))sum(sapply(x%/%10^(0:b),function(y)y%/%10^(0:b)%%10))

Try it online!


I did not see an R solution yet, so here goes..

Python 3, 106 bytes

a=input()
c=[]
d=0
b=[int(g) for g in a]
for i in range(1,len(a)+1):
    c+=b[0:i]
for t in c:
    d+=t
print(d)

Try It Online!

My original code was:

a,c,d=input(),[],0
b=[int(g) for g in a]
for i in range(1,len(a)+1):
    c+=b[0:i]
for t in c:
    d+=t
print(d)

But then I realized that by initializing all of my variables on one line, I gained two characters. :P

Python 3, 94 58 54 bytes

Thanks to Mr. Xcoder for helping me save quite some bytes!

lambda n:sum(int(v)*(len(n)-i)for i,v in enumerate(n))

Try It Online!

Takes input as a string. It simply multiplies each digit by the number of times it needs to be added and returns their sum.

Scala, 64 bytes

def f(s:String)=s.indices.flatMap(i=>s.take(i+1).map(_-'0')).sum

Brain-Flak, 65, 50, 36 bytes

([])({<{}>{<({}[()])>[]}{}<([])>}{})

Try it online!

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nicely it can be expressed in brain-flak.

Most of the byte count comes from handling 0's in the input. In fact, if we could assume there were no 0's in the input, it would be a beautifully short 20-byte answer:

({{<({}[()])>[]}{}})

Try it online!

But unfortunately, brain-flak is notorious for bad handling of edge cases.

Explanation

First, an observation of mine:

If the input is n digits long, the first digit will appear in the triangle n times, the second digit will appear n-1 times, and so on onto the last digit, which will appear once. We can take advantage of this, since it's really easy to calculate how many digits of input are left in brain-flak, namely

[]

So here's how the code works.

# Push the size of the input (to account for 0's)
([])

# Push...
(

    # While True
    {

        # Pop the stack height (evaluates to 0)
        <{}>

        # For each digit *D*...

        # While true
        {

            # Decrement the counter (the current digit we're evaluating), 
            # but evaluate to 0
            <({}[()])>

            # Evaluate the number of digits left in the input
            []

        # Endwhile
        }

        # This whole block evaluates to D * len(remaining_digits), but 
        # without affecting the stack

        # Since we looped D times, D is now 0 and there is one less digit.
        # Pop D (now 0)
        {}

        # Push the stack height (again, evaluating it as 0)
        <([])>

    # End while
    }

    # Pop a 0 off (handles edge case of 0)
    {}

# end push
)

Pyt, 9 6 bytes

ąĐŁř↔·

Explanation:

                 Implicit input
ą                Convert to array of digits
 Đ               Duplicate digit array
   Łř↔           Create a new array [len(array),len(array)-1,...,1]
      ·          Dot product with digit array
                 Implicit output

Java 8, 53 bytes

I implemented a lambda for each acceptable input type. They each iterate through the number's digits, adding the proper multiple of each to an accumulator.

Integer as input (53 bytes)

Lambda from Integer to Integer:

n->{int s=0,i=1;for(;n>0;n/=10)s+=n%10*i++;return s;}

String representation as input (72 bytes)

Lambda from String to Integer:

s->{int l=s.length(),n=0;for(int b:s.getBytes())n+=(b-48)*l--;return n;}

Digit array as input (54 bytes)

Lambda from int[] (of digits, largest place value first) to Integer:

a->{int l=a.length,s=0;for(int n:a)s+=n*l--;return s;}

TXR Lisp, 67 40 bytes

(opip digits reverse conses flatten sum)

Run:

1> (opip digits reverse conses flatten sum)
#<intrinsic fun: 0 param + variadic>
2> [*1 53716]
66

Note that if we take advantage of the input being a list of integers representing digits, this reduces to:

(opip reverse conses flatten sum)

and if the digits may be in reverse order already, then just

(opip conses flatten sum)

Note also that this is a "useless use of opip"; all the terms are function names, and so [chain digits reverse conses flatten sum] could be used, and that would be the recommended way to code this; it's just one character longer.

Röda, 31 21 bytes

{i=0{[i]if i+=_}|sum}

Try it online!

Takes the input as a stream of digits.

31 bytes

{addHead 0|reduceSteps _+_|sum}

Try it online!

Takes the input as a stream of digits.

Explanation:

{addHead 0|reduceSteps _+_|sum} /* An anonymous function */
 addHead 0                      /* Append 0 to the beginning of the stream */
          |reduceSteps _+_      /* Create a cumulative sum */
                          |sum  /* Sum all numbers in the stream */

The reduceSteps function does not return the first item in the stream, so it is necessary to add a zero at the head of the stream.

Excel VBA, 57 Bytes

Anonymous VBE immediate window function that takes input from the range [A1], and outputs the triangle sum described above to the VBE immediate window

l=[Len(A1)]:For i=1To l:s=s+Mid([A1],i,1)*(l+1-i):Next:?s

Math++, 56 bytes

?>n
n>g
o+g%10>o
_(g/10)>g
3+3*!g>$
_(n/10)>n
2+6*!n>$
o

TI-BASIC, 4 bytes

sum(cumSum(Ans

Takes a list of digits as input, and calculates the sum of the cumulative sum (i.e. prefix sum) of the list.

The cumSum( token is 2 bytes large.

Clojure, 26 bytes

#(apply +(reductions + %))

There's a built-in, but in standard Clojure fashion, it's a long-ass word. Takes input as a list of digits.

Vim, 60 59 32 keystrokes

Thanks a lot @CowsQuack for the tip with the recursive macro and the h trick, this saved me 27 bytes!

qqYp$xh@qq@qVHJ:s/./&+/g⏎
C<C-r>=<C-r>"0⏎

Try it online!

Ungolfed/Explained

This will build the triangle like described (only that it keeps it left-aligned):

qq       q    " record the macro q:
  Yp          "   duplicate the line
    $x        "   remove last character
      h       "   move to the left (this is solely that the recursive macro calls stop)
       @q     "   run the macro recursively
          @q  " run the macro

The buffer looks now like this:

53716
5371
537
53
5

Join all lines into one and build an evaluatable expression from it:

VH             " mark everything
  J            " join into one line
   :s/./&+/g⏎  " insert a + between all the characters

The " register now contains the following string (note missing 0):

5+3+7+1+6+ +5+3+7+1+ +5+3+7+ +5+3+ +5+ +

So all we need to do is append a zero and evaluate it:

 C                " delete line and store in " register
  <C-r>=       ⏎  " insert the evaluated expression from
        <C-r>"    " register "
              0   " append the missing 0

inside vim

Taxi, 1478 bytes

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.Go to Chop Suey:n 1 r 1 l 4 r 1 l.[a]Switch to plan "b" if no one is waiting.Pickup a passenger going to The Babelfishery.Go to Zoom Zoom:n 1 l 3 r.1 is waiting at Starchild Numerology.Go to Starchild Numerology:w 4 l 2 r.Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to Addition Alley.Go to The Babelfishery:n 1 r 1 r.Go to Chop Suey:n 6 r 1 l.Switch to plan "a".[b]Go to Addition Alley:n 1 l 2 l.Pickup a passenger going to Cyclone.[c]Go to Zoom Zoom:n 1 l 1 r.Go to Cyclone:w.Pickup a passenger going to The Underground.Pickup a passenger going to Multiplication Station.Go to The Babelfishery:s 1 l 2 r 1 r.Pickup a passenger going to Multiplication Station.Go to Multiplication Station:n 1 r 2 l.Pickup a passenger going to Addition Alley.Go to The Underground:n 2 l 1 r.Switch to plan "d" if no one is waiting.Pickup a passenger going to Cyclone.Go to Addition Alley:n 3 l 1 l.Switch to plan "c".[d]Go to Addition Alley:n 3 l 1 l.[e]Pickup a passenger going to Addition Alley.Go to Zoom Zoom:n 1 l 1 r.Go to Addition Alley:w 1 l 1 r.Pickup a passenger going to Addition Alley.Switch to plan "f" if no one is waiting.Switch to plan "e".[f]Go to Zoom Zoom:n 1 l 1 r.Go to Addition Alley:w 1 l 1 r.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:n 1 r 1 r.Pickup a passenger going to Post Office.Go to Post Office:n 1 l 1 r.

Try it online!

Un-golfed:

[ Pickup stdin and split into digits ]
Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to Chop Suey.
Go to Chop Suey: north 1st right 1st left 4th right 1st left.
[a]
[ Count the digits ]
Switch to plan "b" if no one is waiting.
Pickup a passenger going to The Babelfishery.
Go to Zoom Zoom: north 1st left 3rd right.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: west 4th left 2nd right.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: west 1st right 3rd right 1st right 1st right.
Pickup a passenger going to Addition Alley.
Go to The Babelfishery: north 1st right 1st right.
Go to Chop Suey: north 6th right 1st left.
Switch to plan "a".
[b]
Go to Addition Alley: north 1st left 2nd left.
Pickup a passenger going to Cyclone.
[c]
[ Multiply each digits by Len(stdin)-Position(digit) ]
Go to Zoom Zoom: north 1st left 1st right.
Go to Cyclone: west.
Pickup a passenger going to The Underground.
Pickup a passenger going to Multiplication Station.
Go to The Babelfishery: south 1st left 2nd right 1st right.
Pickup a passenger going to Multiplication Station.
Go to Multiplication Station: north 1st right 2nd left.
Pickup a passenger going to Addition Alley.
Go to The Underground: north 2nd left 1st right.
Switch to plan "d" if no one is waiting.
Pickup a passenger going to Cyclone.
Go to Addition Alley: north 3rd left 1st left.
Switch to plan "c".
[d]
Go to Addition Alley: north 3rd left 1st left.
[e]
[ Sum all the products ]
Pickup a passenger going to Addition Alley.
Go to Zoom Zoom: north 1st left 1st right.
Go to Addition Alley: west 1st left 1st right.
Pickup a passenger going to Addition Alley.
Switch to plan "f" if no one is waiting.
Switch to plan "e".
[f]
[ Output the results ]
Go to Zoom Zoom: north 1st left 1st right.
Go to Addition Alley: west 1st left 1st right.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: north 1st right 1st right.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st left 1st right.

Excel VBA Immediate Window, 60 bytes

a=StrReverse([A1]):For i=1 ToLen(a):b=b+i*Mid(a,i,1):Next:?b

Input is in cell A1 of the active sheet. Output is to the VBA immediate window.

Python 2, 56 bytes

lambda a:sum((i+1)*int(a[-i-1])for i in range(0,len(a)))

Try it online!

Some edit as suggested by @Mr.Xcoder

Python 2, 50 bytes

lambda a:sum(-~i*int(a[~i])for i in range(len(a)))

Try it online!

Ruby, 32 bytes

->a{b=a.pop;a[0]?b+a.sum+f[a]:b}

Try it online!

Neim, 3 bytes

𝐗𝐂𝐬

Explanation:

𝐗        Get prefixes of input, including itself
 𝐂       Implicitly join elements together, and create an array with all the digits
  𝐬      Sum

Try it online!

Alternative answer:

𝐗𝐣𝐬

Explanation:

𝐗       Get prefixes of input, including itself
 𝐣       Join
  𝐬      Implicitly convert to a digit array, and sum

Try it online!

Python 2, 46 bytes

f=lambda a:a and sum(map(int,a))+f(a[:-1])or 0

Try it online!

Brain-Flak, 28 bytes

(([]){[{}]({}<>{})<>([])}{})

Try it online!

14 bytes if we don't need to support zeros (which we do)

({({}<>{})<>})

Try it online!

DJMcMayhem has a cool answer here you should check out. Unfortunately for him I wasn't about to let him win at his own language :P

How does it work?

Lets start with the simple version.

({({}<>{})<>})

The main action here is ({}<>{})<>, that takes the top of the left stack and adds to to the top of the right stack. By looping this operation we sum up the current stack (until it hits a zero) placing the sum on the off stack. That's pretty mundane, the interesting part is that we sum up the results of all these runs as our result. This will calculate the desired value. Why? Well lets take a look at an example, 123. On the first grab we just get 1 so our value is 1

1

On the next grab we return 1 plus the 2

1
1+2

On the last run we have all three together

1
1+2
1+2+3

Do you see the triangle? The sum of all the runs is the "triangle" of the list.


Ok but now we need it to work for zeros, here I used the same trick as DJMcMayhem, plus some fancy footwork. Instead of looping until we hit a zero we loop until the stack is empty.

([])({<{}>({}<>{})<><([])>}{})

I then used this tip, written by none other than yours truly, to golf off another 2 bytes.

(([]){[{}]({}<>{})<>([])}{})

And there we have it. I would be surprised if there was a shorter solution, but then again stranger things have happened.

PHP, 51 55 bytes

+4 bytes—original version failed on all inputs with 0 as a digit.

<?php while($x!=$d=array_pop($argv))$t+=++$p*$d;echo$t;

Try it online!

EXPLANATION:

<?php

The programme takes separate digits as CLI parameter arguments, which arrive in the code as an array, $argv.

Each character at a time is popped from the end of the array. When the array is empty array_pop returns null. Null is detected by comparing the result to an undeclared variable $x, a saving of 2 code bytes over using null itself. (Without this comparison any 0 digit evaluates to false and the loop ends early.)

while ($x != $d = array_pop($argv))

$p is the position from the end i.e. the last digit (the first one popped) is in position 1. $p is undeclared and so equals 0, but is incremented before it is used each time, so starts off as 1.

The position is multiplied by the digit and added to the total $t.

    $t += ++$p * $d;

The final result is printed.

echo $t;

Haskell, 13 bytes

sum.scanl1(+)

Try it online!

Takes input as list of digits. Calculates the cumulative sums then sums them.

APL, 4 bytes

+/+\

This takes the input as a list of digits, e.g.:

      (+/+\) 5 3 7 1 6
66

Explanation

+/    sum of
  +\  partial sums of input

Mathematica, 49 bytes

Tr@Array[Tr@s[[;;#]]&,Length[s=IntegerDigits@#]]&

Retina, 13 bytes

.
$`$&
.
$*
1

Try it online! Link includes test cases. Explanation: The first stage generates all the prefixes of the original number, the second stage converts each digit to unary, and the third stage takes the total.

Husk, 2 bytes

Thanks @H.PWiz for -2 bytes!

Σ∫

Try it online!

"Ungolfed"/Explained

Σ    -- sum all
 ∫   -- prefix sums

Bash + GNU utilities, 32 24

tac|nl -s*|paste -sd+|bc

Input read from STDIN.

Update: I see the input may be given as a list of digits. My input list is newline-delimited.

Try it online.

Explanation

tac                       # reverse digit list
   |nl -s*                # prefix line numbers; separate with "*" operator
          |paste -sd+     # join lines onto one line, separated with "+" operator
                     |bc  # arithmetically evaluate

Python 3, 35 bytes

I just noticed that this is only really a slight golf of Business Cat's answer in the end though!

f=lambda a:a>[]and sum(a)+f(a[:-1])

Try it online!

C# (.NET Core), 59 bytes

using System.Linq;N=>N.Reverse().Select((d,i)=>i*d+d).Sum()

Try it online!

Substantially different from the other C# answers. Input is a list of digits. All test cases included in the TIO link.

Could save a bunch of bytes if allowed to take input as a backwards list of digits with leading 0.

05AB1E, 3 bytes

Code

ηSO

Try it online!

Explanation

η      # Take the prefixes of the number
 S     # Split into single numbers
  O    # Sum all the numbers

C# (.NET Core), 84 68 bytes

a=>a.Select((x,i)=>a.Take(i+1).Sum(c=>c-48)).Sum()

Byte count also includes

using System.Linq;

Try it online!

Explanation:

a=>                     // Take a string
    a                   // Take the string as collection of chars
    .Select((x,i)=>     // Replace the collection with
        a.Take(i+1)     // Substrings increasing in size
        .Sum(c=>c-48))  // Sum each substring's digits (as ints) together
    .Sum()              // Sum the new collection of sums

I know it's a little bigger than there's already posted C# answer, but mine is coming from a different approach so I thought I will post it anyway.

Python 2, 49 45 bytes

-4 bytes thanks to Mr. Xcoder.

lambda n:sum(-~i*n[~i]for i in range(len(n)))

Try it online!

Takes input as a list of digits.

Python 3, 37 bytes

f=lambda n:len(n)and sum(n)+f(n[:-1])

Try it online!

Haskell, 25 bytes

Takes input as list of digits

f[]=0
f x=sum x+f(init x)

Try it online!

Haskell, 41 bytes

Takes input as string representation

f[]=0
f x=sum(map(read.(:[]))x)+f(init x)

Try it online!

JavaScript (ES6), 28 bytes

a=>a.map(d=>t+=c+=d,t=c=0)|t

Takes input as a list of digits.

Jelly,  5  4 bytes

Ṛæ.J

A monadic link taking a list of decimal digits and returning the triangle of the number that list represents.

Try it online!

How?

Ṛæ.J - Link: list of numbers (the decimal digits), d   e.g. [9,4,5,0]
Ṛ    - reverse d                                            [0,5,4,9]
   J - range(length(d))                                     [1,2,3,4]
 æ.  - dot-product            (0*1 + 5*2 + 4*3 + 9*4 = 58)  58

Pyth - 6 4 bytes

ss._

Try it online here.

Nice 6 byte one that doesn't use prefix builtin:

s*V_Sl

Jelly, 3 bytes

+\S

Try it online! Uses the same technique as my Japt answer: cumulative addition, then sum.

Python 3, 58 bytes

lambda n:sum(-~i*int(c)for i,c in enumerate(str(n)[::-1]))

Try it online!

Japt, 7 6 4 bytes

å+ x

Try it online!

Explanation

å+ x    Implicit: input = digit list
å+      Cumulative reduce by addition. Gives the sum of each prefix.
   x    Sum.

Old solution:

å+ ¬¬x

Try it online!

Explanation

å+ ¬¬x   Implicit: input = string
å+       Cumulative reduce by concatenation. Gives the list of prefixes.
   ¬     Join into a single string of digits.
    ¬    Split back into digits.
     x   Sum.
         Implicit: output result of last expression

MATL, 3 bytes

Yss

Try it online!

Takes the input as a list of digits.

C# (.NET Core), 80 bytes

n=>{int v=0,i=0;for(;i<n.Length;)v+=int.Parse(n[i]+"")*(n.Length-i++);return v;}

Try it online!

Takes a string as input and outputs the triangled number.


Explanation:

For each character in the input string, convert the char to an int and multiply it by the length of the string minus the index of the char.

PowerShell, 54 48 40 bytes

param($a)$a|%{$o+=$_*($a.count-$i++)};$o

Try it online!

Takes input as a list of digits.

Note that the output is just the input digit multiplied by its corresponding negative index in the string and then cumulatively summed. So, that's what we do here.

We loop over each element in the input list, each iteration perform a multiplication, and then sum the results together into the total $o+=. That's left on the pipeline, output is implicit.

Gaia, 4 3 bytes

…_Σ

Function accepting a list of digits and leaving the result on the stack.

Try it online!

Explanation

…    Prefixes
 _   Flatten
  Σ  Sum

JavaScript (ES6), 34 bytes

f=(n,i=1)=>n&&n%10*i+f(n/10|0,i+1)

Test cases

f=(n,i=1)=>n&&n%10*i+f(n/10|0,i+1)

console.log(f(0)) // -> 0
console.log(f(1)) // -> 1
console.log(f(12)) // -> 4
console.log(f(123)) // -> 10
console.log(f(999)) // -> 54 
console.log(f(100000)) // -> 6
console.log(f(654321)) // -> 91

Python 2, 56 bytes

lambda x:sum(i*int(`x`[-i])for i in range(1,1+len(`x`)))

Try it online!