Monday, March 5, 2012

AI Challenge

I recently took part in a nice contest hosted at aichallenge.org. For those of you who don't know about it, it's a series of coding contests revolving around AI.  This particular game was 'Ants'. Basically, you controlled an ant colony while they tried to raze enemy hills, collect food, and protect your own ant hill. It was a very good idea and I have nothing but praise for those who organized it :) I did quite well in my country finishing 2nd, but my code was poorly written and choppy so I'm not going to share it unless people ask for it.
The first thing I did was restructure the "starter bot" you were given. I completely tore it apart and re-implemented it. This helped me a lot more as I continued and I think I'll ignore the starter bot next time around and just go with my own code.

If you didn't compete in this one, do compete in the next one. They're great fun and I learned a staggering amount while I was going along. There's a great sense of community, especially on the IRC channel (who always helped me out :) ) and I can't wait for the next one. (Psssst, rumor has it it could be Asteroids ;) )

---NotMyFault

Tuesday, January 3, 2012

ProjectEuler Problem 8

No posts in a long time, but this will now become a blog about projecteuler :) This problem was very easy to do in C++ (Or any other language). Just throw the big number into a string and get substrings of it. here it is:

#include
#include
using namespace std;

int main() {

    string big_number = "7316717...........52963450";

    unsigned long long biggest = 0;
    unsigned long long test_biggest = 0;

    for(int i=0; i        string convert_me = big_number.substr(i, 5); //Get the substring


        for(int j=0; j<5; j++) {
            if(convert_me[j]-'0' == 0)
                break;

            if(test_biggest == 0) {
                test_biggest = convert_me[j]-'0';
                continue;
            }

            test_biggest *= convert_me[j]-'0';

            if(j==4)
                biggest = ( (test_biggest > biggest) ? test_biggest : biggest);
        }

        test_biggest = 0;
    }

    cout << biggest << endl;
    return 0;
}


time: 0.002s



Optimizations would be simple but not needed as its such a simple problem. (e.g, increment i by 4 if it finds a zero)

      --NotMyFault