Solution to reddit programming challenge #134