Nested for loops are your friend I think. Iterate over the string and for each index reiterate over the other indices replacing each with *. You would skip the index of the one you are on to maintain its position. e.g. if input is "abc" then the first "outer" iteration will use 'a' at index 0. So you iterate over the string again and if inner index == outer index (i.e. 0 in this case) use the original char, 'a'. Otherwise replace each other characters with *. You will need to work out how to do a**, ab*, a*c as part of the inner loop...
A different way to look at it; there are two possible states of any given letter position, either display the letter or display an asterisk. If ou let the 0 state signify displaying the letter, and the 1 state signify displaying an asterisk you have this pattern:
The $5 question is, what does that pattern represent, and how could you use it to generate your Strings? [ November 24, 2008: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Joined: Jan 17, 2006
So I just tried out the algorithm I was implicitly suggesting and I got:
abc *bc a*c **c ab* *b* a** ***
instead of the sequence I previously posted. Getting the other sequence seems to be a lot more difficult.
Joined: Jun 26, 2007
@ Garrett Rowe Can you please post the code you tested for this. It would be really helpful.
and to answer the $5 question
DB stores a comma separated list of values that might be in any of these combinations and the user gives the exact string (ex: abc). Now we have to search the entire DB for records that match that sequence as specified.
Coding any other way was giving a performance bottle neck, as trying to get all records and then figuring out which to eleminate resulted in too many loops. DB holds millions of these records, each with a comma saperated list.
The best solution was to generate all possible combinations (in java) and then fire a select query, this way the results would be quick and gain in performance high.
Thanks for all the replies.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com