• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generate string

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok let`s say we have an array string like this:
String[] elements = {"a", "b", "c",...};

All I want is to generate all possible combinations (including also "aa...a","aa...b", etc).
I also run the code posted here here by Sai Narasimha Reddy but the combinations like aa, bb, .....ccb, ccc are not generated.

I tried another permutations and combinations that I found but none of them don`t generate all combinations (such as "aa...a","aa...b",...)


Please help and thanks in advance.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first, the terms 'permutations' and 'combinations' are well defined terms, and are mutually exclusive. or I guess technically, the set of combinations is a subset of permutations (unless i got that backwards).

So, before we can do much else, tell us what you really want. Combinations are where the order doesn't matter, so "ABC" is considered the same thing as "CBA".

Next...do you have to use all the elements each time? if i have 'a', 'b' and 'c', do you want 'ab', 'ac' and 'bc'? (and 'ba', 'ca and 'cb')?

finally, I'll tell you what i would tell anyone.

Before you write a single line of code, write down on paper, in english, how YOU would do this by hand, step-by-step. Then go back and revise each step, making it more and more detailed. Once you do that, writing the code is orders of magnitude easier.

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You say you want "aa...a". I take it that's virtually an infinite number of "a"s. That means that the total number of combinations is just as infinite, and it's going to be impossible to generate them all. After all, once you get "aa...a" of size X, you can get another combination by adding another "a", getting "aa...a" of size X + 1.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and welcome to the Ranch
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic