Added an optimized solution of Ch.8's final task