Generative Recursion in Pharo Smalltalk: Object-Oriented Sudoku Solver
# Generative Recursion in Pharo Smalltalk: Object-Oriented Sudoku Solver 🧩🔍
This repository explores the elegant integration of **Generative Recursion** and **Pure Object-Oriented Programming (OOP)**.
Instead of implementing a naive backtracking loop, this project models the search space, state transitions, and the solver engine as first-class objects within Pharo's live programming environment. By mapping choices and constraints into an elegant graph-based state space, we obtain a general, observable, and visual solution.
---
## 💡 The Philosophy: OOP Meets Generative Recursion
In functional programming, generative recursion (such as state-space search) is a common pattern. In this project, we translate this concept into **pure objects**:
* **State-Space Modeling:** Each step of the Sudoku puzzle is a discrete state node containing its current grid representation, depth, and remaining constraints.
* **The Solver as an Engine:** The `SodokuSolver` manages the recursion depth, active search branches, and backtracking boundaries.
* **Observability & Live Inspection:** Leveraging Pharo's powerful interactive inspector, we can visualize the entire tree of solutions, tracing the path from the initial state to the final leaf (solution).
---
## 📈 Visualizing the State Space
One of the biggest advantages of utilizing Pharo is its dynamic visual tools. The solver builds a decision tree showing all tested state configurations:
### 1. The Initial Unsolved State
The grid starts with open constraints (indicated by zeros) and initial clues.

### 2. The Solution Path Graph
Using Pharo's interactive inspector, we can map out the entire tree of evaluated states. The red node represents the successfully reached solution leaf.

### 3. The Solved Grid
The completed puzzle state reached at the end of the optimized recursive traversal.

---
## 💻 Playground Code Example
To run the solver and inspect the state tree inside your Pharo image, open a **Playground** and execute the following workspace code:
```smalltalk
| solver |
solver := SodokuSolver exampleSolvingEasyOne.
solver iterations: 25.
solver solve.
solver inspect. "Opens the live inspector to explore the Graph and States tabs!"
```
---
## 🚀 How to Load this Project in Pharo
(Tip: Update this section with your actual Metacello/Iceberg loading script if you have it packaged!)
Open the Iceberg tool in Pharo.
Clone this repository using the SSH/HTTPS URL:
git@github.com:josealuna/pharo-sudoku-solver.git
Load the package into your current image.
---
## 🔬 Author & Philosophy
Developed by **Jose Antonio Luna** — Physicist, Software Strategist, and Technical L&D Consultant.
I believe in digging deeper into established mathematical problems to find more elegant, robust, and efficient analytical solutions. This project showcases how combining high-rigor physics with clean-code testing workflows yields highly optimized scientific tools.
* 💼 [LinkedIn Profile](https://www.linkedin.com/in/jose-antonio-luna-perez/)
* 🌐 Explore my other projects on [GitHub](https://github.com/josealuna)