Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Project: Peter's Files
Views: 3893
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu1804
Kernel: Python 3 (system-wide)
import random as rd from numba import njit
@njit def rand_letter(): return 'abcdefghijklmnopqrstuvwxyz'[rd.randint(0,25)] def test(): lastFive = ["z","z","z","z","z"] numEarth = 0 numHeart = 0 while numEarth == 0 and numHeart == 0: word = "".join(lastFive) if word == "heart": numHeart += 1 if word == "earth": numEarth += 1 lastFive = lastFive[1:] + [rand_letter()] return numEarth
test()
0
numEarth = 0 r = 100 for i in range(r): numEarth += test() print(numEarth/r)
Earth = 4 + 12 + 41 Heart = 6 + 8 + 59