Translating the algorithms from Princeton's Coursera Algorithm course to ruby