Is there something exists that will allow me to count from say 0-9 and then from a-z. I know that for hexadecimal I could go from 0-f.
Bascially I am trying to loop through some alphanumeric id and find out which ones are valid. It will take me awhile becasue the id is 12 alphanumeric characters.
Off the top of my head I woudl probably create an array from 0-z and just loop that way. I just wanted to know if there was an easier way or something that may be in the api that I just overlooked.
Ryan Smith
Ranch Hand
Joined: Jun 29, 2004
Posts: 40
posted
0
You may want to try something using the ASCII char codes, using the String methods isDigit and isLetter...
Ryan Smith
Ranch Hand
Joined: Jun 29, 2004
Posts: 40
posted
0
Make those methods in the Character class...sorry!
[Edit:] Alright, let me clarify:
[ July 31, 2004: Message edited by: Ryan Smith ] [ July 31, 2004: Message edited by: Ryan Smith ]
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
Do the characters have to be in a particular order? You might check out the regex stuff.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Anthony Smith
Ranch Hand
Joined: Sep 10, 2001
Posts: 285
posted
0
That helped a little but I am still stuck. I am using ascii char but I am lookling at recursion to try and get done what I need to. Time was a factor, but I guess I got to sit down and pull out some computer science and algorithim skills in order to figure out a soultion.
You know the decimal system, surely the dual, as you mentioned hex. Bases are 10, 2, 16. Not that well known is the octal system with base 8.
Java knows at least the 26+10= 36 base - either in Integer, or Number or String class. It's in the javadocs. isn't it: Integer.parseInt (String, base)?
I don't know whether distinction between lower- and uppercase is suppoerted, which would give a 2*26+10 base.
If you can't find it, ask again, and we will look up the javadocs.
Originally posted by Anthony Smith: Bascially I am trying to loop through some alphanumeric id and find out which ones are valid.
I'm still confused as to what you are trying to accomplish. Are you trying to generate possible valid ids by looping through all possible ids?
Is any id valid that contains alphanumeric chars? i.e. 12d8rit3k901?
Are you trying to assign the ids that have not yet been assigned in numerical order?
Are you trying to rule out ids that contain chars other than 0-9 and a-z?
Do A-Z need to be capitalized or are a-z also acceptable as "valid ids"?
Anthony Smith
Ranch Hand
Joined: Sep 10, 2001
Posts: 285
posted
0
"Is any id valid that contains alphanumeric chars? i.e. 12d8rit3k901? " Yes.
Basically I want to go through all combinations of alphanumeric characters. Case does not matter, it can be upper or lower.
Nick George
Ranch Hand
Joined: Apr 04, 2004
Posts: 815
posted
0
I'd suggest forgetting about any kind of base 36, and build the strings yourself. Just loop through the ascii. One way that might be kind of cool would be to have however many nested for loops. In the very-most inner one, use the cascading loop variables to build your string. The innermost loop will run through all the way before the next one will, which will go all the way until the next one, etc., thus simulating an advancing number system. eh?
I've heard it takes forever to grow a woman from the ground
This code will run appromaxly 8000 years on my machine, which is about 2 years old and wasn't the fastest, when new. An actual machine might need about 2000 years. According to Moores Law, you could wait for about 10 years for a 4 Thz machine, which could solve it in 2 years. It would mean the same to wait 11 years and run the application in 1 year - results would be there in 12 years. Waiting longer wouldn�t make much sense But I would check in 2010, whether Moores Law is still valid
On the other hand: If you have a cluster of 36x36 machines of 4 Ghz, it could be solved in about 2 years.
[ August 01, 2004: Message edited by: Stefan Wagner ] [ August 01, 2004: Message edited by: Stefan Wagner ]
Dan Walin
Ranch Hand
Joined: Nov 11, 2003
Posts: 109
posted
0
That calculation is probably pessimistic, meaning that you have to run through every single combination before finding the right one. On average you'd probably have to go through 1/2 of the combinations before hitting it - so maybe 4000 years?
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
Basically I want to go through all combinations of alphanumeric characters.
This might be one way (needs testing, and plenty of time)
Jack Kay
Ranch Hand
Joined: Aug 01, 2004
Posts: 62
posted
0
Originally posted by Stefan Wagner: On the other hand: If you have a cluster of 36x36 machines of 4 Ghz, it could be solved in about 2 years.
Michael: MAX_RADIX is set to 36, so my solution can't be modified to handle distinguishing of Upper and Lowercase.
While "case does not matter" sounds like "don't distinguish them", the second part of the sentence "it can be upper or lower" sounds like the opposite.
Now Anthony - does it matter or not? do we have 36 different characters, or 62? Ah - the post before he said:
I want to go from 0-Z 0,1,2...9,A,B....Y,Z
But Michael, I guess every character may occur multiple times - this would especially be my expection for a password. And though your solution produces less results when truncated to 36 values, (36*35*34* ... *24) - compared to mine (36^12) - it's slower.
But of course - premature optimization is the root of all evil - so forget about my optimized one, and refactor yours! [ August 01, 2004: Message edited by: Stefan Wagner ]
Anthony Smith
Ranch Hand
Joined: Sep 10, 2001
Posts: 285
posted
0
36 Characters...
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
I guess every character may occur multiple times - this would especially be my expection for a password.