program Example 2-1, cookie problem  with replacement