The Written Digits Sequence

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite












Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.



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 and A5589.)



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 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!










share|improve this question





















  • By the first option, do you mean that 1) 1 should output [0] and 0 should output or 2) 0 should output [0] (as in my former answer)?
    – Erik the Outgolfer
    1 hour ago











  • @EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
    – Jonathan Allan
    1 hour ago















up vote
5
down vote

favorite












Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.



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 and A5589.)



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 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!










share|improve this question





















  • By the first option, do you mean that 1) 1 should output [0] and 0 should output or 2) 0 should output [0] (as in my former answer)?
    – Erik the Outgolfer
    1 hour ago











  • @EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
    – Jonathan Allan
    1 hour ago













up vote
5
down vote

favorite









up vote
5
down vote

favorite











Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.



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 and A5589.)



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 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!










share|improve this question













Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.



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 and A5589.)



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 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!







code-golf sequence arithmetic integer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









Jonathan Allan

49.3k534161




49.3k534161











  • By the first option, do you mean that 1) 1 should output [0] and 0 should output or 2) 0 should output [0] (as in my former answer)?
    – Erik the Outgolfer
    1 hour ago











  • @EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
    – Jonathan Allan
    1 hour ago

















  • By the first option, do you mean that 1) 1 should output [0] and 0 should output or 2) 0 should output [0] (as in my former answer)?
    – Erik the Outgolfer
    1 hour ago











  • @EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
    – Jonathan Allan
    1 hour ago
















By the first option, do you mean that 1) 1 should output [0] and 0 should output or 2) 0 should output [0] (as in my former answer)?
– Erik the Outgolfer
1 hour ago





By the first option, do you mean that 1) 1 should output [0] and 0 should output or 2) 0 should output [0] (as in my former answer)?
– Erik the Outgolfer
1 hour ago













@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
– Jonathan Allan
1 hour ago





@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
– Jonathan Allan
1 hour ago











4 Answers
4






active

oldest

votes

















up vote
2
down vote














Pip, 21 bytes



Lai+:$+4335443554@^Pi


Takes input $n$ as a command-line argument and outputs the first $n$ terms. 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





share|improve this answer



























    up vote
    1
    down vote














    JavaScript (Node.js), 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!






    share|improve this answer





























      up vote
      1
      down vote














      Jelly, 13 bytes



      ṃ“vẋç’ḃ5¤S+Ɗ¡


      Try it online!



      0-indexed.



      Full program; takes input from STDIN.






      share|improve this answer





























        up vote
        0
        down vote














        05AB1E, 15 bytes



        ÎFD•16|/•sSèOO


        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
        •16|/• # 4335443554
        OO # sum digits and sum the stack




        share




















          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "200"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174521%2fthe-written-digits-sequence%23new-answer', 'question_page');

          );

          Post as a guest






























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote














          Pip, 21 bytes



          Lai+:$+4335443554@^Pi


          Takes input $n$ as a command-line argument and outputs the first $n$ terms. 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





          share|improve this answer
























            up vote
            2
            down vote














            Pip, 21 bytes



            Lai+:$+4335443554@^Pi


            Takes input $n$ as a command-line argument and outputs the first $n$ terms. 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





            share|improve this answer






















              up vote
              2
              down vote










              up vote
              2
              down vote










              Pip, 21 bytes



              Lai+:$+4335443554@^Pi


              Takes input $n$ as a command-line argument and outputs the first $n$ terms. 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





              share|improve this answer













              Pip, 21 bytes



              Lai+:$+4335443554@^Pi


              Takes input $n$ as a command-line argument and outputs the first $n$ terms. 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






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 35 mins ago









              DLosc

              18.5k33588




              18.5k33588




















                  up vote
                  1
                  down vote














                  JavaScript (Node.js), 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!






                  share|improve this answer


























                    up vote
                    1
                    down vote














                    JavaScript (Node.js), 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!






                    share|improve this answer
























                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote










                      JavaScript (Node.js), 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!






                      share|improve this answer















                      JavaScript (Node.js), 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!







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 1 hour ago

























                      answered 1 hour ago









                      Luis felipe De jesus Munoz

                      3,36111049




                      3,36111049




















                          up vote
                          1
                          down vote














                          Jelly, 13 bytes



                          ṃ“vẋç’ḃ5¤S+Ɗ¡


                          Try it online!



                          0-indexed.



                          Full program; takes input from STDIN.






                          share|improve this answer


























                            up vote
                            1
                            down vote














                            Jelly, 13 bytes



                            ṃ“vẋç’ḃ5¤S+Ɗ¡


                            Try it online!



                            0-indexed.



                            Full program; takes input from STDIN.






                            share|improve this answer
























                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote










                              Jelly, 13 bytes



                              ṃ“vẋç’ḃ5¤S+Ɗ¡


                              Try it online!



                              0-indexed.



                              Full program; takes input from STDIN.






                              share|improve this answer















                              Jelly, 13 bytes



                              ṃ“vẋç’ḃ5¤S+Ɗ¡


                              Try it online!



                              0-indexed.



                              Full program; takes input from STDIN.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 1 hour ago

























                              answered 1 hour ago









                              Erik the Outgolfer

                              29.8k42899




                              29.8k42899




















                                  up vote
                                  0
                                  down vote














                                  05AB1E, 15 bytes



                                  ÎFD•16|/•sSèOO


                                  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
                                  •16|/• # 4335443554
                                  OO # sum digits and sum the stack




                                  share
























                                    up vote
                                    0
                                    down vote














                                    05AB1E, 15 bytes



                                    ÎFD•16|/•sSèOO


                                    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
                                    •16|/• # 4335443554
                                    OO # sum digits and sum the stack




                                    share






















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote










                                      05AB1E, 15 bytes



                                      ÎFD•16|/•sSèOO


                                      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
                                      •16|/• # 4335443554
                                      OO # sum digits and sum the stack




                                      share













                                      05AB1E, 15 bytes



                                      ÎFD•16|/•sSèOO


                                      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
                                      •16|/• # 4335443554
                                      OO # sum digits and sum the stack





                                      share











                                      share


                                      share










                                      answered 5 mins ago









                                      Emigna

                                      43.9k431133




                                      43.9k431133



























                                           

                                          draft saved


                                          draft discarded















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174521%2fthe-written-digits-sequence%23new-answer', 'question_page');

                                          );

                                          Post as a guest













































































                                          Comments

                                          Popular posts from this blog

                                          What does second last employer means? [closed]

                                          Installing NextGIS Connect into QGIS 3?

                                          One-line joke