Ugly and slow (1m21) solution for problem 44