pattern matching for problem 26