Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Don't ask to ask, just ask
 
PerlMonks  

Re: Better algorithm for Number Place Puzzle

by dash2 (Hermit)
on May 23, 2004 at 22:20 UTC ( #355777=note: print w/ replies, xml ) Need Help??


in reply to Better algorithm for Number Place Puzzle

Just a guess. Perhaps you could use the other monk's blanked out solution to create an initial grid. Then, recreate this solution in the other grids, but transform it in some simple way in order to make sure it doesn't break the rules. My shot - just a first guess - is below, hidden:

Hmm. Let's try a 2 x 2 version. The initial grid is

12 34

obviously. Now you need to fill in

12-- 34-- ---- ----

Clearly, as you move across, you need to shift rows:

1234 3412 ---- ----

And as you move down, you need to shift columns:

1234 3412 21-- 43--

note that the lower left grid is just the upper left grid with columns shifted along. Finally,

1234 3412 2143 4321

it turns out that the column shift from the grid above, and the row shift from the grid to the left, give identical results.

Perhaps this will work with N>2. Or not. Enjoy.

A massive flamewar beneath your chosen depth has not been shown here


Comment on Re: Better algorithm for Number Place Puzzle
Select or Download Code
Re: Re: Better algorithm for Number Place Puzzle
by blokhead (Monsignor) on May 23, 2004 at 23:27 UTC
    This can be extended to create a random solution, just randomize the initial block. (This is similar to Abigail-II's solution). Here @start is a N by N matrix whose entries are a random permutation of {1, .., N^2}.
    my $n = shift || 3; my @start = do { use List::Util 'shuffle'; my @perm = shuffle 1 .. $n*$n; map { my $row = $_; [ map { $perm[$row * $n + $_] } 0 .. $n-1 ] } 0 .. $n-1; }; my @solution; for my $x ( 0 .. $n*$n - 1 ) { for my $y ( 0 .. $n*$n - 1 ) { my $block_x = int ($x / $n); my $block_y = int ($y / $n); $solution[$x][$y] = $start[ ($block_x + $y) % $n ][ ($block_y + $x) % $n ]; } } print join "" => map { "@$_\n" } @solution;

    blokhead

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-04-17 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls