Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
(Inspired by Re: Subroutine overhead in Perl)

Challenge: Golf a sudoku solver. Bonus points to fast solutions as well. Correct solutions must provide all solutions to a given starting position (test data provided below).

If you want, you can use any/all of the following infrastructure:

  1. @grid - starts with the initial position (with 0's for empty squares).
  2. %search - contains 81 entries, indexed by 0-80, each pointing to an arrayref of 21 entries. These entries are squares that cannot contain the same value as the key.
  3. sudoku_print() - a method that prints the sudoku board as listed in @grid.
  4. Assume that the input has already been parsed into @grid.

I'll post my solutions in a response to this post.

Some samples are:

-,-,4,-,-,2,-,-,3 -,2,-,-,9,-,7,1,5 7,-,-,3,1,-,4,-,- -,1,-,-,-,-,2,-,9 -,4,-,2,7,-,-,-,6 2,8,-,5,-,-,-,-,- 5,-,-,-,-,3,6,-,4 -,3,1,-,-,8,-,-,2 4,6,-,-,5,-,-,3,1 -,-,5,-,-,-,-,4,- -,-,-,8,-,-,-,-,6 3,-,2,-,-,1,-,-,- -,-,-,-,-,4,-,2,- -,-,9,-,-,-,5,-,- -,6,-,3,-,-,-,-,- -,-,-,-,-,-,-,-,3 -,-,-,-,-,5,-,-,- -,1,-,-,-,-,6,8,- -,-,-,-,-,-,-,-,- -,-,-,-,-,3,-,8,5 -,-,1,-,2,-,-,-,- -,-,-,5,-,7,-,-,- -,-,4,-,-,-,1,-,- -,9,-,-,-,-,-,-,- 5,-,-,-,-,-,-,7,3 -,-,2,-,1,-,-,-,- -,-,-,-,4,-,-,-,9 (This input has two solutions. Both are required to be correct.) 9,-,6,-,7,-,4,-,3 -,-,-,4,-,-,2,-,- -,7,-,-,2,3,-,1,- 5,-,-,-,-,-,1,-,- -,4,-,2,-,8,-,6,- -,-,3,-,-,-,-,-,5 -,3,-,7,-,-,-,5,- -,-,7,-,-,5,-,-,- 4,-,5,-,1,-,7,-,8

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

In reply to Golf: Sudoku solving by dragonchild

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found