Author |
Topic: list the Combination of a string. (Read 3416 times) |
|
SMQ
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 2084
|
|
Re: list the Combination of a string.
« Reply #25 on: Sep 15th, 2009, 5:58am » |
Quote Modify
|
on Sep 14th, 2009, 2:23pm, mistaken_id wrote:Is there a way to extend this algorithm to print only combinations of strings. For example; given an input "abc" It should print a b c ab ac bc abc Lexicographic order of combinations......... |
| You could simply cull all out-of-order outputs from the algorithm. I.e. change the first line of the loop to "if the first n characters are in increasing order output the first n characters." That would roughly double the runtime but not change the complexity. More efficient would probably be to just loop through each length and list the combinations directly, as here. --SMQ
|
« Last Edit: Sep 15th, 2009, 5:59am by SMQ » |
IP Logged |
--SMQ
|
|
|
|