diff options
author | ian.cowburn <ian.cowburn@ianc-work-macbook.local> | 2021-12-09 15:18:28 +0000 |
---|---|---|
committer | ian.cowburn <ian.cowburn@ianc-work-macbook.local> | 2021-12-09 15:18:28 +0000 |
commit | 0d1e83e9ec2d28b792e912fa21e1aa2815303874 (patch) | |
tree | 64039bb0aea33aaa1969a0650423a62acbd6d165 | |
parent | 8833b7a5b246cad02e253838c07ba1689834e523 (diff) |
Completed part 2 of number 4.
-rw-r--r-- | 4a.c | 64 | ||||
-rw-r--r-- | data.4a | 19 |
2 files changed, 63 insertions, 20 deletions
@@ -31,7 +31,9 @@ int main(void) int x = 0; int y = 0; int i = 0; - int winner_board = -1; + int winner[MAX_BOARDS] = {0}; + int winner_count = 1; + int last_board = 0; int winner_num = -1; int sum = 0; @@ -68,7 +70,7 @@ int main(void) board_count++; } - for(i = 0; i < num_count && winner_board == -1; i++) + for(i = 0; i < num_count && winner_count != board_count + 1; i++) { for(f = 0; f < board_count; f++) { @@ -78,50 +80,72 @@ int main(void) { if (board[f][y][x] == num[i]) { - board[f][y][x] = 0; + board[f][y][x] = -1; } } } } - for(f = 0; f < board_count && winner_board == -1; f++) + for(f = 0; f < board_count; f++) { for(y = 0; y < 5; y++) { - if (board[f][y][0] == 0 && - board[f][y][1] == 0 && - board[f][y][2] == 0 && - board[f][y][3] == 0 && - board[f][y][4] == 0) + if (board[f][y][0] == -1 && + board[f][y][1] == -1 && + board[f][y][2] == -1 && + board[f][y][3] == -1 && + board[f][y][4] == -1) { - winner_board = f; - winner_num = num[i]; + if (winner[f] == 0) + { + winner[f] = winner_count++; + } } } for(x = 0; x < 5; x++) { - if (board[f][0][x] == 0 && - board[f][1][x] == 0 && - board[f][2][x] == 0 && - board[f][3][x] == 0 && - board[f][4][x] == 0) + if (board[f][0][x] == -1 && + board[f][1][x] == -1 && + board[f][2][x] == -1 && + board[f][3][x] == -1 && + board[f][4][x] == -1) { - winner_board = f; - winner_num = num[i]; + if (winner[f] == 0) + { + winner[f] = winner_count++; + } } } } + + winner_num = num[i]; } - printf("winner_board = %d\n", winner_board); + printf("i/num_count = %d/%d\n", i, num_count); + + for(f = 0; f < board_count; f++) + { + if (winner[f] == board_count) + { + last_board = f; + } + } + + printf("board_count = %d\n", board_count); printf("winner_num = %d\n", winner_num); + printf("last_board = %d\n", f); + + sum = 0; for(y = 0; y < 5; y++) { for(x = 0; x < 5; x++) { - sum += board[winner_board][y][x]; + if (board[last_board][y][x] != -1) + { + sum += board[last_board][y][x]; + } } } @@ -0,0 +1,19 @@ +7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 + +22 13 17 11 0 + 8 2 23 4 24 +21 9 14 16 7 + 6 10 3 18 5 + 1 12 20 15 19 + + 3 15 0 2 22 + 9 18 13 17 5 +19 8 7 25 23 +20 11 10 24 4 +14 21 16 12 6 + +14 21 17 24 4 +10 16 15 9 19 +18 8 23 26 20 +22 11 13 6 5 + 2 0 12 3 7 |