Solution for #8, already formatted.