Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: SuDoKu solver

by NetWallah (Canon)
on Jul 18, 2005 at 03:32 UTC ( [id://475630]=note: print w/replies, xml ) Need Help??


in reply to SuDoKu solver

Cool code (++)!

I was attempting to re-write the $grid array-ref initialization in a more "Lazy" manner, using the "x" operator, but the implementation of that operator optimizes in such a way that the operand gets evaluated only once. I had to settle on "map" :

my $grid=[ map {[ map {$init} 1..9 ]} 1..9 ];
If anyone can accomplish this using the "x" operator in a non-obfu way, I'd love to hear it.

     "Income tax returns are the most imaginative fiction being written today." -- Herman Wouk

Replies are listed 'Best First'.
Re^2: SuDoKu solver
by jmcnamara (Monsignor) on Jul 18, 2005 at 08:06 UTC

    I initially wrote this and it appeared correct according to Test::More::is_deeply(). However, despite the test, it is wrong since the inner array ref is copied rather than recreated (which is probably what you are alluding to above).
    my $grid = [([($init) x 9]) x 9]; # ! wrong

    So, perhaps somethings like this:

    my $grid = [map {[($init) x 9]} 1..9];

    I was really addicted to Sudoku puzzles a few weeks ago, but I'm finally getting my life back. :-)

    --
    John.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found