wood burning stoves 2.0*
The moose likes Java in General and the fly likes Bruteforcer with desending order of char[] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Bruteforcer with desending order of char[]" Watch "Bruteforcer with desending order of char[]" New topic
Author

Bruteforcer with desending order of char[]

Ryan Miller
Greenhorn

Joined: Feb 13, 2010
Posts: 3
Been trying to figure this out for days now and could really use to help. Basically I have a bruteforcing algorithm and instead of it generating from 00000 - zzzzzz I want to go from zzzzzz to 00000. The method I have in my bruteforcer uses binary search which requires any char[] to be sorted. I found something on google saying I could achieve the reversal I want by using the reverseOrder() method within the Collection class and I've been trying every possible thing I can but can not get the results I want. Would anyone happen to have any ideas? If not, what would a good way to do this without the binary search be? Just a linkedlist? Thank you!

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

So what is it doing wrong? Be specific about what you want, what it does, and what the difference is.


Steve
Ryan Miller
Greenhorn

Joined: Feb 13, 2010
Posts: 3
The issue is in the increment method. The increment method cycles through every combination of the chars in the array. Say I pass my char[] and a length of 5 through the constructor, it will start at 00000 and will keep going on forever. When I pass my char[], every char must be in ascending order and cannot be mixed do to the nature of the binarySearch(). (It must be 1 2 3 4 and cannot be 2 4 1 3). What I'm trying to do is instead of generating my combinations in ascending order, I want to do them in descending order. i.e. I pass through my char[] and a length of 5 through the constructor and it starts at zzzzz and descends all the way down to 00000. I'm trying to find a way to do this without conflicting with the nature of binarySearch.

Basically I want to count down instead of count up but binarySearch is preventing it because the array passed must be in order i.e.:

char[] charset = {"0", "1", "2"};

and can not pass:

char[] charset = {"2", "1", "0"};
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Ryan Miller wrote:

Basically I want to count down instead of count up but binarySearch is preventing it because the array passed must be in order i.e.:

char[] charset = {"0", "1", "2"};

and can not pass:

char[] charset = {"2", "1", "0"};


If if you're given {0, 1, 2}, and you can't change that, but you want {2, 1, 0}, then simply reverse the order in which you iterate over the array.

The idiom is the most common way to iterate an array, but it's not The Sacred High Writ Of All That Is Holy. The stuff inside the parens is not written in stone. Think about what those pieces actually mean, and how you could change them to iterate in the other direction.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Ryan Miller wrote:The issue is in the increment method.

It may well be, but I'd say you're concentrating far too much on implementation. What you (and we) need to understand is what you want to do; and you DON'T do that by writing code.

Coding is the final result of a lot of thinking, and it's basically a mechanical process. The important (and creative) part of programming comes in ordering your ideas and working out the design - and design is mostly about what, not how.

Being a programmer is a bit like being a writer: For a writer, most of the best words have already been said better by Shakespeare; for programmers, most algorithms (ie, code) have already been written, so the art comes in constructing your programs.

My advice: concentrate on what needs to be done, not how you're going to do it. When you have a good grasp of that, the 'how' will come almost automatically.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bruteforcer with desending order of char[]