UpCount

Discussion of challenges you have already solved
Glagha
Posts: 1
Joined: Thu Sep 30, 2010 8:41 pm

Post 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.
Aghamemnon
Posts: 49
Joined: Fri Jul 02, 2010 9:34 pm
Location: Egypt
Contact:

visual studio .net

Post 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));
	}
}
:twisted: Devilish Angel Aghamemnon :twisted:
space
Posts: 2
Joined: Mon Dec 27, 2010 4:55 pm

Post by space »

that was the most fuc*in chall on this whole site....
Guderian
Posts: 18
Joined: Tue Jan 25, 2011 4:31 pm
Location: Greece

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


User avatar
SinistraD
Posts: 89
Joined: Sun Aug 16, 2009 8:39 am
Location: find me
Contact:

Post 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.
error213
Posts: 4
Joined: Wed Oct 15, 2008 12:00 pm

Post 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));

        }
    }
}

synapsenkoch
Posts: 1
Joined: Tue May 17, 2011 7:07 pm

Post by synapsenkoch »

Ported it in C++, set VS2010 to "release" so it didn't crash.
satfreak666
Posts: 11
Joined: Mon May 16, 2011 8:37 am

Post by satfreak666 »

You can leave the code as it is ... -Xss
moose
Posts: 67
Joined: Fri Jul 16, 2010 7:32 pm

Post 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)
BosseBL
Posts: 6
Joined: Tue Aug 09, 2011 10:47 am
Location: Stockholm

Post 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;
}
Abinmorth
Posts: 4
Joined: Fri Jul 29, 2011 12:32 pm
Location: <u>test</u>

Post 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");
	}
AlbusShin
Posts: 9
Joined: Fri Nov 18, 2011 2:39 pm
Location: Lost in binary

Post 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..
facetoe
Posts: 3
Joined: Wed Jun 13, 2012 6:56 am

Post by facetoe »

I also just ported it to C.
strongdrink
Posts: 4
Joined: Tue Jul 12, 2011 4:31 pm
Location: Floating Around

Post by strongdrink »

java -Xss10m UpCount
Post Reply