public static long fibby(long n){
if (n == 0){
return 1;
}
return (fibby(n/4))+(fibby(3*n/4));
}
public static void sparsetablegen(int start, int end){
long fibbyOut = fibby(start);
long lastFibbyOutput = fibbyOut;
System.out.println(start+" "+fibbyOut);
if(start != end){
sparsetablegen(start+1, end);
if (lastFibbyOutput == fibbyOut){
return;
}
}
}
Disclaimer: This is an assignment for my java project and I've tried multiple approaches and can not figure out a working solution. I will post what my understanding of the code is and what's not working properly.
What my table is supposed to do is take in values, starting from "int start" and finishing at int "end", those values will then be solved by my "fibby" function. Then it should print the values of "start" and fibbyOut side by side until it hits the "end". What I'm supposed to do is skip over any duplicate values of fibbyOut So for example I might see: 1 -> 2 2 -> 3 3 -> 4 4 -> 6 5 -> 6 6 -> 8
And so then I would want to skip over the start value 5, since fibbyOut for 4 is 6 and that's a duplicate value. So instead I should see 1-> 2 2-> 3 3-> 4 4-> 6 6-> 8
I know it's a very basic problem, but I just can't seem to figure how to remove the duplicate values of fibbyOut. Thanks for any help.
if (lastFibbyOutput == fibbyOut)is always true.