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.
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 | #include <stdio.h> int isUnholy(int matrix[8][8]) { for(int i = 0; i < 8; i++) { for(int j = 0; j < 8; j++) { if(matrix[i][j] == 1) { if((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int countUnholyMatrices() { int count = 0; int matrix[8][8]; for(int i = 0; i < 256; i++) { int temp = i; for(int j = 0; j < 8; j++) { for(int k = 0; k < 8; k++) { matrix[j][k] = temp % 2; temp /= 2; } } if(isUnholy(matrix)) { count++; } } return count; } int main() { int count = countUnholyMatrices(); 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 | #include <stdio.h> int isUnholy(int matrix[8][8]) { for(int i = 0; i < 8; i++) { for(int j = 0; j < 8; j++) { if(matrix[i][j] == 1) { if((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int countUnholyMatrices() { int count = 0; int matrix[8][8]; for(int i = 0; i < 256; i++) { int temp = i; for(int j = 0; j < 8; j++) { for(int k = 0; k < 8; k++) { matrix[j][k] = temp % 2; temp /= 2; } } if(isUnholy(matrix)) { count++; } } return count; } int main() { int count = countUnholyMatrices(); 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 | #include <stdio.h> int isUnholy(int matrix[8][8]) { for(int i = 0; i < 8; i++) { for(int j = 0; j < 8; j++) { if(matrix[i][j] == 1) { if((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int countUnholyMatrices() { int count = 0; int matrix[8][8]; for(int i = 0; i < 256; i++) { int temp = i; for(int j = 0; j < 8; j++) { for(int k = 0; k < 8; k++) { matrix[j][k] = temp % 2; temp /= 2; } } if(isUnholy(matrix)) { count++; } } return count; } int main() { int count = countUnholyMatrices(); printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
Total number of unholy 8x8 matrices: 55
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 is 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 | #include <stdio.h> int isUnholy(int mat[8][8]) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (mat[i][j] == 1) { if ((i > 0 && mat[i-1][j] == 1) || (i < 7 && mat[i+1][j] == 1) || (j > 0 && mat[i][j-1] == 1) || (j < 7 && mat[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int count = 0; int mat[8][8] = {0}; for (int i = 0; i < 256; i++) { int num = i; for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { mat[j][k] = num % 2; num = num / 2; } } if (isUnholy(mat)) { 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 | #include <stdio.h> int isUnholy(int mat[8][8]) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (mat[i][j] == 1) { if ((i > 0 && mat[i-1][j] == 1) || (i < 7 && mat[i+1][j] == 1) || (j > 0 && mat[i][j-1] == 1) || (j < 7 && mat[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int count = 0; int mat[8][8] = {0}; for (int i = 0; i < 256; i++) { int num = i; for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { mat[j][k] = num % 2; num = num / 2; } } if (isUnholy(mat)) { 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 | #include <stdio.h> int isUnholy(int mat[8][8]) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (mat[i][j] == 1) { if ((i > 0 && mat[i-1][j] == 1) || (i < 7 && mat[i+1][j] == 1) || (j > 0 && mat[i][j-1] == 1) || (j < 7 && mat[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int count = 0; int mat[8][8] = {0}; for (int i = 0; i < 256; i++) { int num = i; for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { mat[j][k] = num % 2; num = num / 2; } } if (isUnholy(mat)) { count++; } } printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
Total number of unholy 8x8 matrices: 55
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.
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 | #include <stdio.h> int is_unholy(int matrix[8][8]) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int count = 0; for (int i = 0; i < 256; i++) { int matrix[8][8]; int num = i; for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { matrix[j][k] = num % 2; num /= 2; } } if (is_unholy(matrix)) { 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 | #include <stdio.h> int is_unholy(int matrix[8][8]) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int count = 0; for (int i = 0; i < 256; i++) { int matrix[8][8]; int num = i; for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { matrix[j][k] = num % 2; num /= 2; } } if (is_unholy(matrix)) { 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 | #include <stdio.h> int is_unholy(int matrix[8][8]) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int count = 0; for (int i = 0; i < 256; i++) { int matrix[8][8]; int num = i; for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { matrix[j][k] = num % 2; num /= 2; } } if (is_unholy(matrix)) { count++; } } printf("Total number of unholy 8x8 matrices: %d\n", count); return 0; } |
Total number of unholy 8x8 matrices: 55
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.
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> int is_unholy(int matrix[8][8]) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int total_unholy = 0; int matrix[8][8]; int i, j; // Generate all possible binary 8x8 matrices for (i = 0; i < 256; i++) { for (j = 0; j < 8; j++) { matrix[j][0] = (i >> j) & 1; matrix[j][1] = (i >> (j+8)) & 1; matrix[j][2] = (i >> (j+16)) & 1; matrix[j][3] = (i >> (j+24)) & 1; matrix[j][4] = (i >> (j+32)) & 1; matrix[j][5] = (i >> (j+40)) & 1; matrix[j][6] = (i >> (j+48)) & 1; matrix[j][7] = (i >> (j+56)) & 1; } if (is_unholy(matrix)) { total_unholy++; } } printf("Total number of unholy 8x8 matrices: %d\n", total_unholy); 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> int is_unholy(int matrix[8][8]) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int total_unholy = 0; int matrix[8][8]; int i, j; // Generate all possible binary 8x8 matrices for (i = 0; i < 256; i++) { for (j = 0; j < 8; j++) { matrix[j][0] = (i >> j) & 1; matrix[j][1] = (i >> (j+8)) & 1; matrix[j][2] = (i >> (j+16)) & 1; matrix[j][3] = (i >> (j+24)) & 1; matrix[j][4] = (i >> (j+32)) & 1; matrix[j][5] = (i >> (j+40)) & 1; matrix[j][6] = (i >> (j+48)) & 1; matrix[j][7] = (i >> (j+56)) & 1; } if (is_unholy(matrix)) { total_unholy++; } } printf("Total number of unholy 8x8 matrices: %d\n", total_unholy); 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> int is_unholy(int matrix[8][8]) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i > 0 && matrix[i-1][j] == 1) || (i < 7 && matrix[i+1][j] == 1) || (j > 0 && matrix[i][j-1] == 1) || (j < 7 && matrix[i][j+1] == 1)) { return 0; } } } } return 1; } int main() { int total_unholy = 0; int matrix[8][8]; int i, j; // Generate all possible binary 8x8 matrices for (i = 0; i < 256; i++) { for (j = 0; j < 8; j++) { matrix[j][0] = (i >> j) & 1; matrix[j][1] = (i >> (j+8)) & 1; matrix[j][2] = (i >> (j+16)) & 1; matrix[j][3] = (i >> (j+24)) & 1; matrix[j][4] = (i >> (j+32)) & 1; matrix[j][5] = (i >> (j+40)) & 1; matrix[j][6] = (i >> (j+48)) & 1; matrix[j][7] = (i >> (j+56)) & 1; } if (is_unholy(matrix)) { total_unholy++; } } printf("Total number of unholy 8x8 matrices: %d\n", total_unholy); return 0; } |
Total number of unholy 8x8 matrices: 55
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.
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 | #include <stdio.h> int isUnholy(int matrix[8][8]) { int i, j; int isolatedCount = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i == 0 || matrix[i-1][j] == 0) && (i == 7 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == 7 || matrix[i][j+1] == 0)) { isolatedCount++; } } } } if (isolatedCount == 0) { return 1; } else { return 0; } } int main() { int totalUnholyMatrices = 0; int matrix[8][8] = { {1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 1} }; if (isUnholy(matrix)) { totalUnholyMatrices++; } printf("Total number of unholy matrices: %d\n", totalUnholyMatrices); 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 | #include <stdio.h> int isUnholy(int matrix[8][8]) { int i, j; int isolatedCount = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i == 0 || matrix[i-1][j] == 0) && (i == 7 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == 7 || matrix[i][j+1] == 0)) { isolatedCount++; } } } } if (isolatedCount == 0) { return 1; } else { return 0; } } int main() { int totalUnholyMatrices = 0; int matrix[8][8] = { {1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 1} }; if (isUnholy(matrix)) { totalUnholyMatrices++; } printf("Total number of unholy matrices: %d\n", totalUnholyMatrices); 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 | #include <stdio.h> int isUnholy(int matrix[8][8]) { int i, j; int isolatedCount = 0; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (matrix[i][j] == 1) { if ((i == 0 || matrix[i-1][j] == 0) && (i == 7 || matrix[i+1][j] == 0) && (j == 0 || matrix[i][j-1] == 0) && (j == 7 || matrix[i][j+1] == 0)) { isolatedCount++; } } } } if (isolatedCount == 0) { return 1; } else { return 0; } } int main() { int totalUnholyMatrices = 0; int matrix[8][8] = { {1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 1} }; if (isUnholy(matrix)) { totalUnholyMatrices++; } printf("Total number of unholy matrices: %d\n", totalUnholyMatrices); return 0; } |
Total number of unholy matrices: 0
Testing if the previous output contains the string 1121231537486377866
: False