Last active
January 7, 2024 11:59
-
-
Save Frank-Buss/fd2442a478f6662eefba3d339afd716e to your computer and use it in GitHub Desktop.
How likely is it that 5 players are on the same field in Monopoly? Ignoring go to jail, about 1 in 2.5 million dice rolls. Discussion, mathematical results, and improvements here: https://twitter.com/eevblog/status/1743948240616411247
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define PLAYERS 5 | |
uint8_t pos[PLAYERS]; | |
int random2to12() { | |
return (rand() % 11) + 2; | |
} | |
int main(void) { | |
uint8_t i; | |
for (i = 0; i < PLAYERS; i++) { | |
pos[i] = i; | |
} | |
uint64_t roll = 0; | |
int match = 0; | |
int player = 0; | |
while (1) { | |
roll++; | |
pos[player] += random2to12(); | |
pos[player] %= 40; | |
player++; | |
player %= PLAYERS; | |
int p0 = pos[0]; | |
for (int i = 1; i < PLAYERS; i++) { | |
if (pos[i] != p0) { | |
break; | |
} | |
if (i == PLAYERS - 1) { | |
match++; | |
printf("Match %d, rolls: %llu, 1 in %i rolls\n", match, roll, roll / match); | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment