GithubHelp home page GithubHelp logo

patryk27 / nonogram-solver Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 5 KB

Solves monochromatic nonograms, powered by Rust and Z3

License: MIT License

Rust 100.00%
crossword nonogram nonograms puzzle rust sat z3

nonogram-solver's Introduction

nonogram-solver

Solves monochromatic nonograms, powered Rust and Z3, pretty rudimentary.

Usage

(requires rustup and z3)

$ cargo run -- \
     --cols '1|1|2|4|7|9|2,8|1,8|8|1,9|2,7|3,4|6,4|8,5|1,11|1,7|8|1,4,8|6,8|4,7|2,4|1,4|5|1,4|1,5|7|5|3|1|1' \
     --rows '8,7,5,7|5,4,3,3|3,3,2,3|4,3,2,2|3,3,2,2|3,4,2,2|4,5,2|3,5,1|4,3,2|3,4,2|4,4,2|3,6,2|3,2,3,1|4,3,4,2|3,2,3,2|6,5|4,5|3,3|3,3|1,1'

# https://en.wikipedia.org/wiki/Nonogram#/media/File:Nonogram_wiki.svg
******** ******* ***** *******
  *****   ****    ***    ***  
   ***     ***    **     ***  
   ****     ***   **     **   
    ***     ***  **      **   
    ***     **** **     **    
    ****     *****      **    
     ***     *****      *     
     ****     ***      **     
      ***     ****     **     
      ****    ****    **      
       ***   ******   **      
       ***   ** ***   *       
       **** *** **** **       
        *** **   *** **       
        ******   *****        
         ****    *****        
         ***      ***         
         ***      ***         
          *        *

Implementation

Nonogram can be represented as a set of regular expressions - e.g. column with numbers 1 and 8 is:

^[ ]*\*{1}[ ]+\*{8}[ ]*$

... or, with a couple of comments:

^ [ ]* \*{1} [ ]+ \*{8} [ ]* $
  1--- 2---- 3--- 4---- 5--- 

1 - any number of leading spaces
2 - exactly one asterisk
3 - at least one separating space
4 - exactly eight asterisks
5 - any number of trailing spaces

Following on this, nonogram-solver builds a regular expression for each column and row, then sends those constraints to Z3 and parses its response back.

License

Copyright (c) 2024, Patryk Wychowaniec, [email protected]

Licensed under the MIT license.

nonogram-solver's People

Contributors

patryk27 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.