Sunday, November 4, 2012

Project Euler in Ruby, revisited

I was thinking about it tonight, about life and my desire to do more with my time.  Andrew, a buddy at work who also happens to be a Scrum coach talks about using all of the time in a given day.  He talks about training for skiing as he is walking around the campus, about his own business ventures and the evening when he does that, about reading while he is traveling and using all of his time for productive tasks.  I'd really like to accomplish the same.  Dunno if I will ever utilize my time to that degree, but spending a little more time programming and studying math each day is a great start. 

As I was thinking about these things the other day, I thought of something significant.  That you are what you do after-hours, not during the day.  When you have nothing to do (relatively speaking), whatever you do end up doing, is what you are.  So I come home, and usually chill the rest of the evening.  Yes, I spend time with Stepheni and Ephraim, but beyond that my time isn't filled with the things that I would like it to be.  So, "whatever" to my job title not being what I want it to be, I'm gonna do what I want and know I can do at home and be a better example to my loved ones and my friends. 

With that in mind, I want to revisit the Project Euler problems in Ruby.  Ruby is a great language, built on C, and fairly easy to work with.  I am choosing it because there is a great community online for it and I won't get too hung up in the syntax, while focusing on the math behind these problems. 

The best story that I have heard of for optimization, is the one about Gauss and how he showed up his teacher by summing the numbers 1-100 by using a formula rather than 1+2+3+...+99+100. 

Looking at the numbers he saw that 1+100=101, 2+99=101, 3+98=101, etc.  And thereby came up with the formula (n*(n+1))/2, where n is the number you are summing to from 1.  Using this tool he was able to not only finish the task in a few minutes rather than a few hours, he was also able to do it correctly. 

With that in mind, optimization deals with taking a task and making it as fast as it possibly can be, or at least faster than it previously was.

The Project Euler problems, as far as I can tell, are each based off of some principle in math, which when found can lead to fast results. 

No comments:

Post a Comment