Implementing various algorithms using Ruby