# Untitled

a guest
Sep 11th, 2021
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. NM = [0, 0]
2. count = 0
3. for i in input().split():
4. if count == 0:
5. NM[0] = int(i)
6. count += 1
7. else:
8. NM[1] = int(i)
9. l = [0 for _ in range(31)]
10. r = 100000
11. def pattern(t):
12. p1 = list("WBWBWBWB")
13. p2 = list("BWBWBWBW")
14. r1 = 0
15. r2 = 0
16. for i in range(2):
17. for j in range(0, 7, 2):
18. if i == 0:
19. for k in range(8):
20. if p1[k] != list(t[j])[k]:
21. r1 += 1
22. else:
23. for k in range(8):
24. if p2[k] != list(t[j])[k]:
25. r2 += 1
26. for j in range(1, 8, 2):
27. if i == 0:
28. for k in range(8):
29. if p2[k] != list(t[j])[k]:
30. r1 += 1
31. else:
32. for k in range(8):
33. if p1[k] != list(t[j])[k]:
34. r2 += 1
35. if r1 > r2:
36. return r2
37. else:
38. return r1
39. for i in range(NM[0]):
40. l[i] = input()
41. for i in range(NM[1]-7):
42. for j in range(NM[0]-7):
43. t = [0 for _ in range(8)]
44. for k in range(j, j+8):
45. t[k-j] = l[k][i:i+8]
46. if pattern(t) < r:
47. r = pattern(t)
48. print(r)
RAW Paste Data