Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6044707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:02:32+00:00 2026-05-23T07:02:32+00:00

How do I get a sequence of a given number in Groovy, for example:

  • 0

How do I get a sequence of a given number in Groovy, for example:

def number = 169
// need a method in groovy to find the consecutive numbers that is, 1,6,9,16,69,169
// not 19!

There is a method in Groovy called subsequences(), but that is not doing this job exactly. Can anyone say me how can I do this in Groovier way? Or is there any built-in method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:02:32+00:00Added an answer on May 23, 2026 at 7:02 am

    Although late to the game, here’s a solution that is less sophisticated than @tim’s, but also will do the trick:

    def str = 169 as String
    def result = [] as SortedSet
    (0..<str.length()).each { i ->
        (i..<str.length()).each { j ->
            result << str[i..j].toInteger()
        }
    }
    

    Edit:

    The code works like two nested loops that iterate over the String representation of the number and extracting the various substrings from it.

    The outer loop represents the start index of the substring and the inner loop the end index of the substring. The outer loop will go from the beginning to the end of the String, whereas the inner loop starts at the current start index and goes from there to the end.

    The as SortedSet ensures that there are no duplicate numbers in the result and that the numbers are sorted in ascending order.

     1 6 9 
     -----
     0 1 2  <-- index
     =====
    [1]6 9  (i=0; j=0)
    [1 6]9  (i=0; j=1)
    [1 6 9] (i=0; j=2)
     1[6]9  (i=1; j=1)
     1[6 9] (i=1; j=2)
     1 6[9] (i=2; j=2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a sequence number, I need to find the corresponding request message string. I
Given a sequence (for example a string Xa), I want to get the next
How do I get the sequence number of the row just inserted?
Whenever the tags argument is not empty I get a NotSupportedException: Local sequence cannot
Given a sequence of operations: a*b*a*b*a*a*b*a*b is there a way to get the optimal
In Python, I'm constantly using the following sequence to get an integer value from
An HTTP GET query string is a ordered sequence of key/value pairs: ?spam=eggs&spam=ham&foo=bar Is,
Two Questions: Will I get different sequences of numbers for every seed I put
We get the following error; The request was aborted: Could not create SSL/TLS secure
First do note that my english in not the best here. If anyone is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.