solution for problems 1 to 5