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 8688195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:17:56+00:00 2026-06-12T23:17:56+00:00

If I have a string such as ‘abcde’ and I want to get a

  • 0

If I have a string such as ‘abcde’ and I want to get a 2d array of all combinations of 1 or 2 letters.

[ ['a', 'b', 'c', 'd', 'e'], ['ab', 'c', 'de'], ['a', 'bc', 'd', 'e'] ...

How would I go abouts doing so?

I want to do this in ruby, and think I should be using a regex. I’ve tried using

strn = 'abcde'
strn.scan(/[a-z][a-z]/)

but this is only going to give me the distinct sets of 2 characters

['ab', 'cd']
  • 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-06-12T23:17:59+00:00Added an answer on June 12, 2026 at 11:17 pm

    I think this should do it (haven’t tested yet):

    def find_letter_combinations(str)
      return [[]] if str.empty?
      combinations = []
      find_letter_combinations(str[1..-1]).each do |c|
        combinations << c.unshift(str[0])
      end
      return combinations if str.length == 1
      find_letter_combinations(str[2..-1]).each do |c|
        combinations << c.unshift(str[0..1])
      end
      combinations
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string such as big bad dog, how can I get an
If I have a string such as lotsofcrapsomethingimportantmoreotherstuff is it possible to get Regex
Not sure where I am doing wrong. I have a string such as Test
So I have such string (recived from php server... normal print_r of array) Array
I have a string such as 'xxox-x' that I want to mask each line
I have a string such as <html><body><div id=message>Hello World!</div></body></html> and I would like to
I have a string such as Value = $val$ and I want to replace
Let's say I have a string such as: Hello how are you doing? I
I have a requirement to contract a string such as... Would you consider becoming
I have a string such as: #sometag-{serialized-data-here} And I want to match this pattern

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.