Slashdot Mirror


Can You Do the Regular Expression Crossword?

mikejuk writes "Programmers often say that regular expressions are fun ... but now they can be a whole lot of fun in a completely new way. Want to try your hand at a regular expression crossword? The idea is simple enough — create a crossword style puzzle with regular expressions are the 'clues.' In case you don't know what a regular expression is — it is a way of specifying what characters are allowed using wild-card characters and more. For example a dot matches any single character, an * any number of characters and so on. The regular expression crossword is more a sort of Sudoku puzzle than crossword however because the clues determine the pattern that the entries in a row have to satisfy. It also has to use a hexagonal grid to provide three regular expressions to control each entry. This particular regular expression crossword(pdf) was part of this year's MIT Mystery Hunt. This annual event is crammed with a collection of very difficult problems and the regular expression crossword, created by Dan Gulotta from an idea by Palmer Mebane, was just a small part of the whole — and yes there is a solution."

24 of 115 comments (clear)

  1. Just solving it is easy. by Anonymous Coward · · Score: 2, Funny

    Solving it without going insane, on the other hand, is an entirely different story.

  2. Re:Solution by Stradenko · · Score: 4, Informative

    I think you mean .*

  3. Obligatory xkcd by XDLMAO · · Score: 2, Funny
    1. Re:Obligatory xkcd by Anonymous Coward · · Score: 2, Funny
    2. Re:Obligatory xkcd by fche · · Score: 5, Insightful

      Randall should draw a comic about obligatory xkcd references.

  4. Great idea, but... by stephanruby · · Score: 3, Insightful

    It's a great idea, but the puzzle given is too complicated.

    If they really want to popularize this concept among programmers, many of whom have forgotten regular expressions even if they had once mastered them, they should really create much simpler puzzles in a mounting order of difficulty.

    Hopefully, someone enthused by the idea will create and publish such puzzles.

    1. Re:Great idea, but... by Anonymous Coward · · Score: 5, Funny

      The only thing difficult about the puzzle is the format in which it is presented. How many people have printers? Of those, how many have working printers? And, of those, how many also have paper?

    2. Re:Great idea, but... by Anonymous Coward · · Score: 2, Funny

      s/forgotten/never learned/g

    3. Re:Great idea, but... by Goaway · · Score: 2

      It takes about an hour to solve. It isn't terribly complicated.

    4. Re:Great idea, but... by SQLGuru · · Score: 4, Funny

      How many people have printers? Of those, how many have working printers? And, of those, how many also have paper?

      I have all of those........but no ink.

    5. Re:Great idea, but... by Anonymous Coward · · Score: 2, Insightful

      Really? I'm about as far from a Regex Guru as you can get and frequently advocate against using them for anything but the simplest task and I was able to solve it in about 45 minutes or so. When you first sit down with it, it looks near impossible, but there are a handful of hexes that can be deduced immediately and after getting a few more it's not that much harder than a sudoku.
      I though the puzzle was challenging, but not overwhelmingly so in any way and would love to see more of them.

    6. Re:Great idea, but... by ArsenneLupin · · Score: 2

      You could always squirt out some more ink, I mean, you are an octopus, right?

      ... and if you aren't, just use black paper...

  5. simple? by bitingduck · · Score: 4, Funny

    There's probably already a CPAN module for solving it...

  6. Apologies to Betteridge by MtHuurne · · Score: 3, Interesting

    Solved it a few days ago. It was fun. It's not as hard as it looks.

    and yes there is a solution

    In fact, there is exactly one solution.

    1. Re:Apologies to Betteridge by hcs_$reboot · · Score: 3, Funny

      Well done, you deserve your 1?[0-9] points.

      --
      Slashdot, fix the reply notifications... You won't get away with it...
  7. Re:Solution by Coolhand2120 · · Score: 4, Informative

    The article summary was wrong about * and so are you. At least the language in the summary leaves much to be desired, although they are correct about it being a numerator, they leave off the part that it matches the previous character or subexpression. * = the previous character or subexpression zero or more times. As Stradenko pointed out to get ANY character you need . (period). To get any character zero or more times you need .* (period asterix). To get the solution to anything with more than one line you need [\s\S]*.

    So you're pretty far off the mark as far as 42 goes.

  8. Breaking news. by mutube · · Score: 4, Funny

    Yvonne Lee, Community Manager at Dice.com writes,

    ^\\([^ ()]+\\)\\(([0-9]+\\),\\([0-9]+\\))"

  9. Interactive by Ozan · · Score: 5, Informative

    No need to print out the puzzle, somebody made an interactive version:
    http://twoevils.net/cross-regex.html

  10. Re:Rules? by Anonymous Coward · · Score: 2, Insightful

    The rules are anchored to the ends. Printing a ^ and $ on each clue is redundant and silly, when a moderately intelligent person could easily figure that part out for themselves.

  11. Re:Rules? by Aristos+Mazer · · Score: 2

    Not useless. It has to match the whole line. If the regular expression matches zero characters, then the rest of the line is left as the next token in the string. You're thinking of it as a parser... think of it as the results of a parser -- the parser ran, and it returned the complete line of characters as a token when given this regular expression. Does that help you understand why this works?

  12. Re:Rules? by pipatron · · Score: 4, Informative

    Everywhere ^ is used in the puzzle it means that it matches anything not in the group. For example [^abc] would match any character except a, b and c

    --
    c++; /* this makes c bigger but returns the old value */
  13. That's not right by iYk6 · · Score: 2

    For example ... an * [matches] any number of characters and so on.

    No. That's shell expansion, not regular expression. To match any number of characters, you would use ".*".

  14. It's actually easy (really) by Sam+H · · Score: 2

    It took me less than 10 minutes to complete that crossword. It's actually easy, because the clues always give enough information to immediately place a letter somewhere with minor thinking; no tracking back is ever needed (unlike in some Sudoku grids where it's often easier to "try" a number, then cancel if an inconsistency appears).

    Actually most of the clues can be easily translated to natural language and make the puzzle understandable to the average people: [^M]*M[^M]* means "there is one and only one M in this line", (RX|[^R])* means "every R in this line must be followed by an X", etc.

    --
    God, root, what is difference ?
  15. Re:star * by gd2shoe · · Score: 2

    If you put a space anywhere in the puzzle, at least one of the clues will fail. The only solution that works is made entirely of the capital letters found in the clues. Don't believe me? Try to find a complete solution with a space in it.

    And yes, they really do mean .* There are several of those that match empty strings, so you need to be on your guard. There is a single + in the puzzle, right where it needs to be.

    --
    I won't join Slashcott. OTOH, If Beta goes live, I just won't be back until it's fixed. Sorry Dice.