my dog learned polymorphism
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with permutation" Watch "help with permutation" New topic

help with permutation

Miguel Imoooo

Joined: Feb 28, 2002
Posts: 5
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
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 !!!
[ March 30, 2002: Message edited by: Miguel Imoooo ]
Rob Ross

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.

SCJP 1.4
Brent Worden
Ranch Hand

Joined: Nov 26, 2001
Posts: 50
(Shameless plug follows)
Take a look at
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
I agree. Here's the link:
subject: help with permutation
It's not a secret anymore!