programming exercise and solution