Skip to content

A simple Ruby gem that returns the full chain of numbers generated by the Collatz Conjecture starting from any positive integer.

License

Notifications You must be signed in to change notification settings

Torroido/collatz-conjecture

Repository files navigation

CollatzConjecture

A simple Ruby gem that returns the full chain of numbers generated by the Collatz Conjecture starting from any positive integer.


💎 Installation

Since this gem is hosted on GitHub (and not RubyGems.org), you can install it in the following ways:

✅ Option 1: Using Bundler (Recommended)

In your project's Gemfile, add:

gem "collatz_conjecture", github: "torroido/collatz_conjecture"

Then run:

bundle install

✅ Option 2: Install manually from GitHub

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

🚀 How to Use

Once installed, you can use it in any Ruby script or IRB session.

Step 1: Require the gem

require "collatz_conjecture"

Step 2: Call the solver with any positive integer

CollatzConjecture::Solver.solve(6)
# => [6, 3, 10, 5, 16, 8, 4, 2, 1]

Step 3: Handle invalid input (optional)

CollatzConjecture::Solver.solve(-1)
# => raises ArgumentError: Input must be a positive integer

🧪 Quick IRB Test

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]

📁 Development

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

🤝 Contributing

Bug reports and pull requests are welcome on GitHub at:

👉 https://github.com/torroido/collatz_conjecture

Please read the Code of Conduct before contributing.


📄 License

The gem is available as open source under the terms of the MIT License.


🧑‍⚖️ Code of Conduct

Everyone interacting in this project's codebases, issue trackers, and mailing lists is expected to follow the Code of Conduct.

About

A simple Ruby gem that returns the full chain of numbers generated by the Collatz Conjecture starting from any positive integer.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published