solution of Section 2.2 of <<The Beauty of Code>>