UpCount
-
- Posts: 49
- Joined: Fri Jul 02, 2010 9:34 pm
- Location: Egypt
- Contact:
visual studio .net
J# is awesome
you do't need to deal with every detail
you do't need to deal with every detail
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));
}
}
Devilish Angel Aghamemnon
i tried the program in c++ on visual studio 2010. This high level of recursion however made the program crash! i tried it with smaller values and it worked. so i re-wrote the code using an array.
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;
}
i ported in C#
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));
}
}
}
-
- Posts: 1
- Joined: Tue May 17, 2011 7:07 pm
Here is my piece in Python:
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)
Nice solvings.
c programmer as I am, I too did convert the code to c.
however, I found it cleanest to just copy the function calc() and not make a class to call from:
c programmer as I am, I too did convert the code to c.
however, I found it cleanest to just copy the function calc() and not make a class to call from:
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;
}
easy to rewrite to cpp
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");
}
-
- Posts: 4
- Joined: Tue Jul 12, 2011 4:31 pm
- Location: Floating Around