summaryrefslogtreecommitdiff
path: root/4a.c
diff options
context:
space:
mode:
authorian.cowburn <ian.cowburn@ianc-work-macbook.local>2021-12-09 15:18:28 +0000
committerian.cowburn <ian.cowburn@ianc-work-macbook.local>2021-12-09 15:18:28 +0000
commit0d1e83e9ec2d28b792e912fa21e1aa2815303874 (patch)
tree64039bb0aea33aaa1969a0650423a62acbd6d165 /4a.c
parent8833b7a5b246cad02e253838c07ba1689834e523 (diff)
Completed part 2 of number 4.
Diffstat (limited to '4a.c')
-rw-r--r--4a.c64
1 files changed, 44 insertions, 20 deletions
diff --git a/4a.c b/4a.c
index 4851248..0c2a3e5 100644
--- a/4a.c
+++ b/4a.c
@@ -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];
+ }
}
}