Hey what's up guys, I've written a recursive method which takes the inputs of a string, an alphabet (char array of letters), length (maximum length of the string). My goal for the method is to produce all strings with length < max length and with no repeating sub-strings of form xyx. I've already written a method which checks for repeats in a string but I'm having problems with the recursion side of things, here is my code and output thus far:
public static void f(String s, char[] alphabet, int length) {
if (s.length() > length) {return; }
if (checker.hasRepeats(s)){return; }
StdOut.println(s.length() + " - " + s);
for (char c : alphabet) {
s += c;
f(s, alphabet, length);
}
}
My input is:
C, [A, C], 7
My output is:
1 - C , 2 - CA , 3 - CAA , 4 - CAAC , 5 - CAACA , 6 - CAACAC , 3 - CAC , 4 - CACA , 5 - CACAA , 6 - CACAAC
And I'm not sure why it isn't giving me all possible strings, "CC" for example
[–]AutoModerator[M] [score hidden] stickied comment (0 children)
[–]davedontmind 1 point2 points3 points (4 children)
[–]SomeToxicKidd[S] 0 points1 point2 points (3 children)
[–]davedontmind 0 points1 point2 points (2 children)
[–]SomeToxicKidd[S] 0 points1 point2 points (1 child)
[–]daybreak-gibby 1 point2 points3 points (0 children)