I think that is correct. I had to do a mass replace of variable i to o because the forum was interpreting them as formatting codes
public class main {
public static int lotterycount = 0;
public static void main(String args[]) {
int[] ticket = { 1, 2, 3, 4, 5, 6 };
while (ticket[0] != 43) {
increment(ticket, ticket.length - 1);
System.out.println(ticket[0] + " " + ticket[1] + " " + ticket[2]
+ " " + ticket[3] + " " + ticket[4] + " " + ticket[5]);
lotterycount++;
}
System.out.println(lotterycount + "");
}
public static int[] increment(int[] ticket, int position) {
ticket[position]++;
if(ticket[0]==43){return ticket;}//if we incremented the biggest number. return it and exit.
if (ticket[position] == 43) {
ticket[position] = 1;// reset the position
if (position - 1 != -1) {// if we are not attempting to increase a location that does not exist
ticket = increment(ticket, position - 1);
}
}// increment the position to the left
if (duplicate(ticket, position)) {// if a duplicate exists on this
// position, increment it again
ticket = increment(ticket, position);
}
return ticket;
}
public static boolean duplicate(int[] ticket, int position) {
int o = 0;
while (o < ticket.length) {
if (ticket[o] == ticket[position] && o != position) {
return true;
}
o++;
}
return false;// end of the loop and no duplicates, return false
}
}
printing 5 million results takes a while. That is assuming that is all it is printing
Edit: I edited the code like 3 times after posting. The comments I do not expect to help clarify the code, they were written for me to know what I was doing.
The language is java.
edit again: damn I forgot to check for duplicates right to left left to right.