[Tech] Coding challenge

E

elDiablo

Guest
So John, the Introversion Technical Director, pointed me at this site today, and more importantly, the free example.

I quite like the free example. It's a fun little puzzle to solve.

I solved it in C++, in 10 minutes, and got a score of 69 out of 100. John solved it in C++, in 10 minutes, and got a score of 94 out of 100. Since then, I modified John's version (in like 30 seconds) and got 100, which isn't too much of a big deal really, but still.

thatbloke solved it in C, and got a score of 69 out of 100.

Have a go!

Edit - Turns out there is a free edition (very limited), hidden away, here. The pricing on the site is pretty crazy, otherwise...
 

Silk

Well-Known Member
Awww.. 68.75. Failed on the perf tests. *wears dunce cap*

I should cut myself a little slack though, I just basically taught myself C# during that, and pretty sure there will be some nifty functions I could use if I knew the language inside-out.


Edit: Fixed an overflow error and now got 75/100! I'm happy with that to say it was about 30 mins including self teaching ;)
 

thatbloke

Junior Administrator
69 :)

same as me and elD

There is a more simple way of implementing it though, which elD described to me :)
 
E

elDiablo

Guest
For those that care, spoilerific coding:

C++
Code:
// sum the total of all the items in the array
long long sum( const vector<int> &A ) {
	long long result = 0;
	unsigned howMany = A.size();

	for( unsigned i = 0; i < howMany; i++ )
		result += A[i];

	return result;
};

int equi ( const vector<int> &A ) {
	long long total = sum( A );
	long long leftSum = 0;

	for( unsigned i = 0; i < A.size(); i++ )
	{
		long long rightSum = total - leftSum - A[i];

		if( leftSum == rightSum )
			return i;

		leftSum += A[i];
	}

	return -1;
}

Edit - this is a 100% solution, FYI.
 
Top