algorithms in ruby