The Algorithm Design Manual problem solutions in ruby