solve 6
more functional approach for 5