This repository is a collection of educational Python programs and Jupyter notebooks by Peter Norvig, focused on algorithmic problem-solving, puzzle-solving, and data analysis. It is not a deployable application or a formal research pipeline, but rather a set of self-contained explorations that demonstrate a wide range of programming techniques: constraint propagation, recursive search, dynamic programming, Monte Carlo simulation, n-gram language models, and symbolic computation. The code is well-structured, clearly documented, and often includes inline tests and performance benchmarks. While each notebook or script is independent, many contain reusable utility functions and algorithmic patterns that could be extracted for other projects. The repository includes data files (word lists, n-gram counts, bike ride logs, Sudoku puzzles) that are used as inputs for the explorations. The primary value is educational: it teaches how to think algorithmically and write clean, efficient Python code.
This repository implements the Wave Function Collapse (WFC) algorithm, a constraint-based procedural content generation technique. The system takes an input bitmap (or a tileset with adjacency rules) and generates a larger output bitmap that is locally similar to the input, meaning every N×N pattern in the output appears somewhere in the input. It supports two primary models: the OverlappingModel, which extracts patterns from a sample image, and the SimpleTiledModel, which uses predefined tiles and adjacency constraints defined in XML. The algorithm operates by maintaining a 'wave' of possible states for each output cell, iteratively collapsing the cell with the lowest Shannon entropy and propagating constraints until a fully observed state is reached or a contradiction occurs. The architecture is a straightforward console application written in C# targeting .NET 10. The entry point is Program.cs, which reads a configuration file (samples.xml) specifying model parameters and input samples. The core algorithm is encapsulated in the abstract Model class, with concrete implementations in OverlappingModel.cs and SimpleTiledModel.cs. Image loading and saving are handled by the BitmapHelper class using the SixLabors.ImageSharp library. The system outputs PNG images to an 'output' directory. External dependencies are minimal, relying only on ImageSharp for bitmap I/O. The codebase is well-structured and demonstrates clean separation of concerns. The algorithm implementation is faithful to the original paper and includes optimizations such as the AC-4 constraint propagation algorithm and multiple heuristic strategies (entropy, MRV, scanline). The tile symmetry system in SimpleTiledModel reduces the number of explicit adjacency rules needed. While the repository is primarily a reference implementation, its components—particularly the helper utilities and the core propagation logic—are reusable in other procedural generation projects.
OptaPlanner is a Java library for constraint satisfaction optimization, solving planning and scheduling problems such as employee rostering, vehicle routing, and cloud resource allocation. The architecture is modular: a core engine provides heuristic search algorithms (construction heuristics, local search, exhaustive search) and incremental score calculation via two constraint stream implementations (Bavet, a custom tuple-based engine, and Drools, a rule-based engine). The public API centers on annotations (@PlanningSolution, @PlanningEntity, @PlanningVariable) and interfaces (ConstraintProvider, SolverFactory, SolverManager). Key entry points include SolverFactory.create() to build a solver, Solver.solve() to run optimization, and ConstraintVerifier for testing constraints. Data flows involve defining a domain model with planning entities and variables, providing constraints as a ConstraintProvider, and the solver iterating through moves while evaluating scores incrementally. External dependencies include Drools (optional), Quarkus or Spring Boot for integration, Jackson/JAXB for serialization, and JPA for persistence. The repository also includes a benchmarking module, a Kubernetes operator, and extensive example applications.