Project Euler: Problem 25

The Fibonacci sequence is defined by the recurrence relation:
F_n = F_{n-1} + F_{n-2}, where F_1 = 1 and F_2 = 1.

Hence the first 12 terms will be:

  • F_1=1
  • F_2=1
  • F_{11}=89
  • F_{12}=144

The 12th term, F_{12}, is the first term to contain three digits.

What is the first term in the Fibonacci sequence to contain 1000 digits?

Continue reading

Posted in Project Euler, Software Development | Tagged , , , | 1 Comment

Project Euler: Problem 16

2^{15} = 32768 and the sum of its digits is
3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^{1000}?

Continue reading

Posted in Project Euler, Software Development | Tagged , | Leave a comment

The Art of Unit Testing

The Art of Unit Testing (Book cover)Have you gone through three years of computer science bachelor degree fun (or anything similar) and pretty much not heard a word about testing? Or have you heard from all your teachers that testing is extremely important, but never learned how to even write one? That has been the case for me. Testing is important, you all got to do it, it is very important, always test, do it a lot! Well, sure… but how do I do it? How do I write one of these tests?

Continue reading

Posted in Reviews, Software Development | Tagged , , , | 3 Comments

WordPress plugins I use

Thought I could share what plugins I use. I am curious to know what others are using, so it would be kind of rude to not share what I use ;) So without further ado, here they are:

Continue reading

Posted in Software Development | Tagged , | 2 Comments

How to delete WordPress post revisions

Having revisions on my posts is nice I suppose. But I was starting to get a bit annoyed with the increasingly long list of revisions in each post. And they really did get long. Mainly because I am in a bit of a testing and experimenting phase which means that I have done a lost of adjustments to almost every single post so far because I don’t have 100% control on how I want things or how things will end up looking and so on :P

Anyways, I found a nice little MySQL snippet to clear out all of them in a French comment to a blog post. Thought I could share it here. Especially since I then know where to find it and it won’t disappear on me.

Continue reading

Posted in Software Development | Tagged , , | Leave a comment

The Sieve of Atkin in C#

I have previously written about the Sieve of Eratosthenes, which is an algorithm for finding primes. This algorithm worked very well for most of the prime related Euler Problems. However, for one of them it just didn’t do it. Well, it did it, but it did it kind of slow. The problem was to calculate the sum of all the primes below two million, and with that algorithm this took close to 2 seconds on my machine. Not too long you might think, but compared to my other solutions it is ages and ages. So I started to see if I could find a more efficient algorithm to use for that problem.

I quickly found one called the Sieve of Atkin. The Atkin algorithm works similarly to the original Eratosthenes one, but has a more fancy way of sieving out numbers which means it can work a lot faster. However, this also means that it needs to work towards an upper limit and that it have to find all the primes up to that limit in advance. In other words it cannot work incrementally and lazily like my Eratosthenes implementation.

Continue reading

Posted in Software Development | Tagged , , | 3 Comments

The Sieve of Eratosthenes in C#

In some of the Project Euler problems we have needed a source of primes. One algorithm for finding primes is called the Sieve of Eratosthenes. This algorithm is both pretty simple to understand and to implement. It is also fairly fast and usable, at least for the lower primes.

My implementation is based upon the algorithm described on the Wikipedia page and some helpful optimizations I found in an article at Black Wasp. The differences from the original algorithm and the solution at Black Wasp is that it finds the primes incrementally and that it only looks for a new prime when asked.

Continue reading

Posted in Project Euler, Software Development | Tagged , , | Leave a comment