Giter Club home page Giter Club logo

multi-regexp's Introduction

MultiRegExp - A regular expression multiple acceptor

MultiRegExp generates regular expressions which will only accept the multiples of a given number. For example, it can generate a regexp which only accepts multiples of three.

Actually, it can do more than that. It can generate regexps which match numbers which are equal to n modulo m, in base b.

It does not do this efficiently! It's very much a toy, very much unoptimised, and the output scales horrifically with the input parameters.

Background

An XKCD strip introduced the idea of Regex Golf, trying to produce small regexes that accept one list but not the other.

Peter Norvig got involved, and solving it looks NP-hard, due to being rather like set cover.

On the more practical hand, this site lets you play Regex Golf manually. Many work friends did so.

This level of the site wants you to match multiples of three.

This page shows how to solve the problem.

That's one case, solved manually. I can do better than that! Hence this program. :)

As stated above, it's a quick hack. It was built quickly, abondoned on my hard drive, then briefly polished and dumped on the internet as it kinda seemed a shame not to do so.

It's in Haskell, as Haskell was my day-job language for a few years, and it's still my preferred language for rapid development, as it's got much of the expressiveness of scripting languages, but with the benefits of static typing.

It's not production-quality code, it's a hack. Error-checking is minimal. There's no test suite. I think you get the idea. Have fun!

Building

ghc --make MultiRegExp

Using

"./MultiRegExp b m n" generates a regexp that processes numbers shown in base b, matching those that are equal to n mod m.

A very simple example of the non-optimising behaviour of this code can be seen if you try "MultiRegExp b 2 0", where b is even. The simplest result is effectively ".*[0246...]", but the code misses that case!

Things that might be fun to do

"MultiRegExp 10 3 0" is the case that launched writing this code.

You can try scaling the first two parameters, and watch the size of the output scale hugely. Plot it, try to get a bound, that kind of thing.

I was going to try this myself, but I never got around to it (trivial though it is)!

multi-regexp's People

Contributors

simon-frankau 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.