Created
March 27, 2023 15:25
-
-
Save idontwantcookies/1a5612e741f6b5dc2e414249de9fc6fd to your computer and use it in GitHub Desktop.
This file contains 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
TOTAL_TILES = 18 * 34 | |
AVERAGE_TIME_PER_ATTEMPT_IN_SECONDS = 40 | |
ATTEMPTS_PER_TILE = 2 | |
def single_tile(tiles_left: int): | |
wrong_tile = (tiles_left - 1) / tiles_left | |
correct_tile_bad_luck = 1 / (tiles_left - 1) * 1 / 4 | |
return wrong_tile + correct_tile_bad_luck | |
def found_after_n_tiles(n: int,log=False): | |
not_found = 1 | |
for i in range(n): | |
not_found *= single_tile(TOTAL_TILES - i) | |
found = 1 - not_found | |
if log: print(TOTAL_TILES - i, found) | |
return found | |
def stop_after_percentage(percentage: float = 0.50, log=False): | |
not_found = 1 | |
for i in range(TOTAL_TILES): | |
not_found *= single_tile(TOTAL_TILES - i) | |
found = 1 - not_found | |
print(TOTAL_TILES - i, found) | |
if log: print(TOTAL_TILES - i, found) | |
if found >= percentage: | |
return i, found | |
def elapsed_time(tiles: int): | |
time_in_seconds = tiles * AVERAGE_TIME_PER_ATTEMPT_IN_SECONDS * ATTEMPTS_PER_TILE | |
seconds = int(time_in_seconds % 60) | |
minutes = time_in_seconds // 60 | |
hours = minutes // 60 | |
minutes = minutes % 60 | |
return hours, minutes, seconds | |
def pretty_print(tiles, percentage): | |
time_in_seconds = tiles * AVERAGE_TIME_PER_ATTEMPT_IN_SECONDS * ATTEMPTS_PER_TILE | |
hours, minutes, seconds = elapsed_time(tiles) | |
print(f"It takes {tiles} tiles, or " f"{hours}h{minutes}m{seconds}s, for you to have a " \ | |
f"{percentage * 100 :.2f}% chance to find it.") | |
def main(): | |
average_tiles_necessary, percentage = stop_after_percentage(0.50) | |
pretty_print(average_tiles_necessary, percentage) | |
halfway_chance = found_after_n_tiles(TOTAL_TILES // 2) | |
pretty_print(TOTAL_TILES // 2, halfway_chance) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment