Collection of different algorithms, in ruby.
Add this line to your application's Gemfile:
gem 'algorithms', github: 'davidkariuki/algorithms'
And then execute:
$ bundle
# kth_smallest example
arr = (1..100).shuffle
smallest_22 = Algorithms::KthSmallest.new(arr).kth_smallest(22) #returns the 22nd smallest number in arr
# quick_sort! example
Algorithms::QuickSort.new(arr).sort!
# k-means example
clusterer = Algorithms::KMeans::Clusterer.new(filename: 'path-to-file')
clusterer.run
clusterer.to_chart_data #gives clustered data you can throw in a google
visualization (e.g. geochart)
- Fork it ( http://github.com/davidkariuki/algorithms/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request