cheaper soluton for problem 1