Skip to content

A simple webapp (SPA) for solving sudoku puzzles written in Gleam using the Lustre framework

License

Notifications You must be signed in to change notification settings

emarifer/sudoku_gleam_webapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sudoku_gleam_webapp

A simple webapp (SPA) for solving sudoku puzzles written in Gleam using the Lustre framework


GitHub License Static Badge Static Badge Static Badge


🚀 Features

This is the web (SPA) version of the command-line tool for solving Sudoku puzzles written in Gleam, using the Lustre framework. At the same time, both are the almost direct translation of the Elixir version that I made of Peter Norvig's algorithm for solving sudokus. This computer scientist developed his algorithm in Python, based on 2 concepts: constraint propagation and depth-first search (a sort of 'sophisticated' brute force). If you have any difficulty understanding it, you can find more details here.


👨‍🚀 Getting Started

You can try the application at this link. Simply enter the puzzle you want to solve as an 81-character string (9x9 = 81) with no spaces, where empty squares must be represented by periods '.' or zeros '0' and the rest by digits from '1' to '9', something like this: ...8...5..8..3..2.1....4.........8.663.....419.5.........6....3.9..5..1..17..89.... A string entered with a different number of characters or prohibited characters will generate a warning message. Pressing the Import button will display a grid representation of the puzzle you entered, along with the solved Sudoku. The Reset button will return you to the input screen so you can enter a new puzzle.

You can get the strings you need to pass as an entry from this site, where you can find Sudoku puzzles with all levels of difficulty.

  • Working on the code:

    With Gleam installed as explained here (and Erlang and its BEAM VM), you only need to run the following command in a terminal open in the project folder to start the application in development mode:

    gleam add --dev lustre_dev_tools  

    This will download the dependencies, compile the project, and start a development server. In your browser, go to http://localhost:1234 and you will be able to see the application. Any changes you make to the code using your text editor will cause the browser to reload and display the changes.

    The lustre_dev_tools development server watches your filesystem for changes to your gleam code and can automatically reload the browser. For Linux users, this requires inotify-tools be installed. If you do not or cannot install this, the development server will still run but it will not watch your files for changes.

  • Compiling the code for production deployment:

    If, after making changes to the code, you decide to test the SPA application on a static file server, simply run the following command in the project folder opened in a terminal:

    gleam run -m lustre/dev build sudoku_gleam_webapp --minify

    This will compile (or rather transpile) the JavaScript project, generating an HTML skeleton and minifying both the CSS and JavaScript files, saving everything in a /dist folder at the project root. You can find more details about configuring the build for development and production here and here.


📚 Learn more


Happy coding 😀!!

Releases

No releases published

Packages

No packages published