I've been struggling with the final stage of fifteen programming. So far up to move, my coding is working OK. In my 'won' routine, I'm checking all of the tiles are in the ascending order. The blank space is represented by 95, which would be higher than the highest possible tile (i.e., in case of 9x9 board, 80 would be the highest). My coding has two loops, inner loop which would check a row, outerloop which would lead to the next row. After checking all rows are satisfactory, my code, shown below, should return true.

enter image description here

When I run it, however, it keeps on requesting to enter new tile number to move. Below is the copy of the screen.

enter image description here

In debugging, I tried everything I can think of, now I've exhausted with my idea.

I know even if I can clear this problem, with a month left, I won't be able to finish all my problem sets. But I would like to do my best for the remaining period. Looking forward to hearing any suggestion!!

1 Answer 1


Consider what happens during the loop:

i=0, j=0
if board[0][0] > board[0][1]
i=0, j=1
if board[0][1] > board[0][2]
i=0, j=2
if board[0][2] > board[0][3]  // ???

//  does board[0][3] exist?  
// what if the value in it is zero because it's not part of the board?  
// won't you always return false?

Might a simpler test be to see if board[0][0] != 1 ? and board[0][1] != 2 etc? using a counter to count up? You know that the board always starts at 1, so why not use that rather than a generic " greater than the next one "?

  • Thank you Curioskiwi!! It never occurred to me. How stupid of me! My only excuse is that the compiler did not give me any warning.
    – Yoshi Watt
    Nov 30, 2014 at 7:26
  • You're welcome. Please vote to accept my answer so this will be shown as solved.
    – curiouskiwi
    Nov 30, 2014 at 8:25
  • I clicked votes. Is that good enough? If not, pls tell me how to vote.
    – Yoshi Watt
    Dec 1, 2014 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .