Page 2 of 2

Posted: Mon Oct 04, 2010 6:45 pm
by Glagha
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.

visual studio .net

Posted: Tue Nov 09, 2010 3:01 pm
by Aghamemnon
J# is awesome
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));
	}
}

Posted: Wed Jan 12, 2011 5:36 pm
by space
that was the most fuc*in chall on this whole site....

Posted: Wed Jan 26, 2011 9:25 pm
by Guderian
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;	
}



Posted: Sat Feb 05, 2011 3:43 pm
by SinistraD
Wow, how many clever solution. My favorites are the solutions of Theino and dobluth. For me, I just did many of you have done, rewrite the recursion to a for loop.

Posted: Sun May 15, 2011 11:13 pm
by error213
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));

        }
    }
}


Posted: Thu May 19, 2011 10:38 am
by synapsenkoch
Ported it in C++, set VS2010 to "release" so it didn't crash.

Posted: Thu May 19, 2011 12:46 pm
by satfreak666
You can leave the code as it is ... -Xss

Posted: Wed Jun 29, 2011 5:45 pm
by moose
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)

Posted: Sun Aug 14, 2011 5:46 pm
by BosseBL
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:

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;
}

Posted: Tue Sep 27, 2011 2:15 pm
by Abinmorth
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");
	}

Posted: Wed Dec 07, 2011 5:47 am
by AlbusShin
Er... I used c++ instead and just let the recursive function go into 10th loop and then record the answer, then use the answer for next step of recursive loop..

Posted: Wed Jun 13, 2012 2:30 pm
by facetoe
I also just ported it to C.

Posted: Thu Aug 22, 2013 10:51 pm
by strongdrink
java -Xss10m UpCount