Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Sudoku puzzles solved using Regular Expressions

by GrandFather (Cardinal)
on Jun 30, 2005 at 00:59 UTC ( #471199=note: print w/ replies, xml ) Need Help??


in reply to Sudoku puzzles solved using Regular Expressions

Neat. A pity the answer is wrong :-).

Consider the top left cell:

283 157 316

3 repeated and 1 repeated. That's not the way the game is played.


Perl is Huffman encoded by design.


Comment on Re: Sudoku puzzles solved using Regular Expressions
Download Code
Re^2: Sudoku puzzles solved using Regular Expressions
by ikegami (Pope) on Jun 30, 2005 at 04:11 UTC

    Hot diggity! I didn't read the puzzle definition closely enough!

    Well, I could easily fix that by updating valid(). Give me a few minutes and I'll update this node with a solution that solves the puzzle accurately.

    Update: hum... I'm getting protection faults :( I think I can't use regexps in valid() when it's called from within a regexp.

    Update: Fine, I won't use regexp in valid(). What follows is my updated solution. The only difference the var $regsz and valid() has an additional check.

    Original ======== ___1__74_ _5__9__32 __67__9__ 4__8_____ _2_____1_ _____9__5 __4__73__ 73__2__6_ _65__4___ Solution ======== 392185746 857496132 146732958 479851623 528673419 613249875 284567391 731928564 965314287

      I had a play with your code to try and fix the problem, but headed off in a much less elegant direction than you did by adding a $grid_c vector and another nested loop.

      It got rather messy rather quickly. :-(


      Perl is Huffman encoded by design.

        Yeah, there are diminishing returns to adding more shortcuts.

        Technically, $grid_v is not needed at all.

        return if index(substr($grid_v, $x*$size, $size), $n) >= 0;

        can be written as

        foreach my $y_ (0 .. $size-1) { return if substr($grid_h, $y_*$size+$x, 1) eq $n; }

        I just thought the former would be faster, even though we must constantly make copies of $grid_v in addition to $grid_h.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://471199]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-12-18 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (42 votes), past polls