This project is a Go application that attempts to solve the Collatz Conjecture using two methods: a seed-based approach and a brute force approach.
The calculation utilises big.Int and can represent integers as large as can fit in your computer's memory. There is no theoretical limit to the size of a big.Int number, the limit is only practical and depends on the amount of memory your computer has.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Download the collatz.zip file from the repository.
- Extract the
collatz.zipfile to get thecollatzbinary. - Open a terminal and navigate to the directory containing the
collatzbinary. - Run the binary with the desired mode (seed or bruteforce) and the necessary arguments.
./collatz seed -number=<number>- Replace
<number>with the number you want to calculate the Collatz Conjecture.
Example:
./collatz seed -number=27./collatz bruteforce begin=<start_number> end=<end_number>- Replace
<start_number>with the number you want to start the sequence from. - Replace
<end_number>with the number you want to end the sequence at.
Example:
./collatz bruteforce begin=0 end=1234567890./collatz bruteforce -end=1000000 -print-all | sed -E 's/level=INFO msg="([^"]+)"/\1/' | sed -E 's/number: ([0-9]+), steps: ([0-9]+), max: ([0-9]+)/\1,\2,\3/' > example.txtMore options can be found by running the following command:
./collatz --help- Go version 1.23 or higher
- Ensure you have Go version 1.23 or higher installed on your machine.
- Clone the repository to your local machine.
- Navigate to the project directory.
- Run
go mod downloadto download the necessary dependencies.
The application can be run in two modes: seed and bruteforce.
make build: Builds the project and outputs the binary in out/bin/.
The Makefile includes several commands that help with building, testing, and linting the application.
Builds the project and outputs the binary in out/bin/.
make buildRemoves build related files.
make cleanRuns the tests.
make testRuns the tests and exports the coverage.
make coverageRuns golang linting.
make lintShows help information for the Makefile commands.
make help
