Created
November 2, 2025 00:59
-
-
Save rweeks/69af90906ac499ba4eb8ef90e3e0a51d to your computer and use it in GitHub Desktop.
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
| # inspired by https://bsky.app/profile/fritzby.bsky.social/post/3m4k67fsgi22b | |
| # and https://bsky.app/profile/radishharmers.bsky.social/post/3m4mah76u4s27 | |
| from random import random | |
| def gamble(wallet, bet_amount, walk_away_at, win_prob): | |
| while 0 < wallet < walk_away_at: | |
| wallet += bet_amount if random() < win_prob else -1 * bet_amount | |
| return 1 if wallet > 0 else 0 | |
| num_runs = 100000 | |
| results = [ | |
| gamble(100, 10, 110, 0.4) for _ in range(num_runs) | |
| ] | |
| print(f"Success %: {100 * sum(results) / num_runs}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment