Giter VIP home page Giter VIP logo

regex-crossword-solver's Introduction

regex-crossword-solver

Regex Crossword solver written in Python. Runs in both Python 2 and 3.

It solves a puzzle by converting the puzzle into equivalent SMT problem. Detailed method is described here.

Demo

5 x 14 regex crossword posted in BBC Radio 4 Puzzle for Today.

$ python bbc.py

Requirements

You can install them by

pip install ply z3-solver

Make sure you have /usr/local/lib/ and $HOME/.local/lib in LD_LIBRARY_PATH environment variable.

Usage

Solve Regex Crossword puzzle directly.

>>> from crossword import solve_crossword
>>> solve_crossword(["HE|LL|O+","[PLEASE]+"], ["[^SPEAK]+","EP|IP|EF"])
[['H', 'E'], ['L', 'P']]
>>> solve_crossword(["[A-GN-Z]+"], ["[D-HJ-M]","[^A-RU-Z]"], ["[^A-DI-S]+"], ["[^F-KM-Z]","[A-KS-V]"])
[['E', 'T']]

You can also manually find a solution to each regex.

>>> from crossword import solve_regex
>>> solve_regex("(U|O|I)*T[FRO]+", 5)
'IIITF'

Run tests

pip install nose
nosetests

regex-crossword-solver's People

Contributors

blukat29 avatar ysard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

regex-crossword-solver's Issues

Error in repeated capturing group

Hi, I encounter a problem with this not supported regex syntax:

^(A|B){2}-\1$

The parser fails silently until the solver returns None.
I don't know how to tweak the grammar to support this.

The question is:
What should match a back reference to a capture group followed by a quantifier ?
What character should end the string AB- ? A, B or AB ?

Following the advise here: https://regex101.com/

A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated
group to capture all iterations or use a non-capturing group instead if you're not interested in the data.

So the capture should be the content of the last repetition, so in the example, it should be AB-B.

Python implementation is ok with this:

import re
assert re.match(r"^(A|B){2}-\1$", "AB-A") is None
assert re.match(r"^(A|B){2}-\1$", "AB-B").groups() == ('B',)

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.