[Question]
  [
Here's a reasonably trivial sequence which is not in the [Online Encyclopedia of Integer Sequences](https://oeis.org/).
Start with an empty sequence then define each term as the number of characters required to write out, in English, all of the digits of the sequence so far without spaces.\*
For reference the number of characters of all of the (base ten) digits in English are:
```
zero   one    two    three  four   five   six    seven  eight  nine
4      3      3      5      4      4      3      5      5      4
```
(Which is the start of both [A52360](https://oeis.org/A052360) and [A5589](https://oeis.org/A005589).)
This makes the first entry \$a(0) = 0\$ since there are zero digits present in the empty sequence.
This makes the second entry \$a(1) = 4\$ as it takes four characters to write "zero", the only digit present so far.
This makes the third entry \$a(2) = 8\$ as it takes four more characters to write the "four" for a total of eight to write "zerofour".
This makes the fourth entry \$a(3) = 13\$ as it takes five more characters to write "eight" for a total of thirteen to write "zerofoureight".
This makes the fifth entry \$a(4) = 21\$ as it takes eight more characters to write "onethree" for a total of twenty-one to write "zerofoureightonethree".
...and so on. Here are the first 100 entries:
```
0, 4, 8, 13, 21, 27, 35, 44, 52, 59, 67, 75, 84, 93, 102, 112, 121, 130, 142, 152, 162, 171, 182, 193, 205, 216, 225, 235, 247, 259, 270, 282, 293, 305, 318, 331, 344, 357, 371, 384, 398, 412, 422, 432, 444, 456, 467, 479, 492, 503, 516, 526, 536, 548, 561, 571, 583, 597, 610, 620, 630, 642, 652, 662, 671, 682, 693, 705, 718, 731, 744, 757, 771, 784, 798, 812, 823, 836, 849, 862, 873, 888, 903, 916, 926, 936, 948, 961, 971, 983, 997, 1010, 1024, 1038, 1055, 1070, 1086, 1101, 1114, 1127
```
\* We could define it for other languages and/or other bases or with spaces of course
### The challenge
Given \$n\$ output, in as few bytes of code as possible, any of:
* The first \$n\$ terms of the sequence (should work for non-negative integers)
* The value of \$a(n)\$ (should work for non-negative integers)
* The \$n\$th term of the sequence (should work for positive integers - i.e. value of \$a(n-1)\$)
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest answer in bytes wins for each language, and the shortest answer in bytes wins. Don't let golfing languages stop you from entering in your favourite language be it a practical one or an esoteric one!
  
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 45 bytes
```
{({[+] @_.join.uninames>>.comb X-6}...*)[$_]}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WqM6WjtWwSFeLys/M0@vNC8zLzE3tdjOTi85PzdJIULXrFZPT09LM1olPrb2f3FipUKahqGBpjUXhBkHYv8HAA "Perl 6 – Try It Online")
No need for fancy moduloing when you can get the name of the digit directly! Anonymous code block that returns the nth value of the sequence, or you can pass in a range to get a list of values
### Explanation:
```
{(                                     )[$_]}  # Index input into:
  {                               }...*        # An infinite sequence
                                               # Where each element is
   [+]   # The sum of
       @_.join  # All previous elements joined together
              .uninames  # The unicode names for each character
                         # These are names in the form "DIGIT ONE"
                       >>.comb  # Split each to lists of characters
                               X-6  # Subtract 6 from each
```
[Answer]
# JavaScript (ES6), ~~69~~ ~~68~~ ~~61~~ 58 bytes
Returns \$a(n)\$.
```
f=(n,s=0)=>n?f(n-1,[...s+''].map(d=>s+=(d+10)%23%3+3)|s):s
```
[Try it online!](https://tio.run/##FcxBDoIwEEDRq3QBYSaFppWdOngQY0JDqdHglDDGDXL2iru/ePlP//EyLI/53XAKY86RgGshi9TxJQI3rr4aY0RX1c28/AyBOtEEQTuL5aEtW93iV/AoOaYFWJGyJ8XqrJz9h9aohsSSptFM6Q69h2LlDXdXrPsftx7zDw "JavaScript (Node.js) – Try It Online")
### How?
A digit \$d\$ is converted to a number \$n\$ of letters with:
$$n=(((d \times 100 + 10) \bmod 23) \bmod 3)+3$$
```
 d | *100 | +10 | MOD 23 | MOD 3 | +3 | word
---+------+-----+--------+-------+----+-------
 0 |    0 |  10 |   10   |   1   |  4 | zero
 1 |  100 | 110 |   18   |   0   |  3 | one
 2 |  200 | 210 |    3   |   0   |  3 | two
 3 |  300 | 310 |   11   |   2   |  5 | three
 4 |  400 | 410 |   19   |   1   |  4 | four
 5 |  500 | 510 |    4   |   1   |  4 | five
 6 |  600 | 610 |   12   |   0   |  3 | six
 7 |  700 | 710 |   20   |   2   |  5 | seven
 8 |  800 | 810 |    5   |   2   |  5 | eight
 9 |  900 | 910 |   13   |   1   |  4 | nine
```
Because the number is split into digit characters, we can process \$d\times 100+10\$ by just adding \$10\$ (as a string concatenation).
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~14~~ 13 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
┴♥7[╘⌂←─üTJ‼√
```
[Run and debug it](https://staxlang.xyz/#p=c103375bd47f1bc481544a13fb&i=0%0A1%0A2%0A100&a=1&m=2)
The key insight here is that digit `d` requires `((4 - 2 * d) // 3) % 3 + 3` letters to spell. (That's python integer division, and python-style non-negative modulus)
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 21 bytes
```
Lai+:$+4335443554@^Pi
```
Takes input \$n\$ as a command-line argument and outputs the first \$n\$ terms. [Try it online!](https://tio.run/##K8gs@P/fJzFT20pF28TY2NTExNjU1MQhLiDz////JgA "Pip – Try It Online")
### Explanation
```
Lai+:$+4335443554@^Pi
                       a is 1st cmdline arg; i is 0 (implicit)
La                     Loop (a) times:
                   Pi   Print i
                  ^     Split it into a list of characters (i.e. digits)
       4335443554@      Use each digit to index into this number, giving the length of the
                        name of the digit (0 -> 4, 1 -> 3, etc.)
     $+                 Sum the results
  i+:                   Increment i by that amount
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 57 bytes
```
Nest[#+Tr@StringLength@IntegerName@IntegerDigits@#&,0,#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78H1CUmVcS/d8vtbgkWlk7pMghuAQoku6TmpdekuHgmVeSmp5a5JeYmwpju2SmZ5YUOyir6RjoKMeq/dd3UAhKzEtPjTbQMTSIjf0PAA "Wolfram Language (Mathematica) – Try It Online")
`Tr@StringLength@IntegerName@IntegerDigits@#&` lists the digits of `#`, converts each of them to an English name, counts the length, and sums the results. Lots of things thread over lists, it's very exciting. Then we just iteratively apply the definition.
TIO complains that it doesn't have an Internet connection, but I'm not sure why, because it figures out the right answer anyway. Maybe it's checking for updates to the names of integers?
Outputs the value of \$a(n)\$, but we could change it to give the entire list \$a(0), a(1), \dots, a(n)\$ by changing `Nest` to `NestList`.
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 82 bytes
```
import StdEnv,Text
$a=iter a(\n=n+sum[3+indexOf{c}" 9810324765"rem 3\\c<-:""<+n])0
```
[Try it online!](https://tio.run/##JcxNC4IwGADge79iDA@FKZZ9GXqrQxAU1E09vMwZg72vMmcY0V9vCR2fyyO0BHLYVL2WDEGRU9g2xrKbrY70nN/lYCceZMpKw2BaUEZ@12Me@4oqOVzqt/hwluwWUbxcbTdrbiSyuChEGuw5T30qZ5G7WRjHbPxb5rE8CsMkKd1X1BoenQtOZ3d4EaASf1w12Lox@AM "Clean – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~29~~ 28 bytes
```
{{⍵++/3+3|⌊3÷⍨4-2×⍎¨⍕⍵}⍣⍵⊢0}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkG/6urH/Vu1dbWN9Y2rnnU02V8ePuj3hUmukaHpz/q7Tu04lHvVKB87aPexUDqUdcig9r/aUB9QDmIEV3Nh9YbP2qbCOQFBzkDyRAPz@D/aSCNmw0NDAA "APL (Dyalog Unicode) – Try It Online")
Dfn. Prints \$f(input)\$
Thanks to the guys @The APL Orchard for helping with this one:
@ngn for 2 bytes; @H.PWiz for ~~3~~ 4 bytes.
Now using @recursive's formula.
### How:
```
{{⍵++/3+3|⌊3÷⍨4-2×⍎¨⍕⍵}⍣⍵⊢0} ⍝ Main fn
 {                     }⍣⍵⊢0 ⍝ Starting with 0, repeat (⍣) the inner fn input times
      3+3|⌊3÷⍨4-2×⍎¨⍕⍵      ⍝ @recursive's formula
  ⍵++/                       ⍝ Sum with the input.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~15~~ 14 bytes
```
ÎFD•Qb₁ñ•sSèOO
```
[Try it online!](https://tio.run/##yy9OTMpM/f//cJ@by6OGRYFJj5oaD28EsoqDD6/w9///3wQA "05AB1E – Try It Online")
**Explanation**
```
Î                # initialize stack with 0 and input
 F               # input times do:
  D              # duplicate the current number
         sSè     # and use one copy to index into
   •Qb₁ñ•        # 433544355
            OO   # sum digits and sum the stack
```
[Answer]
# [Python 2](https://docs.python.org/2/), 61 bytes
```
n=0
exec"for c in`n`:n+=(4-2*int(c))/3%3+3\n"*input()
print n
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P8/WgCu1IjVZKS2/SCFZITMvIS/BKk/bVsNE10grM69EI1lTU99Y1VjbOCZPCShQUFqioclVUASUUsj7/9/SEgA "Python 2 – Try It Online")
Uses [recursive's digit count mapping](https://codegolf.stackexchange.com/a/174531/20260).
---
**[Python 2](https://docs.python.org/2/), 63 bytes**
```
f=lambda n:n and f(n-1)+sum((4-2*int(c))/3%3+3for c in`f(n-1)`)
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRIc8qTyExL0UhTSNP11BTu7g0V0PDRNdIKzOvRCNZU1PfWNVY2zgtv0ghWSEzLwGiKkHzf0ERSEGahqmm5n8A "Python 2 – Try It Online")
A recursive function version. It takes exponential time to run because it has two recursive calls to `f(n-1)`.
[Answer]
# [Python 2](https://docs.python.org/2/), 71 bytes
```
f=lambda n,k=0:n and f(n-1,k+sum(632179420>>3*int(d)&7for d in`k`))or k
```
[Try it online!](https://tio.run/##FclLCoAgEADQq8wqnD5gGoWBnkVDJLGm6LPo9Fa7B29/rnkjkXPQi1sn74DqpPlI4MhDYNS0darOe2W9FO2gOsGNkWWki3kshrAd4CGSTRbxc8r78V9gSiHmFw "Python 2 – Try It Online")
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), 17 bytes
```
0\{_▒♀*♂+L%3%3+Σ+
```
[Try it online!](https://tio.run/##y00syUjPz0n7/98gpjr@0bRJj2Y2aD2a2aTto2qsaqx9brE2UIbLkMuIy5jLhMuUy4zLnMuCyxIA "MathGolf – Try It Online")
This uses [Arnauld's method](https://codegolf.stackexchange.com/a/174530/76162). Outputs the nth element of the sequence.. If the empty string is okay for `a(0)`, then we could remove the `0\` at the beginning. 
### Explanation:
```
0\                 Setup 0 as the counter
  {                Loop input times
   _▒              Duplicate counter and split to list of digits
     ♀*            Multiply each element by 100
       ♂+          Add 10
         L%        Modulo by 23
           3%      Modulo by 3
             3+    Add 3
               Σ   Sum list
                +  And add to counter
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 21 bytes
```
u+Gs@L+L3jC\᯻3jGTQ0
```
Try it online [here](https://pyth.herokuapp.com/?code=u%2BGs%40L%2BL3jC%5C%E1%AF%BB3jGTQ0&input=6&debug=0).
```
u+Gs@L+L3jC\᯻3jGTQ0   Implicit: Q=eval(input()), T=10
u                Q0   Starting at 0, repeat the following Q times, with current value as G:
          C\᯻           Get character code 7163
         j   3          Convert the above to base 3, yields [1, 0, 0, 2, 1, 1, 0, 2, 2]
      +L3               Add 3 to each to generate digit length dictionary
              jGT       Get digits of G (convert to base 10)
    @L                  Lookup each value in the above in the dictionary, modular indexing
   s                    Take the sum
 +G                     Add G to the above
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 54 bytes
```
->n{s=0;n.times{s+=s.digits.sum{|d|4+392[d]-70[d]}};s}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vutjWwDpPryQzN7W4uljbtlgvJTM9s6RYr7g0t7ompcZE29jSKDolVtfcAEjW1loX1/4vUNAw0NMzNNDUy00s0FBL0@QqUEiLtrSM/Q8A "Ruby – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 95 bytes
```
n->{int l=0;while(n-->0)l+=(""+l).chars().map(x->"4335443554".charAt(x-48)-48).sum();return l;}
```
[Try it online!](https://tio.run/##NU7BaoUwELz7FYunpGKwqFBIFUpPPfTUY@khzdP31sZEks1r4eG322jpYZjdndmdndRVldPpa8N5cZ5gSr2IhEaM0WpCZ8WdzLRRIcCrQgu3DGCJnwY1BFKU6OrwBHPS2Bt5tOf3D1D@HPhhBXix9OxsiPPgYYQONlv2N7QEpqvk9wXNwGxZ9hU3RcfyvDBc6IvygXExq4X9lH3e1HXbNHXbNvmhPVEaNw98h0iXGZd@oOgtGLlu8ogdnWd7CqbISiZ6hPtqL4ri/7NkEkrrYSGG/G9rzXas2y8 "Java (JDK) – Try It Online")
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 13 bytes
```
0?(»Þ([ǒ»Ȯİ∑Ṡ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=0%3F%28%C2%BB%C3%9E%28%5B%C7%92%C2%BB%C8%AE%C4%B0%E2%88%91%E1%B9%A0&inputs=3&header=&footer=)
A port of the 05AB1E answer
## Explained
```
0?(»Þ([ǒ»Ȯİ∑Ṡ
0?              # Push 0 followed by the input number
  (             # Input number of times:
   »Þ([ǒ»       #     Push the number 433544355
         Ȯİ     #     And get the indexes corresponding to the numbers in the second last item on the stack
           ∑Ṡ   #     Sum that list and then the stack
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 82 bytes
```
f=(a,b=1,s=4)=>a?b<a?f(a,++b,s+=[...s+''].reduce((q,w)=>+'4335443554'[w]+q,0)):s:0
```
[Try it online!](https://tio.run/##ZcpBDsIgEADAux8Bskha2V4asQ9pegAKRtMU21X7fORquE7mab@W/P54vc9rmkPO0XArnWklGRTmZgd3tUMsBuAkgRmVUgSMTWoP88cHzjd5lAgMte4QddchG48JNtkI0VPfZJ9WSktQS7rzyIue/qWt5FKJrgSFyD8)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
```
ṃ“vẋç’ḃ5¤S+Ɗ¡
```
[Try it online!](https://tio.run/##ASYA2f9qZWxsef//4bmD4oCcduG6i8On4oCZ4biDNcKkUyvGisKh//85OQ "Jelly – Try It Online")
0-indexed.
Full program; takes input from STDIN.
[Answer]
# [Red](http://www.red-lang.org), 99 95 bytes
```
func[n][d:"4335443554"s: 0 repeat i n[print s foreach c form s[s: s - 48 + do d/(-47 + do c)]]]
```
[Try it online!](https://tio.run/##JcqxCsIwEAbg3af46aRIMZILSh7D9bih5C7YwbQk7fNHpds3fNW0v0xZTjn2vJfERVjjQN4HIh8CDS3Codpq04YZhdc6lw0Neak2pTfSXx80/sWGEfTEFbpAb@eRHofTRUR6xt25/gU "Red – Try It Online")
Just a straightforward solution.
[Answer]
# [J](http://jsoftware.com/), 37 bytes
```
(+1#.|(3+3|23|10+100*]),.&.":)@]^:[&0
```
[Try it online!](https://tio.run/##NYyxCoAgGAZ3n@KjQDPr5zc3oeg9opZIqqXB1Z7dgohbjhvuzCH2BIYH58rYklLljEudS5aNZa5n3ZCkwutxXvwkOWtREFToSaHB7RGiENu6Xwiw/Jlq8aL@LAcc9L5EfgA "J – Try It Online")
Uses Arnauld's method
## Explanation:
The argument is `n` 
```
                                 ^:    - apply the verb on the left hand site
                                   [   - n times
                                    &0 - to a starting value 0
 (                             )@]     - calculate for the current value of the argument
                         ,.&.":        - convert to string and then each char to digit
        (3+3|23|10+100*])              - map each digit to its word length
       |                               - a filler for the fork
    1#.                                - sum the lengths 
   +                                   - add them to the current value
```
[Answer]
**Edited after 1st comment.**
Prints all terms
# Scala, 76 bytes
```
def^(n:Int)=(1 to n).scanLeft(0)((y,_)=>y+(y+"").map(x=>(x*9+1)%13%3+3).sum)
```
[Try it online!](https://tio.run/##DctBCsIwEADAu69YCoVdI6UhJ4UUPAq@oRLTFJR2G8wKCeLbo3Of5N3i6nZ/Bi/gIWQJPCU4xwifOoV5RD5dWMiiBtmAqUve8TXMgj0hlsON7FAUFtU01K0uYrYD5v1RaWq1aY0y//JeqcbXg2VhHFH3RLtvrT8 "Scala – Try It Online")
Prints nth term
# Scala, 72 bytes
```
def^(n:Int)=Stream.iterate(0)(x=>x+(x+"").map(x=>(x*9+1)%13%3+3).sum)(n)
```
# Scala, 69 bytes
```
def^(n:Int)=(0/:(1 to n))((y,_)=>y+(y+"").map(x=>(x*9+1)%13%3+3).sum)
```
# Scala, 67 bytes
```
def s(b:Int):Stream[Int]=b#::s(b+(b+"").map(x=>(x*9+1)%13%3+3).sum)
```
# Scala, 67 bytes
```
val s:Stream[Int]=0#::s.map(x=>x+(x+"").map(x=>(x*9+1)%13%3+3).sum)
```
[Try it online!](https://tio.run/##K05OzEn8n5@UlZpcopCvkFpRkpqXUqzgWFCgUP2/LDFHodgquKQoNTE32jOvJNbWQNnKqlgvN7FAo8LWrkJbo0JbSUkTxteo0LLUNtRUNTRWNdY21tQrLs3V/F9QlJlXkpOnUaxhaKCpyVX7/z8A "Scala – Try It Online")
]