File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes help with permutation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with permutation" Watch "help with permutation" New topic
Author

help with permutation

Miguel Imoooo
Greenhorn

Joined: Feb 28, 2002
Posts: 5
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

Joined: Jan 07, 2002
Posts: 2205
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.


Rob
SCJP 1.4
Brent Worden
Ranch Hand

Joined: Nov 26, 2001
Posts: 50
(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.


Brent Worden
 
 
subject: help with permutation
 
Similar Threads
Can't Break Out of a Loop
split()...
Using interface as a type
permutation
permutations