Created
December 3, 2023 15:59
-
-
Save dmd/d3b632655690605a09cb634273974968 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
from math import comb | |
import sys | |
def probability_of_eights(sequence_length, total_string_length=64): | |
digits = 16 | |
def p(k): | |
placements = comb(total_string_length - k * (sequence_length - 1), k) | |
combinations = digits ** (total_string_length - k * sequence_length) | |
total_ways = digits ** total_string_length | |
return placements * combinations / total_ways | |
probability = 0 | |
sign = 1 | |
for k in range(1, total_string_length // sequence_length + 1): | |
probability += sign * p(k) | |
sign *= -1 | |
return probability | |
sequence_length = int(sys.argv[1]) | |
print(probability_of_eights(sequence_length)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment