Not very hard. Start with the grid in the upper left corner. Assign the numbers to this grid (it doesn't matter in which order). Now copy this first grid all over, except that for each step sideways you rotate a row in the grid (for instance, put the top row at the bottom), and for each step downwards, you rotate a column (for instance, rotate the left most column to the right). Here's a program:
#!/usr/bin/perl use strict; use warnings; no warnings qw /syntax/; my $N = 6; my $SN = $N * $N; my @chars = (0 .. 9, 'A' .. 'Z', 'a' .. 'z', '/', '+'); my $mask; foreach my $x (0 .. $N - 1) { foreach my $y (0 .. $N - 1) { $mask -> [$x] [$y] = $x * $N + $y; } } my $grid; foreach my $X (0 .. $N - 1) { foreach my $Y (0 .. $N - 1) { my $sx = $X * $N; my $sy = $Y * $N; foreach my $x ($sx .. $sx + $N - 1) { foreach my $y ($sy .. $sy + $N - 1) { $grid -> [$x] [$y] = $mask -> [($x + $Y) % $N] [($y + +$X) % $N]; } } } } # # Check correctness. # # Rows and columns. foreach my $x (0 .. $SN - 1) { my %hx; my %hy; foreach my $y (0 .. $SN - 1) { $hx {$grid -> [$x] [$y]} = 1; $hy {$grid -> [$y] [$x]} = 1; } die unless $SN == keys %hx && $SN == keys %hy; } # Grids. foreach my $x (0 .. $N - 1) { foreach my $y (0 .. $N - 1) { my %hg; foreach my $xx (0 .. $N - 1) { foreach my $yy (0 .. $N - 1) { $hg {$grid -> [$x * $N + $xx] [$y * $N + $yy]} = 1; } } die unless $SN == keys %hg; } } # Print results (assume $N <= 8). foreach my $x (0 .. @$grid - 1) { foreach my $y (0 .. @{$grid -> [$x]} - 1) { print $chars [$grid -> [$x] [$y]]; } print "\n"; } __END__ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 6789ABCDEFGHIJKLMNOPQRSTUVWXYZ012345 CDEFGHIJKLMNOPQRSTUVWXYZ0123456789AB IJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH OPQRSTUVWXYZ0123456789ABCDEFGHIJKLMN UVWXYZ0123456789ABCDEFGHIJKLMNOPQRST 123450789AB6DEFGHCJKLMNIPQRSTOVWXYZU 789AB6DEFGHCJKLMNIPQRSTOVWXYZU123450 DEFGHCJKLMNIPQRSTOVWXYZU123450789AB6 JKLMNIPQRSTOVWXYZU123450789AB6DEFGHC PQRSTOVWXYZU123450789AB6DEFGHCJKLMNI VWXYZU123450789AB6DEFGHCJKLMNIPQRSTO 23450189AB67EFGHCDKLMNIJQRSTOPWXYZUV 89AB67EFGHCDKLMNIJQRSTOPWXYZUV234501 EFGHCDKLMNIJQRSTOPWXYZUV23450189AB67 KLMNIJQRSTOPWXYZUV23450189AB67EFGHCD QRSTOPWXYZUV23450189AB67EFGHCDKLMNIJ WXYZUV23450189AB67EFGHCDKLMNIJQRSTOP 3450129AB678FGHCDELMNIJKRSTOPQXYZUVW 9AB678FGHCDELMNIJKRSTOPQXYZUVW345012 FGHCDELMNIJKRSTOPQXYZUVW3450129AB678 LMNIJKRSTOPQXYZUVW3450129AB678FGHCDE RSTOPQXYZUVW3450129AB678FGHCDELMNIJK XYZUVW3450129AB678FGHCDELMNIJKRSTOPQ 450123AB6789GHCDEFMNIJKLSTOPQRYZUVWX AB6789GHCDEFMNIJKLSTOPQRYZUVWX450123 GHCDEFMNIJKLSTOPQRYZUVWX450123AB6789 MNIJKLSTOPQRYZUVWX450123AB6789GHCDEF STOPQRYZUVWX450123AB6789GHCDEFMNIJKL YZUVWX450123AB6789GHCDEFMNIJKLSTOPQR 501234B6789AHCDEFGNIJKLMTOPQRSZUVWXY B6789AHCDEFGNIJKLMTOPQRSZUVWXY501234 HCDEFGNIJKLMTOPQRSZUVWXY501234B6789A NIJKLMTOPQRSZUVWXY501234B6789AHCDEFG TOPQRSZUVWXY501234B6789AHCDEFGNIJKLM ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS

Abigail


In reply to Re: Better algorithm for Number Place Puzzle by Abigail-II
in thread Better algorithm for Number Place Puzzle by davidj

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, details, 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, summary, 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.