Implementing some search algorithms in Ruby