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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:07:03+00:00 2026-06-18T04:07:03+00:00

So I need to get all possible permutations of a string. What I have

  • 0

So I need to get all possible permutations of a string.

What I have now is this:

def uniq_permutations string
  string.split(//).permutation.map(&:join).uniq
end

Ok, now what is my problem: This method works fine for small strings but I want to be able to use it with strings with something like size of 15 or maybe even 20. And with this method it uses a lot of memory (>1gb) and my question is what could I change not to use that much memory?

Is there a better way to generate permutation? Should I persist them at the filesystem and retrieve when I need them (I hope not because this might make my method slow)?

What can I do?

Update:

I actually don’t need to save the result anywhere I just need to lookup for each in a table to see if it exists.

  • 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-18T04:07:04+00:00Added an answer on June 18, 2026 at 4:07 am

    Just to reiterate what Sawa said. You do understand the scope? The number of permutations for any n elements is n!. It’s about the most aggressive mathematical progression operation you can get. The results for n between 1-20 are:

    [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 
     6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000,
     6402373705728000, 121645100408832000, 2432902008176640000]
    

    Where the last number is approximately 2 quintillion, which is 2 billion billion.

    That is 2265820000 gigabytes.

    You can save the results to disk all day long – unless you own all the Google datacenters in the world you’re going to be pretty much out of luck here 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List<List<String>> I need to get a List of all possible concatenation
Possible Duplicate: Generate list of all possible permutations of a string I need to
Not sure if this is possible but here goes... i need to get all
Possible Duplicate: Get all files from VSS for a given date? I need to
I need get all items these have no categories int? categoryId = null; var
I need to get all substrings from string. For ex: StringParser.GetSubstrings([start]aaaaaa[end] wwwww [start]cccccc[end], [start],
Suppose you need to discover all possible permutations of 'n' distinct characters, say 'a',
i have a problem. How do I get all possible combinations of x booleans
I need to get a list of all possible running processes(whether they are stopped
I need to get all possible subsets of an array with a minimum of

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.