Sunday, 7 March 2010

Problem 003

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Solution:
Function Prob003() As Long
Dim Src As Long = 600851475143
Dim PrimeCol As New Collection
For tmpVal As Long = 2 To Src
If tmpVal > System.Math.Sqrt(Src) Then Exit For
If IsPrime(tmpVal) = True Then
PrimeCol.Add(tmpVal)
End If
Next
For k As Integer = 1 To PrimeCol.Count
If Src Mod PrimeCol(k) = 0 Then
If PrimeCol(k) > Prob003 Then Prob003 = PrimeCol(k)
End If
Next
End Function

Summary:
This one was kind of a pain. I had forgotten a lot about what makes a prime and the various rules, tricks, etc. when dealing with them…

Thursday, 4 March 2010

Problem 002

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

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

Solution:
Function Prob002() As Long
Dim Term1 As Long = 1
Dim Term2 As Long = 2
Dim tmpTerm As Long = 0
While Term1 < = 4000000 If Term1 Mod 2 = 0 Then Prob002 += Term1 tmpTerm = Term1 + Term2 Term1 = Term2 Term2 = tmpTerm End While End Function

Summary:
Even though it'll never be as exciting as in the movie Pi, I do love working with Fibonacci sequences.

Wednesday, 3 March 2010

Problem 001

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Solution:
Function Prob001() As Integer
For k As Integer = 3 To 999
If k Mod 3 = 0 OrElse k Mod 5 = 0 Then Prob001 += k
Next
End Function

Summary:
Easy-peasy.

Tuesday, 2 March 2010

Another One Bites The Dust…

A lot of my favorite blogs have been fading away in the past few years and there hasn’t been enough good ones stepping up to take their places.

One developer’s blog I absolutely loved back in the day was Steve Yegge’s Blog Rants. Even though he was always writing crazy-long posts, they were usually quite good, witty, and informative. His last post was in May 2009. While I’ll probably never have my own startup, write in Haskell, or whatever it was he was ranting about, it was always a bit interesting seeing things in a different light.

With a well-written blog and a pretty large audience, I used to read Jeff Attwood’s “Coding Horror” blog all of the time. Now that his focus is on his new company (and rightfully so, I guess), he tends to have a lot less meaningful posts. Instead, it’s either a quick couple paragraphs to talk about new stuff on StackOverflow or it’s just something to get people to react strongly and leave lots of comments agreeing or disagreeing with what he’s written. I don’t get a whole lot out of it anymore, which is a shame.

Last but certainly not least, I guess Joel is going to be added to my list…

I’m pretty bummed to read that Joel Spolsky is giving up on blogging, writing for Inc., and doing podcasts. He had a lot of great insights to share. I really liked hearing about things like evidence-based time estimates on projects. I used to love reading his blog and even have some of the books.

I guess it’s not THAT bad, though. Blogs like these are great when you’re still wet-behind-the-ears and need someone to authoritatively tell you what should and shouldn’t be done. Once you get a feel for real-world development and have a good enough grasp on best-practices, you really don’t need them as much.

If the blogging paradigm is slowly dying for the big and influential bloggers I like, I guess that’s just the way it goes… Thankfully, I still have a few good tech podcasts left :)