In this challenge you are supposed to fill a grid 10x10 with numbers from 1 to 100 (each number once) following this rules:

  • Number 1 must be on the bottom row
  • Number 100 must be on the upper row
  • Two consecutive numbers must be one next to the other (diagonals doesn't count)
  • The grid must be random

It's not necessary at all that all possible outcomes are equiprobable. Still, though, there must be a non-zero chance for every possible grid (that satisfies the first 3 conditions) to occur.

I don't want time to be a problem, but to avoid pure brute force, answers should take less than a minute to run.

Since output shouldn't be the main focus of the challenge I give complete freedom on how to write it, as long as each row in the output corresponds to a row in the grid and numbers are separated by a character (of any kind).

  • 8
    \$\begingroup\$ By "random", do you mean that every grid that satisfies the first 3 conditions has a non-zero chance of being produced? Also, can solutions keep producing random grids until they find one that fits the criteria, or is there a time bound? \$\endgroup\$
    – Zgarb
    Apr 6, 2016 at 19:36
  • 2
    \$\begingroup\$ How should output be presented? Does if have to be a string that gives the grid appearance, or can it be a 2x2 array as a functon return value, for example? If the former, 0 (or 00) to 99 would look neater. That one 3-digit number is a pain aesthetically \$\endgroup\$ Apr 6, 2016 at 19:45
  • 4
    \$\begingroup\$ As it, this allows the cheap solution of generating a random grid, outputting it if it satisfies the properties, and otherwise outputting a fixed grid that works. \$\endgroup\$
    – xnor
    Apr 6, 2016 at 20:28
  • 4
    \$\begingroup\$ What would you consider as brute-force here? Why do you think this can be solved (under all the given conditions) in less than one minute? \$\endgroup\$
    – flawr
    Apr 6, 2016 at 20:52
  • 2
    \$\begingroup\$ @LevelRiverSt It's not cheating at all when it satisfies the rules of the question. I shouldn't have to judge the asker's intent to decide whether a solution method is fair. \$\endgroup\$
    – xnor
    Apr 6, 2016 at 23:35


Browse other questions tagged or ask your own question.