Code: [Select]
public class Driver{
public static void main(String[] args)
{
List l = new List();
for(int i=0; i<12; i++){
l.display();
l.getNext();
}
System.exit(0);
}
}
public class List{
int[] current;
int[] next;
public List(){
current = new int[1];
next = new int[0];
current[0] = 1;
}
public void add(int i){
expand();
next[next.length-1] = i;
}
public void expand(){
int[] temp = new int[next.length+1];
for(int i=0; i<next.length; i++){
temp[i] = next[i];
}
next = temp;
}
public void getNext(){
next = new int[0];
for(int i =0; i<current.length; i++){
if(current[i]>4 && (current[i]-4)%6==0){
add(current[i]*2);
add((current[i]-1)/3);
}else{
add(current[i]*2);
}
}
current = next;
}
public int[] getCurr(){
return current;
}
public void display(){
for(int i =0; i<current.length; i++){
System.out.print(current[i] + " ");
}
System.out.println("");
}
}
I threw together some code on my chromebook for the collatz conjecture. And I don't really want to lose it.
It makes the tree of successors for where each values can go.