This project implements a brute-force search algorithm in C to solve a specific cryptarithmetic problem. It iterates through permutations of a 6-digit number (
The algorithm searches for a 6-digit integer
-
Uniqueness: All digits (
$A, B, C, D, E, F$ ) must be distinct. -
Perfect Square: The number formed by the last two digits (
$EF$ ) must be a perfect square ($x^2$ ). -
Perfect Cube: The number formed by the first three digits (
$ABC$ ) must be a perfect cube ($y^3$ ). -
Linear Relation: Digit
$A$ must be equal to$E + 1$ . -
Divisibility: The number formed by the first two digits (
$AB$ ) must be divisible by 3. -
Primality: The number formed by digits
$D, E, F$ ($DEF$ ) must be a Prime Number.
- Language: C (Standard Library only, no external dependencies).
- Approach: Nested Loops (Exhaustive Search / Brute Force).
- Optimization: The algorithm uses conditional
continuestatements to prune the search tree early. For instance, if the uniqueness constraint fails early, inner loops are skipped to save computational power. - Manual Math Logic: Includes a custom implementation for primality testing (
is_primelogic inside the loop) without using<math.h>functions, demonstrating low-level logic building.
- Compile the code using GCC:
gcc solver.c -o solver
- Run the executable:
./solver
- The program will output the 6-digit number(s) satisfying all criteria.
This repository demonstrates algorithmic thinking and control flow management in C.