Let me introduce you to GAU numbers

GAU(1) = 1
GAU(2) = 1122
GAU(3) = 1122122333
GAU(4) = 11221223331223334444
GAU(6) = 11221223331223334444122333444455555122333444455555666666
...
GAU(10) = 11221223331223334444122333444455555122333444455555666666122333444455555666666777777712233344445555566666677777778888888812233344445555566666677777778888888899999999912233344445555566666677777778888888899999999910101010101010101010


This challenge is pretty simple!

Given an integer n>0, find the number of digits of GAU(n)

Example

Let's make GAU(4)
we take the following steps (until we get to 4) and concatenate them

[1][122][122333][1223334444]


you must write every number as many times as its value, but you have to count every time from 1

Let's try to make GAU(5)
we will have to count from 1 to 1

[1]


then from 1 to 2 (but repeating every number as many times as its value)

[122]


then from 1 to 3

[122333]


then from 1 to 4

[1223334444]


and finally from 1 to 5 (this is the last step because we want to find GAU(5))

[122333444455555]


Now we take all these steps and concatenate them
the result is GAU(5)

11221223331223334444122333444455555


We are interested in the number of digits of these GAU numbers.

Test cases

Input⟼Output

n   ⟼ Length(GAU(n))

1   ⟼ 1
2   ⟼ 4
3   ⟼ 10
10  ⟼ 230
50  ⟼ 42190
100 ⟼ 339240
150 ⟼ 1295790


This is a challenge.
Shortest code in bytes will win.

If you still have any questions please let me know.
I really want everyone here to understand this magic-hidden-complex pattern

• What does GAU stand for? Sep 23, 2017 at 12:06
• G is for GAU, A and U are just there for no reason
– user72253
Sep 23, 2017 at 12:09
• Up until n=9, the lengths are tetrahedral numbers, but beyond that the multi-digit numbers get in the way of a simple closed form
– Miff
Sep 25, 2017 at 13:54
• FYI your test case says n ⟼ Length(GUA(n)), not GAU(n). Sep 28, 2017 at 1:18
• @numbermaniac thanks for spotting this. GUA numbers are totally different. They haven't been invented yet!
– user72253
Sep 30, 2017 at 19:00

SOGL V0.12, 111087 5 bytes

∫∫l*+


Try it Here! - this expects to be called as a function with the input on the stack and the input box empty.
7 byte alternative taking the input from the input box:

0.∫∫l*+


Try it Here!

0      push 0
.     push the input
∫    iterate over a range 1..POP (input) inclusive, pusing the current number
∫    iterate over 1..POP (above loops number) inclusive, pusing the current number
l    push that numbers length without popping the number
*   multiply the length by the number
+  add to the zero, or whatever it is now

• push that numbers length without popping the number nice Sep 23, 2017 at 12:16

f n=sum[j*length(show j)|i<-[1..n],j<-[1..i]]


Try it online!

• A bit more unreadable but one byte cheaper: TIO Sep 23, 2017 at 16:59

Brain-Flak, 166 bytes

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


Try it online!

Explanation

<>(((()()())({}){})())<>           # Initialize second stack with 9 and 10
{({}[()]<                          # Do main loop n times:
({}
({}
<
<>({}[()])                 # Subtract 1 from counter to next power of 10
((){[()](<()>)}{}){        # If reached a power of 10 (say, 10^k):
{}((((({})({})){}{}){})) # Multiply existing (10^k*0.9) by 10 and push twice
<>                       # On first stack
(
({}<({}())>)           # Increment length of numbers
{()<({}[({})])>}{}     # Divide length of new set of numbers by this length
)                        # Add together to get new set of numbers length
(<>)}
{}<>>
({}({})())                   # Add number length to number set length
)                              # Add number set length to new segment length
)                                # Add new segment length to total length
>)}                                # End main loop
{}({}<{}{}{}>)                     # Put result on stack by itself


Husk, 5 bytes

ṁLΣQḣ


Try it online!

Explanation

ṁ  map over
L  length
Σ  sum list
Q  all sublists
ḣ  range 1 .. N

• Nice algorithm! Sep 25, 2017 at 19:33

Jelly, 7 bytes

RxƤDFL


Try it online!

05AB1E, 5 bytes

LŒJJg


Try it online!

Explanation

L      # push [1 .. a]
Œ     # all substrings (a)
J    # numbers to strings (inner)
J   # numbers to strings (outer)
g  # length

• Welcome to the site :) Sep 25, 2017 at 5:01

Python 2, 53 bytes

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


Try it online!

• Sep 30, 2017 at 18:59

Husk, 7 bytes

Σ∫mS*Lḣ


Try it online!

Ungolfed/Explanation

         -- implicit input N                        | 10
m   ḣ  -- map the following function over [1..N]  | [1,2,3,4]
S*L   --   multiply length of number by itself   | [1,2,3,4] (only important for numbers ≥ 10)
∫       -- prefix sums                             | [0,1,3,6,10]
Σ        -- sum                                     | 20


Husk, 7 bytes

ṁLṁṘNḣḣ


Try it online!

Explanation

          Implicit input, e.g 4
ḣ   Range from 1 to n                               [1,2,3,4]
ḣ    Prefixes                                        [[],[1],[1,2],[1,2,3],[1,2,3,4]]
ṁ       Map and then concatenate
ṘN     Repeat each number in each list by its index    [[],[1],[1,2,2],[1,2,2,3,3,3],[1,2,2,3,3,3,4,4,4,4]]
[1,1,2,2,1,2,2,3,3,3,1,2,2,3,3,3,4,4,4,4]
ṁ         Map and then sum
L        Length (of number: 10 -> 2)                     26

• Oh another Husk solution :) Didn't see your submission when posting mine, same bytecount but they're sufficiently different, so I'll leave mine here too. Sep 23, 2017 at 12:34

JavaScript (ES6), 57 55 bytes

n=>[...Array(n)].reduce(x=>x+(++y+"").length*y*n--,y=0)


Try it online!

Python 2, 59 58 bytes

Another one bytes the dust thanks to Jonathan Frech.

f=lambda n:n and sum(i*len(i)for i in range(n+1))+f(n-1)


Try it online!

Not short but eh... what the heck.

• len(i)*i for -> i*len(i)for. Sep 23, 2017 at 17:54
• 53 bytes, non-recursive. Sep 23, 2017 at 22:46

CJam, 20 bytes

q~),(\{),{_s,*+}*+}%


Try it online!

The number is passed in the "input" field.

Ungolfed explanation: (example input = 2)

q~),(\{),{_s,*+}*+}%                                             | Stack:
q                     read input as string                       | "2"
~                    eval input (add it to stack as integer)    | 2
,                  range (convert to array with values 0...N) | [0, 1, 2]
(                 pop first item of array                    | [1, 2] 0
\                swap top two values of stack               | 0 [1, 2]
{           }   for each item in array...                  | 0 1
)              add 1                                      | 0 2
,             range (convert to array with values 0...N) | 0 [0, 1]
{     }      for every element in the array...          | 0 0
_           duplicate                                  | 0 0 0
s          convert to string                          | 0 0 "0"
,         get length of string                       | 0 0 1
*        multiply                                   | 0 0
*     fold                                       | 0 1
%  repeat                                     | 4


It seems hard when explained lol.

JavaScript (ES6), 50 42 bytes

Updated: now basically a port of what other answers are doing.

f=(n,i=1)=>n&&${n}.length*n*i+f(n-1,i+1)  Test cases f=(n,i=1)=>n&&${n}.length*n*i+f(n-1,i+1)

console.log(f(1))   // 1
console.log(f(2))   // 4
console.log(f(3))   // 10
console.log(f(10))  // 230
console.log(f(50))  // 42190
console.log(f(100)) // 339240
console.log(f(150)) // 1295790

J, 24 bytes

[:+/[:+/\[:(*#@":"0)1+i.


Similar high-level approach to dzaima's APL answer, translated into J, except we calculate the number's length by turning it into a string first instead of taking logs, and we get to use J's hook to multiply that length by the number itself: (*#@":"0). After that it's just the sum of the scan sum.

Try it online!

• 1(#.]*#\*#\.)1#@":@+i. also works for 22 bytes Sep 26, 2017 at 2:31
• @miles That's clever -- it took me a bit to figure it out. How long have been programming in J for? Sep 26, 2017 at 5:11
• A bit after I joined code-golf. I don't actually use it to write any real programs as no I know would be able to read it, but I do use it as an advanced desktop calculator now, and usually always have a window open to calculate something. Sep 26, 2017 at 5:47

R, 39 bytes

function(n)sum(nchar(rep(1:n,n:1*1:n)))


Verify all test cases!

Simple algorithm; I observed, as most did, that for i in 1:n, i is repeated i*(n-i+1) times. So I create that vector, count the number of characters in each, and sum them.

Perl 6, 36 bytes

{[+] 1..*Z*($_...1).map:{.chars*$_}}


Test it

Expanded:

{  # bare block lambda with implicit parameter ｢$_｣ [+] # reduce the following using &infix:«+» 1 .. * # Range from 1 to infinity Z* # zip using &infix:«*» ($_ ... 1 )    # sequence from the input down to 1
.map:           # for each one
{ .chars * $_ } # multiply the number of digits with itself }  Röda, 31 bytes {f={seq 1,_}f|f|[#$_*_1]|sum}


Try it online!

Python 2, 51 50 bytes

lambda n:sum(~k*(k-n)*len(k+1)for k in range(n))

• @LeakyNun Why? I developed this answer myself. I didn't even check the other answers.
– orlp
Sep 23, 2017 at 12:12
• This doesn't even output the right answer, gives 0 for n=1, 3 for n=2 and 14 for n=3 Sep 23, 2017 at 12:12
• @HalvardHummel Oops, messed up a sign and forgot a +1. Fixed now.
– orlp
Sep 23, 2017 at 12:16
• I see that you finally understood the patern! Is there a way to test your code online or the other Python 2 answer covers this, too?
– user72253
Sep 23, 2017 at 13:28

Mathematica, 66 bytes

Tr[1^(f=Flatten)[IntegerDigits/@f@(a=Array)[a[#~Table~#&,#]&,#]]]&


QBIC, 21 bytes

[:|[a|[c|A=A+!c$}?_lA  Actually, 13 bytes R♂R♂i⌠;n⌡Mεjl  Try it online! Explanation: R♂R♂i⌠;n⌡Mεjl R range(1, n+1) ♂R range(1, x+1) for x in previous ♂i flatten into 1D list ⌠;n⌡M for x in list: ;n repeat x x times εj concatenate to string l length  Japt, 121110 9 bytes õõÈ*sÊÃxx  Explanation Implicit input of integer U. õõ  Generate an array of integers from 1 to U and then generate sub-arrays from 1 to each integer. È Ã  Pass the elements of each sub-array through a function. *sÊ  Convert the current element to a string (s), get it's length (Ê) and multiply it by the element. xx  Reduce the main array by addition after first doing the same to each sub-array. Jq 1.5, 8249 43 bytes [range(.)+1|range(.)+1|"\(.)"*.|length]|add  Expanded [ range(.)+1 # for i=1 to N | range(.)+1 # for j=1 to i | "\(.)"*. # "j" copied j times | length # convert to length ] | add # add lengths  Sample Run $ jq -Mr '[range(.)+1|range(.)+1|"\(.)"*.|length]|add' <<< "150"
1295790


Stacked, 28 bytes

[~>[~>[:rep]"!]"!flat''##']


Try it online!

Some might ask, "At which point are aliases unreadable?" If this isn't close, you have a very liberal definition of "readability".

Explanation

[~>[~>[:rep]"!]"!flat''##']    input: N
~>[          ]"!               for each number K from 1 to N
~>[    ]"!                  for each number J from 1 to K
:rep                     repeat J J times
flat           flatten the resultant array
''#       join by the empty string
#'     get the length of said string


Ruby, 41 40 bytes

->n{(1..n).map{|x|[x]*x*=-x-~n}*''=~/\$/}


Try it online!

C# (.NET Core), 9480 74 bytes

n=>{int b=0,a=0,i;while(a++<n)for(i=0;i++<a;)b+=(i+"").Length*i;return b;}


Try it online!

I was hoping to find a direct solution like what @kamoroso94's answer started, but gave up as I was spending too much time on it. There probably is a way of doing it, but the formula needs to adjust for every magnitude step.

Acknowledgements

14 bytes saved thanks to @someone

6 bytes saved thanks to @Kevin Cruijssen

• n=>{int b=0,a=0,i;for(;a++<n;)for(i=0;i++<a;)b+=i.ToString().Length*i;return b;} Try it online! for 80 bytes and performance. Sep 24, 2017 at 10:54
• i.ToString() can be (i+"") to save some more bytes. Sep 25, 2017 at 7:42

MATL, 15 bytes

:ttP*Y"10&YlQks


Try it online!

Explanation:

:                range 1:input (implicit input)
tt              duplicate twice
P             reverse
*            multiply elementwise
Y"          runlength decoding
10&Yl     log10
Qk   increment and floor
s  sum (implicit output)

• That logarithm is expensive :-) You can replace it by converting to string, removing spaces, length: :ttP*Y"VXzn Oct 6, 2017 at 23:33

Charcoal, 18 14 bytes

ＩΣＥ⊕ＮΣＥ⊕ι×λＬＩλ


Try it online! Link is to verbose version of code. Edit: Using Sum saved me 4 bytes. Explanation:

  Ｅ⊕Ｎ           Map from 0 to the input (loop variable i)
Ｅ⊕ι       Map from 0 to i (loop variable l)
Ｉλ  Cast l to string
Ｌ    Take the length
×λ     Multiply by l
Σ          Sum the results
Σ              Sum the results
Ｉ               Cast to string
Implicitly print

• :| Sum sums numbers in the strings when given string arguments Oct 4, 2017 at 11:23
• @ASCII-only It wasn't that, it was just printing a Σ instead...
– Neil
Oct 4, 2017 at 12:36
• @ASCII-only Also, best I can do with Sum is still 18 bytes: Print(Cast(Sum(Map(InclusiveRange(1, InputNumber()), Sum(Map(InclusiveRange(1, i), Times(l, Length(Cast(l)))))))));
– Neil
Oct 4, 2017 at 12:46
• wait you keep forgetting Incremented :P Oct 4, 2017 at 12:50
• @ASCII-only I tried sum of product but that was 17 bytes: ≔⊕ＮθＩΣＥθ×⁻θι×ιＬＩι. However, using Incremented instead of InclusiveRange shaves 4 bytes off my previous comment!
– Neil
Oct 4, 2017 at 14:08

Ohm v2, 7 bytes

@@D×JJl


Try it online!

[Dyalog APL], 22 20 bytes

{+/≢¨⍕¨↑,/(/⍨¨⍳¨⍳⍵)}


Try it online!

Explanation:

{+/≢¨⍕¨↑,/(/⍨¨⍳¨⍳⍵)}
{                  } anonymous function with right argument named ⍵
⍳⍵   range 1 to right arg
⍳¨     for each, range 1 to it
¨       for each
/⍨          for each item, repeat right arg left arg times
(       )  take that and
,/           join the sub-arrays together
↑             convert from a nested array to a simple array (or something like that, I don't quite understand it :p)
⍕¨              convert each number to a char-array (aka string version)
≢¨                get length of each
+/                  sum that together