A simple Ruby gem that returns the full chain of numbers generated by the Collatz Conjecture starting from any positive integer.
Since this gem is hosted on GitHub (and not RubyGems.org), you can install it in the following ways:
In your project's Gemfile
, add:
gem "collatz_conjecture", github: "torroido/collatz_conjecture"
Then run:
bundle install
git clone https://github.com/torroido/collatz_conjecture.git
cd collatz_conjecture
gem build collatz_conjecture.gemspec
gem install ./collatz_conjecture-0.1.0.gem
Once installed, you can use it in any Ruby script or IRB session.
require "collatz_conjecture"
CollatzConjecture::Solver.solve(6)
# => [6, 3, 10, 5, 16, 8, 4, 2, 1]
CollatzConjecture::Solver.solve(-1)
# => raises ArgumentError: Input must be a positive integer
You can also test it directly in IRB:
irb
require "collatz_conjecture"
CollatzConjecture::Solver.solve(13)
# => [13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
To get started with development:
bin/setup # Install dependencies
bin/console # Start an interactive Ruby shell with the gem loaded
bundle exec rake # Run any tasks (if added)
To build and install the gem locally:
bundle exec rake install
To release a new version (after updating version.rb
):
bundle exec rake release
Bug reports and pull requests are welcome on GitHub at:
👉 https://github.com/torroido/collatz_conjecture
Please read the Code of Conduct before contributing.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in this project's codebases, issue trackers, and mailing lists is expected to follow the Code of Conduct.