Basic algorithms implemented in Ruby