Solving one more problem. With two approaces, being one a more C++-ish and slower version