Posted: Mon Oct 04, 2010 6:45 pm
Yeah, I just did it non-recursively, which was only after I looked at it and tried to figure out what the method did, up until I realized that doing it in reverse was much easier.
Code: Select all
public class UpCount {
private long calc(int depth) {
if (depth == 0) return 1;
long cc = calc(depth - 1);
return cc + (depth % 7) + ((((cc ^ depth) % 4) == 0) ? 1 : 0);
}
public static void main(String[] args) {
UpCount uc = new UpCount();
System.out.println(uc.calc(11589));
}
}
Code: Select all
#include <iostream>
using namespace std;
void main(void) {
int result[11590];
result[0]=1;
for (int i=1;i<11590;i++) {
result[i]=result[i-1]+(i % 7) + ((((result[i-1] ^ i) % 4) == 0) ? 1 : 0);
}
cout << "result: " << result[11589] <<endl;
}
Code: Select all
namespace ConsoleApplication1
{
class Program
{
private long calc(int depth)
{
if (depth == 0) return 1;
long cc = calc(depth - 1);
return cc + (depth % 7) + ((((cc ^ depth) % 4) == 0) ? 1 : 0);
}
static void Main(string[] args)
{
Program uc = new Program();
Console.WriteLine(uc.calc(11589));
}
}
}
Code: Select all
import sys
sys.setrecursionlimit(100000)
def calc(depth):
if depth == 0:
return 1
else:
cc = calc(depth-1)
if ( (cc^depth) % 4) == 0:
tmp = 1
else:
tmp = 0
return cc + (depth % 7) + tmp
print calc(11589)
Code: Select all
int calc(int depth) {
if (depth == 0) return 1;
int cc = calc(depth - 1);
return ( cc + (depth % 7) + ((((cc ^ depth) % 4) == 0) ? 1 : 0) );
}
int main () {
cout <<( calc(11589) );
cin.get();
return 0;
}
Code: Select all
#include <iostream>
using namespace std;
long calc(int depth) {
if (depth == 0) return 1;
long cc = calc(depth - 1);
return cc + (depth % 7) + ((((cc ^ depth) % 4) == 0) ? 1 : 0);
}
int main() {
cout << calc(11589) << endl;
system("Pause");
}