Projects >> An incremental programme
Posted by ItinitI on 10:12:00 07-27-2003
I'm writing [or thinking of writing] a programme to print out a list [to a text file] of every possible alpha-numeric character [including ".", "-", and "_"] combonation. Since I'm quite novice at programming, I'm having some difficulty determining how to do this. I'm thinking perhaps an array to hold the charactors, and a while loop to do the incrementing.
Any suggestions? ThanX!
Posted by split on 11:42:00 07-29-2003
Are you talking about permutations? That could be fairly easily accomplished with a LOT of (especially in your case) nested for loops. I'm sure there's a more elegant way to do it, though.
Posted by DInsane on 01:34:00 07-31-2003
That would be relatively easy, like you said. A simple loop script, printing out every combination until it hits a point when it recognizes it. It would be a cinch in the wonderful PHP language! lol [addsig]
Posted by split on 10:23:00 08-01-2003
"a point until it recognizes it"?

Certainly you don't mean checking every combo you make with the already created list of combos. That would be realllly inefficient.
Posted by DInsane on 07:28:00 08-05-2003
Well, I was speaking by possibility wise, not "I already have an idea" wise.
Posted by inhahe on 14:40:00 09-21-2003
Quote:
On 2003-07-29 11:42, split wrote:
Are you talking about permutations? That could be fairly easily accomplished with a LOT of (especially in your case) nested for loops. I'm sure there's a more elegant way to do it, though.


Quote:
On 2003-07-29 11:42, split wrote:
Are you talking about permutations? That could be fairly easily accomplished with a LOT of (especially in your case) nested for loops. I'm sure there's a more elegant way to do it, though.


I think the more elegent way is with a recursive function. like:

s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-"

list = []
def i(c, l):
for x in s[:]:
if len(c) == l-1:
list.append(c+x)
else:
i(x+c, l)

i("", 5)
print list


That way you can specify an arbitrary number of characters.
I have a feeling it's unelegant to have the if inside of the for loop, but it was hard enough just to get it working. i seem to s_ck at recursive programming.

I guess he wants something like:

for x in range(10): i("", x)


[ This Message was edited by: inhahe on 2003-09-21 14:40 ]

[ This Message was edited by: inhahe on 2003-09-21 14:41 ]

[ This Message was edited by: inhahe on 2003-09-21 14:45 ]