This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with permutation

 
Miguel Imoooo
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to take a string and make all possible permutations taken at some length at a time. The length depends upon the number of underscores in a string( this is a crossword puzzle helper application).

For example,
String s = "abcde"
results for length 3
abc
abd
ebd
ced
ace
and so on..

==============================
User input string: Ja_aRan_h
Characters availabe to user: abdefde
the program would get all permutaions and stick them in the underscores, and check a database if that word exists...
====================================

here is my method
Public String[] permutations(String s, int numUnderScores){
int numberOfPermutations = factorial(s.length () )/factorial(s.length()-numUnderScores);
// this is how many different permutation of length numUnderScores you can get with string s..
// I dont know what to do after this....=(
}
Thanks a lot !!!
Mike
[ March 30, 2002: Message edited by: Miguel Imoooo ]
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't really care *how* many permutations you have, you just want to list them all. I would probably look at some type of looping construct with recursion.
 
Brent Worden
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Shameless plug follows)
Take a look at http://www.brent.worden.org/algorithm/combinatorics/enumeratePermutations.html
It's an algorithm to enumerate permutations of an int array. It's written in C++ but should be easily adapted to Java.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic