[Question]
  [
# 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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") 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
  
[Answer]
# [SOGL V0.12](https://github.com/dzaima/SOGL), ~~11~~ ~~10~~ ~~8~~ ~~7~~ 5 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md)
```
∫∫l*+
```
[Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JXUyMjJCJXUyMjJCbCorRiUwQTEwJXUyMDFEckY_) - 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!](https://dzaima.github.io/SOGLOnline/?code=MC4ldTIyMkIldTIyMkJsKis_,inputs=MTA_)
```
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
```
[Answer]
# [Haskell](https://www.haskell.org/), 45 bytes
```
f n=sum[j*length(show j)|i<-[1..n],j<-[1..i]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz7a4NDc6SysnNS@9JEOjOCO/XCFLsybTRjfaUE8vL1YnC8LKjI39n5uYmadgq5CSr8DFmZtY4KugUVCUmVeil6apAFJiaBCLKW5qoGNoAMSmBrH/AQ "Haskell – Try It Online")
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 166 bytes
```
<>(((()()())({}){})())<>{({}[()]<({}({}<<>({}[()])((){[()](<()>)}{}){{}((((({})({})){}{}){}))<>(({}<({}())>){()<({}[({})])>}{})(<>)}{}<>>({}({})())))>)}{}({}<{}{}{}>)
```
[Try it online!](https://tio.run/##JY2xCoAwDER/JzcIOriF/Ih0qIMgioNr6LfXO5smJG3vXva3ns903PXq3cMY0IFlA5OTR/KyGYqzM5268QCqU4O5IdDkoUQhL4uMAYLg9AoBatPgP4V/BSGV@Y/wiLFHyzGwcoqULdD7ss4f "Brain-Flak – 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
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 bytes
```
ṁLΣQḣ
```
[Try it online!](https://tio.run/##yygtzv7//@HORp9ziwMf7lj8//9/QwMA "Husk – Try It Online")
**Explanation**
```
ṁ  map over
 L  length
  Σ  sum list
   Q  all sublists
    ḣ  range 1 .. N
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
Rx`ƤDFL
```
[Try it online!](https://tio.run/##y0rNyan8/z@oIuHYEhc3n////xsaAAA "Jelly – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
LŒJJg
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f5@gkL6/0//8NDQA "05AB1E – Try It Online")
**Explanation**
```
L      # push [1 .. a]
 Œ     # all substrings (a)
  J    # numbers to strings (inner)
   J   # numbers to strings (outer)
    g  # length
```
[Answer]
# [Python 2](https://docs.python.org/2/), 53 bytes
```
lambda x:sum(len(`i`)*i*(x-i+1)for i in range(1,x+1))
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaHCqrg0VyMnNU8jITNBUytTS6NCN1PbUDMtv0ghUyEzT6EoMS89VcNQpwIoqPkfLhxtqGOkY6xjaKBjagAkgdjUINaKi7OgKDOvRCNNIxOoGAA)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
Σ∫mS*Lḣ
```
[Try it online!](https://tio.run/##yygtzv7//9ziRx2rc4O1fB7uWPz//39DAwMA "Husk – 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
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
ṁLṁṘNḣḣ
```
[Try it online!](https://tio.run/##yygtzv7//@HORh8gfrhzht/DHYuB6P///4amBgA "Husk – 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
```
[Answer]
# JavaScript (ES6), ~~57~~ 55 bytes
```
n=>[...Array(n)].reduce(x=>x+(++y+"").length*y*n--,y=0)
```
[Try it online!](https://tio.run/##BcFLCoAgEADQu7SayRxatlHoHNFCbOiDjKEVenp773Kfyz6d96Mlbtx8lBwDU4g7QBNjFyKaU3IVBFdKvL2eoRhbFChVVdchBZb9Ofrai9ZDNSM2hAmx/Q)
[Answer]
# [Python 2](https://docs.python.org/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!](https://tio.run/##PYnBCoMwEAXvfsUed2sKieJF8EtKwRRNXdCnxPTg18ecOjBzmeNKy44m5zCsfvtMntCDPCY6fxvrY53Bo44S9khKCooe35lRO5E6MJ5O8v@9nGlMa5w1nS0tdvbdV1Q4oiJxYBXJNw "Python 2 – Try It Online")
Not short but eh... what the heck.
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 20 bytes
```
q~),(\{),{_s,*+}*+}%
```
[Try it online!](https://tio.run/##S85KzP3/v7BOU0cjplpTpzq@WEdLuxaIVP//BwA "CJam – 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
  )                   add 1                                      | 3
   ,                  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
              +       add                                        | 0 1
                *     fold                                       | 0 1
                 +    add                                        | 1
                   %  repeat                                     | 4
```
It seems hard when explained lol.
[Answer]
# 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
```
[Answer]
# 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!](https://tio.run/##y/r/P91WTyHaSlsfhGOirTS0lB2UrJQMNA21M/W4UpMz8hXSFQxhDCMYwxguZYBgGfz/DwA "J – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 39 bytes
```
function(n)sum(nchar(rep(1:n,n:1*1:n)))
```
[Verify all test cases!](https://tio.run/##DYhBCoAwDMC@00oPG7LLwMeM4lDQWjp38PW1hyQQ8755n8Lv@QgIjnmD8NEMbFfIVUhqXqKI6KOpXh9w/JVyopLCQUlIHf0H)
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.
[Answer]
# [Perl 6](https://perl6.org), 36 bytes
```
{[+] 1..*Z*($_...1).map:{.chars*$_}}
```
[Test it](https://tio.run/##ZY5NTsMwEIX3PsUsIpSfMq2dpChERWzZs@JHUXCmIlJ@rDhFoJKzcBBYcRQuEuzUrNjY7z1/88aKhmY7HzTByxZlzto3OJN9RbCbj/fRI3DE8C70vQIReYBtqS6PKJ/LQYdeMU2z4a9H0iPsoKk70r5jGMA7yr598tcPVbQOvj/xphtX4BVsYnbdrRnKmWrKDqKlIWf7fnBl51fge3WnDnaCXhXJkSojK9IyAFtea7DfdFTwH2PTzAHg5@MLzM2E04nR8V@@McYe1ojYCGCps4ng2el5s/g4zkSyBOkp4CJLLyzyCw "Perl 6 – Try It Online")
## 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
}
```
[Answer]
# [Röda](https://github.com/fergusq/roda), 31 bytes
```
{f={seq 1,_}f|f|[#`$_`*_1]|sum}
```
[Try it online!](https://tio.run/##K8pPSfzv9r86zba6OLVQwVAnvjatJq0mWjlBJT5BK94wtqa4NLf2f25iZp5CNZcCEBQUZeaVKBSUFmdoGJoaaCrUKLhpaHLV/gcA "Röda – Try It Online")
[Answer]
# Python 2, 51 50 bytes
```
lambda n:sum(~k*(k-n)*len(`k+1`)for k in range(n))
```
[Answer]
# Mathematica, 66 bytes
```
Tr[1^(f=Flatten)[IntegerDigits/@f@(a=Array)[a[#~Table~#&,#]&,#]]]&
```
[Answer]
# [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 21 bytes
```
[:|[a|[c|A=A+!c$}?_lA
```
[Answer]
# [Actually](https://github.com/Mego/Seriously), 13 bytes
```
R♂R♂i⌠;n⌡Mεjl
```
[Try it online!](https://tio.run/##S0wuKU3Myan8/z/o0cwmEM581LPAOu9Rz0Lfc1uzcv7/NzQAAA "Actually – 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
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~12~~ ~~11~~ ~~10~~ 9 bytes
```
õõÈ*sÊÃxx
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=9fXIKnPKw3h4&input=OA==) or [test all numbers from 1 to 150](https://ethproductions.github.io/japt/?v=1.4.5&code=9V/19cgqc8rDeHg=&input=MTUw).
---
## 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.
[Answer]
# [Jq 1.5](https://stedolan.github.io/jq/), ~~82~~ ~~49~~ 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
```
[Try it online!](https://tio.run/##yyr8b1rzP7ooMS89VUNPU9uwBompFAOklbT0anJS89JLMmJrElNS/v//l19QkpmfV/xfVzevNCdHNzOvoLQEyClKLNfNLy0BcgA "jq – Try It Online") also [jqplay.org](https://jqplay.org/s/eo2lWPgLj0)
[Answer]
# [Stacked](https://github.com/ConorOBrien-Foxx/stacked), 28 bytes
```
[~>[~>[:rep]"!]"!flat''#`#']
```
[Try it online!](https://tio.run/##Ky5JTM5OTfn/P7rODoSsilILYpUUgSgtJ7FEXV05QVk99r@DVRoXl6GBQp2dgoapgYKhARCbGmgq6ChEWymkASl1BV07IJGVn5mnkF9aEquQm1jwHwA "Stacked – 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
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~41~~ 40 bytes
```
->n{(1..n).map{|x|[x]*x*=-x-~n}*''=~/$/}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsNQTy9PUy83saC6pqImuiJWq0LLVrdCty6vVktd3bZOX0W/9j9IkaEBVFVRTYFCdJFOWnRRbGztfwA "Ruby – Try It Online")
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 94 80 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!](https://tio.run/##fY6xasMwEEDn6CuOTFKcGich00VZAp1SKDSQWVbU5MA9EUluKcbf7opCoUPs4Q4ej8edjU/WBze0kfgKb98xuQ8U/6k8Et9R2MbECK@diMkksvDcst0RpyXktYcTaBhY77tMUOtqafIQft2ocdIUxY7Vuw@SdIWUyaCqCy2pmM9VeXR8TbcFYXCpDQw19gOKv0Ofni7wYoilEp2YHTxH37jyHCi5/JqTJ7lSCh@b9ajZjJpVNaq21UQ1lU12v7IX/fAD "C# (.NET Core) – Try It Online")
I was hoping to find a direct solution like what [@kamoroso94's answer](https://codegolf.stackexchange.com/a/143614/73579) 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
[Answer]
# [MATL](https://github.com/lmendo/MATL), 15 bytes
```
:ttP*Y"10&YlQks
```
[Try it online!](https://tio.run/##y00syfn/36qkJEArUsnQQC0yJzC7@P9/Q1MDAA "MATL – 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)
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~18~~ 14 bytes
```
ＩΣＥ⊕ＮΣＥ⊕ι×λＬＩλ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8M3sUDDMy@5KDU3Na8kNQXILigt8SvNTUot0tDU1FHApiYTKB6SmZtarJGjo@CTmpdekgExMEcTBqz//zc0@K9b9l@3OAcA "Charcoal – 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
```
[Answer]
# [Ohm v2](https://github.com/MiningPotatoes/Ohm), 7 bytes
```
@@D×JJl
```
[Try it online!](https://tio.run/##y8/INfr/38HB5fB0L6@c//8NDQz@AwA "Ohm v2 – Try It Online")
[Answer]
# [Dyalog APL], ~~22~~ 20 bytes
```
{+/≢¨⍕¨↑,/(/⍨¨⍳¨⍳⍵)}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P03hUdsEhWpt/Uediw6teNQ7FUi0TdTR19B/1LsCJLAZTDzq3apZ@/9R31Sw8rRDKxSAgqZccAEFQwMkjqnBfwA "APL (Dyalog Unicode) – 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
```
]