I am working in an Authomata and need three numbers that suumed equal n For example, if n = 2 the numbers I need are:
200
020
002
110
101
011
It doesn´t matter if the combination are repeated.
If n = 3 I need:
300
030
003
210
201
021
120
012
102
111
So I read thar this was similar to the partition in the theory of numbers but I can get the particular case where only 3 numbers give me the target value (n). (The code is from a example I get here)
package automata2;
import java.util.ArrayList;
/**
*
* @author jaime
*/
public class Automata2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int N = 14;
partition(N);
}
public static void partition(int n) {
partition(n, n, "");
}
public static void partition(int n, int max, String prefix) {
if (n == 0) {
System.out.println(prefix);
return;
}
for (int i = Math.min(max, n); i >= 1; i--) {
partition(n-i, i, prefix + " " + i);
}
}
}
But I only need al the combinations with three digits, not all since 14 until 1 1 1 1 1 1 1 1 1 1 1 1 1 1