Completes exercise 4.
starts extra credit (subset enumeration optimization)