Brute Force Algorythm

I have been trying to make a program that just spits out every possible combinations in the char list i specify and the length i specify. The problem is that I cant think of a decent alg for it. I have read about it and stuff but I just cant sem to find a way to do it. The only way I can think of doing it is by making a ton of integrated for loops which is totally wrong and inefficient. How can I do this? Thanks...

Example:

Number Of Chars: 4

Pattern List: 0123456789

Output:

0000

0111

0011

1111

0112...etc except with all the numbers and stuff.

[610 byte] By [Sucka8a] at [2007-11-26 20:49:09]
# 1

> 0000

> 0111

> 0011

> 1111

> 0112...etc except with all the numbers and stuff.

Why not

0000

0001

0002

...

0009

0010

0011

0012 etc. ?

Use the digits as indices to the array with the characters and just use some loops to do the trick.

Cinnama at 2007-7-10 2:12:49 > top of Java-index,Java Essentials,Java Programming...
# 2

A tree data structure would fit this problem.

Attach all possibilities for the first digit to the top node of the tree, and attach a node for each possibility for the second digit to each node of the first digit layer of the tree, etc.This way, if you need to add a digit, you simply stick another layer onto the tree.

Do a pre-order traversal of the tree to get your sorted list.

Can't find any examples off hand.

kevjavaa at 2007-7-10 2:12:49 > top of Java-index,Java Essentials,Java Programming...
# 3
1) Why are you trying to do this?2) Why are you trying to do this with Java?3) Have you tried searching Google for "brute force algorithm"?
Djaunla at 2007-7-10 2:12:49 > top of Java-index,Java Essentials,Java Programming...
# 4
1) Because Its Fun2) Its My Strongest Programming Language3) I Have Searched ALOT ALOT ALOT And Found Some Examples But I Had Trouble Understanding Them.
Sucka8a at 2007-7-10 2:12:49 > top of Java-index,Java Essentials,Java Programming...