Pset3 won-function successfully passed this test ./fifteen 3 < ~cs50/pset3/3x3.txt
only for a 3 × 3 board. For a 4x4 board the program's output is:
1 2 3 4
5 6 7 _
9 10 12 8
13 11 15 14
ftw!
The blank space is d*d. The won function contains 2 nested for-loops and inside the one long condition:
for(int i = 0; i < d; i++)
{
for(int j = 0; j < d; j++)
{
if (i + 1 < d && i - 1 >= 0 && j + 1 <= d && j - 1 >= 0 && board[i][j - 1] == board[i][j] - 1 && board[i][j + 1] == board[i][j] + 1 && board[i - 1][j] == board[i][j] - d && board[i + 1][j] == board[i][j] + d)
{
return true;
}
}
}
return false;