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 | #include <stdio.h> #include <stdbool.h> #include <stdint.h> #define SIZE 8 bool is_unholy(uint64_t matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix & (1ULL << (row * SIZE + col))) != 0) { bool has_neighbor = false; // Check up if (row > 0 && (matrix & (1ULL << ((row - 1) * SIZE + col))) != 0) has_neighbor = true; // Check down if (row < SIZE - 1 && (matrix & (1ULL << ((row + 1) * SIZE + col))) != 0) has_neighbor = true; // Check left if (col > 0 && (matrix & (1ULL << (row * SIZE + col - 1))) != 0) has_neighbor = true; // Check right if (col < SIZE - 1 && (matrix & (1ULL << (row * SIZE + col + 1))) != 0) has_neighbor = true; if (!has_neighbor) return false; } } } return true; } int main() { uint64_t count = 0; uint64_t total = 1ULL << (SIZE * SIZE); for (uint64_t i = 0; i < total; i++) { if (is_unholy(i)) count++; } printf("Total number of unholy 8x8 matrices: %llu\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 | #include <stdio.h> #include <stdbool.h> #include <stdint.h> #define SIZE 8 bool is_unholy(uint64_t matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix & (1ULL << (row * SIZE + col))) != 0) { bool has_neighbor = false; // Check up if (row > 0 && (matrix & (1ULL << ((row - 1) * SIZE + col))) != 0) has_neighbor = true; // Check down if (row < SIZE - 1 && (matrix & (1ULL << ((row + 1) * SIZE + col))) != 0) has_neighbor = true; // Check left if (col > 0 && (matrix & (1ULL << (row * SIZE + col - 1))) != 0) has_neighbor = true; // Check right if (col < SIZE - 1 && (matrix & (1ULL << (row * SIZE + col + 1))) != 0) has_neighbor = true; if (!has_neighbor) return false; } } } return true; } int main() { uint64_t count = 0; uint64_t total = 1ULL << (SIZE * SIZE); for (uint64_t i = 0; i < total; i++) { if (is_unholy(i)) count++; } printf("Total number of unholy 8x8 matrices: %llu\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 | #include <stdio.h> #include <stdbool.h> #include <stdint.h> #define SIZE 8 bool is_unholy(uint64_t matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix & (1ULL << (row * SIZE + col))) != 0) { bool has_neighbor = false; // Check up if (row > 0 && (matrix & (1ULL << ((row - 1) * SIZE + col))) != 0) has_neighbor = true; // Check down if (row < SIZE - 1 && (matrix & (1ULL << ((row + 1) * SIZE + col))) != 0) has_neighbor = true; // Check left if (col > 0 && (matrix & (1ULL << (row * SIZE + col - 1))) != 0) has_neighbor = true; // Check right if (col < SIZE - 1 && (matrix & (1ULL << (row * SIZE + col + 1))) != 0) has_neighbor = true; if (!has_neighbor) return false; } } } return true; } int main() { uint64_t count = 0; uint64_t total = 1ULL << (SIZE * SIZE); for (uint64_t i = 0; i < total; i++) { if (is_unholy(i)) count++; } printf("Total number of unholy 8x8 matrices: %llu\n", count); return 0; } |
Total number of unholy 8x8 matrices: 0
main.c: In function 'main':
main.c:37:27: warning: left shift count >= width of type [-Wshift-count-overflow]
37 | uint64_t total = 1ULL << (SIZE * SIZE);
| ^~
main.c:44:53: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 2 has type 'uint64_t' {aka 'long unsigned int'} [-Wformat=]
44 | printf("Total number of unholy 8x8 matrices: %llu\n", count);
| ~~~^ ~~~~~
| | |
| | uint64_t {aka long unsigned int}
| long long unsigned int
| %lu
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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define MAX_MATRICES (1ULL << (SIZE * SIZE)) bool is_unholy(unsigned long long matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if ((matrix >> (i * SIZE + j)) & 1) { bool has_adjacent = false; // Check up if (i > 0 && ((matrix >> ((i-1) * SIZE + j)) & 1)) has_adjacent = true; // Check down if (i < SIZE-1 && ((matrix >> ((i+1) * SIZE + j)) & 1)) has_adjacent = true; // Check left if (j > 0 && ((matrix >> (i * SIZE + j-1)) & 1)) has_adjacent = true; // Check right if (j < SIZE-1 && ((matrix >> (i * SIZE + j+1)) & 1)) has_adjacent = true; if (!has_adjacent) return false; } } } return true; } int main() { unsigned long long count = 0; for (unsigned long long matrix = 0; matrix < MAX_MATRICES; matrix++) { if (is_unholy(matrix)) { count++; } } printf("Total number of unholy 8x8 matrices: %llu\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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define MAX_MATRICES (1ULL << (SIZE * SIZE)) bool is_unholy(unsigned long long matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if ((matrix >> (i * SIZE + j)) & 1) { bool has_adjacent = false; // Check up if (i > 0 && ((matrix >> ((i-1) * SIZE + j)) & 1)) has_adjacent = true; // Check down if (i < SIZE-1 && ((matrix >> ((i+1) * SIZE + j)) & 1)) has_adjacent = true; // Check left if (j > 0 && ((matrix >> (i * SIZE + j-1)) & 1)) has_adjacent = true; // Check right if (j < SIZE-1 && ((matrix >> (i * SIZE + j+1)) & 1)) has_adjacent = true; if (!has_adjacent) return false; } } } return true; } int main() { unsigned long long count = 0; for (unsigned long long matrix = 0; matrix < MAX_MATRICES; matrix++) { if (is_unholy(matrix)) { count++; } } printf("Total number of unholy 8x8 matrices: %llu\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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define MAX_MATRICES (1ULL << (SIZE * SIZE)) bool is_unholy(unsigned long long matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if ((matrix >> (i * SIZE + j)) & 1) { bool has_adjacent = false; // Check up if (i > 0 && ((matrix >> ((i-1) * SIZE + j)) & 1)) has_adjacent = true; // Check down if (i < SIZE-1 && ((matrix >> ((i+1) * SIZE + j)) & 1)) has_adjacent = true; // Check left if (j > 0 && ((matrix >> (i * SIZE + j-1)) & 1)) has_adjacent = true; // Check right if (j < SIZE-1 && ((matrix >> (i * SIZE + j+1)) & 1)) has_adjacent = true; if (!has_adjacent) return false; } } } return true; } int main() { unsigned long long count = 0; for (unsigned long long matrix = 0; matrix < MAX_MATRICES; matrix++) { if (is_unholy(matrix)) { count++; } } printf("Total number of unholy 8x8 matrices: %llu\n", count); return 0; } |
Total number of unholy 8x8 matrices: 0
main.c: In function 'main':
main.c:6:28: warning: left shift count >= width of type [-Wshift-count-overflow]
6 | #define MAX_MATRICES (1ULL << (SIZE * SIZE))
| ^~
main.c:38:50: note: in expansion of macro 'MAX_MATRICES'
38 | for (unsigned long long matrix = 0; matrix < MAX_MATRICES; matrix++) {
| ^~~~~~~~~~~~
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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if ((matrix >> (i * SIZE + j)) & 1) { bool has_adjacent = false; // Check top if (i > 0 && (matrix >> ((i-1) * SIZE + j)) & 1) has_adjacent = true; // Check bottom if (i < SIZE-1 && (matrix >> ((i+1) * SIZE + j)) & 1) has_adjacent = true; // Check left if (j > 0 && (matrix >> (i * SIZE + j-1)) & 1) has_adjacent = true; // Check right if (j < SIZE-1 && (matrix >> (i * SIZE + j+1)) & 1) has_adjacent = true; if (!has_adjacent) return false; } } } return true; } int main() { unsigned long long count = 0; unsigned long long max = 1ULL << TOTAL_CELLS; for (unsigned long long i = 0; i < max; i++) { if (is_unholy(i)) { count++; } } printf("Total number of unholy 8x8 matrices: %llu\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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if ((matrix >> (i * SIZE + j)) & 1) { bool has_adjacent = false; // Check top if (i > 0 && (matrix >> ((i-1) * SIZE + j)) & 1) has_adjacent = true; // Check bottom if (i < SIZE-1 && (matrix >> ((i+1) * SIZE + j)) & 1) has_adjacent = true; // Check left if (j > 0 && (matrix >> (i * SIZE + j-1)) & 1) has_adjacent = true; // Check right if (j < SIZE-1 && (matrix >> (i * SIZE + j+1)) & 1) has_adjacent = true; if (!has_adjacent) return false; } } } return true; } int main() { unsigned long long count = 0; unsigned long long max = 1ULL << TOTAL_CELLS; for (unsigned long long i = 0; i < max; i++) { if (is_unholy(i)) { count++; } } printf("Total number of unholy 8x8 matrices: %llu\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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { if ((matrix >> (i * SIZE + j)) & 1) { bool has_adjacent = false; // Check top if (i > 0 && (matrix >> ((i-1) * SIZE + j)) & 1) has_adjacent = true; // Check bottom if (i < SIZE-1 && (matrix >> ((i+1) * SIZE + j)) & 1) has_adjacent = true; // Check left if (j > 0 && (matrix >> (i * SIZE + j-1)) & 1) has_adjacent = true; // Check right if (j < SIZE-1 && (matrix >> (i * SIZE + j+1)) & 1) has_adjacent = true; if (!has_adjacent) return false; } } } return true; } int main() { unsigned long long count = 0; unsigned long long max = 1ULL << TOTAL_CELLS; for (unsigned long long i = 0; i < max; i++) { if (is_unholy(i)) { count++; } } printf("Total number of unholy 8x8 matrices: %llu\n", count); return 0; } |
Total number of unholy 8x8 matrices: 0
main.c: In function 'main':
main.c:37:35: warning: left shift count >= width of type [-Wshift-count-overflow]
37 | unsigned long long max = 1ULL << TOTAL_CELLS;
| ^~
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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix >> (row * SIZE + col)) & 1) { bool isolated = true; // Check up if (row > 0 && (matrix >> ((row - 1) * SIZE + col)) & 1) isolated = false; // Check down if (row < SIZE - 1 && (matrix >> ((row + 1) * SIZE + col)) & 1) isolated = false; // Check left if (col > 0 && (matrix >> (row * SIZE + col - 1)) & 1) isolated = false; // Check right if (col < SIZE - 1 && (matrix >> (row * SIZE + col + 1)) & 1) isolated = false; if (isolated) return false; } } } return true; } unsigned long long count_unholy_matrices() { unsigned long long count = 0; unsigned long long max_value = 1ULL << TOTAL_CELLS; for (unsigned long long matrix = 0; matrix < max_value; matrix++) { if (is_unholy(matrix)) { count++; } } return count; } int main() { unsigned long long result = count_unholy_matrices(); printf("Total number of unholy 8x8 matrices: %llu\n", result); 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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix >> (row * SIZE + col)) & 1) { bool isolated = true; // Check up if (row > 0 && (matrix >> ((row - 1) * SIZE + col)) & 1) isolated = false; // Check down if (row < SIZE - 1 && (matrix >> ((row + 1) * SIZE + col)) & 1) isolated = false; // Check left if (col > 0 && (matrix >> (row * SIZE + col - 1)) & 1) isolated = false; // Check right if (col < SIZE - 1 && (matrix >> (row * SIZE + col + 1)) & 1) isolated = false; if (isolated) return false; } } } return true; } unsigned long long count_unholy_matrices() { unsigned long long count = 0; unsigned long long max_value = 1ULL << TOTAL_CELLS; for (unsigned long long matrix = 0; matrix < max_value; matrix++) { if (is_unholy(matrix)) { count++; } } return count; } int main() { unsigned long long result = count_unholy_matrices(); printf("Total number of unholy 8x8 matrices: %llu\n", result); 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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix >> (row * SIZE + col)) & 1) { bool isolated = true; // Check up if (row > 0 && (matrix >> ((row - 1) * SIZE + col)) & 1) isolated = false; // Check down if (row < SIZE - 1 && (matrix >> ((row + 1) * SIZE + col)) & 1) isolated = false; // Check left if (col > 0 && (matrix >> (row * SIZE + col - 1)) & 1) isolated = false; // Check right if (col < SIZE - 1 && (matrix >> (row * SIZE + col + 1)) & 1) isolated = false; if (isolated) return false; } } } return true; } unsigned long long count_unholy_matrices() { unsigned long long count = 0; unsigned long long max_value = 1ULL << TOTAL_CELLS; for (unsigned long long matrix = 0; matrix < max_value; matrix++) { if (is_unholy(matrix)) { count++; } } return count; } int main() { unsigned long long result = count_unholy_matrices(); printf("Total number of unholy 8x8 matrices: %llu\n", result); return 0; } |
Total number of unholy 8x8 matrices: 0
main.c: In function 'count_unholy_matrices':
main.c:37:41: warning: left shift count >= width of type [-Wshift-count-overflow]
37 | unsigned long long max_value = 1ULL << TOTAL_CELLS;
| ^~
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 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix >> (row * SIZE + col)) & 1) { bool isolated = true; // Check up if (row > 0 && (matrix >> ((row - 1) * SIZE + col)) & 1) isolated = false; // Check down if (row < SIZE - 1 && (matrix >> ((row + 1) * SIZE + col)) & 1) isolated = false; // Check left if (col > 0 && (matrix >> (row * SIZE + col - 1)) & 1) isolated = false; // Check right if (col < SIZE - 1 && (matrix >> (row * SIZE + col + 1)) & 1) isolated = false; if (isolated) return false; } } } return true; } void count_unholy_matrices(unsigned long long matrix, int index, unsigned long long* count) { if (index == TOTAL_CELLS) { if (is_unholy(matrix)) { (*count)++; } return; } // Try 0 count_unholy_matrices(matrix, index + 1, count); // Try 1 count_unholy_matrices(matrix | (1ULL << index), index + 1, count); } int main() { unsigned long long count = 0; count_unholy_matrices(0, 0, &count); printf("Total number of unholy 8x8 matrices: %llu\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 56 57 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix >> (row * SIZE + col)) & 1) { bool isolated = true; // Check up if (row > 0 && (matrix >> ((row - 1) * SIZE + col)) & 1) isolated = false; // Check down if (row < SIZE - 1 && (matrix >> ((row + 1) * SIZE + col)) & 1) isolated = false; // Check left if (col > 0 && (matrix >> (row * SIZE + col - 1)) & 1) isolated = false; // Check right if (col < SIZE - 1 && (matrix >> (row * SIZE + col + 1)) & 1) isolated = false; if (isolated) return false; } } } return true; } void count_unholy_matrices(unsigned long long matrix, int index, unsigned long long* count) { if (index == TOTAL_CELLS) { if (is_unholy(matrix)) { (*count)++; } return; } // Try 0 count_unholy_matrices(matrix, index + 1, count); // Try 1 count_unholy_matrices(matrix | (1ULL << index), index + 1, count); } int main() { unsigned long long count = 0; count_unholy_matrices(0, 0, &count); printf("Total number of unholy 8x8 matrices: %llu\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 56 57 | #include <stdio.h> #include <stdbool.h> #define SIZE 8 #define TOTAL_CELLS (SIZE * SIZE) bool is_unholy(unsigned long long matrix) { for (int row = 0; row < SIZE; row++) { for (int col = 0; col < SIZE; col++) { if ((matrix >> (row * SIZE + col)) & 1) { bool isolated = true; // Check up if (row > 0 && (matrix >> ((row - 1) * SIZE + col)) & 1) isolated = false; // Check down if (row < SIZE - 1 && (matrix >> ((row + 1) * SIZE + col)) & 1) isolated = false; // Check left if (col > 0 && (matrix >> (row * SIZE + col - 1)) & 1) isolated = false; // Check right if (col < SIZE - 1 && (matrix >> (row * SIZE + col + 1)) & 1) isolated = false; if (isolated) return false; } } } return true; } void count_unholy_matrices(unsigned long long matrix, int index, unsigned long long* count) { if (index == TOTAL_CELLS) { if (is_unholy(matrix)) { (*count)++; } return; } // Try 0 count_unholy_matrices(matrix, index + 1, count); // Try 1 count_unholy_matrices(matrix | (1ULL << index), index + 1, count); } int main() { unsigned long long count = 0; count_unholy_matrices(0, 0, &count); printf("Total number of unholy 8x8 matrices: %llu\n", count); return 0; } |
Timeout: function took too long to complete
Testing if the previous output contains the string 1121231537486377866
: False