{ Code: Impossible } | this = HowI.Roll();

Archive for September 2009

If you’re like me, you recently upgraded to Sql Server 2008 (or just installed the Management Studio). If you’re really like me you found the “Saving changes is not permitted” dialog that pops up every time you try to save a modified table annoying.

You may not have found it annoying enough to investigate but I sure did. I don’t remember Management Studio 2005 complaining when I changed a table and saved it. Why the change in 2008?

Well, anyway, here’s your chance to get rid of that dialog once and for all.

In Sql Management Studio, go to Tools -> Options, expand down the Designers node, and select Table and Database Designers. In the Table Options section uncheck Prevent saving changes that require table re-creation and you’re done!

You can now change your database tables hassle free!

·

works-on-my-machine-starburst

Project Euler is an awesome website that I found out about a while back via this question on StackOverflow. Basically, it’s a website that poses a ton of programmer related challenges and it keeps track of the problems that you solve.

The problems start out relatively easy (Add all the natural numbers below one thousand that are multiples of 3 or 5.) and progress all the way to insane (Caradano Triplets and Covex Holes).

I’m on the easy side, I just started working through them tonight and thought it would be cool to post how I build the solution to each problem as I complete them.

Problem 2 is pretty easy:

“Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million.”

So first things first, I’ll need to pick a language to use to solve this. I chose javascript simply because it was something I knew I could get running pretty quickly.

Next I’ll need some variables. (note: if you’re not familiar with Fibonacci numbers Wikipedia has an awesome article on them.)


var start = 1, end = 4000000, current = 1, previous = 1, sum = 0, temp = 0;

That should do. I’ve got my start variable (dropping the 0 in favor of more readable code), my end counter, and my “where-am-i” variables: current, previous, temp and my sum variable.

Obviously we’ll need some kind of loop. How about a while loop?


while( current <= end )
{

}

Cool. Now when the loop is running I'll need a way to keep track of the current value, the previous value and I need to add the current value to the sum. So....


while( current <= end )
{
    temp = current;
    current = current + previous;
    sum += current;
    previous = temp;
}

And there we hav... Oh Wait!

I overlooked a pretty important part of the problem description: "sum of all the even-valued terms"!!!

So given this new(ish) piece of info my solution end sup being:


var start = 1, end = 4000000, current = 1, previous = 1, sum = 0, temp = 0;

while( current <= end )
{
	temp = current;
	current = current + previous;

	if( current%2 == 0 )
		sum += current;

	previous = temp;
}

alert(sum);

·

Theme Design by devolux.nh2.me