Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

liliy

  • 3 years ago

how do i go about programming this:(JAVA) You have to put the numbers 1-8 in the eight available cells in such a way that no number borders a consecutive number, even diagonally.

  • This Question is Closed
  1. liliy
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    1 Attachment
  2. Chris2332
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I would create a map of each cell and its adjacent cells. Then make sure that the number in the cell does not have a consecutive number in any of the adjacent cells. Create a loop to try the different combinations.

  3. Chris2332
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The mathematical solution can be found here: http://www.geeksforgeeks.org/forum/topic/fill-numbers-puzzle

  4. snark
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you can write it as a backtracking problem - label boxes to fill from 0-7, and successively try to put a number in it: while (boxnumber < 8){ // if 8, are done ...put unused number in box ...test conditions ...if ok boxnumber += 1 // on to the next ...if not erase last try if more numbers to try, try next else backup a level, erase number there, and try next number the annoying part is keeping track of everything.

  5. snark
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    my sleazy python program finds 16 solutions

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy