I'd better express this with a example, I'm trying to write a program, say I have a function like this:
static List<Integer> int2List(int l, int base)
the input and output should be
l=0, base=3, return {1}
l=1, base=3, return {2}
l=2, base=3, return {3}
l=3, base=3, return {1,1}
l=4, base=3, return {1,2}
l=5, base=3, return {1,3}
l=6, base=3, return {2,1}
l=7, base=3, return {2,2}
l=8, base=3, return {2,3}
l=9, base=3, return {3,1}
l=10, base=3, return {3,2}
l=11, base=3, return {3,3}
l=12, base=3, return {1,1,1}
l=13, base=3, return {1,1,2}
l=14, base=3, return {1,1,3}
... It's quite like recursively mod but there are some condition I can't figure out.
Thanks
Thanks for all your comments and I've updated the question content and the signature of the method, I wanted to display the content of a list and I forgot to add comma between elements.
So here's my code, it's not correct yet but I think you can get some sense from it. It's also quite like the Long.toString(int i, int radix), the differences are first I need to add those leading zeros, and second I need to do a "+1" from every element in the list, but doing that not gives me correct either...
static List<Integer> int2List(int l, int base) {
// String s = Long.toString(l,base);
List<Integer> list = new ArrayList<Integer>();
int k = l % base;
int j = l / base;
int m = 0;
list.add((int) (k + 1));
while (j > base) {
k = j % base;
list.add((int) (k));
if (j == base)
break;
j = j / base;
}
if (j == base) {
list.add((int) (j));
} else {
if (j > 0) {
list.add((int) (j));
}
}
Collections.reverse(list);
return list;
}
I'm aware of the mistakes I've made in the first version, I now fix my mistakes and update the question to be more specific, can you remove the "not worth reading" please, I'll really appreciate..
===================
Hmm, the method is supposed to be used in a loop, such that it will output all possible sequences composed by number in range [1,base], and the l
can be seen as an index.