A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
To count the total number of unholy 8x8 matrices, we can use a recursive approach with backtracking. Here's a C program that solves the problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <stdio.h> #include <stdbool.h> #define ROWS 8 #define COLS 8 int count = 0; bool isIsolated(int matrix[ROWS][COLS], int row, int col) { if (row > 0 && matrix[row - 1][col] == 1) return false; if (row < ROWS - 1 && matrix[row + 1][col] == 1) return false; if (col > 0 && matrix[row][col - 1] == 1) return false; if (col < COLS - 1 && matrix[row][col + 1] == 1) return false; return true; } bool isUnholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1 && isIsolated(matrix, i, j)) return false; } } return true; } void backtrack(int matrix[ROWS][COLS], int row, int col) { if (col == COLS) { col = 0; row++; } if (row == ROWS) { if (isUnholy(matrix)) count++; return; } matrix[row][col] = 0; backtrack(matrix, row, col + 1); matrix[row][col] = 1; backtrack(matrix, row, col + 1); } int main() { int matrix[ROWS][COLS] = {0}; backtrack(matrix, 0, 0); printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <stdio.h> #include <stdbool.h> #define ROWS 8 #define COLS 8 int count = 0; bool isIsolated(int matrix[ROWS][COLS], int row, int col) { if (row > 0 && matrix[row - 1][col] == 1) return false; if (row < ROWS - 1 && matrix[row + 1][col] == 1) return false; if (col > 0 && matrix[row][col - 1] == 1) return false; if (col < COLS - 1 && matrix[row][col + 1] == 1) return false; return true; } bool isUnholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1 && isIsolated(matrix, i, j)) return false; } } return true; } void backtrack(int matrix[ROWS][COLS], int row, int col) { if (col == COLS) { col = 0; row++; } if (row == ROWS) { if (isUnholy(matrix)) count++; return; } matrix[row][col] = 0; backtrack(matrix, row, col + 1); matrix[row][col] = 1; backtrack(matrix, row, col + 1); } int main() { int matrix[ROWS][COLS] = {0}; backtrack(matrix, 0, 0); printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <stdio.h> #include <stdbool.h> #define ROWS 8 #define COLS 8 int count = 0; bool isIsolated(int matrix[ROWS][COLS], int row, int col) { if (row > 0 && matrix[row - 1][col] == 1) return false; if (row < ROWS - 1 && matrix[row + 1][col] == 1) return false; if (col > 0 && matrix[row][col - 1] == 1) return false; if (col < COLS - 1 && matrix[row][col + 1] == 1) return false; return true; } bool isUnholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1 && isIsolated(matrix, i, j)) return false; } } return true; } void backtrack(int matrix[ROWS][COLS], int row, int col) { if (col == COLS) { col = 0; row++; } if (row == ROWS) { if (isUnholy(matrix)) count++; return; } matrix[row][col] = 0; backtrack(matrix, row, col + 1); matrix[row][col] = 1; backtrack(matrix, row, col + 1); } int main() { int matrix[ROWS][COLS] = {0}; backtrack(matrix, 0, 0); printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
Timeout: function took too long to complete
Testing if the previous output contains the string 1121231537486377866
: False
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
Here's a C program that counts the total number of unholy 8x8 matrices:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <stdio.h> #define SIZE 8 int is_unholy(int matrix[SIZE][SIZE]) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if (matrix[i][j] == 1) { int is_isolated = 1; if (i > 0 && matrix[i-1][j] == 1) is_isolated = 0; if (i < SIZE-1 && matrix[i+1][j] == 1) is_isolated = 0; if (j > 0 && matrix[i][j-1] == 1) is_isolated = 0; if (j < SIZE-1 && matrix[i][j+1] == 1) is_isolated = 0; if (is_isolated) return 0; } } } return 1; } void generate_matrices(int matrix[SIZE][SIZE], int row, int col, long long *count) { if (row == SIZE) { if (is_unholy(matrix)) (*count)++; return; } if (col == SIZE) { generate_matrices(matrix, row + 1, 0, count); return; } matrix[row][col] = 0; generate_matrices(matrix, row, col + 1, count); matrix[row][col] = 1; generate_matrices(matrix, row, col + 1, count); } int main() { int matrix[SIZE][SIZE]; long long count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %lld\n", count); return 0; } |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <stdio.h> #define SIZE 8 int is_unholy(int matrix[SIZE][SIZE]) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if (matrix[i][j] == 1) { int is_isolated = 1; if (i > 0 && matrix[i-1][j] == 1) is_isolated = 0; if (i < SIZE-1 && matrix[i+1][j] == 1) is_isolated = 0; if (j > 0 && matrix[i][j-1] == 1) is_isolated = 0; if (j < SIZE-1 && matrix[i][j+1] == 1) is_isolated = 0; if (is_isolated) return 0; } } } return 1; } void generate_matrices(int matrix[SIZE][SIZE], int row, int col, long long *count) { if (row == SIZE) { if (is_unholy(matrix)) (*count)++; return; } if (col == SIZE) { generate_matrices(matrix, row + 1, 0, count); return; } matrix[row][col] = 0; generate_matrices(matrix, row, col + 1, count); matrix[row][col] = 1; generate_matrices(matrix, row, col + 1, count); } int main() { int matrix[SIZE][SIZE]; long long count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %lld\n", count); return 0; } |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <stdio.h> #define SIZE 8 int is_unholy(int matrix[SIZE][SIZE]) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if (matrix[i][j] == 1) { int is_isolated = 1; if (i > 0 && matrix[i-1][j] == 1) is_isolated = 0; if (i < SIZE-1 && matrix[i+1][j] == 1) is_isolated = 0; if (j > 0 && matrix[i][j-1] == 1) is_isolated = 0; if (j < SIZE-1 && matrix[i][j+1] == 1) is_isolated = 0; if (is_isolated) return 0; } } } return 1; } void generate_matrices(int matrix[SIZE][SIZE], int row, int col, long long *count) { if (row == SIZE) { if (is_unholy(matrix)) (*count)++; return; } if (col == SIZE) { generate_matrices(matrix, row + 1, 0, count); return; } matrix[row][col] = 0; generate_matrices(matrix, row, col + 1, count); matrix[row][col] = 1; generate_matrices(matrix, row, col + 1, count); } int main() { int matrix[SIZE][SIZE]; long long count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %lld\n", count); return 0; } |
Timeout: function took too long to complete
Testing if the previous output contains the string 1121231537486377866
: False
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
Here's a C program that counts the total number of unholy 8x8 matrices:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <stdio.h> #define ROWS 8 #define COLS 8 int is_unholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1) { if ((i == 0 || matrix[i-1][j] == 0) && (i == ROWS-1 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == COLS-1 || matrix[i][j+1] == 0)) { return 0; } } } } return 1; } void generate_matrices(int matrix[ROWS][COLS], int row, int col, int *count) { if (row == ROWS) { if (is_unholy(matrix)) { (*count)++; } return; } int next_row = (col == COLS - 1) ? row + 1 : row; int next_col = (col + 1) % COLS; matrix[row][col] = 0; generate_matrices(matrix, next_row, next_col, count); matrix[row][col] = 1; generate_matrices(matrix, next_row, next_col, count); } int main() { int matrix[ROWS][COLS] = {0}; int count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <stdio.h> #define ROWS 8 #define COLS 8 int is_unholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1) { if ((i == 0 || matrix[i-1][j] == 0) && (i == ROWS-1 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == COLS-1 || matrix[i][j+1] == 0)) { return 0; } } } } return 1; } void generate_matrices(int matrix[ROWS][COLS], int row, int col, int *count) { if (row == ROWS) { if (is_unholy(matrix)) { (*count)++; } return; } int next_row = (col == COLS - 1) ? row + 1 : row; int next_col = (col + 1) % COLS; matrix[row][col] = 0; generate_matrices(matrix, next_row, next_col, count); matrix[row][col] = 1; generate_matrices(matrix, next_row, next_col, count); } int main() { int matrix[ROWS][COLS] = {0}; int count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <stdio.h> #define ROWS 8 #define COLS 8 int is_unholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1) { if ((i == 0 || matrix[i-1][j] == 0) && (i == ROWS-1 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == COLS-1 || matrix[i][j+1] == 0)) { return 0; } } } } return 1; } void generate_matrices(int matrix[ROWS][COLS], int row, int col, int *count) { if (row == ROWS) { if (is_unholy(matrix)) { (*count)++; } return; } int next_row = (col == COLS - 1) ? row + 1 : row; int next_col = (col + 1) % COLS; matrix[row][col] = 0; generate_matrices(matrix, next_row, next_col, count); matrix[row][col] = 1; generate_matrices(matrix, next_row, next_col, count); } int main() { int matrix[ROWS][COLS] = {0}; int count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
Timeout: function took too long to complete
Testing if the previous output contains the string 1121231537486377866
: False
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
Here's a C program that counts the total number of unholy 8x8 matrices:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <stdio.h> #include <stdbool.h> #define ROWS 8 #define COLS 8 // Function to check if a matrix is unholy bool isUnholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1) { // Check if the 1 is isolated bool isolated = true; // Check the four cardinal directions int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; for (int k = 0; k < 4; k++) { int nx = i + dx[k]; int ny = j + dy[k]; if (nx >= 0 && nx < ROWS && ny >= 0 && ny < COLS && matrix[nx][ny] == 1) { isolated = false; break; } } if (isolated) { return false; } } } } return true; } // Function to generate and count unholy matrices int countUnholyMatrices() { int count = 0; int matrix[ROWS][COLS]; // Generate all possible matrices for (int i = 0; i < (1 << (ROWS * COLS)); i++) { for (int j = 0; j < ROWS * COLS; j++) { matrix[j / COLS][j % COLS] = (i >> j) & 1; } // Check if the matrix is unholy if (isUnholy(matrix)) { count++; } } return count; } int main() { int unholyCount = countUnholyMatrices(); printf("Total number of unholy 8x8 matrices: %d\n", unholyCount); return 0; } |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <stdio.h> #include <stdbool.h> #define ROWS 8 #define COLS 8 // Function to check if a matrix is unholy bool isUnholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1) { // Check if the 1 is isolated bool isolated = true; // Check the four cardinal directions int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; for (int k = 0; k < 4; k++) { int nx = i + dx[k]; int ny = j + dy[k]; if (nx >= 0 && nx < ROWS && ny >= 0 && ny < COLS && matrix[nx][ny] == 1) { isolated = false; break; } } if (isolated) { return false; } } } } return true; } // Function to generate and count unholy matrices int countUnholyMatrices() { int count = 0; int matrix[ROWS][COLS]; // Generate all possible matrices for (int i = 0; i < (1 << (ROWS * COLS)); i++) { for (int j = 0; j < ROWS * COLS; j++) { matrix[j / COLS][j % COLS] = (i >> j) & 1; } // Check if the matrix is unholy if (isUnholy(matrix)) { count++; } } return count; } int main() { int unholyCount = countUnholyMatrices(); printf("Total number of unholy 8x8 matrices: %d\n", unholyCount); return 0; } |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <stdio.h> #include <stdbool.h> #define ROWS 8 #define COLS 8 // Function to check if a matrix is unholy bool isUnholy(int matrix[ROWS][COLS]) { for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (matrix[i][j] == 1) { // Check if the 1 is isolated bool isolated = true; // Check the four cardinal directions int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; for (int k = 0; k < 4; k++) { int nx = i + dx[k]; int ny = j + dy[k]; if (nx >= 0 && nx < ROWS && ny >= 0 && ny < COLS && matrix[nx][ny] == 1) { isolated = false; break; } } if (isolated) { return false; } } } } return true; } // Function to generate and count unholy matrices int countUnholyMatrices() { int count = 0; int matrix[ROWS][COLS]; // Generate all possible matrices for (int i = 0; i < (1 << (ROWS * COLS)); i++) { for (int j = 0; j < ROWS * COLS; j++) { matrix[j / COLS][j % COLS] = (i >> j) & 1; } // Check if the matrix is unholy if (isUnholy(matrix)) { count++; } } return count; } int main() { int unholyCount = countUnholyMatrices(); printf("Total number of unholy 8x8 matrices: %d\n", unholyCount); return 0; } |
Total number of unholy 8x8 matrices: 0
main.c: In function 'countUnholyMatrices':
main.c:45:28: warning: left shift count >= width of type [-Wshift-count-overflow]
45 | for (int i = 0; i < (1 << (ROWS * COLS)); i++) {
| ^~
Testing if the previous output contains the string 1121231537486377866
: False
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
A binary 8x8 matrix is 'unholy' if there are no isolated 1s. A 1 is isolated if there isn't another 1 in any of the 4 direct cardinal directions. Write a C program that counts the total number of unholy 8x8 matricies.
Here's a C program that counts the total number of unholy 8x8 matrices:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <stdio.h> #define N 8 int is_unholy(int matrix[N][N]) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (matrix[i][j] == 1) { // Check if the 1 is isolated if ((i == 0 || matrix[i-1][j] == 0) && (i == N-1 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == N-1 || matrix[i][j+1] == 0)) { return 0; // The matrix is not unholy } } } } return 1; // The matrix is unholy } void generate_matrices(int matrix[N][N], int row, int col, long long *count) { if (row == N) { // Matrix is complete, check if it is unholy if (is_unholy(matrix)) { (*count)++; } return; } if (col == N) { // Move to the next row generate_matrices(matrix, row + 1, 0, count); return; } // Fill the current cell with 0 and move to the next cell matrix[row][col] = 0; generate_matrices(matrix, row, col + 1, count); // Fill the current cell with 1 and move to the next cell matrix[row][col] = 1; generate_matrices(matrix, row, col + 1, count); } int main() { int matrix[N][N] = {0}; long long count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %lld\n", count); return 0; } |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <stdio.h> #define N 8 int is_unholy(int matrix[N][N]) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (matrix[i][j] == 1) { // Check if the 1 is isolated if ((i == 0 || matrix[i-1][j] == 0) && (i == N-1 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == N-1 || matrix[i][j+1] == 0)) { return 0; // The matrix is not unholy } } } } return 1; // The matrix is unholy } void generate_matrices(int matrix[N][N], int row, int col, long long *count) { if (row == N) { // Matrix is complete, check if it is unholy if (is_unholy(matrix)) { (*count)++; } return; } if (col == N) { // Move to the next row generate_matrices(matrix, row + 1, 0, count); return; } // Fill the current cell with 0 and move to the next cell matrix[row][col] = 0; generate_matrices(matrix, row, col + 1, count); // Fill the current cell with 1 and move to the next cell matrix[row][col] = 1; generate_matrices(matrix, row, col + 1, count); } int main() { int matrix[N][N] = {0}; long long count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %lld\n", count); return 0; } |
Running the following program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <stdio.h> #define N 8 int is_unholy(int matrix[N][N]) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (matrix[i][j] == 1) { // Check if the 1 is isolated if ((i == 0 || matrix[i-1][j] == 0) && (i == N-1 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == N-1 || matrix[i][j+1] == 0)) { return 0; // The matrix is not unholy } } } } return 1; // The matrix is unholy } void generate_matrices(int matrix[N][N], int row, int col, long long *count) { if (row == N) { // Matrix is complete, check if it is unholy if (is_unholy(matrix)) { (*count)++; } return; } if (col == N) { // Move to the next row generate_matrices(matrix, row + 1, 0, count); return; } // Fill the current cell with 0 and move to the next cell matrix[row][col] = 0; generate_matrices(matrix, row, col + 1, count); // Fill the current cell with 1 and move to the next cell matrix[row][col] = 1; generate_matrices(matrix, row, col + 1, count); } int main() { int matrix[N][N] = {0}; long long count = 0; generate_matrices(matrix, 0, 0, &count); printf("Total number of unholy 8x8 matrices: %lld\n", count); return 0; } |
Timeout: function took too long to complete
Testing if the previous output contains the string 1121231537486377866
: False