Skip to content

Instantly share code, notes, and snippets.

@ikhlestov
Created September 20, 2017 00:16
Show Gist options
  • Save ikhlestov/2e7738acf5c09f1f5f0b024dee559b47 to your computer and use it in GitHub Desktop.
Save ikhlestov/2e7738acf5c09f1f5f0b024dee559b47 to your computer and use it in GitHub Desktop.
probability_theory
from itertools import combinations, permutations
import numpy as np
def check_line(line):
start = False
for i in line:
if i != 0 and not start:
start = True
counter = 0
elif i == 0 and start:
counter += 1
elif i != 0 and start:
if counter <= 1:
return 1
else:
return 0
def check_n(n):
res = list(set(list(permutations('12'.zfill(n), n))))
res = [[int(i) for i in r] for r in res]
checked = [check_line(r) for r in res]
ok_res = sum(checked)
print('%d/%d,' % (ok_res, len(res)), "divided:%d/%d" % (ok_res//2, len(res)//2))
for i in range(2, 11):
check_n(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment