Solution for Project Euler 55, done by test-driven development