SH
ShotsMan2/Integer-Constraint-Search-Algorithm
C-based exhaustive search algorithm designed to identify 6-digit integers that satisfy a complex set of number theory constraints (Primes, Perfect Squares/Cubes, and Distinct Digits).
Integer Constraint Search Algorithm
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 (
๐ฏ Problem Definition
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.
โ๏ธ Technical Implementation
- 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.
๐ How to Run
- 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.