A C++ application that simulates the Collatz (3x+1) conjecture, stores results in JSON files, and provides a web interface to visualize sequences in real time.
CollatzVisualizer is a C++ web server that:
- Computes the Collatz sequence for a given number.
- Saves it to
./computated/<number>.json. - Serves a live webpage with a Chart.js line graph and output data.
- Linux (tested on Ubuntu; adaptable)
g++(C++17-compatible compiler)libboost-all-devgit,curl
Crow(v1.2.0) — single header web frameworknlohmann/json(v3.11.3)
git clone https://github.com/your-username/CollatzVisualizer.git
cd CollatzVisualizer
chmod +x setup_and_run.sh
./setup_and_run.sh --install
This will:
- Install packages and dependencies
- Download headers
- Compile the server
- Create
computated/output folder
File: ./computated/6.json
{
"number": 6,
"sequence": [6, 3, 10, 5, 16, 8, 4, 2, 1],
"steps": 8,
"max_value": 16
}
./setup_and_run.sh --run
Open your browser and go to:
http://localhost:8080
- Input any number.
- Visualize the sequence steps.
- See chart and JSON output.
- JSON is saved to
./computated/.
./setup_and_run.sh --help
--install: Install and compile--run: Start the web server--clean: Remove the compiled binary
sudo chmod -R u+w include
Or download manually:
mkdir -p include/nlohmann
curl -L https://github.com/nlohmann/json/releases/download/v3.11.3/json.hpp -o include/nlohmann/json.hpp
sudo apt-get install -y libboost-all-dev
CollatzVisualizer/
├── collatz_webserver.cpp
├── setup_and_run.sh
├── computated/
├── include/
│ ├── crow.h
│ └── nlohmann/
│ └── json.hpp
PRs and issues welcome on GitHub.
MIT License.