Adding (ugly) solution for problem 27