1. # -*- coding: utf-8 -*-
  2.  
  3. #stones = [ '●', '○' ]
  4. stones = [ 'o', 'x' ]
  5. patterns = [ '00', '10', '01', '11' ]
  6.  
  7. def test(n, a, b, c, d):
  8. print('=' * 50)
  9. print(" Stones: {}".format(n))
  10. print(" - oo: {}, ox: {},".format(a, b))
  11. print(" - xo: {}, xx: {}".format(c, d))
  12. print('=' * 50)
  13. lines = [ "{{:0{}b}}".format(n).format(x) for x in range(2 ** n) ]
  14. count = 0
  15. for x in lines:
  16. matched = [ 0 ] * len(patterns)
  17. for y in range(0, len(x)-1):
  18. for i, z in enumerate(patterns):
  19. if z == x[y:y+2]:
  20. matched[i] += 1
  21. if matched == [ a, b, c, d ]:
  22. count += 1
  23. print(' ', x.replace('0', stones[0]).replace('1', stones[1]))
  24. print('=' * 50)
  25. print(" Result: {}".format(count))
  26. print('=' * 50)
  27. print()
  28.  
  29. test(6, 2, 1, 1, 1)
  30. test(10, 4, 2, 2, 1)


는 내가 계산 안함


http://ideone.com/lXhaox