1
0
Fork 0

Problem 84 - The problem was in the double rolls! You go to jail only if you roll three CONSECUTIVE doubles.

Also printing the top three squares was setting entries to 0 prematurely.
This commit is contained in:
Jonathan Chan 2018-08-24 22:18:21 -07:00
parent c50425679e
commit e590e70f36
2 changed files with 8 additions and 6 deletions

BIN
84

Binary file not shown.

14
84.c
View File

@ -48,14 +48,16 @@ int main(void) {
srand(time(NULL));
for (int i = 0; i < rolls; i++) {
int die1 = rand() / ((double) RAND_MAX + 1) * 6 + 1;
int die2 = rand() / ((double) RAND_MAX + 1) * 6 + 1;
int die1 = (rand() % 4) + 1;
int die2 = (rand() % 4) + 1;
position = (position + die1 + die2) % 40;
if (die1 == die2) {
doubleRolls = (doubleRolls + 1) % 3;
if (doubleRolls == 0) {
if (++doubleRolls == 3) {
doubleRolls = 0;
position = JAIL;
}
} else {
doubleRolls = 0;
}
if (position == G2J) {
position = JAIL;
@ -75,9 +77,9 @@ int main(void) {
if (freq[j] > topValue) {
topSquare = j;
topValue = freq[j];
freq[j] = 0;
}
}
printf("#%d: %d @ %f%%\n", i, topSquare, (float) topValue / rolls * 100);
freq[topSquare] = 0;
printf("#%d: %02d @ %f%%\n", i, topSquare, (double) topValue / rolls * 100);
}
}