KiK0S

Untitled

Mar 13th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1.  
  2. def check(my_list):
  3.     return my_list[0] == my_list[1]
  4.  
  5. total = 0
  6. correct = 0
  7.  
  8. def generate(my_list, a, b, c):
  9.     if a == 0 and b == 0 and c == 0:
  10.         global total, correct
  11.         total += 1
  12.         if check(my_list):
  13.             correct += 1
  14.         return
  15.     if a > 0:
  16.         generate(my_list + [0], a - 1, b, c)
  17.     if b > 0:
  18.         generate(my_list + [1], a, b - 1, c)
  19.     if c > 0:
  20.         generate(my_list + [2], a, b, c - 1)
  21.  
  22. generate([], 2, 2, 2)
  23. print('total =', total)
  24. print('correct =', correct)
  25. print('accuracy =', correct / total)
Advertisement
Add Comment
Please, Sign In to add comment