solution for programming exercise