How many consecutive descending numbers in my number?












4














2019 has come and probably eveyone has noticed the peculiarity of this number: it's in fact composed by two sub-numbers (20 and 19) representing a sequence of consecutive descending numbers.



Challenge



Given a number x, return the length of the maximum sequence of descending numbers that can be formed by taking sub-numbers of x.



Notes :




  • sub-numbers cannot contain leading zeros (e.g. 1009 cannot be split into 10,09)

  • the sequence must be obtained by the full number, e.g. in 7321 you can't discard 7 and get the sequence 3,2,1

  • only one sequence can be obtained from the number, e.g. 3211098 cannot be split into two sequences 3,2,1 and 10,9,8


Input




  • An integer number (>= 0) : can be a number or a string or list of digits


Output




  • A single integer given the maximum number of decreasing sub-numbers (note that the lower-bound of this number is 1, i.e. a number is composed by itself in a descending sequence of length one)


Examples :



2019         --> 20,19           --> output : 2
201200199198 --> 201,200,199,198 --> output : 4
3246 --> 3246 --> output : 1
87654 --> 8,7,6,5,4 --> output : 5
123456 --> 123456 --> output : 1
1009998 --> 100,99,98 --> output : 3
100908 --> 100908 --> output : 1
1110987 --> 11,10,9,8,7 --> output : 5
210 --> 2,1,0 --> output : 3


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.










share|improve this question






















  • Migrated from sandbox : codegolf.meta.stackexchange.com/questions/2140/…
    – digEmAll
    2 hours ago
















4














2019 has come and probably eveyone has noticed the peculiarity of this number: it's in fact composed by two sub-numbers (20 and 19) representing a sequence of consecutive descending numbers.



Challenge



Given a number x, return the length of the maximum sequence of descending numbers that can be formed by taking sub-numbers of x.



Notes :




  • sub-numbers cannot contain leading zeros (e.g. 1009 cannot be split into 10,09)

  • the sequence must be obtained by the full number, e.g. in 7321 you can't discard 7 and get the sequence 3,2,1

  • only one sequence can be obtained from the number, e.g. 3211098 cannot be split into two sequences 3,2,1 and 10,9,8


Input




  • An integer number (>= 0) : can be a number or a string or list of digits


Output




  • A single integer given the maximum number of decreasing sub-numbers (note that the lower-bound of this number is 1, i.e. a number is composed by itself in a descending sequence of length one)


Examples :



2019         --> 20,19           --> output : 2
201200199198 --> 201,200,199,198 --> output : 4
3246 --> 3246 --> output : 1
87654 --> 8,7,6,5,4 --> output : 5
123456 --> 123456 --> output : 1
1009998 --> 100,99,98 --> output : 3
100908 --> 100908 --> output : 1
1110987 --> 11,10,9,8,7 --> output : 5
210 --> 2,1,0 --> output : 3


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.










share|improve this question






















  • Migrated from sandbox : codegolf.meta.stackexchange.com/questions/2140/…
    – digEmAll
    2 hours ago














4












4








4







2019 has come and probably eveyone has noticed the peculiarity of this number: it's in fact composed by two sub-numbers (20 and 19) representing a sequence of consecutive descending numbers.



Challenge



Given a number x, return the length of the maximum sequence of descending numbers that can be formed by taking sub-numbers of x.



Notes :




  • sub-numbers cannot contain leading zeros (e.g. 1009 cannot be split into 10,09)

  • the sequence must be obtained by the full number, e.g. in 7321 you can't discard 7 and get the sequence 3,2,1

  • only one sequence can be obtained from the number, e.g. 3211098 cannot be split into two sequences 3,2,1 and 10,9,8


Input




  • An integer number (>= 0) : can be a number or a string or list of digits


Output




  • A single integer given the maximum number of decreasing sub-numbers (note that the lower-bound of this number is 1, i.e. a number is composed by itself in a descending sequence of length one)


Examples :



2019         --> 20,19           --> output : 2
201200199198 --> 201,200,199,198 --> output : 4
3246 --> 3246 --> output : 1
87654 --> 8,7,6,5,4 --> output : 5
123456 --> 123456 --> output : 1
1009998 --> 100,99,98 --> output : 3
100908 --> 100908 --> output : 1
1110987 --> 11,10,9,8,7 --> output : 5
210 --> 2,1,0 --> output : 3


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.










share|improve this question













2019 has come and probably eveyone has noticed the peculiarity of this number: it's in fact composed by two sub-numbers (20 and 19) representing a sequence of consecutive descending numbers.



Challenge



Given a number x, return the length of the maximum sequence of descending numbers that can be formed by taking sub-numbers of x.



Notes :




  • sub-numbers cannot contain leading zeros (e.g. 1009 cannot be split into 10,09)

  • the sequence must be obtained by the full number, e.g. in 7321 you can't discard 7 and get the sequence 3,2,1

  • only one sequence can be obtained from the number, e.g. 3211098 cannot be split into two sequences 3,2,1 and 10,9,8


Input




  • An integer number (>= 0) : can be a number or a string or list of digits


Output




  • A single integer given the maximum number of decreasing sub-numbers (note that the lower-bound of this number is 1, i.e. a number is composed by itself in a descending sequence of length one)


Examples :



2019         --> 20,19           --> output : 2
201200199198 --> 201,200,199,198 --> output : 4
3246 --> 3246 --> output : 1
87654 --> 8,7,6,5,4 --> output : 5
123456 --> 123456 --> output : 1
1009998 --> 100,99,98 --> output : 3
100908 --> 100908 --> output : 1
1110987 --> 11,10,9,8,7 --> output : 5
210 --> 2,1,0 --> output : 3


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.







code-golf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









digEmAll

2,491410




2,491410












  • Migrated from sandbox : codegolf.meta.stackexchange.com/questions/2140/…
    – digEmAll
    2 hours ago


















  • Migrated from sandbox : codegolf.meta.stackexchange.com/questions/2140/…
    – digEmAll
    2 hours ago
















Migrated from sandbox : codegolf.meta.stackexchange.com/questions/2140/…
– digEmAll
2 hours ago




Migrated from sandbox : codegolf.meta.stackexchange.com/questions/2140/…
– digEmAll
2 hours ago










5 Answers
5






active

oldest

votes


















3















Perl 6, 42 bytes





{/^(<-[0]>.*?|0)+<?{2>set 1..*Z+$0}>/;+$0}


Try it online!



Regex based solution. I'm trying to come up with a better way to match from a descending list instead, but Perl 6 doesn't do partitions well






share|improve this answer































    2














    JavaScript (ES6), 66 bytes



    Takes input as a string.





    f=(s,n=x='',o=p=n,i=0)=>s[i++]?o==s?i:f(s,--n,o+n,i):f(s,p+s[x++])


    Try it online!






    share|improve this answer





























      2















      Jelly,  15  9 bytes



      RṚẆDfŒṖẈṀ


      Try it online! (even 321 takes half a minute since the code is $O(2^N)$)



      How?



      RṚẆDfŒṖẈṀ - Link: integer, n
      R - range = [1,2,3,...,n]
      Ṛ - reverse = [n,...,3,2,1]
      Ẇ - all contiguous slices = [[n],...,[3],[2],[1],[n,n-1],...,[2,1],[n,n-1,n-2],...,[3,2,1],...,[n,n-1,n-2,...,3,2,1]]
      D - to decimal (vectorises)
      ŒṖ - partitions of (implicit decimal digits of) n
      f - filter discard from left if in right
      Ẉ - length of each
      Ṁ - maximum





      share|improve this answer























      • ẆU saves a byte, as W already casts to range.
        – Dennis
        4 mins ago



















      1















      05AB1E, 10 bytes



      ÝRŒʒJQ}€gà


      Extremely slow, so the TIO below only works for test cases below 750..



      Try it online.



      Explanation:





      Ý           # Create a list in the range [0, (implicit) input]
      # i.e. 109 → [0,1,2,...,107,108,109]
      R # Reverse it
      # i.e. [0,1,2,...,107,108,109] → [109,108,107,...,2,1,0]
      Π# Get all possible sublists of this list
      # i.e. [109,108,107,...,2,1,0]
      # → [[109],[109,108],[109,108,107],...,[2,1,0],[1],[1,0],[0]]
      ʒ } # Filter it by:
      J # Where the sublist joined together
      # i.e. [10,9] → "109"
      # i.e. [109,108,107] → "109108107"
      Q # Are equal to the (implicit) input
      # i.e. 109 and "109" → 1 (truthy)
      # i.e. 109 and "109108107" → 0 (falsey)
      €g # After filtering, take the length of each remaining inner list
      # i.e. [[109],[[10,9]] → [1,2]
      à # And only leave the maximum length (which is output implicitly)
      # i.e. [1,2] → 2





      share|improve this answer































        1














        Pyth, 16 bytes



        lef!.EhM.+vMT./z


        Try it online here, or verify all the test cases at once here.



        lef!.EhM.+vMT./z   Implicit: z=input as string
        ./z Get all divisions of z into disjoint substrings
        f Filter the above, as T, keeping those where the following is truthy:
        vMT Parse each substring as an int
        .+ Get difference between each pair
        hM Increment each
        !.E Are all elements 0? { NOT(ANY(...)) }
        e Take the last element of the filtered divisions
        Divisions are generated with fewest substrings first, so last remaining division is also the longest
        l Length of the above, implicit print





        share|improve this answer





















          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          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%2f178373%2fhow-many-consecutive-descending-numbers-in-my-number%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3















          Perl 6, 42 bytes





          {/^(<-[0]>.*?|0)+<?{2>set 1..*Z+$0}>/;+$0}


          Try it online!



          Regex based solution. I'm trying to come up with a better way to match from a descending list instead, but Perl 6 doesn't do partitions well






          share|improve this answer




























            3















            Perl 6, 42 bytes





            {/^(<-[0]>.*?|0)+<?{2>set 1..*Z+$0}>/;+$0}


            Try it online!



            Regex based solution. I'm trying to come up with a better way to match from a descending list instead, but Perl 6 doesn't do partitions well






            share|improve this answer


























              3












              3








              3







              Perl 6, 42 bytes





              {/^(<-[0]>.*?|0)+<?{2>set 1..*Z+$0}>/;+$0}


              Try it online!



              Regex based solution. I'm trying to come up with a better way to match from a descending list instead, but Perl 6 doesn't do partitions well






              share|improve this answer















              Perl 6, 42 bytes





              {/^(<-[0]>.*?|0)+<?{2>set 1..*Z+$0}>/;+$0}


              Try it online!



              Regex based solution. I'm trying to come up with a better way to match from a descending list instead, but Perl 6 doesn't do partitions well







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 24 mins ago

























              answered 1 hour ago









              Jo King

              20.9k248110




              20.9k248110























                  2














                  JavaScript (ES6), 66 bytes



                  Takes input as a string.





                  f=(s,n=x='',o=p=n,i=0)=>s[i++]?o==s?i:f(s,--n,o+n,i):f(s,p+s[x++])


                  Try it online!






                  share|improve this answer


























                    2














                    JavaScript (ES6), 66 bytes



                    Takes input as a string.





                    f=(s,n=x='',o=p=n,i=0)=>s[i++]?o==s?i:f(s,--n,o+n,i):f(s,p+s[x++])


                    Try it online!






                    share|improve this answer
























                      2












                      2








                      2






                      JavaScript (ES6), 66 bytes



                      Takes input as a string.





                      f=(s,n=x='',o=p=n,i=0)=>s[i++]?o==s?i:f(s,--n,o+n,i):f(s,p+s[x++])


                      Try it online!






                      share|improve this answer












                      JavaScript (ES6), 66 bytes



                      Takes input as a string.





                      f=(s,n=x='',o=p=n,i=0)=>s[i++]?o==s?i:f(s,--n,o+n,i):f(s,p+s[x++])


                      Try it online!







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 1 hour ago









                      Arnauld

                      72.6k689305




                      72.6k689305























                          2















                          Jelly,  15  9 bytes



                          RṚẆDfŒṖẈṀ


                          Try it online! (even 321 takes half a minute since the code is $O(2^N)$)



                          How?



                          RṚẆDfŒṖẈṀ - Link: integer, n
                          R - range = [1,2,3,...,n]
                          Ṛ - reverse = [n,...,3,2,1]
                          Ẇ - all contiguous slices = [[n],...,[3],[2],[1],[n,n-1],...,[2,1],[n,n-1,n-2],...,[3,2,1],...,[n,n-1,n-2,...,3,2,1]]
                          D - to decimal (vectorises)
                          ŒṖ - partitions of (implicit decimal digits of) n
                          f - filter discard from left if in right
                          Ẉ - length of each
                          Ṁ - maximum





                          share|improve this answer























                          • ẆU saves a byte, as W already casts to range.
                            – Dennis
                            4 mins ago
















                          2















                          Jelly,  15  9 bytes



                          RṚẆDfŒṖẈṀ


                          Try it online! (even 321 takes half a minute since the code is $O(2^N)$)



                          How?



                          RṚẆDfŒṖẈṀ - Link: integer, n
                          R - range = [1,2,3,...,n]
                          Ṛ - reverse = [n,...,3,2,1]
                          Ẇ - all contiguous slices = [[n],...,[3],[2],[1],[n,n-1],...,[2,1],[n,n-1,n-2],...,[3,2,1],...,[n,n-1,n-2,...,3,2,1]]
                          D - to decimal (vectorises)
                          ŒṖ - partitions of (implicit decimal digits of) n
                          f - filter discard from left if in right
                          Ẉ - length of each
                          Ṁ - maximum





                          share|improve this answer























                          • ẆU saves a byte, as W already casts to range.
                            – Dennis
                            4 mins ago














                          2












                          2








                          2







                          Jelly,  15  9 bytes



                          RṚẆDfŒṖẈṀ


                          Try it online! (even 321 takes half a minute since the code is $O(2^N)$)



                          How?



                          RṚẆDfŒṖẈṀ - Link: integer, n
                          R - range = [1,2,3,...,n]
                          Ṛ - reverse = [n,...,3,2,1]
                          Ẇ - all contiguous slices = [[n],...,[3],[2],[1],[n,n-1],...,[2,1],[n,n-1,n-2],...,[3,2,1],...,[n,n-1,n-2,...,3,2,1]]
                          D - to decimal (vectorises)
                          ŒṖ - partitions of (implicit decimal digits of) n
                          f - filter discard from left if in right
                          Ẉ - length of each
                          Ṁ - maximum





                          share|improve this answer















                          Jelly,  15  9 bytes



                          RṚẆDfŒṖẈṀ


                          Try it online! (even 321 takes half a minute since the code is $O(2^N)$)



                          How?



                          RṚẆDfŒṖẈṀ - Link: integer, n
                          R - range = [1,2,3,...,n]
                          Ṛ - reverse = [n,...,3,2,1]
                          Ẇ - all contiguous slices = [[n],...,[3],[2],[1],[n,n-1],...,[2,1],[n,n-1,n-2],...,[3,2,1],...,[n,n-1,n-2,...,3,2,1]]
                          D - to decimal (vectorises)
                          ŒṖ - partitions of (implicit decimal digits of) n
                          f - filter discard from left if in right
                          Ẉ - length of each
                          Ṁ - maximum






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 29 mins ago

























                          answered 49 mins ago









                          Jonathan Allan

                          50.7k534165




                          50.7k534165












                          • ẆU saves a byte, as W already casts to range.
                            – Dennis
                            4 mins ago


















                          • ẆU saves a byte, as W already casts to range.
                            – Dennis
                            4 mins ago
















                          ẆU saves a byte, as W already casts to range.
                          – Dennis
                          4 mins ago




                          ẆU saves a byte, as W already casts to range.
                          – Dennis
                          4 mins ago











                          1















                          05AB1E, 10 bytes



                          ÝRŒʒJQ}€gà


                          Extremely slow, so the TIO below only works for test cases below 750..



                          Try it online.



                          Explanation:





                          Ý           # Create a list in the range [0, (implicit) input]
                          # i.e. 109 → [0,1,2,...,107,108,109]
                          R # Reverse it
                          # i.e. [0,1,2,...,107,108,109] → [109,108,107,...,2,1,0]
                          Π# Get all possible sublists of this list
                          # i.e. [109,108,107,...,2,1,0]
                          # → [[109],[109,108],[109,108,107],...,[2,1,0],[1],[1,0],[0]]
                          ʒ } # Filter it by:
                          J # Where the sublist joined together
                          # i.e. [10,9] → "109"
                          # i.e. [109,108,107] → "109108107"
                          Q # Are equal to the (implicit) input
                          # i.e. 109 and "109" → 1 (truthy)
                          # i.e. 109 and "109108107" → 0 (falsey)
                          €g # After filtering, take the length of each remaining inner list
                          # i.e. [[109],[[10,9]] → [1,2]
                          à # And only leave the maximum length (which is output implicitly)
                          # i.e. [1,2] → 2





                          share|improve this answer




























                            1















                            05AB1E, 10 bytes



                            ÝRŒʒJQ}€gà


                            Extremely slow, so the TIO below only works for test cases below 750..



                            Try it online.



                            Explanation:





                            Ý           # Create a list in the range [0, (implicit) input]
                            # i.e. 109 → [0,1,2,...,107,108,109]
                            R # Reverse it
                            # i.e. [0,1,2,...,107,108,109] → [109,108,107,...,2,1,0]
                            Π# Get all possible sublists of this list
                            # i.e. [109,108,107,...,2,1,0]
                            # → [[109],[109,108],[109,108,107],...,[2,1,0],[1],[1,0],[0]]
                            ʒ } # Filter it by:
                            J # Where the sublist joined together
                            # i.e. [10,9] → "109"
                            # i.e. [109,108,107] → "109108107"
                            Q # Are equal to the (implicit) input
                            # i.e. 109 and "109" → 1 (truthy)
                            # i.e. 109 and "109108107" → 0 (falsey)
                            €g # After filtering, take the length of each remaining inner list
                            # i.e. [[109],[[10,9]] → [1,2]
                            à # And only leave the maximum length (which is output implicitly)
                            # i.e. [1,2] → 2





                            share|improve this answer


























                              1












                              1








                              1







                              05AB1E, 10 bytes



                              ÝRŒʒJQ}€gà


                              Extremely slow, so the TIO below only works for test cases below 750..



                              Try it online.



                              Explanation:





                              Ý           # Create a list in the range [0, (implicit) input]
                              # i.e. 109 → [0,1,2,...,107,108,109]
                              R # Reverse it
                              # i.e. [0,1,2,...,107,108,109] → [109,108,107,...,2,1,0]
                              Π# Get all possible sublists of this list
                              # i.e. [109,108,107,...,2,1,0]
                              # → [[109],[109,108],[109,108,107],...,[2,1,0],[1],[1,0],[0]]
                              ʒ } # Filter it by:
                              J # Where the sublist joined together
                              # i.e. [10,9] → "109"
                              # i.e. [109,108,107] → "109108107"
                              Q # Are equal to the (implicit) input
                              # i.e. 109 and "109" → 1 (truthy)
                              # i.e. 109 and "109108107" → 0 (falsey)
                              €g # After filtering, take the length of each remaining inner list
                              # i.e. [[109],[[10,9]] → [1,2]
                              à # And only leave the maximum length (which is output implicitly)
                              # i.e. [1,2] → 2





                              share|improve this answer















                              05AB1E, 10 bytes



                              ÝRŒʒJQ}€gà


                              Extremely slow, so the TIO below only works for test cases below 750..



                              Try it online.



                              Explanation:





                              Ý           # Create a list in the range [0, (implicit) input]
                              # i.e. 109 → [0,1,2,...,107,108,109]
                              R # Reverse it
                              # i.e. [0,1,2,...,107,108,109] → [109,108,107,...,2,1,0]
                              Π# Get all possible sublists of this list
                              # i.e. [109,108,107,...,2,1,0]
                              # → [[109],[109,108],[109,108,107],...,[2,1,0],[1],[1,0],[0]]
                              ʒ } # Filter it by:
                              J # Where the sublist joined together
                              # i.e. [10,9] → "109"
                              # i.e. [109,108,107] → "109108107"
                              Q # Are equal to the (implicit) input
                              # i.e. 109 and "109" → 1 (truthy)
                              # i.e. 109 and "109108107" → 0 (falsey)
                              €g # After filtering, take the length of each remaining inner list
                              # i.e. [[109],[[10,9]] → [1,2]
                              à # And only leave the maximum length (which is output implicitly)
                              # i.e. [1,2] → 2






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 39 mins ago

























                              answered 49 mins ago









                              Kevin Cruijssen

                              35.8k554187




                              35.8k554187























                                  1














                                  Pyth, 16 bytes



                                  lef!.EhM.+vMT./z


                                  Try it online here, or verify all the test cases at once here.



                                  lef!.EhM.+vMT./z   Implicit: z=input as string
                                  ./z Get all divisions of z into disjoint substrings
                                  f Filter the above, as T, keeping those where the following is truthy:
                                  vMT Parse each substring as an int
                                  .+ Get difference between each pair
                                  hM Increment each
                                  !.E Are all elements 0? { NOT(ANY(...)) }
                                  e Take the last element of the filtered divisions
                                  Divisions are generated with fewest substrings first, so last remaining division is also the longest
                                  l Length of the above, implicit print





                                  share|improve this answer


























                                    1














                                    Pyth, 16 bytes



                                    lef!.EhM.+vMT./z


                                    Try it online here, or verify all the test cases at once here.



                                    lef!.EhM.+vMT./z   Implicit: z=input as string
                                    ./z Get all divisions of z into disjoint substrings
                                    f Filter the above, as T, keeping those where the following is truthy:
                                    vMT Parse each substring as an int
                                    .+ Get difference between each pair
                                    hM Increment each
                                    !.E Are all elements 0? { NOT(ANY(...)) }
                                    e Take the last element of the filtered divisions
                                    Divisions are generated with fewest substrings first, so last remaining division is also the longest
                                    l Length of the above, implicit print





                                    share|improve this answer
























                                      1












                                      1








                                      1






                                      Pyth, 16 bytes



                                      lef!.EhM.+vMT./z


                                      Try it online here, or verify all the test cases at once here.



                                      lef!.EhM.+vMT./z   Implicit: z=input as string
                                      ./z Get all divisions of z into disjoint substrings
                                      f Filter the above, as T, keeping those where the following is truthy:
                                      vMT Parse each substring as an int
                                      .+ Get difference between each pair
                                      hM Increment each
                                      !.E Are all elements 0? { NOT(ANY(...)) }
                                      e Take the last element of the filtered divisions
                                      Divisions are generated with fewest substrings first, so last remaining division is also the longest
                                      l Length of the above, implicit print





                                      share|improve this answer












                                      Pyth, 16 bytes



                                      lef!.EhM.+vMT./z


                                      Try it online here, or verify all the test cases at once here.



                                      lef!.EhM.+vMT./z   Implicit: z=input as string
                                      ./z Get all divisions of z into disjoint substrings
                                      f Filter the above, as T, keeping those where the following is truthy:
                                      vMT Parse each substring as an int
                                      .+ Get difference between each pair
                                      hM Increment each
                                      !.E Are all elements 0? { NOT(ANY(...)) }
                                      e Take the last element of the filtered divisions
                                      Divisions are generated with fewest substrings first, so last remaining division is also the longest
                                      l Length of the above, implicit print






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 15 mins ago









                                      Sok

                                      3,567722




                                      3,567722






























                                          draft saved

                                          draft discarded




















































                                          If this is an answer to a challenge…




                                          • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                          • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                            Explanations of your answer make it more interesting to read and are very much encouraged.


                                          • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                          More generally…




                                          • …Please make sure to answer the question and provide sufficient detail.


                                          • …Avoid asking for help, clarification or responding to other answers (use comments instead).






                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178373%2fhow-many-consecutive-descending-numbers-in-my-number%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Understanding the information contained in the Deep Space Network XML data?

                                          Ross-on-Wye

                                          Eastern Orthodox Church