#! /usr/bin/env python3 # def pi_digits_test ( ): # Reference: # # John D Cook, # The coupon collector problem and pi, # Posted 12 March 2023. # https://www.johndcook.com/blog/2023/03/12/coupon-collector/ # from mpmath import mp from sympy import EulerGamma import numpy as np print ( '' ) print ( 'pi_digits_test():' ) print ( ' How many digits of pi must we scan before seeing all 10 digits?' ) print ( ' Before seeing all 100 pairs, or 1000 triples of digits?' ) print ( '' ) mp.dps = 30_000 s = str(mp.pi)[2:] for k in [ 1, 2, 3 ]: n = 10**k # tuples = [ s[i:i+k] for i in range(0, len(s), k) ] tuples = [ s[i:i+k] for i in range(0, len(s) - k) ] d = dict() i = 0 while len ( d ) < n: d[tuples[i]] = 1 i = i + 1 print ( i, n * harmonic ( n ), n * np.log ( n + float ( EulerGamma ) ) ) # # Terminate. # print ( '' ) print ( 'pi_digits_test():' ) print ( ' Normal end of execution.' ) return def harmonic ( n ): #*****************************************************************************80 # ## harmonic() evaluates a Harmonic sequence number. # # Discussion: # # H(N) = Sum ( 1 <= I <= N ) 1 / I # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 May 2022 # # Author: # # John Burkardt # # Input: # # integer N: the index of the harmonic number. # # Output: # # real VALUE, the value of the harmonic number. # value = 0.0 for i in range ( 1, n + 1 ): value = value + 1.0 / float ( i ) return value if ( __name__ == "__main__" ): pi_digits_test ( )