Some simple solutions using Functional Programming idioms.