#!/bin/python3
import numpy as np
uniform = np.random.random
from time import sleep

p = 0.6
q = 0.2

N = 10000
visits = [0, 0]
cur = 0
for i in range(N):
    if cur == 0:
        if uniform() < p:
            cur = 1
            visits[1] += 1
        else:
            visits[0] += 1
    elif cur == 1:
        if uniform() < q:
            cur = 0
            visits[0] += 1
        else:
            visits[1] += 1
    #print(f"From total {N} visits:")
    #print(f"  {visits[0]} visits to 0")
    #print(f"  {visits[1]} visits to 1")
    #sleep(15/1000)
n = sum(visits)
print(f"{n}/{N}")
print(f"  {visits[0]/n:.4f} of the time at 0 {visits[0]} total")
print(f"  {visits[1]/n:.4f} of the time at 1 {visits[1]} total")
