Algorithm exercises in ruby