Anagram Help - Oracle9i Enterprise Edition Release 9.2.0.7.0
451271Apr 16 2007 — edited Aug 8 2008I need help with procedure to get Anagrams from inserted word. Because I am new this can anyone please help me?
For example: I want to insert word "USB" and procedure will give me all the possible
combinations for this tree letters "U", "S" and "B".
Like this: "BSU", "BUS", "SUB", "SBU", ......
I have found some links with code but I can't find any in SQL language. Can anyone please help me or can anyone just give me some directions to some web site that could help me.
Just for help I have found this code's but I don't realy understand them:
Private Function Anagram(Word$) As String
Dim QQ%, An%, An1%
ReDim An2%(Len(Word))
Anagram = ""
For An = 1 To Len(Word)
NewRnd:
Randomize
An1 = Int(Rnd * Len(Word)) + 1
For QQ = 1 To An
If An2(QQ) = An1 Then GoTo NewRnd
Next QQ
An2(An) = An1
Anagram = Anagram + Mid(Word, An1, 1)
Next An
End Function
or this one:
import java.io.IOException;
public class AnagramApp {
static int size;
static int count;
static char[] charArray;
public static void main(String[] args) throws IOException {
String input = "Java Source and Support";
size = input.length();
count = 0;
charArray = new char[size];
for (int j = 0; j < size; j++)
charArray[j] = input.charAt(j);
doAnagram(size);
}
public static void doAnagram(int newSize) {
int limit;
if (newSize == 1) // if too small, return;
return;
// for each position,
for (int i = 0; i < newSize; i++) {
doAnagram(newSize - 1); // anagram remaining
if (newSize == 2) // if innermost,
display();
rotate(newSize); // rotate word
}
}
// rotate left all chars from position to end
public static void rotate(int newSize) {
int i;
int position = size - newSize;
// save first letter
char temp = charArray[position];
//shift others left
for (i = position + 1; i < size; i++)
charArray[i - 1] = charArray;
//put first on right
charArray[i - 1] = temp;
}
public static void display() {
System.out.print(++count + " ");
for (int i = 0; i < size; i++)
System.out.print(charArray[i]);
System.out.println();
}
}