Skip to content

Instantly share code, notes, and snippets.

/fifteen.c Secret

Created August 10, 2016 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/86bdd4c778dc8001ea475b63cb91a79b to your computer and use it in GitHub Desktop.
Save anonymous/86bdd4c778dc8001ea475b63cb91a79b to your computer and use it in GitHub Desktop.
fifteen.c - shared from CS50 IDE
int init(void)
{
// TODO
int i;
int j;
int board[DIM_MAX][DIM_MAX];
int x = d*d;
for ( i = 0; i < d; i ++)
{
for ( j = 0; j < d; j++)
{
x = x-1;
board[i][j] = x;
}
}
// Swap 2 and 1
if ((((d * d) - 1) % 2) != 0)
{
int hold = board[d-1][d-2];
board[d-1][d-2] = board[d-1][d-3];
board[d-1][d-3] = hold;
}
return board[i][j];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment