Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I wrote a program that builds a regexp to solves Sudoku puzzles. The generated regexp is hidden underneath the "readmore" below.

Update: The generated regexp is too big to fit in a post. An abridged version was used.

sub valid { my $spot = substr($grid_h, $_[0]*$size+$_[1], 1); return 1 if $spot eq $_[2]; return if $spot ne '_'; return if index(substr($grid_h, $_[0] * $size, $size), $_[2]) >= 0; return if index(substr($grid_v, $_[1] * $size, $size), $_[2]) >= 0; return 1; } $re = qr/ (?: (?(?{ !valid(0, 0, '1') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '1') +; }) | (?(?{ !valid(0, 0, '2') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '2') +; }) | (?(?{ !valid(0, 0, '3') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '3') +; }) | (?(?{ !valid(0, 0, '4') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '4') +; }) | (?(?{ !valid(0, 0, '5') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '5') +; }) | (?(?{ !valid(0, 0, '6') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '6') +; }) | (?(?{ !valid(0, 0, '7') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '7') +; }) | (?(?{ !valid(0, 0, '8') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '8') +; }) | (?(?{ !valid(0, 0, '9') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 0, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 0, 1, '9') +; }) ) (?: (?(?{ !valid(0, 1, '1') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '1') +; }) | (?(?{ !valid(0, 1, '2') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '2') +; }) | (?(?{ !valid(0, 1, '3') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '3') +; }) | (?(?{ !valid(0, 1, '4') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '4') +; }) | (?(?{ !valid(0, 1, '5') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '5') +; }) | (?(?{ !valid(0, 1, '6') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '6') +; }) | (?(?{ !valid(0, 1, '7') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '7') +; }) | (?(?{ !valid(0, 1, '8') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '8') +; }) | (?(?{ !valid(0, 1, '9') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 1, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 9, 1, '9') +; }) ) (?: (?(?{ !valid(0, 2, '1') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '1' +); }) | (?(?{ !valid(0, 2, '2') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '2' +); }) | (?(?{ !valid(0, 2, '3') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '3' +); }) | (?(?{ !valid(0, 2, '4') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '4' +); }) | (?(?{ !valid(0, 2, '5') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '5' +); }) | (?(?{ !valid(0, 2, '6') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '6' +); }) | (?(?{ !valid(0, 2, '7') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '7' +); }) | (?(?{ !valid(0, 2, '8') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '8' +); }) | (?(?{ !valid(0, 2, '9') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 2, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 18, 1, '9' +); }) ) . . . (?: (?(?{ !valid(8, 6, '1') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '1 +'); }) | (?(?{ !valid(8, 6, '2') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '2 +'); }) | (?(?{ !valid(8, 6, '3') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '3 +'); }) | (?(?{ !valid(8, 6, '4') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '4 +'); }) | (?(?{ !valid(8, 6, '5') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '5 +'); }) | (?(?{ !valid(8, 6, '6') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '6 +'); }) | (?(?{ !valid(8, 6, '7') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '7 +'); }) | (?(?{ !valid(8, 6, '8') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '8 +'); }) | (?(?{ !valid(8, 6, '9') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 78, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 62, 1, '9 +'); }) ) (?: (?(?{ !valid(8, 7, '1') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '1 +'); }) | (?(?{ !valid(8, 7, '2') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '2 +'); }) | (?(?{ !valid(8, 7, '3') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '3 +'); }) | (?(?{ !valid(8, 7, '4') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '4 +'); }) | (?(?{ !valid(8, 7, '5') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '5 +'); }) | (?(?{ !valid(8, 7, '6') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '6 +'); }) | (?(?{ !valid(8, 7, '7') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '7 +'); }) | (?(?{ !valid(8, 7, '8') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '8 +'); }) | (?(?{ !valid(8, 7, '9') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 79, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 71, 1, '9 +'); }) ) (?: (?(?{ !valid(8, 8, '1') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '1'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '1 +'); }) | (?(?{ !valid(8, 8, '2') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '2'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '2 +'); }) | (?(?{ !valid(8, 8, '3') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '3'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '3 +'); }) | (?(?{ !valid(8, 8, '4') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '4'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '4 +'); }) | (?(?{ !valid(8, 8, '5') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '5'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '5 +'); }) | (?(?{ !valid(8, 8, '6') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '6'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '6 +'); }) | (?(?{ !valid(8, 8, '7') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '7'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '7 +'); }) | (?(?{ !valid(8, 8, '8') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '8'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '8 +'); }) | (?(?{ !valid(8, 8, '9') })x)(?{ local $grid_h = $grid_h; substr($gr +id_h, 80, 1, '9'); local $grid_v = $grid_v; substr($grid_v, 80, 1, '9 +'); }) ) (?{ $match_grid = $grid_h }) /x;

In reply to Re: The craziest RegExes you ever created by ikegami
in thread The craziest RegExes you ever created by Ieronim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2020-11-24 03:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?