Solution code for IBM Research "ponder this" challenge, Nov 2013