Results 1 to 4 of 4
 06242013, 07:14 AM #1Member
 Join Date
 Sep 2012
 Posts
 42
 Rep Power
 0
I have trouble with an algorithm!! Help!!
Hey guys, so basically i'm trying to brute force hack my pw to see how strong it is. While looking/thinking for an algorithm, i found this. Can someone explain why it works?
Java Code:class asd { public static void main(String[] args) { printWordsRec("", 2); } private static void printWordsRec(String base, int length) { for (char c = 'a'; c <= 'z'; c++) { if (length == 1) { System.out.println(base + c); } else { printWordsRec(base + c, length  1); } } } }
It goes A, then AA, then A(base) + B(c), then A(base) + C(c b/c of new for loop)
However, when c = z, and you get A (base) + Z (c) why does it then add one to base to make it B (base) + A (c)? If the loop is over, then shouldn't it just quit? And what is making A(base) turn into B(base)
 06242013, 07:24 AM #2
Re: I have trouble with an algorithm!! Help!!
This is a recursive method. You need to fully understand how recursion works. I suggest you search the net for simple examples first and try ti understand them. Factorial is a perfect example.
 06242013, 08:46 AM #3
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Re: I have trouble with an algorithm!! Help!!
Think of ordinary base ten numbers; you can enumerate all, say, three digit numbers by enumerating all two digit numbers and append either a 0 or a 1 or a 2 ... to them. Your algorithm does the same with base 26 numbers.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
 06242013, 05:12 PM #4Member
 Join Date
 Sep 2012
 Posts
 42
 Rep Power
 0
Similar Threads

Mph to Kph Algorithm
By jbing109 in forum New To JavaReplies: 4Last Post: 01212013, 08:26 AM 
all i need is algorithm
By naved in forum New To JavaReplies: 4Last Post: 04062011, 02:34 PM 
Algorithm help? :)
By Mirix in forum New To JavaReplies: 6Last Post: 05242010, 02:08 AM 
Need some help in an algorithm
By ea09530 in forum New To JavaReplies: 3Last Post: 04042010, 01:13 PM 
Help with an Algorithm
By Manfizy in forum New To JavaReplies: 22Last Post: 07032009, 07:16 AM
Bookmarks