solution for number pairs problem