Solves polynomial equations of degree 2 or lower. Prints the reduced form, the degree, the sign of the discriminant and the real or complex solutions. A 42 Abu Dhabi project.
python3 computor.py "5 * X^0 + 4 * X^1 = 4 * X^0"
echo "5 * X^0 + 4 * X^1 = 4 * X^0" | python3 computor.py
python3 computor.py --help
python3 test_computor.py
32 checks: the six worked examples of the subject byte for byte, the five fixed defects, the parser error messages, and the bonus output.
Free form entry is always on: python3 computor.py "5 + 4 * X + X^2 = X^2".
Five more features print behind a flag.
| Flag | Prints |
|---|---|
--steps |
The intermediate calculation. |
--fractions |
Each solution as an irreducible fraction. |
--verbose |
The coefficient table of the two sides. |
--plot |
The curve, drawn with ASCII characters, roots marked. |
Entry mistakes print error: <reason> on stderr and exit 1. No traceback.
docs/computorv1-explained.html is an interactive single file guide: the maths,
the pipeline, a live solver, a discriminant explorer, the code walkthrough, the
edge cases, and the defense answers. Open it in a browser, no build step.
- Square roots are hand-written Newton iterations. The file imports
sysandfractions, nothing else. - Coefficients, the discriminant and the roots stay exact
Fractionvalues. Only printing converts tofloat. PROGRESS.mdis the development log.